[email protected] | aaa11b3 | 2012-03-08 12:30:13 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [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 | |
| 5 | #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 6 | |
Peter Boström | fb60ea0 | 2021-04-05 21:06:12 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
brettw | 669d47b1 | 2015-02-13 21:17:38 | [diff] [blame] | 9 | #include "base/numerics/safe_conversions.h" |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 11 | #include "gpu/command_buffer/client/gles2_implementation.h" |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 12 | #include "gpu/command_buffer/common/command_buffer.h" |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 13 | #include "gpu/command_buffer/common/sync_token.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 14 | #include "ppapi/c/pp_errors.h" |
| 15 | #include "ppapi/proxy/enter_proxy.h" |
| 16 | #include "ppapi/proxy/plugin_dispatcher.h" |
[email protected] | aaa11b3 | 2012-03-08 12:30:13 | [diff] [blame] | 17 | #include "ppapi/proxy/ppapi_command_buffer_proxy.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 18 | #include "ppapi/proxy/ppapi_messages.h" |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 19 | #include "ppapi/shared_impl/ppapi_globals.h" |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 20 | #include "ppapi/thunk/enter.h" |
| 21 | #include "ppapi/thunk/resource_creation_api.h" |
| 22 | #include "ppapi/thunk/thunk.h" |
| 23 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 24 | using ppapi::thunk::EnterResourceNoLock; |
| 25 | using ppapi::thunk::PPB_Graphics3D_API; |
| 26 | using ppapi::thunk::ResourceCreationAPI; |
| 27 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 28 | namespace ppapi { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 29 | namespace proxy { |
| 30 | |
| 31 | namespace { |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 32 | |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 33 | #if !BUILDFLAG(IS_NACL) |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 34 | base::UnsafeSharedMemoryRegion TransportSHMHandle( |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 35 | Dispatcher* dispatcher, |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 36 | const base::UnsafeSharedMemoryRegion& region) { |
| 37 | return dispatcher->ShareUnsafeSharedMemoryRegionWithRemote(region); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 38 | } |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 39 | #endif // !BUILDFLAG(IS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 40 | |
[email protected] | 914f526 | 2013-06-01 00:17:22 | [diff] [blame] | 41 | gpu::CommandBuffer::State GetErrorState() { |
| 42 | gpu::CommandBuffer::State error_state; |
| 43 | error_state.error = gpu::error::kGenericError; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 44 | return error_state; |
| 45 | } |
| 46 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 47 | } // namespace |
| 48 | |
Daniele Castagna | 141a88a | 2018-07-30 19:41:23 | [diff] [blame] | 49 | Graphics3D::Graphics3D(const HostResource& resource, |
| 50 | const gfx::Size& size, |
| 51 | const bool single_buffer) |
| 52 | : PPB_Graphics3D_Shared(resource, size), single_buffer(single_buffer) {} |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 53 | |
| 54 | Graphics3D::~Graphics3D() { |
[email protected] | edccb56 | 2013-10-02 00:01:20 | [diff] [blame] | 55 | DestroyGLES2Impl(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 56 | } |
| 57 | |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 58 | bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2, |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 59 | const gpu::Capabilities& capabilities, |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 60 | SerializedHandle shared_state, |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 61 | gpu::CommandBufferId command_buffer_id) { |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 62 | PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 63 | if (!dispatcher) |
| 64 | return false; |
| 65 | |
Sunny Sachanandani | fd979a8 | 2018-03-27 00:26:03 | [diff] [blame] | 66 | InstanceData* data = dispatcher->GetInstanceData(host_resource().instance()); |
| 67 | DCHECK(data); |
| 68 | |
Peter Boström | fb60ea0 | 2021-04-05 21:06:12 | [diff] [blame] | 69 | command_buffer_ = std::make_unique<PpapiCommandBufferProxy>( |
Sunny Sachanandani | fd979a8 | 2018-03-27 00:26:03 | [diff] [blame] | 70 | host_resource(), &data->flush_info, dispatcher, capabilities, |
Peter Boström | fb60ea0 | 2021-04-05 21:06:12 | [diff] [blame] | 71 | std::move(shared_state), command_buffer_id); |
[email protected] | 84b44c55 | 2012-10-15 20:58:17 | [diff] [blame] | 72 | |
Eric Karl | 2fc4409b9 | 2017-08-18 18:48:39 | [diff] [blame] | 73 | return CreateGLES2Impl(share_gles2); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 74 | } |
| 75 | |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 76 | PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 77 | return PP_FALSE; |
| 78 | } |
| 79 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 80 | PP_Bool Graphics3D::Flush(int32_t put_offset) { |
| 81 | return PP_FALSE; |
| 82 | } |
| 83 | |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 84 | scoped_refptr<gpu::Buffer> Graphics3D::CreateTransferBuffer( |
| 85 | uint32_t size, |
| 86 | int32_t* id) { |
| 87 | *id = -1; |
kylechar | 8b8ecebb | 2019-10-29 20:08:10 | [diff] [blame] | 88 | return nullptr; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) { |
| 92 | return PP_FALSE; |
| 93 | } |
| 94 | |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 95 | gpu::CommandBuffer::State Graphics3D::WaitForTokenInRange(int32_t start, |
| 96 | int32_t end) { |
| 97 | return GetErrorState(); |
| 98 | } |
| 99 | |
Antoine Labour | d346994 | 2017-05-16 21:23:42 | [diff] [blame] | 100 | gpu::CommandBuffer::State Graphics3D::WaitForGetOffsetInRange( |
| 101 | uint32_t set_get_buffer_count, |
| 102 | int32_t start, |
| 103 | int32_t end) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 104 | return GetErrorState(); |
| 105 | } |
| 106 | |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 107 | void Graphics3D::EnsureWorkVisible() { |
| 108 | NOTREACHED(); |
| 109 | } |
| 110 | |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 111 | void Graphics3D::TakeFrontBuffer() { |
| 112 | NOTREACHED(); |
| 113 | } |
| 114 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 115 | gpu::CommandBuffer* Graphics3D::GetCommandBuffer() { |
[email protected] | 4e46a73 | 2013-09-30 18:35:59 | [diff] [blame] | 116 | return command_buffer_.get(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | 744e079 | 2013-09-27 01:18:35 | [diff] [blame] | 119 | gpu::GpuControl* Graphics3D::GetGpuControl() { |
| 120 | return command_buffer_.get(); |
| 121 | } |
| 122 | |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 123 | int32_t Graphics3D::DoSwapBuffers(const gpu::SyncToken& sync_token, |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 124 | const gfx::Size& size) { |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 125 | // A valid sync token would indicate a swap buffer already happened somehow. |
| 126 | DCHECK(!sync_token.HasData()); |
| 127 | |
| 128 | gpu::gles2::GLES2Implementation* gl = gles2_impl(); |
Eric Karl | b6b2c63 | 2018-05-07 22:45:04 | [diff] [blame] | 129 | gl->SwapBuffers(swap_id_++); |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 130 | |
Daniele Castagna | 141a88a | 2018-07-30 19:41:23 | [diff] [blame] | 131 | if (!single_buffer || swap_id_ == 1) { |
| 132 | PluginDispatcher::GetForResource(this)->Send( |
| 133 | new PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer(API_ID_PPB_GRAPHICS_3D, |
| 134 | host_resource())); |
| 135 | } |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 136 | |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 137 | gpu::SyncToken new_sync_token; |
Sunny Sachanandani | c94b8de | 2017-12-16 03:30:30 | [diff] [blame] | 138 | gl->GenSyncTokenCHROMIUM(new_sync_token.GetData()); |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 139 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 140 | IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers( |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 141 | API_ID_PPB_GRAPHICS_3D, host_resource(), new_sync_token, size); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 142 | msg->set_unblock(true); |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 143 | PluginDispatcher::GetForResource(this)->Send(msg); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 144 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 145 | return PP_OK_COMPLETIONPENDING; |
| 146 | } |
| 147 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 148 | PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher) |
| 149 | : InterfaceProxy(dispatcher), |
[email protected] | a2f53dc | 2013-04-30 01:06:35 | [diff] [blame] | 150 | callback_factory_(this) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() { |
| 154 | } |
| 155 | |
| 156 | // static |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 157 | PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource( |
| 158 | PP_Instance instance, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 159 | PP_Resource share_context, |
| 160 | const int32_t* attrib_list) { |
| 161 | PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 162 | if (!dispatcher) |
| 163 | return PP_ERROR_BADARGUMENT; |
| 164 | |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 165 | HostResource share_host; |
kylechar | 8b8ecebb | 2019-10-29 20:08:10 | [diff] [blame] | 166 | gpu::gles2::GLES2Implementation* share_gles2 = nullptr; |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 167 | if (share_context != 0) { |
| 168 | EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 169 | if (enter.failed()) |
| 170 | return PP_ERROR_BADARGUMENT; |
| 171 | |
| 172 | PPB_Graphics3D_Shared* share_graphics = |
| 173 | static_cast<PPB_Graphics3D_Shared*>(enter.object()); |
| 174 | share_host = share_graphics->host_resource(); |
| 175 | share_gles2 = share_graphics->gles2_impl(); |
| 176 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 177 | |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 178 | gpu::ContextCreationAttribs attrib_helper; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 179 | if (attrib_list) { |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 180 | for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE; |
[email protected] | 0e50fc4d | 2011-08-01 15:33:51 | [diff] [blame] | 181 | attr += 2) { |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 182 | int32_t key = attr[0]; |
| 183 | int32_t value = attr[1]; |
| 184 | switch (key) { |
| 185 | case PP_GRAPHICS3DATTRIB_ALPHA_SIZE: |
| 186 | attrib_helper.alpha_size = value; |
| 187 | break; |
| 188 | case PP_GRAPHICS3DATTRIB_BLUE_SIZE: |
| 189 | attrib_helper.blue_size = value; |
| 190 | break; |
| 191 | case PP_GRAPHICS3DATTRIB_GREEN_SIZE: |
| 192 | attrib_helper.green_size = value; |
| 193 | break; |
| 194 | case PP_GRAPHICS3DATTRIB_RED_SIZE: |
| 195 | attrib_helper.red_size = value; |
| 196 | break; |
| 197 | case PP_GRAPHICS3DATTRIB_DEPTH_SIZE: |
| 198 | attrib_helper.depth_size = value; |
| 199 | break; |
| 200 | case PP_GRAPHICS3DATTRIB_STENCIL_SIZE: |
| 201 | attrib_helper.stencil_size = value; |
| 202 | break; |
| 203 | case PP_GRAPHICS3DATTRIB_SAMPLES: |
| 204 | attrib_helper.samples = value; |
| 205 | break; |
| 206 | case PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS: |
| 207 | attrib_helper.sample_buffers = value; |
| 208 | break; |
| 209 | case PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR: |
| 210 | attrib_helper.buffer_preserved = |
| 211 | value == PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED; |
| 212 | break; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 213 | case PP_GRAPHICS3DATTRIB_WIDTH: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 214 | attrib_helper.offscreen_framebuffer_size.set_width(value); |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 215 | break; |
| 216 | case PP_GRAPHICS3DATTRIB_HEIGHT: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 217 | attrib_helper.offscreen_framebuffer_size.set_height(value); |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 218 | break; |
| 219 | case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE: |
| 220 | attrib_helper.gpu_preference = |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 221 | (value == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER) |
Zhenyao Mo | dd6173b0 | 2019-05-23 23:04:27 | [diff] [blame] | 222 | ? gl::GpuPreference::kLowPower |
| 223 | : gl::GpuPreference::kHighPerformance; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 224 | break; |
David Reveman | ca46de73 | 2017-06-09 19:48:19 | [diff] [blame] | 225 | case PP_GRAPHICS3DATTRIB_SINGLE_BUFFER: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 226 | attrib_helper.single_buffer = !!value; |
David Reveman | ca46de73 | 2017-06-09 19:48:19 | [diff] [blame] | 227 | break; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 228 | default: |
Antoine Labour | 492d57a1 | 2017-12-21 02:42:11 | [diff] [blame] | 229 | DLOG(ERROR) << "Invalid context creation attribute: " << attr[0]; |
| 230 | return 0; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 231 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 232 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | HostResource result; |
piman | 360175c | 2014-11-07 02:30:01 | [diff] [blame] | 236 | gpu::Capabilities capabilities; |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 237 | ppapi::proxy::SerializedHandle shared_state; |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 238 | gpu::CommandBufferId command_buffer_id; |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 239 | dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create( |
| 240 | API_ID_PPB_GRAPHICS_3D, instance, share_host, attrib_helper, &result, |
| 241 | &capabilities, &shared_state, &command_buffer_id)); |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 242 | |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 243 | if (result.is_null()) |
| 244 | return 0; |
| 245 | |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 246 | scoped_refptr<Graphics3D> graphics_3d( |
Daniele Castagna | 141a88a | 2018-07-30 19:41:23 | [diff] [blame] | 247 | new Graphics3D(result, attrib_helper.offscreen_framebuffer_size, |
| 248 | attrib_helper.single_buffer)); |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 249 | if (!graphics_3d->Init(share_gles2, capabilities, std::move(shared_state), |
dyen | 12e4596 | 2015-09-18 00:13:51 | [diff] [blame] | 250 | command_buffer_id)) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 251 | return 0; |
dyen | 12e4596 | 2015-09-18 00:13:51 | [diff] [blame] | 252 | } |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 253 | return graphics_3d->GetReference(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 257 | bool handled = true; |
| 258 | IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg) |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 259 | #if !BUILDFLAG(IS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 260 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create, |
| 261 | OnMsgCreate) |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 262 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer, |
| 263 | OnMsgSetGetBuffer) |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 264 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange, |
| 265 | OnMsgWaitForTokenInRange) |
| 266 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange, |
| 267 | OnMsgWaitForGetOffsetInRange) |
| 268 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush, OnMsgAsyncFlush) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 269 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer, |
| 270 | OnMsgCreateTransferBuffer) |
| 271 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer, |
| 272 | OnMsgDestroyTransferBuffer) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 273 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers, |
| 274 | OnMsgSwapBuffers) |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 275 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer, |
| 276 | OnMsgTakeFrontBuffer) |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 277 | IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_EnsureWorkVisible, |
| 278 | OnMsgEnsureWorkVisible) |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 279 | #endif // !BUILDFLAG(IS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 280 | |
| 281 | IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK, |
| 282 | OnMsgSwapBuffersACK) |
| 283 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 284 | |
| 285 | IPC_END_MESSAGE_MAP() |
| 286 | // FIXME(brettw) handle bad messages! |
| 287 | return handled; |
| 288 | } |
| 289 | |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 290 | #if !BUILDFLAG(IS_NACL) |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 291 | void PPB_Graphics3D_Proxy::OnMsgCreate( |
| 292 | PP_Instance instance, |
| 293 | HostResource share_context, |
Antoine Labour | feab239 | 2017-12-21 20:28:39 | [diff] [blame] | 294 | const gpu::ContextCreationAttribs& attrib_helper, |
lukasza | 2573ce7d | 2016-02-16 19:17:22 | [diff] [blame] | 295 | HostResource* result, |
| 296 | gpu::Capabilities* capabilities, |
| 297 | SerializedHandle* shared_state, |
| 298 | gpu::CommandBufferId* command_buffer_id) { |
Matthew Cary | fc3757f | 2019-07-30 21:32:46 | [diff] [blame] | 299 | shared_state->set_null_shmem_region(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 300 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 301 | thunk::EnterResourceCreation enter(instance); |
[email protected] | 9ed07f8 | 2012-05-29 21:54:55 | [diff] [blame] | 302 | |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 303 | if (!enter.succeeded()) |
| 304 | return; |
| 305 | |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 306 | const base::UnsafeSharedMemoryRegion* region = nullptr; |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 307 | result->SetHostResource( |
piman | fe4e488 | 2016-07-09 01:18:21 | [diff] [blame] | 308 | instance, enter.functions()->CreateGraphics3DRaw( |
| 309 | instance, share_context.host_resource(), attrib_helper, |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 310 | capabilities, ®ion, command_buffer_id)); |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 311 | if (!result->is_null()) { |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 312 | shared_state->set_shmem_region( |
| 313 | base::UnsafeSharedMemoryRegion::TakeHandleForSerialization( |
| 314 | TransportSHMHandle(dispatcher(), *region))); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 318 | void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(const HostResource& context, |
| 319 | int32_t transfer_buffer_id) { |
[email protected] | 503b3a2 | 2011-12-12 23:29:40 | [diff] [blame] | 320 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 321 | if (enter.succeeded()) |
| 322 | enter.object()->SetGetBuffer(transfer_buffer_id); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 325 | void PPB_Graphics3D_Proxy::OnMsgWaitForTokenInRange( |
| 326 | const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 327 | int32_t start, |
| 328 | int32_t end, |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 329 | gpu::CommandBuffer::State* state, |
| 330 | bool* success) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 331 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 332 | if (enter.failed()) { |
| 333 | *success = false; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 334 | return; |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 335 | } |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 336 | *state = enter.object()->WaitForTokenInRange(start, end); |
| 337 | *success = true; |
| 338 | } |
| 339 | |
| 340 | void PPB_Graphics3D_Proxy::OnMsgWaitForGetOffsetInRange( |
| 341 | const HostResource& context, |
Antoine Labour | d346994 | 2017-05-16 21:23:42 | [diff] [blame] | 342 | uint32_t set_get_buffer_count, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 343 | int32_t start, |
| 344 | int32_t end, |
[email protected] | 7fe4198b | 2014-03-18 21:52:36 | [diff] [blame] | 345 | gpu::CommandBuffer::State* state, |
| 346 | bool* success) { |
| 347 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 348 | if (enter.failed()) { |
| 349 | *success = false; |
| 350 | return; |
| 351 | } |
Antoine Labour | d346994 | 2017-05-16 21:23:42 | [diff] [blame] | 352 | *state = |
| 353 | enter.object()->WaitForGetOffsetInRange(set_get_buffer_count, start, end); |
[email protected] | 571b35e8 | 2012-05-19 00:04:35 | [diff] [blame] | 354 | *success = true; |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 358 | int32_t put_offset) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 359 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 360 | if (enter.succeeded()) |
| 361 | enter.object()->Flush(put_offset); |
| 362 | } |
| 363 | |
| 364 | void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer( |
| 365 | const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 366 | uint32_t size, |
| 367 | int32_t* id, |
penghuang | a206fb49 | 2014-09-09 21:27:32 | [diff] [blame] | 368 | SerializedHandle* transfer_buffer) { |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 369 | transfer_buffer->set_null_shmem_region(); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 370 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 371 | if (enter.succeeded()) { |
| 372 | scoped_refptr<gpu::Buffer> buffer = |
| 373 | enter.object()->CreateTransferBuffer(size, id); |
Daniel Cheng | 6d3ae97 | 2014-08-26 00:27:38 | [diff] [blame] | 374 | if (!buffer.get()) |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 375 | return; |
[email protected] | 8a978df | 2014-04-02 23:54:09 | [diff] [blame] | 376 | gpu::SharedMemoryBufferBacking* backing = |
| 377 | static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing()); |
Alexandr Ilin | 15bb703 | 2018-07-13 10:09:06 | [diff] [blame] | 378 | DCHECK(backing && backing->shared_memory_region().IsValid()); |
| 379 | transfer_buffer->set_shmem_region( |
| 380 | base::UnsafeSharedMemoryRegion::TakeHandleForSerialization( |
| 381 | TransportSHMHandle(dispatcher(), backing->shared_memory_region()))); |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 382 | } else { |
[email protected] | 67c8078 | 2012-12-21 01:16:52 | [diff] [blame] | 383 | *id = -1; |
[email protected] | 046fa1ac | 2014-04-01 09:06:43 | [diff] [blame] | 384 | } |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer( |
| 388 | const HostResource& context, |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 389 | int32_t id) { |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 390 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 391 | if (enter.succeeded()) |
| 392 | enter.object()->DestroyTransferBuffer(id); |
| 393 | } |
| 394 | |
dyen | ddfdbbb | 2016-01-14 22:21:38 | [diff] [blame] | 395 | void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context, |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 396 | const gpu::SyncToken& sync_token, |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 397 | const gfx::Size& size) { |
[email protected] | 79d23c7 | 2011-08-08 19:40:40 | [diff] [blame] | 398 | EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter( |
| 399 | context, callback_factory_, |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 400 | &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 401 | if (enter.succeeded()) |
erikchen | b13637b | 2016-07-08 09:38:56 | [diff] [blame] | 402 | enter.SetResult(enter.object()->SwapBuffersWithSyncToken( |
piman | b36392c2 | 2016-07-13 02:11:36 | [diff] [blame] | 403 | enter.callback(), sync_token, size)); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 404 | } |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 405 | |
erikchen | 438b044 | 2016-05-11 18:33:30 | [diff] [blame] | 406 | void PPB_Graphics3D_Proxy::OnMsgTakeFrontBuffer(const HostResource& context) { |
| 407 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 408 | if (enter.succeeded()) |
| 409 | enter.object()->TakeFrontBuffer(); |
| 410 | } |
| 411 | |
dyen | 4de3d345f | 2016-01-12 18:30:42 | [diff] [blame] | 412 | void PPB_Graphics3D_Proxy::OnMsgEnsureWorkVisible(const HostResource& context) { |
| 413 | EnterHostFromHostResource<PPB_Graphics3D_API> enter(context); |
| 414 | if (enter.succeeded()) |
| 415 | enter.object()->EnsureWorkVisible(); |
| 416 | } |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 417 | #endif // !BUILDFLAG(IS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 418 | |
| 419 | void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource, |
| 420 | int32_t pp_error) { |
| 421 | EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource); |
| 422 | if (enter.succeeded()) |
| 423 | static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error); |
| 424 | } |
| 425 | |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 426 | #if !BUILDFLAG(IS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 427 | void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin( |
| 428 | int32_t result, |
| 429 | const HostResource& context) { |
| 430 | dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK( |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 431 | API_ID_PPB_GRAPHICS_3D, context, result)); |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 432 | } |
Xiaohan Wang | 0fd6e56a | 2022-01-13 20:26:11 | [diff] [blame] | 433 | #endif // !BUILDFLAG(IS_NACL) |
[email protected] | eeb4e4a | 2011-07-19 16:22:06 | [diff] [blame] | 434 | |
| 435 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 436 | } // namespace ppapi |