[email protected] | aaa11b3 | 2012-03-08 12:30:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 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" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 14 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | 47a961c | 2012-07-13 19:18:52 | [diff] [blame] | 15 | #include "ppapi/proxy/proxy_completion_callback_factory.h" |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 16 | #include "ppapi/proxy/serialized_structs.h" |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 17 | #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 18 | #include "ppapi/shared_impl/resource.h" |
[email protected] | ae5ff9ae | 2012-01-06 22:50:33 | [diff] [blame] | 19 | #include "ppapi/utility/completion_callback_factory.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 20 | |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 21 | namespace ppapi { |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 22 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 23 | class HostResource; |
| 24 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 25 | namespace proxy { |
| 26 | |
[email protected] | 614888b | 2012-01-05 06:18:12 | [diff] [blame] | 27 | class Graphics3D : public PPB_Graphics3D_Shared { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 28 | public: |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 29 | explicit Graphics3D(const HostResource& resource); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 30 | virtual ~Graphics3D(); |
| 31 | |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 32 | bool Init(gpu::gles2::GLES2Implementation* share_gles2); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 33 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 34 | // Graphics3DTrusted API. These are not implemented in the proxy. |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 35 | virtual PP_Bool InitCommandBuffer() OVERRIDE; |
| 36 | virtual PP_Bool SetGetBuffer(int32_t shm_id) OVERRIDE; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 37 | virtual PP_Graphics3DTrustedState GetState() OVERRIDE; |
| 38 | virtual PP_Bool Flush(int32_t put_offset) OVERRIDE; |
| 39 | virtual PP_Graphics3DTrustedState 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 PP_Graphics3DTrustedState FlushSyncFast( |
| 46 | int32_t put_offset, |
| 47 | int32_t last_known_get) OVERRIDE; |
| 48 | |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame^] | 49 | private: |
| 50 | class LockingCommandBuffer; |
| 51 | |
| 52 | // PPB_Graphics3D_Shared overrides. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 53 | virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE; |
| 54 | virtual int32 DoSwapBuffers() OVERRIDE; |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame^] | 55 | virtual void PushAlreadyLocked() OVERRIDE; |
| 56 | virtual void PopAlreadyLocked() OVERRIDE; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 57 | |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame^] | 58 | int num_already_locked_calls_; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 59 | scoped_ptr<gpu::CommandBuffer> command_buffer_; |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame^] | 60 | scoped_ptr<LockingCommandBuffer> locking_command_buffer_; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 61 | |
| 62 | DISALLOW_COPY_AND_ASSIGN(Graphics3D); |
| 63 | }; |
| 64 | |
| 65 | class PPB_Graphics3D_Proxy : public InterfaceProxy { |
| 66 | public: |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 67 | PPB_Graphics3D_Proxy(Dispatcher* dispatcher); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 68 | virtual ~PPB_Graphics3D_Proxy(); |
| 69 | |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 70 | static PP_Resource CreateProxyResource( |
| 71 | PP_Instance instance, |
| 72 | PP_Resource share_context, |
| 73 | const int32_t* attrib_list); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 74 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 75 | // InterfaceProxy implementation. |
| 76 | virtual bool OnMessageReceived(const IPC::Message& msg); |
| 77 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 78 | static const ApiID kApiID = API_ID_PPB_GRAPHICS_3D; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 79 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 80 | private: |
| 81 | void OnMsgCreate(PP_Instance instance, |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 82 | HostResource share_context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 83 | const std::vector<int32_t>& attribs, |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 84 | HostResource* result); |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 85 | void OnMsgInitCommandBuffer(const HostResource& context); |
| 86 | void OnMsgSetGetBuffer(const HostResource& context, |
| 87 | int32 id); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 88 | void OnMsgGetState(const HostResource& context, |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 89 | gpu::CommandBuffer::State* state, |
| 90 | bool* success); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 91 | void OnMsgFlush(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 92 | int32 put_offset, |
| 93 | int32 last_known_get, |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 94 | gpu::CommandBuffer::State* state, |
| 95 | bool* success); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 96 | void OnMsgAsyncFlush(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 97 | int32 put_offset); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 98 | void OnMsgCreateTransferBuffer(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 99 | int32 size, |
| 100 | int32* id); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 101 | void OnMsgDestroyTransferBuffer(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 102 | int32 id); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 103 | void OnMsgGetTransferBuffer(const HostResource& context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 104 | int32 id, |
[email protected] | 246fc49 | 2012-08-27 20:28:18 | [diff] [blame] | 105 | ppapi::proxy::SerializedHandle* transfer_buffer); |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 106 | void OnMsgSwapBuffers(const HostResource& context); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 107 | // Renderer->plugin message handlers. |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 108 | void OnMsgSwapBuffersACK(const HostResource& context, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 109 | int32_t pp_error); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 110 | |
| 111 | void SendSwapBuffersACKToPlugin(int32_t result, |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 112 | const HostResource& context); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 113 | |
[email protected] | 47a961c | 2012-07-13 19:18:52 | [diff] [blame] | 114 | ProxyCompletionCallbackFactory<PPB_Graphics3D_Proxy> callback_factory_; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 115 | |
| 116 | DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Proxy); |
| 117 | }; |
| 118 | |
| 119 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 120 | } // namespace ppapi |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 121 | |
| 122 | #endif // PPAPI_PROXY_PPB_GRAPHICS_3D_PROXY_H_ |
| 123 | |