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_PPB_GRAPHICS_3D_PROXY_H_ 6 #define PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_ 7 8 #include <vector> 9 10 #include "base/memory/shared_memory.h" 11 #include "gpu/command_buffer/common/command_buffer.h" 12 #include "ppapi/c/pp_graphics_3d.h" 13 #include "ppapi/c/pp_instance.h" 14 #include "ppapi/proxy/interface_proxy.h" 15 #include "ppapi/proxy/proxy_completion_callback_factory.h" 16 #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" 17 #include "ppapi/shared_impl/resource.h" 18 #include "ppapi/utility/completion_callback_factory.h" 19 20 namespace ppapi { 21 22 class HostResource; 23 24 namespace proxy { 25 26 class SerializedHandle; 27 28 class Graphics3D : public PPB_Graphics3D_Shared { 29 public: 30 explicit Graphics3D(const HostResource& resource); 31 virtual ~Graphics3D(); 32 33 bool Init(gpu::gles2::GLES2Implementation* share_gles2); 34 35 // Graphics3DTrusted API. These are not implemented in the proxy. 36 virtual PP_Bool SetGetBuffer(int32_t shm_id) OVERRIDE; 37 virtual gpu::CommandBuffer::State GetState() OVERRIDE; 38 virtual PP_Bool Flush(int32_t put_offset) OVERRIDE; 39 virtual gpu::CommandBuffer::State FlushSync(int32_t put_offset) OVERRIDE; 40 virtual int32_t CreateTransferBuffer(uint32_t size) OVERRIDE; 41 virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE; 42 virtual PP_Bool GetTransferBuffer(int32_t id, 43 int* shm_handle, 44 uint32_t* shm_size) OVERRIDE; 45 virtual gpu::CommandBuffer::State FlushSyncFast( 46 int32_t put_offset, 47 int32_t last_known_get) OVERRIDE; 48 virtual uint32_t InsertSyncPoint() OVERRIDE; 49 50 private: 51 class LockingCommandBuffer; 52 53 // PPB_Graphics3D_Shared overrides. 54 virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE; 55 virtual int32 DoSwapBuffers() OVERRIDE; 56 virtual void PushAlreadyLocked() OVERRIDE; 57 virtual void PopAlreadyLocked() OVERRIDE; 58 59 int num_already_locked_calls_; 60 scoped_ptr<gpu::CommandBuffer> command_buffer_; 61 scoped_ptr<LockingCommandBuffer> locking_command_buffer_; 62 63 DISALLOW_COPY_AND_ASSIGN(Graphics3D); 64 }; 65 66 class PPB_Graphics3D_Proxy : public InterfaceProxy { 67 public: 68 PPB_Graphics3D_Proxy(Dispatcher* dispatcher); 69 virtual ~PPB_Graphics3D_Proxy(); 70 71 static PP_Resource CreateProxyResource( 72 PP_Instance instance, 73 PP_Resource share_context, 74 const int32_t* attrib_list); 75 76 // InterfaceProxy implementation. 77 virtual bool OnMessageReceived(const IPC::Message& msg); 78 79 static const ApiID kApiID = API_ID_PPB_GRAPHICS_3D; 80 81 private: 82 void OnMsgCreate(PP_Instance instance, 83 HostResource share_context, 84 const std::vector<int32_t>& attribs, 85 HostResource* result); 86 void OnMsgSetGetBuffer(const HostResource& context, 87 int32 id); 88 void OnMsgGetState(const HostResource& context, 89 gpu::CommandBuffer::State* state, 90 bool* success); 91 void OnMsgFlush(const HostResource& context, 92 int32 put_offset, 93 int32 last_known_get, 94 gpu::CommandBuffer::State* state, 95 bool* success); 96 void OnMsgAsyncFlush(const HostResource& context, 97 int32 put_offset); 98 void OnMsgCreateTransferBuffer(const HostResource& context, 99 uint32 size, 100 int32* id); 101 void OnMsgDestroyTransferBuffer(const HostResource& context, 102 int32 id); 103 void OnMsgGetTransferBuffer(const HostResource& context, 104 int32 id, 105 ppapi::proxy::SerializedHandle* transfer_buffer); 106 void OnMsgSwapBuffers(const HostResource& context); 107 void OnMsgInsertSyncPoint(const HostResource& context, uint32* sync_point); 108 // Renderer->plugin message handlers. 109 void OnMsgSwapBuffersACK(const HostResource& context, 110 int32_t pp_error); 111 112 void SendSwapBuffersACKToPlugin(int32_t result, 113 const HostResource& context); 114 115 ProxyCompletionCallbackFactory<PPB_Graphics3D_Proxy> callback_factory_; 116 117 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Proxy); 118 }; 119 120 } // namespace proxy 121 } // namespace ppapi 122 123 #endif // PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_ 124 125