[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 1 | // Copyright (c) 2011 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/shared_memory.h" |
| 11 | #include "gpu/command_buffer/common/command_buffer.h" |
[email protected] | fae0e94 | 2011-09-07 17:10:46 | [diff] [blame] | 12 | #include "ppapi/c/pp_graphics_3d.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 13 | #include "ppapi/c/pp_instance.h" |
| 14 | #include "ppapi/cpp/completion_callback.h" |
| 15 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 16 | #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" |
| 17 | #include "ppapi/shared_impl/graphics_3d_impl.h" |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 18 | #include "ppapi/shared_impl/resource.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 19 | |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 20 | namespace ppapi { |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 21 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 22 | class HostResource; |
| 23 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 24 | namespace proxy { |
| 25 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 26 | class Graphics3D : public Resource, public Graphics3DImpl { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 27 | public: |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 28 | explicit Graphics3D(const HostResource& resource); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 29 | virtual ~Graphics3D(); |
| 30 | |
| 31 | bool Init(); |
| 32 | |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 33 | // Resource overrides. |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 34 | virtual thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() OVERRIDE { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 35 | return this; |
| 36 | } |
| 37 | |
| 38 | // Graphics3DTrusted API. These are not implemented in the proxy. |
| 39 | virtual PP_Bool InitCommandBuffer(int32_t size) OVERRIDE; |
| 40 | virtual PP_Bool GetRingBuffer(int* shm_handle, uint32_t* shm_size) OVERRIDE; |
| 41 | virtual PP_Graphics3DTrustedState GetState() OVERRIDE; |
| 42 | virtual PP_Bool Flush(int32_t put_offset) OVERRIDE; |
| 43 | virtual PP_Graphics3DTrustedState FlushSync(int32_t put_offset) OVERRIDE; |
| 44 | virtual int32_t CreateTransferBuffer(uint32_t size) OVERRIDE; |
| 45 | virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE; |
| 46 | virtual PP_Bool GetTransferBuffer(int32_t id, |
| 47 | int* shm_handle, |
| 48 | uint32_t* shm_size) OVERRIDE; |
| 49 | virtual PP_Graphics3DTrustedState FlushSyncFast( |
| 50 | int32_t put_offset, |
| 51 | int32_t last_known_get) OVERRIDE; |
| 52 | |
| 53 | protected: |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 54 | // Graphics3DImpl overrides. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 55 | virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE; |
| 56 | virtual int32 DoSwapBuffers() OVERRIDE; |
| 57 | |
| 58 | private: |
| 59 | scoped_ptr<gpu::CommandBuffer> command_buffer_; |
| 60 | |
| 61 | DISALLOW_COPY_AND_ASSIGN(Graphics3D); |
| 62 | }; |
| 63 | |
| 64 | class PPB_Graphics3D_Proxy : public InterfaceProxy { |
| 65 | public: |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 66 | PPB_Graphics3D_Proxy(Dispatcher* dispatcher); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 67 | virtual ~PPB_Graphics3D_Proxy(); |
| 68 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 69 | static PP_Resource CreateProxyResource(PP_Instance instance, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 70 | PP_Resource share_context, |
| 71 | const int32_t* attrib_list); |
| 72 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 73 | // InterfaceProxy implementation. |
| 74 | virtual bool OnMessageReceived(const IPC::Message& msg); |
| 75 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame^] | 76 | static const ApiID kApiID = API_ID_PPB_GRAPHICS_3D; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 77 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 78 | private: |
| 79 | void OnMsgCreate(PP_Instance instance, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 80 | const std::vector<int32_t>& attribs, |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 81 | HostResource* result); |
| 82 | void OnMsgInitCommandBuffer(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 83 | int32 size, |
| 84 | base::SharedMemoryHandle* ring_buffer); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 85 | void OnMsgGetState(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 86 | gpu::CommandBuffer::State* state); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 87 | void OnMsgFlush(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 88 | int32 put_offset, |
| 89 | int32 last_known_get, |
| 90 | gpu::CommandBuffer::State* state); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 91 | void OnMsgAsyncFlush(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 92 | int32 put_offset); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 93 | void OnMsgCreateTransferBuffer(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 94 | int32 size, |
| 95 | int32* id); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 96 | void OnMsgDestroyTransferBuffer(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 97 | int32 id); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 98 | void OnMsgGetTransferBuffer(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 99 | int32 id, |
| 100 | base::SharedMemoryHandle* transfer_buffer, |
| 101 | uint32* size); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 102 | void OnMsgSwapBuffers(const HostResource& context); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 103 | // Renderer->plugin message handlers. |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 104 | void OnMsgSwapBuffersACK(const HostResource& context, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 105 | int32_t pp_error); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 106 | |
| 107 | void SendSwapBuffersACKToPlugin(int32_t result, |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 108 | const HostResource& context); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 109 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 110 | pp::CompletionCallbackFactory<PPB_Graphics3D_Proxy, |
| 111 | ProxyNonThreadSafeRefCount> callback_factory_; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 112 | |
| 113 | DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Proxy); |
| 114 | }; |
| 115 | |
| 116 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 117 | } // namespace ppapi |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 118 | |
| 119 | #endif // PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_ |
| 120 | |