blob: 4da2f8f15e3787a563f2ff4feb747cd794d0ffe4 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[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
Vasiliy Telezhnikov2e6fab12022-12-01 17:08:0412#include "base/containers/flat_map.h"
Alexandr Ilin15bb7032018-07-13 10:09:0613#include "base/memory/unsafe_shared_memory_region.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 {
piman360175c2014-11-07 02:30:0123struct Capabilities;
Saifuddin Hitawalab2da4f02023-10-04 15:36:4624struct GLCapabilities;
penghuang346a46f92016-03-31 21:37:5225class CommandBufferProxyImpl;
Vasiliy Telezhnikov2e6fab12022-12-01 17:08:0426class ClientSharedImageInterface;
piman360175c2014-11-07 02:30:0127}
28
[email protected]adab2332013-07-25 18:04:3229namespace content {
[email protected]5bba4dc22010-08-17 19:45:2830
danakj10057772016-04-12 19:35:4431class PPB_Graphics3D_Impl : public ppapi::PPB_Graphics3D_Shared,
32 public gpu::GpuControlClient {
[email protected]5bba4dc22010-08-17 19:45:2833 public:
Alexandr Ilin15bb7032018-07-13 10:09:0634 static PP_Resource CreateRaw(
35 PP_Instance instance,
36 PP_Resource share_context,
Vasiliy Telezhnikov2741f482023-05-29 17:23:2637 const ppapi::Graphics3DContextAttribs& context_attribs,
Alexandr Ilin15bb7032018-07-13 10:09:0638 gpu::Capabilities* capabilities,
Saifuddin Hitawalab2da4f02023-10-04 15:36:4639 gpu::GLCapabilities* gl_capabilities,
Alexandr Ilin15bb7032018-07-13 10:09:0640 const base::UnsafeSharedMemoryRegion** shared_state_region,
41 gpu::CommandBufferId* command_buffer_id);
[email protected]66789462011-04-07 20:07:1842
Peter Boström9b036532021-10-28 23:37:2843 PPB_Graphics3D_Impl(const PPB_Graphics3D_Impl&) = delete;
44 PPB_Graphics3D_Impl& operator=(const PPB_Graphics3D_Impl&) = delete;
45
[email protected]eeb4e4a2011-07-19 16:22:0646 // PPB_Graphics3D_API trusted implementation.
dcheng6d18e402014-10-21 12:32:5247 PP_Bool SetGetBuffer(int32_t transfer_buffer_id) override;
48 scoped_refptr<gpu::Buffer> CreateTransferBuffer(uint32_t size,
avi1023d012015-12-25 02:39:1449 int32_t* id) override;
dcheng6d18e402014-10-21 12:32:5250 PP_Bool DestroyTransferBuffer(int32_t id) override;
Yuzhu Shenb152e7d42024-10-08 04:39:0251 PP_Bool Flush(int32_t put_offset, uint64_t release_count) override;
dcheng6d18e402014-10-21 12:32:5252 gpu::CommandBuffer::State WaitForTokenInRange(int32_t start,
53 int32_t end) override;
Antoine Labourd3469942017-05-16 21:23:4254 gpu::CommandBuffer::State WaitForGetOffsetInRange(
55 uint32_t set_get_buffer_count,
56 int32_t start,
57 int32_t end) override;
dyen4de3d345f2016-01-12 18:30:4258 void EnsureWorkVisible() override;
erikchen438b0442016-05-11 18:33:3059 void ReturnFrontBuffer(const gpu::Mailbox& mailbox,
60 const gpu::SyncToken& sync_token,
61 bool is_lost);
Vasiliy Telezhnikov2e6fab12022-12-01 17:08:0462 void ResolveAndDetachFramebuffer() override;
63 void DoResize(gfx::Size size) override;
[email protected]eeb4e4a2011-07-19 16:22:0664
65 // Binds/unbinds the graphics of this context with the associated instance.
66 // Returns true if binding/unbinding is successful.
67 bool BindToInstance(bool bind);
68
[email protected]3e4d8de2012-03-06 03:59:1769 // Returns true if the backing texture is always opaque.
70 bool IsOpaque();
71
[email protected]29ed96a2012-02-04 18:12:1672 // Notifications about the view's progress painting. See PluginInstance.
73 // These messages are used to send Flush callbacks to the plugin.
[email protected]eeb4e4a2011-07-19 16:22:0674 void ViewInitiatedPaint();
[email protected]eeb4e4a2011-07-19 16:22:0675
penghuang346a46f92016-03-31 21:37:5276 gpu::CommandBufferProxyImpl* GetCommandBufferProxy();
[email protected]22069422014-05-02 04:29:0077
[email protected]eeb4e4a2011-07-19 16:22:0678 protected:
dcheng6d18e402014-10-21 12:32:5279 ~PPB_Graphics3D_Impl() override;
[email protected]9a578392011-12-07 18:59:2780 // ppapi::PPB_Graphics3D_Shared overrides.
dcheng6d18e402014-10-21 12:32:5281 gpu::CommandBuffer* GetCommandBuffer() override;
82 gpu::GpuControl* GetGpuControl() override;
erikchenb13637b2016-07-08 09:38:5683 int32_t DoSwapBuffers(const gpu::SyncToken& sync_token,
pimanb36392c22016-07-13 02:11:3684 const gfx::Size& size) override;
[email protected]e18e6392011-06-22 20:57:0085
86 private:
Vasiliy Telezhnikov2e6fab12022-12-01 17:08:0487 class ColorBuffer;
88
[email protected]bbf076f12011-08-24 15:19:3789 explicit PPB_Graphics3D_Impl(PP_Instance instance);
[email protected]66789462011-04-07 20:07:1890
penghuanga206fb492014-09-09 21:27:3291 bool InitRaw(PPB_Graphics3D_API* share_context,
Vasiliy Telezhnikov2741f482023-05-29 17:23:2692 const ppapi::Graphics3DContextAttribs& requested_attribs,
piman360175c2014-11-07 02:30:0193 gpu::Capabilities* capabilities,
Saifuddin Hitawalab2da4f02023-10-04 15:36:4694 gpu::GLCapabilities* gl_capabilities,
Alexandr Ilin15bb7032018-07-13 10:09:0695 const base::UnsafeSharedMemoryRegion** shared_state_region,
lukasza2573ce7d2016-02-16 19:17:2296 gpu::CommandBufferId* command_buffer_id);
[email protected]eeb4e4a2011-07-19 16:22:0697
danakj10057772016-04-12 19:35:4498 // GpuControlClient implementation.
99 void OnGpuControlLostContext() final;
danakj90fcc5e2016-04-29 04:21:00100 void OnGpuControlLostContextMaybeReentrant() final;
danakj10057772016-04-12 19:35:44101 void OnGpuControlErrorMessage(const char* msg, int id) final;
Austin Eng6ef198c52019-02-28 19:19:04102 void OnGpuControlReturnData(base::span<const uint8_t> data) final;
danakj10057772016-04-12 19:35:44103
104 // Other notifications from the GPU process.
[email protected]eeb4e4a2011-07-19 16:22:06105 void OnSwapBuffers();
[email protected]eeb4e4a2011-07-19 16:22:06106 // Notifications sent to plugin.
107 void SendContextLost();
108
Vasiliy Telezhnikov2e6fab12022-12-01 17:08:04109 // This is called by NaCL process when it wants to present next frame
110 // (SwapBuffers call from the plugin). Note that
111 // `ResolveAndDetachFramebuffer()` must be called before and `sync_token` must
112 // be submitted after that call.
113 int32_t DoPresent(const gpu::SyncToken& sync_token, const gfx::Size& size);
114
115 // Returns ColorBuffer for the next frame. It will try to re-use one of
116 // `available_color_buffers_` first and create new one if there is none.
117 std::unique_ptr<ColorBuffer> GetOrCreateColorBuffer();
118
119 // This returns ColorBuffer from the display compositor. If it's not lost and
120 // have the same size, it will be put in `available_color_buffers_` or
121 // Destroyed otherwise.
122 void RecycleColorBuffer(std::unique_ptr<ColorBuffer> buffer,
123 const gpu::SyncToken& sync_token,
124 bool is_lost);
125
126 gfx::Size swapchain_size_;
127 std::vector<std::unique_ptr<ColorBuffer>> available_color_buffers_;
128 std::unique_ptr<ColorBuffer> current_color_buffer_;
129 base::flat_map<gpu::Mailbox, std::unique_ptr<ColorBuffer>>
130 inflight_color_buffers_;
131
[email protected]eeb4e4a2011-07-19 16:22:06132 // True if context is bound to instance.
133 bool bound_to_instance_;
134 // True when waiting for compositor to commit our backing texture.
135 bool commit_pending_;
[email protected]22069422014-05-02 04:29:00136
danakj10057772016-04-12 19:35:44137#if DCHECK_IS_ON()
138 bool lost_context_ = false;
139#endif
140
Vasiliy Telezhnikov2e6fab12022-12-01 17:08:04141 bool has_alpha_ = false;
142 bool is_single_buffered_ = false;
143 int samples_count_ = 0;
144 bool preserve_ = false;
145 bool needs_depth_ = false;
146 bool needs_stencil_ = false;
147
dchengcedca5612016-04-09 01:40:15148 std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_;
Mingjing Zhang506608b2024-01-23 03:10:00149 scoped_refptr<gpu::ClientSharedImageInterface> shared_image_interface_;
[email protected]22069422014-05-02 04:29:00150
Jeremy Roman3bca4bf2019-07-11 03:41:25151 base::WeakPtrFactory<PPB_Graphics3D_Impl> weak_ptr_factory_{this};
[email protected]5bba4dc22010-08-17 19:45:28152};
153
[email protected]adab2332013-07-25 18:04:32154} // namespace content
[email protected]5bba4dc22010-08-17 19:45:28155
[email protected]20790a222013-07-25 02:23:05156#endif // CONTENT_RENDERER_PEPPER_PPB_GRAPHICS_3D_IMPL_H_