| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 if (pp_draw && !draw_surface) | 412 if (pp_draw && !draw_surface) |
| 412 return PP_ERROR_BADRESOURCE; | 413 return PP_ERROR_BADRESOURCE; |
| 413 if (pp_read && !read_surface) | 414 if (pp_read && !read_surface) |
| 414 return PP_ERROR_BADRESOURCE; | 415 return PP_ERROR_BADRESOURCE; |
| 415 HostResource host_draw = | 416 HostResource host_draw = |
| 416 draw_surface ? draw_surface->host_resource() : HostResource(); | 417 draw_surface ? draw_surface->host_resource() : HostResource(); |
| 417 HostResource host_read = | 418 HostResource host_read = |
| 418 read_surface ? read_surface->host_resource() : HostResource(); | 419 read_surface ? read_surface->host_resource() : HostResource(); |
| 419 | 420 |
| 420 int32_t result; | 421 int32_t result; |
| 421 GetDispatcher()->Send(new PpapiHostMsg_PPBContext3D_BindSurfaces( | 422 PluginDispatcher::GetForResource(this)->Send( |
| 422 INTERFACE_ID_PPB_CONTEXT_3D, | 423 new PpapiHostMsg_PPBContext3D_BindSurfaces( |
| 423 host_resource(), host_draw, host_read, &result)); | 424 INTERFACE_ID_PPB_CONTEXT_3D, |
| 425 host_resource(), host_draw, host_read, &result)); |
| 424 if (result != PP_OK) | 426 if (result != PP_OK) |
| 425 return result; | 427 return result; |
| 426 | 428 |
| 427 if (draw_surface != draw_) { | 429 if (draw_surface != draw_) { |
| 428 if (draw_) | 430 if (draw_) |
| 429 draw_->set_context(NULL); | 431 draw_->set_context(NULL); |
| 430 if (draw_surface) { | 432 if (draw_surface) { |
| 431 draw_surface->set_context(this); | 433 draw_surface->set_context(this); |
| 432 // Resize the backing texture to the size of the instance when it is | 434 // Resize the backing texture to the size of the instance when it is |
| 433 // bound. | 435 // bound. |
| 434 // TODO(alokp): This should be the responsibility of plugins. | 436 // TODO(alokp): This should be the responsibility of plugins. |
| 435 InstanceData* data = GetDispatcher()->GetInstanceData(instance()); | 437 InstanceData* data = |
| 438 PluginDispatcher::GetForResource(this)->GetInstanceData( |
| 439 pp_instance()); |
| 436 gles2_impl()->ResizeCHROMIUM(data->position.size.width, | 440 gles2_impl()->ResizeCHROMIUM(data->position.size.width, |
| 437 data->position.size.height); | 441 data->position.size.height); |
| 438 } | 442 } |
| 439 draw_ = draw_surface; | 443 draw_ = draw_surface; |
| 440 } | 444 } |
| 441 read_ = read_surface; | 445 read_ = read_surface; |
| 442 return PP_OK; | 446 return PP_OK; |
| 443 } | 447 } |
| 444 | 448 |
| 445 int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { | 449 int32_t Context3D::GetBoundSurfaces(PP_Resource* draw, PP_Resource* read) { |
| 446 *draw = draw_ ? draw_->resource() : 0; | 450 *draw = draw_ ? draw_->pp_resource() : 0; |
| 447 *read = read_ ? read_->resource() : 0; | 451 *read = read_ ? read_->pp_resource() : 0; |
| 448 return PP_OK; | 452 return PP_OK; |
| 449 } | 453 } |
| 450 | 454 |
| 451 PP_Bool Context3D::InitializeTrusted(int32_t size) { | 455 PP_Bool Context3D::InitializeTrusted(int32_t size) { |
| 452 // Trusted interface not implemented in the proxy. | 456 // Trusted interface not implemented in the proxy. |
| 453 return PP_FALSE; | 457 return PP_FALSE; |
| 454 } | 458 } |
| 455 | 459 |
| 456 PP_Bool Context3D::GetRingBuffer(int* shm_handle, | 460 PP_Bool Context3D::GetRingBuffer(int* shm_handle, |
| 457 uint32_t* shm_size) { | 461 uint32_t* shm_size) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 580 |
| 577 HostResource result; | 581 HostResource result; |
| 578 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( | 582 dispatcher->Send(new PpapiHostMsg_PPBContext3D_Create( |
| 579 INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); | 583 INTERFACE_ID_PPB_CONTEXT_3D, instance, config, attribs, &result)); |
| 580 | 584 |
| 581 if (result.is_null()) | 585 if (result.is_null()) |
| 582 return 0; | 586 return 0; |
| 583 scoped_refptr<Context3D> context_3d(new Context3D(result)); | 587 scoped_refptr<Context3D> context_3d(new Context3D(result)); |
| 584 if (!context_3d->CreateImplementation()) | 588 if (!context_3d->CreateImplementation()) |
| 585 return 0; | 589 return 0; |
| 586 return PluginResourceTracker::GetInstance()->AddResource(context_3d); | 590 return context_3d->GetReference(); |
| 587 } | 591 } |
| 588 | 592 |
| 589 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { | 593 bool PPB_Context3D_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 590 bool handled = true; | 594 bool handled = true; |
| 591 IPC_BEGIN_MESSAGE_MAP(PPB_Context3D_Proxy, msg) | 595 IPC_BEGIN_MESSAGE_MAP(PPB_Context3D_Proxy, msg) |
| 592 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Create, | 596 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Create, |
| 593 OnMsgCreate) | 597 OnMsgCreate) |
| 594 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_BindSurfaces, | 598 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_BindSurfaces, |
| 595 OnMsgBindSurfaces) | 599 OnMsgBindSurfaces) |
| 596 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Initialize, | 600 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBContext3D_Initialize, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 uint32_t shm_size = 0; | 725 uint32_t shm_size = 0; |
| 722 if (enter.succeeded() && | 726 if (enter.succeeded() && |
| 723 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { | 727 enter.object()->GetTransferBuffer(id, &shm_handle, &shm_size)) { |
| 724 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); | 728 *transfer_buffer = TransportSHMHandleFromInt(dispatcher(), shm_handle); |
| 725 *size = shm_size; | 729 *size = shm_size; |
| 726 } | 730 } |
| 727 } | 731 } |
| 728 | 732 |
| 729 } // namespace proxy | 733 } // namespace proxy |
| 730 } // namespace pp | 734 } // namespace pp |
| OLD | NEW |