[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [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 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 5 | #ifndef WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_ |
| 6 | #define WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_ |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 7 | |
[email protected] | fa48a62b | 2011-10-07 21:45:32 | [diff] [blame^] | 8 | #include "base/memory/weak_ptr.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 9 | #include "ppapi/shared_impl/graphics_3d_impl.h" |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 10 | #include "ppapi/shared_impl/resource.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 11 | #include "webkit/plugins/ppapi/plugin_delegate.h" |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 12 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 13 | namespace webkit { |
| 14 | namespace ppapi { |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 15 | |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 16 | class PPB_Graphics3D_Impl : public ::ppapi::Resource, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 17 | public ::ppapi::Graphics3DImpl { |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 18 | public: |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 19 | virtual ~PPB_Graphics3D_Impl(); |
| 20 | |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 21 | static PP_Resource Create(PP_Instance instance, |
[email protected] | e18e639 | 2011-06-22 20:57:00 | [diff] [blame] | 22 | PP_Resource share_context, |
| 23 | const int32_t* attrib_list); |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 24 | static PP_Resource CreateRaw(PP_Instance instance, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 25 | PP_Resource share_context, |
| 26 | const int32_t* attrib_list); |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 27 | |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 28 | // Resource override. |
[email protected] | e18e639 | 2011-06-22 20:57:00 | [diff] [blame] | 29 | virtual ::ppapi::thunk::PPB_Graphics3D_API* AsPPB_Graphics3D_API() OVERRIDE; |
| 30 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 31 | // PPB_Graphics3D_API trusted implementation. |
| 32 | virtual PP_Bool InitCommandBuffer(int32_t size) OVERRIDE; |
| 33 | virtual PP_Bool GetRingBuffer(int* shm_handle, |
| 34 | uint32_t* shm_size) OVERRIDE; |
| 35 | virtual PP_Graphics3DTrustedState GetState() OVERRIDE; |
| 36 | virtual int32_t CreateTransferBuffer(uint32_t size) OVERRIDE; |
| 37 | virtual PP_Bool DestroyTransferBuffer(int32_t id) OVERRIDE; |
| 38 | virtual PP_Bool GetTransferBuffer(int32_t id, |
| 39 | int* shm_handle, |
| 40 | uint32_t* shm_size) OVERRIDE; |
| 41 | virtual PP_Bool Flush(int32_t put_offset) OVERRIDE; |
| 42 | virtual PP_Graphics3DTrustedState FlushSync(int32_t put_offset) OVERRIDE; |
| 43 | virtual PP_Graphics3DTrustedState FlushSyncFast( |
| 44 | int32_t put_offset, |
| 45 | int32_t last_known_get) OVERRIDE; |
| 46 | |
| 47 | // Binds/unbinds the graphics of this context with the associated instance. |
| 48 | // Returns true if binding/unbinding is successful. |
| 49 | bool BindToInstance(bool bind); |
| 50 | |
| 51 | // Returns the id of texture that can be used by the compositor. |
| 52 | unsigned int GetBackingTextureId(); |
| 53 | |
| 54 | // Notifications that the view has rendered the page and that it has been |
| 55 | // flushed to the screen. These messages are used to send Flush callbacks to |
| 56 | // the plugin. |
| 57 | void ViewInitiatedPaint(); |
| 58 | void ViewFlushedPaint(); |
| 59 | |
[email protected] | 1b2ec22e | 2011-08-30 00:48:33 | [diff] [blame] | 60 | PluginDelegate::PlatformContext3D* platform_context() { |
| 61 | return platform_context_.get(); |
| 62 | } |
| 63 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 64 | protected: |
| 65 | // ppapi::Graphics3DImpl overrides. |
| 66 | virtual gpu::CommandBuffer* GetCommandBuffer() OVERRIDE; |
| 67 | virtual int32 DoSwapBuffers() OVERRIDE; |
[email protected] | e18e639 | 2011-06-22 20:57:00 | [diff] [blame] | 68 | |
| 69 | private: |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 70 | explicit PPB_Graphics3D_Impl(PP_Instance instance); |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 71 | |
[email protected] | 9d8fe82 | 2011-08-16 21:02:52 | [diff] [blame] | 72 | bool Init(PP_Resource share_context, |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 73 | const int32_t* attrib_list); |
[email protected] | 9d8fe82 | 2011-08-16 21:02:52 | [diff] [blame] | 74 | bool InitRaw(PP_Resource share_context, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 75 | const int32_t* attrib_list); |
| 76 | |
| 77 | // Notifications received from the GPU process. |
| 78 | void OnSwapBuffers(); |
| 79 | void OnContextLost(); |
| 80 | // Notifications sent to plugin. |
| 81 | void SendContextLost(); |
| 82 | |
| 83 | // True if context is bound to instance. |
| 84 | bool bound_to_instance_; |
| 85 | // True when waiting for compositor to commit our backing texture. |
| 86 | bool commit_pending_; |
| 87 | // PluginDelegate's 3D Context. Responsible for providing the command buffer. |
| 88 | scoped_ptr<PluginDelegate::PlatformContext3D> platform_context_; |
[email protected] | fa48a62b | 2011-10-07 21:45:32 | [diff] [blame^] | 89 | base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_; |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 90 | |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 91 | DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl); |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 92 | }; |
| 93 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 94 | } // namespace ppapi |
| 95 | } // namespace webkit |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 96 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 97 | #endif // WEBKIT_PLUGINS_PPAPI_PPB_GRAPHICS_3D_IMPL_H_ |