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