1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_ 6 #define PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_ 7 8 #include "base/callback.h" 9 #include "base/containers/hash_tables.h" 10 #include "gpu/command_buffer/common/command_buffer.h" 11 #include "gpu/command_buffer/common/gpu_control.h" 12 #include "ppapi/proxy/ppapi_proxy_export.h" 13 #include "ppapi/shared_impl/host_resource.h" 14 15 namespace IPC { 16 class Message; 17 } 18 19 namespace ppapi { 20 namespace proxy { 21 22 class ProxyChannel; 23 24 class PPAPI_PROXY_EXPORT PpapiCommandBufferProxy : public gpu::CommandBuffer, 25 public gpu::GpuControl { 26 public: 27 PpapiCommandBufferProxy(const HostResource& resource, 28 ProxyChannel* channel); 29 virtual ~PpapiCommandBufferProxy(); 30 31 // gpu::CommandBuffer implementation: 32 virtual bool Initialize() OVERRIDE; 33 virtual State GetState() OVERRIDE; 34 virtual State GetLastState() OVERRIDE; 35 virtual int32 GetLastToken() OVERRIDE; 36 virtual void Flush(int32 put_offset) OVERRIDE; 37 virtual State FlushSync(int32 put_offset, int32 last_known_get) OVERRIDE; 38 virtual void SetGetBuffer(int32 transfer_buffer_id) OVERRIDE; 39 virtual void SetGetOffset(int32 get_offset) OVERRIDE; 40 virtual gpu::Buffer CreateTransferBuffer(size_t size, int32* id) OVERRIDE; 41 virtual void DestroyTransferBuffer(int32 id) OVERRIDE; 42 virtual gpu::Buffer GetTransferBuffer(int32 id) OVERRIDE; 43 virtual void SetToken(int32 token) OVERRIDE; 44 virtual void SetParseError(gpu::error::Error error) OVERRIDE; 45 virtual void SetContextLostReason(gpu::error::ContextLostReason reason) 46 OVERRIDE; 47 48 // gpu::GpuControl implementation: 49 virtual gpu::Capabilities GetCapabilities() OVERRIDE; 50 virtual gfx::GpuMemoryBuffer* CreateGpuMemoryBuffer( 51 size_t width, 52 size_t height, 53 unsigned internalformat, 54 int32* id) OVERRIDE; 55 virtual void DestroyGpuMemoryBuffer(int32 id) OVERRIDE; 56 virtual bool GenerateMailboxNames(unsigned num, 57 std::vector<gpu::Mailbox>* names) OVERRIDE; 58 virtual uint32 InsertSyncPoint() OVERRIDE; 59 virtual void SignalSyncPoint(uint32 sync_point, 60 const base::Closure& callback) OVERRIDE; 61 virtual void SignalQuery(uint32 query, 62 const base::Closure& callback) OVERRIDE; 63 virtual void SetSurfaceVisible(bool visible) OVERRIDE; 64 virtual void SendManagedMemoryStats(const gpu::ManagedMemoryStats& stats) 65 OVERRIDE; 66 virtual void Echo(const base::Closure& callback) OVERRIDE; 67 68 private: 69 bool Send(IPC::Message* msg); 70 void UpdateState(const gpu::CommandBuffer::State& state, bool success); 71 72 typedef base::hash_map<int32, gpu::Buffer> TransferBufferMap; 73 TransferBufferMap transfer_buffers_; 74 75 State last_state_; 76 77 HostResource resource_; 78 ProxyChannel* channel_; 79 80 base::Closure channel_error_callback_; 81 82 DISALLOW_COPY_AND_ASSIGN(PpapiCommandBufferProxy); 83 }; 84 85 } // namespace proxy 86 } // namespace ppapi 87 88 #endif // PPAPI_PROXY_COMMAND_BUFFER_PROXY_H_ 89