[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 5 | #ifndef CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_ |
| 6 | #define CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_ |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 7 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
| 10 | #include "base/macros.h" |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 11 | #include "base/memory/shared_memory.h" |
[email protected] | fa48a62b | 2011-10-07 21:45:32 | [diff] [blame] | 12 | #include "base/memory/weak_ptr.h" |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 13 | #include "gpu/command_buffer/common/command_buffer_id.h" |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 14 | #include "gpu/command_buffer/common/mailbox.h" |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 15 | #include "gpu/command_buffer/common/sync_token.h" |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 16 | #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 17 | #include "ppapi/shared_impl/resource.h" |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 18 | |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 19 | namespace gpu { |
| 20 | struct Capabilities; |
| 21 | } |
| 22 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 23 | namespace content { |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 24 | class CommandBufferProxyImpl; |
| 25 | class GpuChannelHost; |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 26 | |
[email protected] | 49323b3 | 2013-08-09 16:05:06 | [diff] [blame] | 27 | class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared { |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 28 | public: |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 29 | static PP_Resource Create(PP_Instance instance, |
[email protected] | e18e639 | 2011-06-22 20:57:00 | [diff] [blame] | 30 | PP_Resource share_context, |
| 31 | const int32_t* attrib_list); |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 32 | static PP_Resource CreateRaw(PP_Instance instance, |
| 33 | PP_Resource share_context, |
| 34 | const int32_t* attrib_list, |
| 35 | gpu::Capabilities* capabilities, |
| 36 | base::SharedMemoryHandle* shared_state_handle, |
| 37 | gpu::CommandBufferId* command_buffer_id); |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 38 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 39 | // PPB_Graphics3D_API trusted implementation. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 40 | PP_Bool SetGetBuffer(int32_t transfer_buffer_id) override; |
| 41 | scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size, |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 42 | int32_t* id) override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 43 | PP_Bool DestroyTransferBuffer(int32_t id) override; |
| 44 | PP_Bool Flush(int32_t put_offset) override; |
| 45 | gpu::CommandBuffer::State WaitForTokenInRange(int32_t start, |
| 46 | int32_t end) override; |
| 47 | gpu::CommandBuffer::State WaitForGetOffsetInRange(int32_t start, |
| 48 | int32_t end) override; |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 49 | void EnsureWorkVisible() override; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 50 | |
| 51 | // Binds/unbinds the graphics of this context with the associated instance. |
| 52 | // Returns true if binding/unbinding is successful. |
| 53 | bool BindToInstance(bool bind); |
| 54 | |
[email protected] | 3e4d8de | 2012-03-06 03:59:17 | [diff] [blame] | 55 | // Returns true if the backing texture is always opaque. |
| 56 | bool IsOpaque(); |
| 57 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 58 | // Notifications about the view's progress painting. See PluginInstance. |
| 59 | // These messages are used to send Flush callbacks to the plugin. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 60 | void ViewInitiatedPaint(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 61 | |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 62 | void GetBackingMailbox(gpu::Mailbox* mailbox, gpu::SyncToken* sync_token) { |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 63 | *mailbox = mailbox_; |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 64 | *sync_token = sync_token_; |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 65 | } |
| 66 | |
sunnyps | 0e85ce58 | 2015-08-04 05:01:13 | [diff] [blame] | 67 | CommandBufferProxyImpl* GetCommandBufferProxy(); |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 68 | |
Daniel Cheng | 58241662 | 2014-08-26 02:03:58 | [diff] [blame] | 69 | GpuChannelHost* channel() { return channel_.get(); } |
[email protected] | 1b2ec22e | 2011-08-30 00:48:33 | [diff] [blame] | 70 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 71 | protected: |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 72 | ~PPB_Graphics3D_Impl() override; |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 73 | // ppapi::PPB_Graphics3D_Shared overrides. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 74 | gpu::CommandBuffer* GetCommandBuffer() override; |
| 75 | gpu::GpuControl* GetGpuControl() override; |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 76 | int32_t DoSwapBuffers(const gpu::SyncToken& sync_token) override; |
[email protected] | e18e639 | 2011-06-22 20:57:00 | [diff] [blame] | 77 | |
| 78 | private: |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 79 | explicit PPB_Graphics3D_Impl(PP_Instance instance); |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 80 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 81 | bool Init(PPB_Graphics3D_API* share_context, const int32_t* attrib_list); |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 82 | bool InitRaw(PPB_Graphics3D_API* share_context, |
| 83 | const int32_t* attrib_list, |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 84 | gpu::Capabilities* capabilities, |
dyen | 12e4596 | 2015-09-18 00:13:51 | [diff] [blame] | 85 | base::SharedMemoryHandle* shared_state_handle, |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 86 | gpu::CommandBufferId* command_buffer_id); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 87 | |
| 88 | // Notifications received from the GPU process. |
| 89 | void OnSwapBuffers(); |
| 90 | void OnContextLost(); |
[email protected] | 4d2a5ef | 2012-03-16 23:15:39 | [diff] [blame] | 91 | void OnConsoleMessage(const std::string& msg, int id); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 92 | // Notifications sent to plugin. |
| 93 | void SendContextLost(); |
| 94 | |
| 95 | // True if context is bound to instance. |
| 96 | bool bound_to_instance_; |
| 97 | // True when waiting for compositor to commit our backing texture. |
| 98 | bool commit_pending_; |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 99 | |
| 100 | gpu::Mailbox mailbox_; |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 101 | gpu::SyncToken sync_token_; |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 102 | bool has_alpha_; |
| 103 | scoped_refptr<GpuChannelHost> channel_; |
sunnyps | 0e85ce58 | 2015-08-04 05:01:13 | [diff] [blame] | 104 | scoped_ptr<CommandBufferProxyImpl> command_buffer_; |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 105 | |
[email protected] | fa48a62b | 2011-10-07 21:45:32 | [diff] [blame] | 106 | base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_; |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 107 | |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 108 | DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl); |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 109 | }; |
| 110 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 111 | } // namespace content |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 112 | |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 113 | #endif // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_ |