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