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