OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_context_3d_proxy.h" | 5 #include "ppapi/proxy/ppb_context_3d_proxy.h" |
6 | 6 |
7 #include "base/hash_tables.h" | 7 #include "base/hash_tables.h" |
8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
11 #include "ppapi/c/pp_resource.h" | 11 #include "ppapi/c/pp_resource.h" |
12 #include "ppapi/c/dev/ppb_context_3d_dev.h" | 12 #include "ppapi/c/dev/ppb_context_3d_dev.h" |
13 #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" | 13 #include "ppapi/c/dev/ppb_context_3d_trusted_dev.h" |
14 #include "ppapi/proxy/enter_proxy.h" | 14 #include "ppapi/proxy/enter_proxy.h" |
15 #include "ppapi/proxy/plugin_dispatcher.h" | 15 #include "ppapi/proxy/plugin_dispatcher.h" |
16 #include "ppapi/proxy/plugin_resource.h" | |
17 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
18 #include "ppapi/proxy/ppb_surface_3d_proxy.h" | 17 #include "ppapi/proxy/ppb_surface_3d_proxy.h" |
19 #include "ppapi/thunk/enter.h" | 18 #include "ppapi/thunk/enter.h" |
20 #include "ppapi/thunk/resource_creation_api.h" | 19 #include "ppapi/thunk/resource_creation_api.h" |
21 #include "ppapi/thunk/thunk.h" | 20 #include "ppapi/thunk/thunk.h" |
22 | 21 |
23 using ppapi::HostResource; | 22 using ppapi::HostResource; |
| 23 using ppapi::Resource; |
24 using ppapi::thunk::EnterFunctionNoLock; | 24 using ppapi::thunk::EnterFunctionNoLock; |
25 using ppapi::thunk::EnterResourceNoLock; | 25 using ppapi::thunk::EnterResourceNoLock; |
26 using ppapi::thunk::PPB_Context3D_API; | 26 using ppapi::thunk::PPB_Context3D_API; |
27 using ppapi::thunk::PPB_Surface3D_API; | 27 using ppapi::thunk::PPB_Surface3D_API; |
28 using ppapi::thunk::ResourceCreationAPI; | 28 using ppapi::thunk::ResourceCreationAPI; |
29 | 29 |
30 namespace pp { | 30 namespace pp { |
31 namespace proxy { | 31 namespace proxy { |
32 | 32 |
33 namespace { | 33 namespace { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 void PepperCommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) { | 333 void PepperCommandBuffer::UpdateState(const gpu::CommandBuffer::State& state) { |
334 // Handle wraparound. It works as long as we don't have more than 2B state | 334 // Handle wraparound. It works as long as we don't have more than 2B state |
335 // updates in flight across which reordering occurs. | 335 // updates in flight across which reordering occurs. |
336 if (state.generation - last_state_.generation < 0x80000000U) | 336 if (state.generation - last_state_.generation < 0x80000000U) |
337 last_state_ = state; | 337 last_state_ = state; |
338 } | 338 } |
339 | 339 |
340 // Context3D ------------------------------------------------------------------- | 340 // Context3D ------------------------------------------------------------------- |
341 | 341 |
342 Context3D::Context3D(const HostResource& resource) | 342 Context3D::Context3D(const HostResource& resource) |
343 : PluginResource(resource), | 343 : Resource(resource), |
344 draw_(NULL), | 344 draw_(NULL), |
345 read_(NULL), | 345 read_(NULL), |
346 transfer_buffer_id_(0) { | 346 transfer_buffer_id_(0) { |
347 } | 347 } |
348 | 348 |
349 Context3D::~Context3D() { | 349 Context3D::~Context3D() { |
350 if (draw_) | 350 if (draw_) |
351 draw_->set_context(NULL); | 351 draw_->set_context(NULL); |
352 } | 352 } |
353 | 353 |
354 PPB_Context3D_API* Context3D::AsPPB_Context3D_API() { | 354 PPB_Context3D_API* Context3D::AsPPB_Context3D_API() { |
355 return this; | 355 return this; |
356 } | 356 } |
357 | 357 |
358 bool Context3D::CreateImplementation() { | 358 bool Context3D::CreateImplementation() { |
359 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance()); | 359 PluginDispatcher* dispatcher = |
| 360 PluginDispatcher::GetForInstance(pp_instance()); |
360 if (!dispatcher) | 361 if (!dispatcher) |
361 return false; | 362 return false; |
362 | 363 |
363 command_buffer_.reset(new PepperCommandBuffer(host_resource(), dispatcher)); | 364 command_buffer_.reset(new PepperCommandBuffer(host_resource(), dispatcher)); |
364 | 365 |
365 if (!command_buffer_->Initialize(kCommandBufferSize)) | 366 if (!command_buffer_->Initialize(kCommandBufferSize)) |
366 return false; | 367 return false; |
367 | 368 |
368 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); | 369 helper_.reset(new gpu::gles2::GLES2CmdHelper(command_buffer_.get())); |
369 if (!helper_->Initialize(kCommandBufferSize)) | 370 if (!helper_->Initialize(kCommandBufferSize)) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 if (pp_draw && !draw_surface) | 411 if (pp_draw && !draw_surface) |
411 return PP_ERROR_BADRESOURCE; | 412 return PP_ERROR_BADRESOURCE; |
412 if (pp_read && !read_surface) | 413 if (pp_read && !read_surface) |
413 return PP_ERROR_BADRESOURCE; | 414 return PP_ERROR_BADRESOURCE; |
414 HostResource host_draw = | 415 HostResource host_draw = |
415 draw_surface ? draw_surface->host_resource() : HostResource(); | 416 draw_surface ? draw_surface->host_resource() : HostResource(); |
416 HostResource host_read = | 417 HostResource host_read = |
417 read_surface ? read_surface->host_resource() : HostResource(); | 418 read_surface ? read_surface->host_resource() : HostResource(); |
418 | 419 |
419 int32_t result; | 420 int32_t result; |
420 GetDispatcher()->Send(new PpapiHostMsg_PPBContext3D_BindSurfaces( | 421 PluginDispatcher::GetForResource(this)->Send( |
421 INTERFACE_ID_PPB_CONTEXT_3D, | 422 new PpapiHostMsg_PPBContext3D_BindSurfaces( |
422 host_resource(), host_draw, host_read, &result)); | 423 INTERFACE_ID_PPB_CONTEXT_3D, |
| 424 host_resource(), host_draw, host_read, &result)); |
423 if (result != PP_OK) | 425 if (result != PP_OK) |
424 return result; | 426 return result; |
425 | 427 |
426 if (draw_surface != draw_) { | 428 if (draw_surface != draw_) { |
427 if (draw_) | 429 if (draw_) |
428 draw_->set_context(NULL); | 430 draw_->set_context(NULL); |
429 if (draw_surface) { | 431 if (draw_surface) { |
430 draw_surface->set_context(this); | 432 draw_surface->set_context(this); |
431 // Resize the backing texture to the size of the instance when it is | 433 // Resize the backing texture to the size of the instance when it is |
432 // bound. | 434 // bound. |
433 // TODO(alokp): This should be the responsibility of plugins. | 435 // TODO(alokp): This should be the responsibility of plugins. |
434 InstanceData* data = GetDispatcher()->GetInstanceData(instance()); | 436 InstanceData* data = |
| 437 PluginDispatcher::GetForResource(this)->GetInstanceData( |
| 438 pp_instance()); |
435 gles2_impl()->ResizeCHROMIUM(data->position.size.width, | 439 gles2_impl()->ResizeCHROMIUM(data->position.size.width, |
436 data->position.size.height); | 440 data->position.size.height); |
437 } | 441 } |
438 draw_ = draw_surface; | 442 draw_ = draw_surface; |
439 } | 443 } |
440 read_ = read_surface; | 444 read_ = read_surface; |
441 return PP_OK; | 445 return PP_OK; |
442 } | 446 } |
443 | 447 |
444 int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { | 448 int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { |
445 *draw = draw_ ? draw_->resource() : 0; | 449 *draw = draw_ ? draw_->pp_resource() : 0; |
446 *read = read_ ? read_->resource() : 0; | 450 *read = read_ ? read_->pp_resource() : 0; |
447 return PP_OK; | 451 return PP_OK; |
448 } | 452 } |
449 | 453 |
450 PP_Bool Context3D::InitializeTrusted(int32_t size) { | 454 PP_Bool Context3D::InitializeTrusted(int32_t size) { |
451 // Trusted interface not implemented in the proxy. | 455 // Trusted interface not implemented in the proxy. |
452 return PP_FALSE; | 456 return PP_FALSE; |
453 } | 457 } |
454 | 458 |
455 PP_Bool Context3D::GetRingBuffer(int* shm_handle, | 459 PP_Bool Context3D::GetRingBuffer(int* shm_handle, |
456 uint32_t* shm_size) { | 460 uint32_t* shm_size) { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 | 579 |
576 HostResource result; | 580 HostResource result; |
577 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( | 581 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( |
578 INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); | 582 INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); |
579 | 583 |
580 if (result.is_null()) | 584 if (result.is_null()) |
581 return 0; | 585 return 0; |
582 scoped_refptr<Context3D> context_3d(new Context3D(result)); | 586 scoped_refptr<Context3D> context_3d(new Context3D(result)); |
583 if (!context_3d->CreateImplementation()) | 587 if (!context_3d->CreateImplementation()) |
584 return 0; | 588 return 0; |
585 return PluginResourceTracker::GetInstance()->AddResource(context_3d); | 589 return context_3d->GetReference(); |
586 } | 590 } |
587 | 591 |
588 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 592 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
589 bool handled = true; | 593 bool handled = true; |
590 IPC_BEGIN_MESSAGE_MAP(PPB_Context3D_Proxy, msg) | 594 IPC_BEGIN_MESSAGE_MAP(PPB_Context3D_Proxy, msg) |
591 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Create, | 595 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Create, |
592 OnMsgCreate) | 596 OnMsgCreate) |
593 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_BindSurfaces, | 597 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_BindSurfaces, |
594 OnMsgBindSurfaces) | 598 OnMsgBindSurfaces) |
595 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Initialize, | 599 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Initialize, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 uint32_t shm_size = 0; | 724 uint32_t shm_size = 0; |
721 if (enter.succeeded() && | 725 if (enter.succeeded() && |
722 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { | 726 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { |
723 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | 727 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); |
724 *size = shm_size; | 728 *size = shm_size; |
725 } | 729 } |
726 } | 730 } |
727 | 731 |
728 } // namespace proxy | 732 } // namespace proxy |
729 } // namespace pp | 733 } // namespace pp |
OLD | NEW |