OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_image_data_proxy.h" | 5 #include "ppapi/proxy/ppb_image_data_proxy.h" |
6 | 6 |
7 #include <string.h> // For memcpy | 7 #include <string.h> // For memcpy |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <vector> | 10 #include <vector> |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 340 |
341 void ImageData::InstanceWasDeleted() { | 341 void ImageData::InstanceWasDeleted() { |
342 ImageDataCache::GetInstance()->DidDeleteInstance(pp_instance()); | 342 ImageDataCache::GetInstance()->DidDeleteInstance(pp_instance()); |
343 } | 343 } |
344 | 344 |
345 PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { | 345 PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { |
346 memcpy(desc, &desc_, sizeof(PP_ImageDataDesc)); | 346 memcpy(desc, &desc_, sizeof(PP_ImageDataDesc)); |
347 return PP_TRUE; | 347 return PP_TRUE; |
348 } | 348 } |
349 | 349 |
350 int32_t ImageData::GetSharedMemory(int* /* handle */, | 350 int32_t ImageData::GetSharedMemory(base::SharedMemoryHandle* /* handle */, |
351 uint32_t* /* byte_count */) { | 351 uint32_t* /* byte_count */) { |
352 // Not supported in the proxy (this method is for actually implementing the | 352 // Not supported in the proxy (this method is for actually implementing the |
353 // proxy in the host). | 353 // proxy in the host). |
354 return PP_ERROR_NOACCESS; | 354 return PP_ERROR_NOACCESS; |
355 } | 355 } |
356 | 356 |
357 void ImageData::SetIsCandidateForReuse() { | 357 void ImageData::SetIsCandidateForReuse() { |
358 is_candidate_for_reuse_ = true; | 358 is_candidate_for_reuse_ = true; |
359 } | 359 } |
360 | 360 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 | 548 |
549 #if !defined(OS_NACL) | 549 #if !defined(OS_NACL) |
550 // static | 550 // static |
551 PP_Resource PPB_ImageData_Proxy::CreateImageData( | 551 PP_Resource PPB_ImageData_Proxy::CreateImageData( |
552 PP_Instance instance, | 552 PP_Instance instance, |
553 PPB_ImageData_Shared::ImageDataType type, | 553 PPB_ImageData_Shared::ImageDataType type, |
554 PP_ImageDataFormat format, | 554 PP_ImageDataFormat format, |
555 const PP_Size& size, | 555 const PP_Size& size, |
556 bool init_to_zero, | 556 bool init_to_zero, |
557 PP_ImageDataDesc* desc, | 557 PP_ImageDataDesc* desc, |
558 IPC::PlatformFileForTransit* image_handle, | 558 base::SharedMemoryHandle* image_handle, |
559 uint32_t* byte_count) { | 559 uint32_t* byte_count) { |
560 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 560 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
561 if (!dispatcher) | 561 if (!dispatcher) |
562 return 0; | 562 return 0; |
563 | 563 |
564 thunk::EnterResourceCreation enter(instance); | 564 thunk::EnterResourceCreation enter(instance); |
565 if (enter.failed()) | 565 if (enter.failed()) |
566 return 0; | 566 return 0; |
567 | 567 |
568 PP_Bool pp_init_to_zero = init_to_zero ? PP_TRUE : PP_FALSE; | 568 PP_Bool pp_init_to_zero = init_to_zero ? PP_TRUE : PP_FALSE; |
(...skipping 17 matching lines...) Expand all Loading... |
586 ppapi::ScopedPPResource resource(ppapi::ScopedPPResource::PassRef(), | 586 ppapi::ScopedPPResource resource(ppapi::ScopedPPResource::PassRef(), |
587 pp_resource); | 587 pp_resource); |
588 | 588 |
589 thunk::EnterResourceNoLock<PPB_ImageData_API> enter_resource(resource.get(), | 589 thunk::EnterResourceNoLock<PPB_ImageData_API> enter_resource(resource.get(), |
590 false); | 590 false); |
591 if (enter_resource.object()->Describe(desc) != PP_TRUE) { | 591 if (enter_resource.object()->Describe(desc) != PP_TRUE) { |
592 DVLOG(1) << "CreateImageData failed: could not Describe"; | 592 DVLOG(1) << "CreateImageData failed: could not Describe"; |
593 return 0; | 593 return 0; |
594 } | 594 } |
595 | 595 |
596 int local_fd = 0; | 596 base::SharedMemoryHandle local_handle; |
597 if (enter_resource.object()->GetSharedMemory(&local_fd, | 597 if (enter_resource.object()->GetSharedMemory(&local_handle, byte_count) != |
598 byte_count) != PP_OK) { | 598 PP_OK) { |
599 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory"; | 599 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory"; |
600 return 0; | 600 return 0; |
601 } | 601 } |
602 | 602 |
603 #if defined(OS_WIN) | 603 *image_handle = dispatcher->ShareSharedMemoryHandleWithRemote(local_handle); |
604 *image_handle = dispatcher->ShareHandleWithRemote( | |
605 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); | |
606 #elif defined(OS_POSIX) | |
607 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); | |
608 #else | |
609 #error Not implemented. | |
610 #endif | |
611 | |
612 return resource.Release(); | 604 return resource.Release(); |
613 } | 605 } |
614 | 606 |
615 void PPB_ImageData_Proxy::OnHostMsgCreatePlatform( | 607 void PPB_ImageData_Proxy::OnHostMsgCreatePlatform( |
616 PP_Instance instance, | 608 PP_Instance instance, |
617 int32_t format, | 609 int32_t format, |
618 const PP_Size& size, | 610 const PP_Size& size, |
619 PP_Bool init_to_zero, | 611 PP_Bool init_to_zero, |
620 HostResource* result, | 612 HostResource* result, |
621 PP_ImageDataDesc* desc, | 613 PP_ImageDataDesc* desc, |
622 ImageHandle* result_image_handle) { | 614 ImageHandle* result_image_handle) { |
623 // Clear |desc| so we don't send unitialized memory to the plugin. | 615 // Clear |desc| so we don't send unitialized memory to the plugin. |
624 // https://crbug.com/391023. | 616 // https://crbug.com/391023. |
625 *desc = PP_ImageDataDesc(); | 617 *desc = PP_ImageDataDesc(); |
626 IPC::PlatformFileForTransit image_handle; | 618 base::SharedMemoryHandle image_handle; |
627 uint32_t byte_count; | 619 uint32_t byte_count; |
628 PP_Resource resource = | 620 PP_Resource resource = |
629 CreateImageData(instance, | 621 CreateImageData(instance, |
630 PPB_ImageData_Shared::PLATFORM, | 622 PPB_ImageData_Shared::PLATFORM, |
631 static_cast<PP_ImageDataFormat>(format), | 623 static_cast<PP_ImageDataFormat>(format), |
632 size, | 624 size, |
633 true /* init_to_zero */, | 625 true /* init_to_zero */, |
634 desc, &image_handle, &byte_count); | 626 desc, &image_handle, &byte_count); |
635 result->SetHostResource(instance, resource); | 627 result->SetHostResource(instance, resource); |
636 if (resource) { | 628 if (resource) { |
637 *result_image_handle = image_handle; | 629 *result_image_handle = image_handle; |
638 } else { | 630 } else { |
639 *result_image_handle = PlatformImageData::NullHandle(); | 631 *result_image_handle = PlatformImageData::NullHandle(); |
640 } | 632 } |
641 } | 633 } |
642 | 634 |
643 void PPB_ImageData_Proxy::OnHostMsgCreateSimple( | 635 void PPB_ImageData_Proxy::OnHostMsgCreateSimple( |
644 PP_Instance instance, | 636 PP_Instance instance, |
645 int32_t format, | 637 int32_t format, |
646 const PP_Size& size, | 638 const PP_Size& size, |
647 PP_Bool init_to_zero, | 639 PP_Bool init_to_zero, |
648 HostResource* result, | 640 HostResource* result, |
649 PP_ImageDataDesc* desc, | 641 PP_ImageDataDesc* desc, |
650 ppapi::proxy::SerializedHandle* result_image_handle) { | 642 ppapi::proxy::SerializedHandle* result_image_handle) { |
651 // Clear |desc| so we don't send unitialized memory to the plugin. | 643 // Clear |desc| so we don't send unitialized memory to the plugin. |
652 // https://crbug.com/391023. | 644 // https://crbug.com/391023. |
653 *desc = PP_ImageDataDesc(); | 645 *desc = PP_ImageDataDesc(); |
654 IPC::PlatformFileForTransit image_handle; | 646 base::SharedMemoryHandle image_handle; |
655 uint32_t byte_count; | 647 uint32_t byte_count; |
656 PP_Resource resource = | 648 PP_Resource resource = |
657 CreateImageData(instance, | 649 CreateImageData(instance, |
658 PPB_ImageData_Shared::SIMPLE, | 650 PPB_ImageData_Shared::SIMPLE, |
659 static_cast<PP_ImageDataFormat>(format), | 651 static_cast<PP_ImageDataFormat>(format), |
660 size, | 652 size, |
661 true /* init_to_zero */, | 653 true /* init_to_zero */, |
662 desc, &image_handle, &byte_count); | 654 desc, &image_handle, &byte_count); |
663 | 655 |
664 result->SetHostResource(instance, resource); | 656 result->SetHostResource(instance, resource); |
(...skipping 22 matching lines...) Expand all Loading... |
687 // still cached in our process, the proxy still holds a reference so we can | 679 // still cached in our process, the proxy still holds a reference so we can |
688 // remove the one the renderer just sent is. If the proxy no longer holds a | 680 // remove the one the renderer just sent is. If the proxy no longer holds a |
689 // reference, we released everything and we should also release the one the | 681 // reference, we released everything and we should also release the one the |
690 // renderer just sent us. | 682 // renderer just sent us. |
691 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( | 683 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( |
692 API_ID_PPB_CORE, old_image_data)); | 684 API_ID_PPB_CORE, old_image_data)); |
693 } | 685 } |
694 | 686 |
695 } // namespace proxy | 687 } // namespace proxy |
696 } // namespace ppapi | 688 } // namespace ppapi |
OLD | NEW |