blob: 854b91e9226bdcff049d6578ae860715f3375621 [file] [log] [blame]
[email protected]aaa11b32012-03-08 12:30:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]eeb4e4a2011-07-19 16:22:062// 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ömfb60ea02021-04-05 21:06:127#include <memory>
8
brettw669d47b12015-02-13 21:17:389#include "base/numerics/safe_conversions.h"
avie029c4132015-12-23 06:45:2210#include "build/build_config.h"
[email protected]eeb4e4a2011-07-19 16:22:0611#include "gpu/command_buffer/client/gles2_implementation.h"
[email protected]84b44c552012-10-15 20:58:1712#include "gpu/command_buffer/common/command_buffer.h"
dyenddfdbbb2016-01-14 22:21:3813#include "gpu/command_buffer/common/sync_token.h"
[email protected]eeb4e4a2011-07-19 16:22:0614#include "ppapi/c/pp_errors.h"
15#include "ppapi/proxy/enter_proxy.h"
16#include "ppapi/proxy/plugin_dispatcher.h"
[email protected]aaa11b32012-03-08 12:30:1317#include "ppapi/proxy/ppapi_command_buffer_proxy.h"
[email protected]eeb4e4a2011-07-19 16:22:0618#include "ppapi/proxy/ppapi_messages.h"
[email protected]84b44c552012-10-15 20:58:1719#include "ppapi/shared_impl/ppapi_globals.h"
[email protected]eeb4e4a2011-07-19 16:22:0620#include "ppapi/thunk/enter.h"
21#include "ppapi/thunk/resource_creation_api.h"
22#include "ppapi/thunk/thunk.h"
23
[email protected]eeb4e4a2011-07-19 16:22:0624using ppapi::thunk::EnterResourceNoLock;
25using ppapi::thunk::PPB_Graphics3D_API;
26using ppapi::thunk::ResourceCreationAPI;
27
[email protected]4d2efd22011-08-18 21:58:0228namespace ppapi {
[email protected]eeb4e4a2011-07-19 16:22:0629namespace proxy {
30
31namespace {
[email protected]84b44c552012-10-15 20:58:1732
Xiaohan Wang0fd6e56a2022-01-13 20:26:1133#if !BUILDFLAG(IS_NACL)
Alexandr Ilin15bb7032018-07-13 10:09:0634base::UnsafeSharedMemoryRegion TransportSHMHandle(
penghuanga206fb492014-09-09 21:27:3235 Dispatcher* dispatcher,
Alexandr Ilin15bb7032018-07-13 10:09:0636 const base::UnsafeSharedMemoryRegion& region) {
37 return dispatcher->ShareUnsafeSharedMemoryRegionWithRemote(region);
[email protected]eeb4e4a2011-07-19 16:22:0638}
Xiaohan Wang0fd6e56a2022-01-13 20:26:1139#endif // !BUILDFLAG(IS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:0640
[email protected]914f5262013-06-01 00:17:2241gpu::CommandBuffer::State GetErrorState() {
42 gpu::CommandBuffer::State error_state;
43 error_state.error = gpu::error::kGenericError;
[email protected]eeb4e4a2011-07-19 16:22:0644 return error_state;
45}
46
[email protected]eeb4e4a2011-07-19 16:22:0647} // namespace
48
Daniele Castagna141a88a2018-07-30 19:41:2349Graphics3D::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]eeb4e4a2011-07-19 16:22:0653
54Graphics3D::~Graphics3D() {
[email protected]edccb562013-10-02 00:01:2055 DestroyGLES2Impl();
[email protected]eeb4e4a2011-07-19 16:22:0656}
57
penghuanga206fb492014-09-09 21:27:3258bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2,
piman360175c2014-11-07 02:30:0159 const gpu::Capabilities& capabilities,
Alexandr Ilin15bb7032018-07-13 10:09:0660 SerializedHandle shared_state,
lukasza2573ce7d2016-02-16 19:17:2261 gpu::CommandBufferId command_buffer_id) {
[email protected]7f8b26b2011-08-18 15:41:0162 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
[email protected]eeb4e4a2011-07-19 16:22:0663 if (!dispatcher)
64 return false;
65
Sunny Sachanandanifd979a82018-03-27 00:26:0366 InstanceData* data = dispatcher->GetInstanceData(host_resource().instance());
67 DCHECK(data);
68
Peter Boströmfb60ea02021-04-05 21:06:1269 command_buffer_ = std::make_unique<PpapiCommandBufferProxy>(
Sunny Sachanandanifd979a82018-03-27 00:26:0370 host_resource(), &data->flush_info, dispatcher, capabilities,
Peter Boströmfb60ea02021-04-05 21:06:1271 std::move(shared_state), command_buffer_id);
[email protected]84b44c552012-10-15 20:58:1772
Eric Karl2fc4409b92017-08-18 18:48:3973 return CreateGLES2Impl(share_gles2);
[email protected]eeb4e4a2011-07-19 16:22:0674}
75
[email protected]503b3a22011-12-12 23:29:4076PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) {
[email protected]eeb4e4a2011-07-19 16:22:0677 return PP_FALSE;
78}
79
[email protected]eeb4e4a2011-07-19 16:22:0680PP_Bool Graphics3D::Flush(int32_t put_offset) {
81 return PP_FALSE;
82}
83
[email protected]046fa1ac2014-04-01 09:06:4384scoped_refptr<gpu::Buffer> Graphics3D::CreateTransferBuffer(
85 uint32_t size,
86 int32_t* id) {
87 *id = -1;
kylechar8b8ecebb2019-10-29 20:08:1088 return nullptr;
[email protected]eeb4e4a2011-07-19 16:22:0689}
90
91PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) {
92 return PP_FALSE;
93}
94
[email protected]7fe4198b2014-03-18 21:52:3695gpu::CommandBuffer::State Graphics3D::WaitForTokenInRange(int32_t start,
96 int32_t end) {
97 return GetErrorState();
98}
99
Antoine Labourd3469942017-05-16 21:23:42100gpu::CommandBuffer::State Graphics3D::WaitForGetOffsetInRange(
101 uint32_t set_get_buffer_count,
102 int32_t start,
103 int32_t end) {
[email protected]eeb4e4a2011-07-19 16:22:06104 return GetErrorState();
105}
106
dyen4de3d345f2016-01-12 18:30:42107void Graphics3D::EnsureWorkVisible() {
108 NOTREACHED();
109}
110
erikchen438b0442016-05-11 18:33:30111void Graphics3D::TakeFrontBuffer() {
112 NOTREACHED();
113}
114
[email protected]eeb4e4a2011-07-19 16:22:06115gpu::CommandBuffer* Graphics3D::GetCommandBuffer() {
[email protected]4e46a732013-09-30 18:35:59116 return command_buffer_.get();
[email protected]eeb4e4a2011-07-19 16:22:06117}
118
[email protected]744e0792013-09-27 01:18:35119gpu::GpuControl* Graphics3D::GetGpuControl() {
120 return command_buffer_.get();
121}
122
erikchenb13637b2016-07-08 09:38:56123int32_t Graphics3D::DoSwapBuffers(const gpu::SyncToken& sync_token,
pimanb36392c22016-07-13 02:11:36124 const gfx::Size& size) {
dyenddfdbbb2016-01-14 22:21:38125 // 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 Karlb6b2c632018-05-07 22:45:04129 gl->SwapBuffers(swap_id_++);
erikchen438b0442016-05-11 18:33:30130
Daniele Castagna141a88a2018-07-30 19:41:23131 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 }
erikchen438b0442016-05-11 18:33:30136
dyenddfdbbb2016-01-14 22:21:38137 gpu::SyncToken new_sync_token;
Sunny Sachanandanic94b8de2017-12-16 03:30:30138 gl->GenSyncTokenCHROMIUM(new_sync_token.GetData());
dyenddfdbbb2016-01-14 22:21:38139
[email protected]eeb4e4a2011-07-19 16:22:06140 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers(
pimanb36392c22016-07-13 02:11:36141 API_ID_PPB_GRAPHICS_3D, host_resource(), new_sync_token, size);
[email protected]eeb4e4a2011-07-19 16:22:06142 msg->set_unblock(true);
[email protected]7f8b26b2011-08-18 15:41:01143 PluginDispatcher::GetForResource(this)->Send(msg);
[email protected]eeb4e4a2011-07-19 16:22:06144
[email protected]eeb4e4a2011-07-19 16:22:06145 return PP_OK_COMPLETIONPENDING;
146}
147
[email protected]5c966022011-09-13 18:09:37148PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher)
149 : InterfaceProxy(dispatcher),
[email protected]a2f53dc2013-04-30 01:06:35150 callback_factory_(this) {
[email protected]eeb4e4a2011-07-19 16:22:06151}
152
153PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() {
154}
155
156// static
[email protected]eeb4e4a2011-07-19 16:22:06157PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource(
158 PP_Instance instance,
[email protected]eeb4e4a2011-07-19 16:22:06159 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]9ed07f82012-05-29 21:54:55165 HostResource share_host;
kylechar8b8ecebb2019-10-29 20:08:10166 gpu::gles2::GLES2Implementation* share_gles2 = nullptr;
[email protected]9ed07f82012-05-29 21:54:55167 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]eeb4e4a2011-07-19 16:22:06177
Antoine Labourfeab2392017-12-21 20:28:39178 gpu::ContextCreationAttribs attrib_helper;
[email protected]eeb4e4a2011-07-19 16:22:06179 if (attrib_list) {
pimanfe4e4882016-07-09 01:18:21180 for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE;
[email protected]0e50fc4d2011-08-01 15:33:51181 attr += 2) {
Antoine Labour492d57a12017-12-21 02:42:11182 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;
pimanfe4e4882016-07-09 01:18:21213 case PP_GRAPHICS3DATTRIB_WIDTH:
Antoine Labour492d57a12017-12-21 02:42:11214 attrib_helper.offscreen_framebuffer_size.set_width(value);
pimanfe4e4882016-07-09 01:18:21215 break;
216 case PP_GRAPHICS3DATTRIB_HEIGHT:
Antoine Labour492d57a12017-12-21 02:42:11217 attrib_helper.offscreen_framebuffer_size.set_height(value);
pimanfe4e4882016-07-09 01:18:21218 break;
219 case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE:
220 attrib_helper.gpu_preference =
Antoine Labour492d57a12017-12-21 02:42:11221 (value == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER)
Zhenyao Modd6173b02019-05-23 23:04:27222 ? gl::GpuPreference::kLowPower
223 : gl::GpuPreference::kHighPerformance;
pimanfe4e4882016-07-09 01:18:21224 break;
David Revemanca46de732017-06-09 19:48:19225 case PP_GRAPHICS3DATTRIB_SINGLE_BUFFER:
Antoine Labour492d57a12017-12-21 02:42:11226 attrib_helper.single_buffer = !!value;
David Revemanca46de732017-06-09 19:48:19227 break;
pimanfe4e4882016-07-09 01:18:21228 default:
Antoine Labour492d57a12017-12-21 02:42:11229 DLOG(ERROR) << "Invalid context creation attribute: " << attr[0];
230 return 0;
pimanfe4e4882016-07-09 01:18:21231 }
[email protected]eeb4e4a2011-07-19 16:22:06232 }
[email protected]eeb4e4a2011-07-19 16:22:06233 }
234
235 HostResource result;
piman360175c2014-11-07 02:30:01236 gpu::Capabilities capabilities;
penghuanga206fb492014-09-09 21:27:32237 ppapi::proxy::SerializedHandle shared_state;
lukasza2573ce7d2016-02-16 19:17:22238 gpu::CommandBufferId command_buffer_id;
pimanfe4e4882016-07-09 01:18:21239 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));
penghuanga206fb492014-09-09 21:27:32242
[email protected]eeb4e4a2011-07-19 16:22:06243 if (result.is_null())
244 return 0;
245
pimanb36392c22016-07-13 02:11:36246 scoped_refptr<Graphics3D> graphics_3d(
Daniele Castagna141a88a2018-07-30 19:41:23247 new Graphics3D(result, attrib_helper.offscreen_framebuffer_size,
248 attrib_helper.single_buffer));
Alexandr Ilin15bb7032018-07-13 10:09:06249 if (!graphics_3d->Init(share_gles2, capabilities, std::move(shared_state),
dyen12e45962015-09-18 00:13:51250 command_buffer_id)) {
[email protected]eeb4e4a2011-07-19 16:22:06251 return 0;
dyen12e45962015-09-18 00:13:51252 }
[email protected]7f8b26b2011-08-18 15:41:01253 return graphics_3d->GetReference();
[email protected]eeb4e4a2011-07-19 16:22:06254}
255
256bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
257 bool handled = true;
258 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg)
Xiaohan Wang0fd6e56a2022-01-13 20:26:11259#if !BUILDFLAG(IS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06260 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create,
261 OnMsgCreate)
[email protected]503b3a22011-12-12 23:29:40262 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer,
263 OnMsgSetGetBuffer)
[email protected]7fe4198b2014-03-18 21:52:36264 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]eeb4e4a2011-07-19 16:22:06269 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
270 OnMsgCreateTransferBuffer)
271 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
272 OnMsgDestroyTransferBuffer)
[email protected]eeb4e4a2011-07-19 16:22:06273 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
274 OnMsgSwapBuffers)
erikchen438b0442016-05-11 18:33:30275 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer,
276 OnMsgTakeFrontBuffer)
dyen4de3d345f2016-01-12 18:30:42277 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_EnsureWorkVisible,
278 OnMsgEnsureWorkVisible)
Xiaohan Wang0fd6e56a2022-01-13 20:26:11279#endif // !BUILDFLAG(IS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06280
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 Wang0fd6e56a2022-01-13 20:26:11290#if !BUILDFLAG(IS_NACL)
lukasza2573ce7d2016-02-16 19:17:22291void PPB_Graphics3D_Proxy::OnMsgCreate(
292 PP_Instance instance,
293 HostResource share_context,
Antoine Labourfeab2392017-12-21 20:28:39294 const gpu::ContextCreationAttribs& attrib_helper,
lukasza2573ce7d2016-02-16 19:17:22295 HostResource* result,
296 gpu::Capabilities* capabilities,
297 SerializedHandle* shared_state,
298 gpu::CommandBufferId* command_buffer_id) {
Matthew Caryfc3757f2019-07-30 21:32:46299 shared_state->set_null_shmem_region();
[email protected]eeb4e4a2011-07-19 16:22:06300
[email protected]5c966022011-09-13 18:09:37301 thunk::EnterResourceCreation enter(instance);
[email protected]9ed07f82012-05-29 21:54:55302
penghuanga206fb492014-09-09 21:27:32303 if (!enter.succeeded())
304 return;
305
Alexandr Ilin15bb7032018-07-13 10:09:06306 const base::UnsafeSharedMemoryRegion* region = nullptr;
penghuanga206fb492014-09-09 21:27:32307 result->SetHostResource(
pimanfe4e4882016-07-09 01:18:21308 instance, enter.functions()->CreateGraphics3DRaw(
309 instance, share_context.host_resource(), attrib_helper,
Alexandr Ilin15bb7032018-07-13 10:09:06310 capabilities, &region, command_buffer_id));
penghuanga206fb492014-09-09 21:27:32311 if (!result->is_null()) {
Alexandr Ilin15bb7032018-07-13 10:09:06312 shared_state->set_shmem_region(
313 base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
314 TransportSHMHandle(dispatcher(), *region)));
[email protected]eeb4e4a2011-07-19 16:22:06315 }
316}
317
avie029c4132015-12-23 06:45:22318void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(const HostResource& context,
319 int32_t transfer_buffer_id) {
[email protected]503b3a22011-12-12 23:29:40320 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
321 if (enter.succeeded())
322 enter.object()->SetGetBuffer(transfer_buffer_id);
[email protected]eeb4e4a2011-07-19 16:22:06323}
324
[email protected]7fe4198b2014-03-18 21:52:36325void PPB_Graphics3D_Proxy::OnMsgWaitForTokenInRange(
326 const HostResource& context,
avie029c4132015-12-23 06:45:22327 int32_t start,
328 int32_t end,
[email protected]7fe4198b2014-03-18 21:52:36329 gpu::CommandBuffer::State* state,
330 bool* success) {
[email protected]eeb4e4a2011-07-19 16:22:06331 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]571b35e82012-05-19 00:04:35332 if (enter.failed()) {
333 *success = false;
[email protected]eeb4e4a2011-07-19 16:22:06334 return;
[email protected]571b35e82012-05-19 00:04:35335 }
[email protected]7fe4198b2014-03-18 21:52:36336 *state = enter.object()->WaitForTokenInRange(start, end);
337 *success = true;
338}
339
340void PPB_Graphics3D_Proxy::OnMsgWaitForGetOffsetInRange(
341 const HostResource& context,
Antoine Labourd3469942017-05-16 21:23:42342 uint32_t set_get_buffer_count,
avie029c4132015-12-23 06:45:22343 int32_t start,
344 int32_t end,
[email protected]7fe4198b2014-03-18 21:52:36345 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 Labourd3469942017-05-16 21:23:42352 *state =
353 enter.object()->WaitForGetOffsetInRange(set_get_buffer_count, start, end);
[email protected]571b35e82012-05-19 00:04:35354 *success = true;
[email protected]eeb4e4a2011-07-19 16:22:06355}
356
357void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context,
avie029c4132015-12-23 06:45:22358 int32_t put_offset) {
[email protected]eeb4e4a2011-07-19 16:22:06359 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
360 if (enter.succeeded())
361 enter.object()->Flush(put_offset);
362}
363
364void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer(
365 const HostResource& context,
avie029c4132015-12-23 06:45:22366 uint32_t size,
367 int32_t* id,
penghuanga206fb492014-09-09 21:27:32368 SerializedHandle* transfer_buffer) {
Alexandr Ilin15bb7032018-07-13 10:09:06369 transfer_buffer->set_null_shmem_region();
[email protected]eeb4e4a2011-07-19 16:22:06370 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]046fa1ac2014-04-01 09:06:43371 if (enter.succeeded()) {
372 scoped_refptr<gpu::Buffer> buffer =
373 enter.object()->CreateTransferBuffer(size, id);
Daniel Cheng6d3ae972014-08-26 00:27:38374 if (!buffer.get())
[email protected]046fa1ac2014-04-01 09:06:43375 return;
[email protected]8a978df2014-04-02 23:54:09376 gpu::SharedMemoryBufferBacking* backing =
377 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing());
Alexandr Ilin15bb7032018-07-13 10:09:06378 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]046fa1ac2014-04-01 09:06:43382 } else {
[email protected]67c80782012-12-21 01:16:52383 *id = -1;
[email protected]046fa1ac2014-04-01 09:06:43384 }
[email protected]eeb4e4a2011-07-19 16:22:06385}
386
387void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
388 const HostResource& context,
avie029c4132015-12-23 06:45:22389 int32_t id) {
[email protected]eeb4e4a2011-07-19 16:22:06390 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
391 if (enter.succeeded())
392 enter.object()->DestroyTransferBuffer(id);
393}
394
dyenddfdbbb2016-01-14 22:21:38395void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context,
erikchenb13637b2016-07-08 09:38:56396 const gpu::SyncToken& sync_token,
pimanb36392c22016-07-13 02:11:36397 const gfx::Size& size) {
[email protected]79d23c72011-08-08 19:40:40398 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter(
399 context, callback_factory_,
[email protected]eeb4e4a2011-07-19 16:22:06400 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context);
[email protected]eeb4e4a2011-07-19 16:22:06401 if (enter.succeeded())
erikchenb13637b2016-07-08 09:38:56402 enter.SetResult(enter.object()->SwapBuffersWithSyncToken(
pimanb36392c22016-07-13 02:11:36403 enter.callback(), sync_token, size));
[email protected]eeb4e4a2011-07-19 16:22:06404}
[email protected]b096d032013-03-08 03:08:01405
erikchen438b0442016-05-11 18:33:30406void PPB_Graphics3D_Proxy::OnMsgTakeFrontBuffer(const HostResource& context) {
407 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
408 if (enter.succeeded())
409 enter.object()->TakeFrontBuffer();
410}
411
dyen4de3d345f2016-01-12 18:30:42412void PPB_Graphics3D_Proxy::OnMsgEnsureWorkVisible(const HostResource& context) {
413 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
414 if (enter.succeeded())
415 enter.object()->EnsureWorkVisible();
416}
Xiaohan Wang0fd6e56a2022-01-13 20:26:11417#endif // !BUILDFLAG(IS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06418
419void 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 Wang0fd6e56a2022-01-13 20:26:11426#if !BUILDFLAG(IS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06427void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin(
428 int32_t result,
429 const HostResource& context) {
430 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK(
[email protected]ac4b54d2011-10-20 23:09:28431 API_ID_PPB_GRAPHICS_3D, context, result));
[email protected]eeb4e4a2011-07-19 16:22:06432}
Xiaohan Wang0fd6e56a2022-01-13 20:26:11433#endif // !BUILDFLAG(IS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06434
435} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02436} // namespace ppapi