blob: 8d6a17a4db3869410802917f70ad00b605f4b618 [file] [log] [blame]
[email protected]29ed96a2012-02-04 18:12:161// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5bba4dc22010-08-17 19:45:282// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]20790a222013-07-25 02:23:055#ifndef CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
6#define CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_
[email protected]5bba4dc22010-08-17 19:45:287
avi1023d012015-12-25 02:39:148#include <stdint.h>
9
mostynb6682b1c42016-04-19 10:17:3010#include <memory>
11
avi1023d012015-12-25 02:39:1412#include "base/macros.h"
penghuanga206fb492014-09-09 21:27:3213#include "base/memory/shared_memory.h"
[email protected]fa48a62b2011-10-07 21:45:3214#include "base/memory/weak_ptr.h"
danakj10057772016-04-12 19:35:4415#include "gpu/command_buffer/client/gpu_control_client.h"
lukasza2573ce7d2016-02-16 19:17:2216#include "gpu/command_buffer/common/command_buffer_id.h"
[email protected]22069422014-05-02 04:29:0017#include "gpu/command_buffer/common/mailbox.h"
dyenddfdbbb2016-01-14 22:21:3818#include "gpu/command_buffer/common/sync_token.h"
[email protected]9a578392011-12-07 18:59:2719#include "ppapi/shared_impl/ppb_graphics_3d_shared.h"
[email protected]bbf076f12011-08-24 15:19:3720#include "ppapi/shared_impl/resource.h"
[email protected]5bba4dc22010-08-17 19:45:2821
piman360175c2014-11-07 02:30:0122namespace gpu {
pimanfe4e4882016-07-09 01:18:2123namespace gles2 {
24struct ContextCreationAttribHelper;
25}
piman360175c2014-11-07 02:30:0126struct Capabilities;
penghuang346a46f92016-03-31 21:37:5227class CommandBufferProxyImpl;
piman360175c2014-11-07 02:30:0128}
29
[email protected]adab2332013-07-25 18:04:3230namespace content {
[email protected]5bba4dc22010-08-17 19:45:2831
danakj10057772016-04-12 19:35:4432class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared,
33 public gpu::GpuControlClient {
[email protected]5bba4dc22010-08-17 19:45:2834 public:
pimanfe4e4882016-07-09 01:18:2135 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]66789462011-04-07 20:07:1842
[email protected]eeb4e4a2011-07-19 16:22:0643 // PPB_Graphics3D_API trusted implementation.
dcheng6d18e402014-10-21 12:32:5244 PP_Bool SetGetBuffer(int32_t transfer_buffer_id) override;
45 scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
avi1023d012015-12-25 02:39:1446 int32_t* id) override;
dcheng6d18e402014-10-21 12:32:5247 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 Labourd3469942017-05-16 21:23:4251 gpu::CommandBuffer::State WaitForGetOffsetInRange(
52 uint32_t set_get_buffer_count,
53 int32_t start,
54 int32_t end) override;
dyen4de3d345f2016-01-12 18:30:4255 void EnsureWorkVisible() override;
erikchen438b0442016-05-11 18:33:3056 void TakeFrontBuffer() override;
57 void ReturnFrontBuffer(const gpu::Mailbox& mailbox,
58 const gpu::SyncToken& sync_token,
59 bool is_lost);
[email protected]eeb4e4a2011-07-19 16:22:0660
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]3e4d8de2012-03-06 03:59:1765 // Returns true if the backing texture is always opaque.
66 bool IsOpaque();
67
[email protected]29ed96a2012-02-04 18:12:1668 // Notifications about the view's progress painting. See PluginInstance.
69 // These messages are used to send Flush callbacks to the plugin.
[email protected]eeb4e4a2011-07-19 16:22:0670 void ViewInitiatedPaint();
[email protected]eeb4e4a2011-07-19 16:22:0671
penghuang346a46f92016-03-31 21:37:5272 gpu::CommandBufferProxyImpl* GetCommandBufferProxy();
[email protected]22069422014-05-02 04:29:0073
[email protected]eeb4e4a2011-07-19 16:22:0674 protected:
dcheng6d18e402014-10-21 12:32:5275 ~PPB_Graphics3D_Impl() override;
[email protected]9a578392011-12-07 18:59:2776 // ppapi::PPB_Graphics3D_Shared overrides.
dcheng6d18e402014-10-21 12:32:5277 gpu::CommandBuffer* GetCommandBuffer() override;
78 gpu::GpuControl* GetGpuControl() override;
erikchenb13637b2016-07-08 09:38:5679 int32_t DoSwapBuffers(const gpu::SyncToken& sync_token,
pimanb36392c22016-07-13 02:11:3680 const gfx::Size& size) override;
[email protected]e18e6392011-06-22 20:57:0081
82 private:
[email protected]bbf076f12011-08-24 15:19:3783 explicit PPB_Graphics3D_Impl(PP_Instance instance);
[email protected]66789462011-04-07 20:07:1884
penghuanga206fb492014-09-09 21:27:3285 bool InitRaw(PPB_Graphics3D_API* share_context,
pimanfe4e4882016-07-09 01:18:2186 const gpu::gles2::ContextCreationAttribHelper& requested_attribs,
piman360175c2014-11-07 02:30:0187 gpu::Capabilities* capabilities,
dyen12e45962015-09-18 00:13:5188 base::SharedMemoryHandle* shared_state_handle,
lukasza2573ce7d2016-02-16 19:17:2289 gpu::CommandBufferId* command_buffer_id);
[email protected]eeb4e4a2011-07-19 16:22:0690
danakj10057772016-04-12 19:35:4491 // GpuControlClient implementation.
92 void OnGpuControlLostContext() final;
danakj90fcc5e2016-04-29 04:21:0093 void OnGpuControlLostContextMaybeReentrant() final;
danakj10057772016-04-12 19:35:4494 void OnGpuControlErrorMessage(const char* msg, int id) final;
95
96 // Other notifications from the GPU process.
[email protected]eeb4e4a2011-07-19 16:22:0697 void OnSwapBuffers();
[email protected]eeb4e4a2011-07-19 16:22:0698 // Notifications sent to plugin.
99 void SendContextLost();
100
erikchen438b0442016-05-11 18:33:30101 // 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]eeb4e4a2011-07-19 16:22:06111 // 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]22069422014-05-02 04:29:00115
danakj10057772016-04-12 19:35:44116#if DCHECK_IS_ON()
117 bool lost_context_ = false;
118#endif
119
[email protected]22069422014-05-02 04:29:00120 bool has_alpha_;
revemanb288ced2017-01-19 00:26:10121 const bool use_image_chromium_;
dchengcedca5612016-04-09 01:40:15122 std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_;
[email protected]22069422014-05-02 04:29:00123
[email protected]fa48a62b2011-10-07 21:45:32124 base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_;
[email protected]66789462011-04-07 20:07:18125
[email protected]66789462011-04-07 20:07:18126 DISALLOW_COPY_AND_ASSIGN(PPB_Graphics3D_Impl);
[email protected]5bba4dc22010-08-17 19:45:28127};
128
[email protected]adab2332013-07-25 18:04:32129} // namespace content
[email protected]5bba4dc22010-08-17 19:45:28130
[email protected]20790a222013-07-25 02:23:05131#endif // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_