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