[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 | |
mostynb | 6682b1c4 | 2016-04-19 10:17:30 | [diff] [blame] | 10 | #include <memory> |
| 11 | |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 12 | #include "base/macros.h" |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 13 | #include "base/memory/shared_memory.h" |
[email protected] | fa48a62b | 2011-10-07 21:45:32 | [diff] [blame] | 14 | #include "base/memory/weak_ptr.h" |
danakj | 1005777 | 2016-04-12 19:35:44 | [diff] [blame] | 15 | #include "gpu/command_buffer/client/gpu_control_client.h" |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 16 | #include "gpu/command_buffer/common/command_buffer_id.h" |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 17 | #include "gpu/command_buffer/common/mailbox.h" |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 18 | #include "gpu/command_buffer/common/sync_token.h" |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 19 | #include "ppapi/shared_impl/ppb_graphics_3d_shared.h" |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 20 | #include "ppapi/shared_impl/resource.h" |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 21 | |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 22 | namespace gpu { |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 23 | namespace gles2 { |
| 24 | struct ContextCreationAttribHelper; |
| 25 | } |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 26 | struct Capabilities; |
penghuang | 346a46f9 | 2016-03-31 21:37:52 | [diff] [blame] | 27 | class CommandBufferProxyImpl; |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 28 | } |
| 29 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 30 | namespace content { |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 31 | |
danakj | 1005777 | 2016-04-12 19:35:44 | [diff] [blame] | 32 | class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared, |
| 33 | public gpu::GpuControlClient { |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 34 | public: |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 35 | static PP_Resource CreateRaw( |
| 36 | PP_Instance instance, |
| 37 | PP_Resource share_context, |
| 38 | const gpu::gles2::ContextCreationAttribHelper& attrib_helper, |
| 39 | gpu::Capabilities* capabilities, |
| 40 | base::SharedMemoryHandle* shared_state_handle, |
| 41 | gpu::CommandBufferId* command_buffer_id); |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 42 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 43 | // PPB_Graphics3D_API trusted implementation. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 44 | PP_Bool SetGetBuffer(int32_t transfer_buffer_id) override; |
| 45 | scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size, |
avi | 1023d01 | 2015-12-25 02:39:14 | [diff] [blame] | 46 | int32_t* id) override; |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 47 | PP_Bool DestroyTransferBuffer(int32_t id) override; |
| 48 | PP_Bool Flush(int32_t put_offset) override; |
| 49 | gpu::CommandBuffer::State WaitForTokenInRange(int32_t start, |
| 50 | int32_t end) override; |
Antoine Labour | d346994 | 2017-05-16 21:23:42 | [diff] [blame^] | 51 | gpu::CommandBuffer::State WaitForGetOffsetInRange( |
| 52 | uint32_t set_get_buffer_count, |
| 53 | int32_t start, |
| 54 | int32_t end) override; |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 55 | void EnsureWorkVisible() override; |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 56 | void TakeFrontBuffer() override; |
| 57 | void ReturnFrontBuffer(const gpu::Mailbox& mailbox, |
| 58 | const gpu::SyncToken& sync_token, |
| 59 | bool is_lost); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 60 | |
| 61 | // Binds/unbinds the graphics of this context with the associated instance. |
| 62 | // Returns true if binding/unbinding is successful. |
| 63 | bool BindToInstance(bool bind); |
| 64 | |
[email protected] | 3e4d8de | 2012-03-06 03:59:17 | [diff] [blame] | 65 | // Returns true if the backing texture is always opaque. |
| 66 | bool IsOpaque(); |
| 67 | |
[email protected] | 29ed96a | 2012-02-04 18:12:16 | [diff] [blame] | 68 | // Notifications about the view's progress painting. See PluginInstance. |
| 69 | // These messages are used to send Flush callbacks to the plugin. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 70 | void ViewInitiatedPaint(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 71 | |
penghuang | 346a46f9 | 2016-03-31 21:37:52 | [diff] [blame] | 72 | gpu::CommandBufferProxyImpl* GetCommandBufferProxy(); |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 73 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 74 | protected: |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 75 | ~PPB_Graphics3D_Impl() override; |
[email protected] | 9a57839 | 2011-12-07 18:59:27 | [diff] [blame] | 76 | // ppapi::PPB_Graphics3D_Shared overrides. |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 77 | gpu::CommandBuffer* GetCommandBuffer() override; |
| 78 | gpu::GpuControl* GetGpuControl() override; |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 79 | int32_t DoSwapBuffers(const gpu::SyncToken& sync_token, |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 80 | const gfx::Size& size) override; |
[email protected] | e18e639 | 2011-06-22 20:57:00 | [diff] [blame] | 81 | |
| 82 | private: |
[email protected] | bbf076f1 | 2011-08-24 15:19:37 | [diff] [blame] | 83 | explicit PPB_Graphics3D_Impl(PP_Instance instance); |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 84 | |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 85 | bool InitRaw(PPB_Graphics3D_API* share_context, |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 86 | const gpu::gles2::ContextCreationAttribHelper& requested_attribs, |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 87 | gpu::Capabilities* capabilities, |
dyen | 12e4596 | 2015-09-18 00:13:51 | [diff] [blame] | 88 | base::SharedMemoryHandle* shared_state_handle, |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 89 | gpu::CommandBufferId* command_buffer_id); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 90 | |
danakj | 1005777 | 2016-04-12 19:35:44 | [diff] [blame] | 91 | // GpuControlClient implementation. |
| 92 | void OnGpuControlLostContext() final; |
danakj | 90fcc5e | 2016-04-29 04:21:00 | [diff] [blame] | 93 | void OnGpuControlLostContextMaybeReentrant() final; |
danakj | 1005777 | 2016-04-12 19:35:44 | [diff] [blame] | 94 | void OnGpuControlErrorMessage(const char* msg, int id) final; |
| 95 | |
| 96 | // Other notifications from the GPU process. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 97 | void OnSwapBuffers(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 98 | // Notifications sent to plugin. |
| 99 | void SendContextLost(); |
| 100 | |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 101 | // Reuses a mailbox if one is available, otherwise makes a new one. |
| 102 | gpu::Mailbox GenerateMailbox(); |
| 103 | |
| 104 | // A front buffer that was recently taken from the command buffer. This should |
| 105 | // be immediately consumed by DoSwapBuffers(). |
| 106 | gpu::Mailbox taken_front_buffer_; |
| 107 | |
| 108 | // Mailboxes that are no longer in use. |
| 109 | std::vector<gpu::Mailbox> mailboxes_to_reuse_; |
| 110 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 111 | // True if context is bound to instance. |
| 112 | bool bound_to_instance_; |
| 113 | // True when waiting for compositor to commit our backing texture. |
| 114 | bool commit_pending_; |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 115 | |
danakj | 1005777 | 2016-04-12 19:35:44 | [diff] [blame] | 116 | #if DCHECK_IS_ON() |
| 117 | bool lost_context_ = false; |
| 118 | #endif |
| 119 | |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 120 | bool has_alpha_; |
reveman | b288ced | 2017-01-19 00:26:10 | [diff] [blame] | 121 | const bool use_image_chromium_; |
dcheng | cedca561 | 2016-04-09 01:40:15 | [diff] [blame] | 122 | std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_; |
[email protected] | 2206942 | 2014-05-02 04:29:00 | [diff] [blame] | 123 | |
[email protected] | fa48a62b | 2011-10-07 21:45:32 | [diff] [blame] | 124 | base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_; |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 125 | |
[email protected] | 6678946 | 2011-04-07 20:07:18 | [diff] [blame] | 126 | DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl); |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 127 | }; |
| 128 | |
[email protected] | adab233 | 2013-07-25 18:04:32 | [diff] [blame] | 129 | } // namespace content |
[email protected] | 5bba4dc2 | 2010-08-17 19:45:28 | [diff] [blame] | 130 | |
[email protected] | 20790a22 | 2013-07-25 02:23:05 | [diff] [blame] | 131 | #endif // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_ |