blob: 5d04041e4e5484769f0efebbf7057afb3cfeab16 [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
brettw669d47b12015-02-13 21:17:387#include "base/numerics/safe_conversions.h"
avie029c4132015-12-23 06:45:228#include "build/build_config.h"
[email protected]eeb4e4a2011-07-19 16:22:069#include "gpu/command_buffer/client/gles2_implementation.h"
[email protected]84b44c552012-10-15 20:58:1710#include "gpu/command_buffer/common/command_buffer.h"
dyenddfdbbb2016-01-14 22:21:3811#include "gpu/command_buffer/common/sync_token.h"
[email protected]eeb4e4a2011-07-19 16:22:0612#include "ppapi/c/pp_errors.h"
13#include "ppapi/proxy/enter_proxy.h"
14#include "ppapi/proxy/plugin_dispatcher.h"
[email protected]aaa11b32012-03-08 12:30:1315#include "ppapi/proxy/ppapi_command_buffer_proxy.h"
[email protected]eeb4e4a2011-07-19 16:22:0616#include "ppapi/proxy/ppapi_messages.h"
[email protected]84b44c552012-10-15 20:58:1717#include "ppapi/shared_impl/ppapi_globals.h"
[email protected]eeb4e4a2011-07-19 16:22:0618#include "ppapi/thunk/enter.h"
19#include "ppapi/thunk/resource_creation_api.h"
20#include "ppapi/thunk/thunk.h"
21
[email protected]eeb4e4a2011-07-19 16:22:0622using ppapi::thunk::EnterResourceNoLock;
23using ppapi::thunk::PPB_Graphics3D_API;
24using ppapi::thunk::ResourceCreationAPI;
25
[email protected]4d2efd22011-08-18 21:58:0226namespace ppapi {
[email protected]eeb4e4a2011-07-19 16:22:0627namespace proxy {
28
29namespace {
[email protected]84b44c552012-10-15 20:58:1730
mazda9cfbcfb2014-11-12 17:07:1131#if !defined(OS_NACL)
Alexandr Ilin15bb7032018-07-13 10:09:0632base::UnsafeSharedMemoryRegion TransportSHMHandle(
penghuanga206fb492014-09-09 21:27:3233 Dispatcher* dispatcher,
Alexandr Ilin15bb7032018-07-13 10:09:0634 const base::UnsafeSharedMemoryRegion& region) {
35 return dispatcher->ShareUnsafeSharedMemoryRegionWithRemote(region);
[email protected]eeb4e4a2011-07-19 16:22:0636}
mazda9cfbcfb2014-11-12 17:07:1137#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:0638
[email protected]914f5262013-06-01 00:17:2239gpu::CommandBuffer::State GetErrorState() {
40 gpu::CommandBuffer::State error_state;
41 error_state.error = gpu::error::kGenericError;
[email protected]eeb4e4a2011-07-19 16:22:0642 return error_state;
43}
44
[email protected]eeb4e4a2011-07-19 16:22:0645} // namespace
46
Daniele Castagna141a88a2018-07-30 19:41:2347Graphics3D::Graphics3D(const HostResource& resource,
48 const gfx::Size& size,
49 const bool single_buffer)
50 : PPB_Graphics3D_Shared(resource, size), single_buffer(single_buffer) {}
[email protected]eeb4e4a2011-07-19 16:22:0651
52Graphics3D::~Graphics3D() {
[email protected]edccb562013-10-02 00:01:2053 DestroyGLES2Impl();
[email protected]eeb4e4a2011-07-19 16:22:0654}
55
penghuanga206fb492014-09-09 21:27:3256bool Graphics3D::Init(gpu::gles2::GLES2Implementation* share_gles2,
piman360175c2014-11-07 02:30:0157 const gpu::Capabilities& capabilities,
Alexandr Ilin15bb7032018-07-13 10:09:0658 SerializedHandle shared_state,
lukasza2573ce7d2016-02-16 19:17:2259 gpu::CommandBufferId command_buffer_id) {
[email protected]7f8b26b2011-08-18 15:41:0160 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
[email protected]eeb4e4a2011-07-19 16:22:0661 if (!dispatcher)
62 return false;
63
Sunny Sachanandanifd979a82018-03-27 00:26:0364 InstanceData* data = dispatcher->GetInstanceData(host_resource().instance());
65 DCHECK(data);
66
piman360175c2014-11-07 02:30:0167 command_buffer_.reset(new PpapiCommandBufferProxy(
Sunny Sachanandanifd979a82018-03-27 00:26:0368 host_resource(), &data->flush_info, dispatcher, capabilities,
Alexandr Ilin15bb7032018-07-13 10:09:0669 std::move(shared_state), command_buffer_id));
[email protected]84b44c552012-10-15 20:58:1770
Eric Karl2fc4409b92017-08-18 18:48:3971 return CreateGLES2Impl(share_gles2);
[email protected]eeb4e4a2011-07-19 16:22:0672}
73
[email protected]503b3a22011-12-12 23:29:4074PP_Bool Graphics3D::SetGetBuffer(int32_t /* transfer_buffer_id */) {
[email protected]eeb4e4a2011-07-19 16:22:0675 return PP_FALSE;
76}
77
[email protected]eeb4e4a2011-07-19 16:22:0678PP_Bool Graphics3D::Flush(int32_t put_offset) {
79 return PP_FALSE;
80}
81
[email protected]046fa1ac2014-04-01 09:06:4382scoped_refptr<gpu::Buffer> Graphics3D::CreateTransferBuffer(
83 uint32_t size,
84 int32_t* id) {
85 *id = -1;
kylechar8b8ecebb2019-10-29 20:08:1086 return nullptr;
[email protected]eeb4e4a2011-07-19 16:22:0687}
88
89PP_Bool Graphics3D::DestroyTransferBuffer(int32_t id) {
90 return PP_FALSE;
91}
92
[email protected]7fe4198b2014-03-18 21:52:3693gpu::CommandBuffer::State Graphics3D::WaitForTokenInRange(int32_t start,
94 int32_t end) {
95 return GetErrorState();
96}
97
Antoine Labourd3469942017-05-16 21:23:4298gpu::CommandBuffer::State Graphics3D::WaitForGetOffsetInRange(
99 uint32_t set_get_buffer_count,
100 int32_t start,
101 int32_t end) {
[email protected]eeb4e4a2011-07-19 16:22:06102 return GetErrorState();
103}
104
dyen4de3d345f2016-01-12 18:30:42105void Graphics3D::EnsureWorkVisible() {
106 NOTREACHED();
107}
108
erikchen438b0442016-05-11 18:33:30109void Graphics3D::TakeFrontBuffer() {
110 NOTREACHED();
111}
112
[email protected]eeb4e4a2011-07-19 16:22:06113gpu::CommandBuffer* Graphics3D::GetCommandBuffer() {
[email protected]4e46a732013-09-30 18:35:59114 return command_buffer_.get();
[email protected]eeb4e4a2011-07-19 16:22:06115}
116
[email protected]744e0792013-09-27 01:18:35117gpu::GpuControl* Graphics3D::GetGpuControl() {
118 return command_buffer_.get();
119}
120
erikchenb13637b2016-07-08 09:38:56121int32_t Graphics3D::DoSwapBuffers(const gpu::SyncToken& sync_token,
pimanb36392c22016-07-13 02:11:36122 const gfx::Size& size) {
dyenddfdbbb2016-01-14 22:21:38123 // A valid sync token would indicate a swap buffer already happened somehow.
124 DCHECK(!sync_token.HasData());
125
126 gpu::gles2::GLES2Implementation* gl = gles2_impl();
Eric Karlb6b2c632018-05-07 22:45:04127 gl->SwapBuffers(swap_id_++);
erikchen438b0442016-05-11 18:33:30128
Daniele Castagna141a88a2018-07-30 19:41:23129 if (!single_buffer || swap_id_ == 1) {
130 PluginDispatcher::GetForResource(this)->Send(
131 new PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer(API_ID_PPB_GRAPHICS_3D,
132 host_resource()));
133 }
erikchen438b0442016-05-11 18:33:30134
dyenddfdbbb2016-01-14 22:21:38135 gpu::SyncToken new_sync_token;
Sunny Sachanandanic94b8de2017-12-16 03:30:30136 gl->GenSyncTokenCHROMIUM(new_sync_token.GetData());
dyenddfdbbb2016-01-14 22:21:38137
[email protected]eeb4e4a2011-07-19 16:22:06138 IPC::Message* msg = new PpapiHostMsg_PPBGraphics3D_SwapBuffers(
pimanb36392c22016-07-13 02:11:36139 API_ID_PPB_GRAPHICS_3D, host_resource(), new_sync_token, size);
[email protected]eeb4e4a2011-07-19 16:22:06140 msg->set_unblock(true);
[email protected]7f8b26b2011-08-18 15:41:01141 PluginDispatcher::GetForResource(this)->Send(msg);
[email protected]eeb4e4a2011-07-19 16:22:06142
[email protected]eeb4e4a2011-07-19 16:22:06143 return PP_OK_COMPLETIONPENDING;
144}
145
[email protected]5c966022011-09-13 18:09:37146PPB_Graphics3D_Proxy::PPB_Graphics3D_Proxy(Dispatcher* dispatcher)
147 : InterfaceProxy(dispatcher),
[email protected]a2f53dc2013-04-30 01:06:35148 callback_factory_(this) {
[email protected]eeb4e4a2011-07-19 16:22:06149}
150
151PPB_Graphics3D_Proxy::~PPB_Graphics3D_Proxy() {
152}
153
154// static
[email protected]eeb4e4a2011-07-19 16:22:06155PP_Resource PPB_Graphics3D_Proxy::CreateProxyResource(
156 PP_Instance instance,
[email protected]eeb4e4a2011-07-19 16:22:06157 PP_Resource share_context,
158 const int32_t* attrib_list) {
159 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
160 if (!dispatcher)
161 return PP_ERROR_BADARGUMENT;
162
[email protected]9ed07f82012-05-29 21:54:55163 HostResource share_host;
kylechar8b8ecebb2019-10-29 20:08:10164 gpu::gles2::GLES2Implementation* share_gles2 = nullptr;
[email protected]9ed07f82012-05-29 21:54:55165 if (share_context != 0) {
166 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true);
167 if (enter.failed())
168 return PP_ERROR_BADARGUMENT;
169
170 PPB_Graphics3D_Shared* share_graphics =
171 static_cast<PPB_Graphics3D_Shared*>(enter.object());
172 share_host = share_graphics->host_resource();
173 share_gles2 = share_graphics->gles2_impl();
174 }
[email protected]eeb4e4a2011-07-19 16:22:06175
Antoine Labourfeab2392017-12-21 20:28:39176 gpu::ContextCreationAttribs attrib_helper;
[email protected]eeb4e4a2011-07-19 16:22:06177 if (attrib_list) {
pimanfe4e4882016-07-09 01:18:21178 for (const int32_t* attr = attrib_list; attr[0] != PP_GRAPHICS3DATTRIB_NONE;
[email protected]0e50fc4d2011-08-01 15:33:51179 attr += 2) {
Antoine Labour492d57a12017-12-21 02:42:11180 int32_t key = attr[0];
181 int32_t value = attr[1];
182 switch (key) {
183 case PP_GRAPHICS3DATTRIB_ALPHA_SIZE:
184 attrib_helper.alpha_size = value;
185 break;
186 case PP_GRAPHICS3DATTRIB_BLUE_SIZE:
187 attrib_helper.blue_size = value;
188 break;
189 case PP_GRAPHICS3DATTRIB_GREEN_SIZE:
190 attrib_helper.green_size = value;
191 break;
192 case PP_GRAPHICS3DATTRIB_RED_SIZE:
193 attrib_helper.red_size = value;
194 break;
195 case PP_GRAPHICS3DATTRIB_DEPTH_SIZE:
196 attrib_helper.depth_size = value;
197 break;
198 case PP_GRAPHICS3DATTRIB_STENCIL_SIZE:
199 attrib_helper.stencil_size = value;
200 break;
201 case PP_GRAPHICS3DATTRIB_SAMPLES:
202 attrib_helper.samples = value;
203 break;
204 case PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS:
205 attrib_helper.sample_buffers = value;
206 break;
207 case PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR:
208 attrib_helper.buffer_preserved =
209 value == PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED;
210 break;
pimanfe4e4882016-07-09 01:18:21211 case PP_GRAPHICS3DATTRIB_WIDTH:
Antoine Labour492d57a12017-12-21 02:42:11212 attrib_helper.offscreen_framebuffer_size.set_width(value);
pimanfe4e4882016-07-09 01:18:21213 break;
214 case PP_GRAPHICS3DATTRIB_HEIGHT:
Antoine Labour492d57a12017-12-21 02:42:11215 attrib_helper.offscreen_framebuffer_size.set_height(value);
pimanfe4e4882016-07-09 01:18:21216 break;
217 case PP_GRAPHICS3DATTRIB_GPU_PREFERENCE:
218 attrib_helper.gpu_preference =
Antoine Labour492d57a12017-12-21 02:42:11219 (value == PP_GRAPHICS3DATTRIB_GPU_PREFERENCE_LOW_POWER)
Zhenyao Modd6173b02019-05-23 23:04:27220 ? gl::GpuPreference::kLowPower
221 : gl::GpuPreference::kHighPerformance;
pimanfe4e4882016-07-09 01:18:21222 break;
David Revemanca46de732017-06-09 19:48:19223 case PP_GRAPHICS3DATTRIB_SINGLE_BUFFER:
Antoine Labour492d57a12017-12-21 02:42:11224 attrib_helper.single_buffer = !!value;
David Revemanca46de732017-06-09 19:48:19225 break;
pimanfe4e4882016-07-09 01:18:21226 default:
Antoine Labour492d57a12017-12-21 02:42:11227 DLOG(ERROR) << "Invalid context creation attribute: " << attr[0];
228 return 0;
pimanfe4e4882016-07-09 01:18:21229 }
[email protected]eeb4e4a2011-07-19 16:22:06230 }
[email protected]eeb4e4a2011-07-19 16:22:06231 }
[email protected]eeb4e4a2011-07-19 16:22:06232
233 HostResource result;
piman360175c2014-11-07 02:30:01234 gpu::Capabilities capabilities;
penghuanga206fb492014-09-09 21:27:32235 ppapi::proxy::SerializedHandle shared_state;
lukasza2573ce7d2016-02-16 19:17:22236 gpu::CommandBufferId command_buffer_id;
pimanfe4e4882016-07-09 01:18:21237 dispatcher->Send(new PpapiHostMsg_PPBGraphics3D_Create(
238 API_ID_PPB_GRAPHICS_3D, instance, share_host, attrib_helper, &result,
239 &capabilities, &shared_state, &command_buffer_id));
penghuanga206fb492014-09-09 21:27:32240
[email protected]eeb4e4a2011-07-19 16:22:06241 if (result.is_null())
242 return 0;
243
pimanb36392c22016-07-13 02:11:36244 scoped_refptr<Graphics3D> graphics_3d(
Daniele Castagna141a88a2018-07-30 19:41:23245 new Graphics3D(result, attrib_helper.offscreen_framebuffer_size,
246 attrib_helper.single_buffer));
Alexandr Ilin15bb7032018-07-13 10:09:06247 if (!graphics_3d->Init(share_gles2, capabilities, std::move(shared_state),
dyen12e45962015-09-18 00:13:51248 command_buffer_id)) {
[email protected]eeb4e4a2011-07-19 16:22:06249 return 0;
dyen12e45962015-09-18 00:13:51250 }
[email protected]7f8b26b2011-08-18 15:41:01251 return graphics_3d->GetReference();
[email protected]eeb4e4a2011-07-19 16:22:06252}
253
254bool PPB_Graphics3D_Proxy::OnMessageReceived(const IPC::Message& msg) {
255 bool handled = true;
256 IPC_BEGIN_MESSAGE_MAP(PPB_Graphics3D_Proxy, msg)
[email protected]11494c5c2012-11-13 02:50:57257#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06258 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_Create,
259 OnMsgCreate)
[email protected]503b3a22011-12-12 23:29:40260 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SetGetBuffer,
261 OnMsgSetGetBuffer)
[email protected]7fe4198b2014-03-18 21:52:36262 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_WaitForTokenInRange,
263 OnMsgWaitForTokenInRange)
264 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_WaitForGetOffsetInRange,
265 OnMsgWaitForGetOffsetInRange)
266 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_AsyncFlush, OnMsgAsyncFlush)
[email protected]eeb4e4a2011-07-19 16:22:06267 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_CreateTransferBuffer,
268 OnMsgCreateTransferBuffer)
269 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_DestroyTransferBuffer,
270 OnMsgDestroyTransferBuffer)
[email protected]eeb4e4a2011-07-19 16:22:06271 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_SwapBuffers,
272 OnMsgSwapBuffers)
erikchen438b0442016-05-11 18:33:30273 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_TakeFrontBuffer,
274 OnMsgTakeFrontBuffer)
dyen4de3d345f2016-01-12 18:30:42275 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBGraphics3D_EnsureWorkVisible,
276 OnMsgEnsureWorkVisible)
[email protected]11494c5c2012-11-13 02:50:57277#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06278
279 IPC_MESSAGE_HANDLER(PpapiMsg_PPBGraphics3D_SwapBuffersACK,
280 OnMsgSwapBuffersACK)
281 IPC_MESSAGE_UNHANDLED(handled = false)
282
283 IPC_END_MESSAGE_MAP()
284 // FIXME(brettw) handle bad messages!
285 return handled;
286}
287
[email protected]11494c5c2012-11-13 02:50:57288#if !defined(OS_NACL)
lukasza2573ce7d2016-02-16 19:17:22289void PPB_Graphics3D_Proxy::OnMsgCreate(
290 PP_Instance instance,
291 HostResource share_context,
Antoine Labourfeab2392017-12-21 20:28:39292 const gpu::ContextCreationAttribs& attrib_helper,
lukasza2573ce7d2016-02-16 19:17:22293 HostResource* result,
294 gpu::Capabilities* capabilities,
295 SerializedHandle* shared_state,
296 gpu::CommandBufferId* command_buffer_id) {
Matthew Caryfc3757f2019-07-30 21:32:46297 shared_state->set_null_shmem_region();
[email protected]eeb4e4a2011-07-19 16:22:06298
[email protected]5c966022011-09-13 18:09:37299 thunk::EnterResourceCreation enter(instance);
[email protected]9ed07f82012-05-29 21:54:55300
penghuanga206fb492014-09-09 21:27:32301 if (!enter.succeeded())
302 return;
303
Alexandr Ilin15bb7032018-07-13 10:09:06304 const base::UnsafeSharedMemoryRegion* region = nullptr;
penghuanga206fb492014-09-09 21:27:32305 result->SetHostResource(
pimanfe4e4882016-07-09 01:18:21306 instance, enter.functions()->CreateGraphics3DRaw(
307 instance, share_context.host_resource(), attrib_helper,
Alexandr Ilin15bb7032018-07-13 10:09:06308 capabilities, &region, command_buffer_id));
penghuanga206fb492014-09-09 21:27:32309 if (!result->is_null()) {
Alexandr Ilin15bb7032018-07-13 10:09:06310 shared_state->set_shmem_region(
311 base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
312 TransportSHMHandle(dispatcher(), *region)));
[email protected]eeb4e4a2011-07-19 16:22:06313 }
314}
315
avie029c4132015-12-23 06:45:22316void PPB_Graphics3D_Proxy::OnMsgSetGetBuffer(const HostResource& context,
317 int32_t transfer_buffer_id) {
[email protected]503b3a22011-12-12 23:29:40318 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
319 if (enter.succeeded())
320 enter.object()->SetGetBuffer(transfer_buffer_id);
[email protected]eeb4e4a2011-07-19 16:22:06321}
322
[email protected]7fe4198b2014-03-18 21:52:36323void PPB_Graphics3D_Proxy::OnMsgWaitForTokenInRange(
324 const HostResource& context,
avie029c4132015-12-23 06:45:22325 int32_t start,
326 int32_t end,
[email protected]7fe4198b2014-03-18 21:52:36327 gpu::CommandBuffer::State* state,
328 bool* success) {
[email protected]eeb4e4a2011-07-19 16:22:06329 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]571b35e82012-05-19 00:04:35330 if (enter.failed()) {
331 *success = false;
[email protected]eeb4e4a2011-07-19 16:22:06332 return;
[email protected]571b35e82012-05-19 00:04:35333 }
[email protected]7fe4198b2014-03-18 21:52:36334 *state = enter.object()->WaitForTokenInRange(start, end);
335 *success = true;
336}
337
338void PPB_Graphics3D_Proxy::OnMsgWaitForGetOffsetInRange(
339 const HostResource& context,
Antoine Labourd3469942017-05-16 21:23:42340 uint32_t set_get_buffer_count,
avie029c4132015-12-23 06:45:22341 int32_t start,
342 int32_t end,
[email protected]7fe4198b2014-03-18 21:52:36343 gpu::CommandBuffer::State* state,
344 bool* success) {
345 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
346 if (enter.failed()) {
347 *success = false;
348 return;
349 }
Antoine Labourd3469942017-05-16 21:23:42350 *state =
351 enter.object()->WaitForGetOffsetInRange(set_get_buffer_count, start, end);
[email protected]571b35e82012-05-19 00:04:35352 *success = true;
[email protected]eeb4e4a2011-07-19 16:22:06353}
354
355void PPB_Graphics3D_Proxy::OnMsgAsyncFlush(const HostResource& context,
avie029c4132015-12-23 06:45:22356 int32_t put_offset) {
[email protected]eeb4e4a2011-07-19 16:22:06357 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
358 if (enter.succeeded())
359 enter.object()->Flush(put_offset);
360}
361
362void PPB_Graphics3D_Proxy::OnMsgCreateTransferBuffer(
363 const HostResource& context,
avie029c4132015-12-23 06:45:22364 uint32_t size,
365 int32_t* id,
penghuanga206fb492014-09-09 21:27:32366 SerializedHandle* transfer_buffer) {
Alexandr Ilin15bb7032018-07-13 10:09:06367 transfer_buffer->set_null_shmem_region();
[email protected]eeb4e4a2011-07-19 16:22:06368 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
[email protected]046fa1ac2014-04-01 09:06:43369 if (enter.succeeded()) {
370 scoped_refptr<gpu::Buffer> buffer =
371 enter.object()->CreateTransferBuffer(size, id);
Daniel Cheng6d3ae972014-08-26 00:27:38372 if (!buffer.get())
[email protected]046fa1ac2014-04-01 09:06:43373 return;
[email protected]8a978df2014-04-02 23:54:09374 gpu::SharedMemoryBufferBacking* backing =
375 static_cast<gpu::SharedMemoryBufferBacking*>(buffer->backing());
Alexandr Ilin15bb7032018-07-13 10:09:06376 DCHECK(backing && backing->shared_memory_region().IsValid());
377 transfer_buffer->set_shmem_region(
378 base::UnsafeSharedMemoryRegion::TakeHandleForSerialization(
379 TransportSHMHandle(dispatcher(), backing->shared_memory_region())));
[email protected]046fa1ac2014-04-01 09:06:43380 } else {
[email protected]67c80782012-12-21 01:16:52381 *id = -1;
[email protected]046fa1ac2014-04-01 09:06:43382 }
[email protected]eeb4e4a2011-07-19 16:22:06383}
384
385void PPB_Graphics3D_Proxy::OnMsgDestroyTransferBuffer(
386 const HostResource& context,
avie029c4132015-12-23 06:45:22387 int32_t id) {
[email protected]eeb4e4a2011-07-19 16:22:06388 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
389 if (enter.succeeded())
390 enter.object()->DestroyTransferBuffer(id);
391}
392
dyenddfdbbb2016-01-14 22:21:38393void PPB_Graphics3D_Proxy::OnMsgSwapBuffers(const HostResource& context,
erikchenb13637b2016-07-08 09:38:56394 const gpu::SyncToken& sync_token,
pimanb36392c22016-07-13 02:11:36395 const gfx::Size& size) {
[email protected]79d23c72011-08-08 19:40:40396 EnterHostFromHostResourceForceCallback<PPB_Graphics3D_API> enter(
397 context, callback_factory_,
[email protected]eeb4e4a2011-07-19 16:22:06398 &PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin, context);
[email protected]eeb4e4a2011-07-19 16:22:06399 if (enter.succeeded())
erikchenb13637b2016-07-08 09:38:56400 enter.SetResult(enter.object()->SwapBuffersWithSyncToken(
pimanb36392c22016-07-13 02:11:36401 enter.callback(), sync_token, size));
[email protected]eeb4e4a2011-07-19 16:22:06402}
[email protected]b096d032013-03-08 03:08:01403
erikchen438b0442016-05-11 18:33:30404void PPB_Graphics3D_Proxy::OnMsgTakeFrontBuffer(const HostResource& context) {
405 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
406 if (enter.succeeded())
407 enter.object()->TakeFrontBuffer();
408}
409
dyen4de3d345f2016-01-12 18:30:42410void PPB_Graphics3D_Proxy::OnMsgEnsureWorkVisible(const HostResource& context) {
411 EnterHostFromHostResource<PPB_Graphics3D_API> enter(context);
412 if (enter.succeeded())
413 enter.object()->EnsureWorkVisible();
414}
[email protected]11494c5c2012-11-13 02:50:57415#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06416
417void PPB_Graphics3D_Proxy::OnMsgSwapBuffersACK(const HostResource& resource,
418 int32_t pp_error) {
419 EnterPluginFromHostResource<PPB_Graphics3D_API> enter(resource);
420 if (enter.succeeded())
421 static_cast<Graphics3D*>(enter.object())->SwapBuffersACK(pp_error);
422}
423
[email protected]11494c5c2012-11-13 02:50:57424#if !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06425void PPB_Graphics3D_Proxy::SendSwapBuffersACKToPlugin(
426 int32_t result,
427 const HostResource& context) {
428 dispatcher()->Send(new PpapiMsg_PPBGraphics3D_SwapBuffersACK(
[email protected]ac4b54d2011-10-20 23:09:28429 API_ID_PPB_GRAPHICS_3D, context, result));
[email protected]eeb4e4a2011-07-19 16:22:06430}
[email protected]11494c5c2012-11-13 02:50:57431#endif // !defined(OS_NACL)
[email protected]eeb4e4a2011-07-19 16:22:06432
433} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02434} // namespace ppapi