Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(580)

Side by Side Diff: ppapi/proxy/ppb_image_data_proxy.cc

Issue 13771020: Add Pepper VideoReader and VideoWriter plumbing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, clean up some headers. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppapi_messages.h ('k') | ppapi/proxy/resource_creation_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/memory/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "ppapi/c/pp_completion_callback.h" 16 #include "ppapi/c/pp_completion_callback.h"
17 #include "ppapi/c/pp_errors.h" 17 #include "ppapi/c/pp_errors.h"
18 #include "ppapi/c/pp_resource.h" 18 #include "ppapi/c/pp_resource.h"
19 #include "ppapi/proxy/enter_proxy.h" 19 #include "ppapi/proxy/enter_proxy.h"
20 #include "ppapi/proxy/host_dispatcher.h" 20 #include "ppapi/proxy/host_dispatcher.h"
21 #include "ppapi/proxy/plugin_dispatcher.h" 21 #include "ppapi/proxy/plugin_dispatcher.h"
22 #include "ppapi/proxy/plugin_globals.h" 22 #include "ppapi/proxy/plugin_globals.h"
23 #include "ppapi/proxy/plugin_resource_tracker.h" 23 #include "ppapi/proxy/plugin_resource_tracker.h"
24 #include "ppapi/proxy/ppapi_messages.h" 24 #include "ppapi/proxy/ppapi_messages.h"
25 #include "ppapi/shared_impl/host_resource.h" 25 #include "ppapi/shared_impl/host_resource.h"
26 #include "ppapi/shared_impl/proxy_lock.h" 26 #include "ppapi/shared_impl/proxy_lock.h"
27 #include "ppapi/shared_impl/resource.h" 27 #include "ppapi/shared_impl/resource.h"
28 #include "ppapi/shared_impl/scoped_pp_resource.h"
28 #include "ppapi/thunk/enter.h" 29 #include "ppapi/thunk/enter.h"
29 #include "ppapi/thunk/thunk.h" 30 #include "ppapi/thunk/thunk.h"
30 31
31 #if !defined(OS_NACL) 32 #if !defined(OS_NACL)
32 #include "skia/ext/platform_canvas.h" 33 #include "skia/ext/platform_canvas.h"
33 #include "ui/surface/transport_dib.h" 34 #include "ui/surface/transport_dib.h"
34 #endif 35 #endif
35 36
36 using ppapi::thunk::PPB_ImageData_API; 37 using ppapi::thunk::PPB_ImageData_API;
37 38
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 IPC::PlatformFileForTransit* image_handle, 531 IPC::PlatformFileForTransit* image_handle,
531 uint32_t* byte_count) { 532 uint32_t* byte_count) {
532 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); 533 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
533 if (!dispatcher) 534 if (!dispatcher)
534 return 0; 535 return 0;
535 536
536 thunk::EnterResourceCreation enter(instance); 537 thunk::EnterResourceCreation enter(instance);
537 if (enter.failed()) 538 if (enter.failed())
538 return 0; 539 return 0;
539 540
540 PP_Resource result = 0; 541 PP_Bool pp_init_to_zero = init_to_zero ? PP_TRUE : PP_FALSE;
541 PP_Bool clear = init_to_zero ? PP_TRUE : PP_FALSE; 542 ppapi::ScopedPPResource resource(
542 if (is_nacl_plugin) { 543 ppapi::ScopedPPResource::PassRef(),
543 result = enter.functions()->CreateImageDataNaCl( 544 is_nacl_plugin ?
544 instance, static_cast<PP_ImageDataFormat>(format), &size, clear); 545 enter.functions()->CreateImageDataNaCl(instance, format, &size,
545 } else { 546 pp_init_to_zero) :
546 result = enter.functions()->CreateImageData( 547 enter.functions()->CreateImageData(instance, format, &size,
547 instance, static_cast<PP_ImageDataFormat>(format), &size, clear); 548 pp_init_to_zero));
548 } 549 if (!resource.get())
549 if (!result)
550 return 0; 550 return 0;
551 551
552 thunk::EnterResourceNoLock<PPB_ImageData_API> enter_resource(result, false); 552 thunk::EnterResourceNoLock<PPB_ImageData_API> enter_resource(resource.get(),
553 if (enter_resource.object()->Describe(desc) != PP_TRUE) 553 false);
554 if (enter_resource.object()->Describe(desc) != PP_TRUE) {
554 DVLOG(1) << "CreateImageData failed: could not Describe"; 555 DVLOG(1) << "CreateImageData failed: could not Describe";
556 return 0;
557 }
555 558
556 int local_fd = 0; 559 int local_fd = 0;
557 if (enter_resource.object()->GetSharedMemory(&local_fd, byte_count) != PP_OK) 560 if (enter_resource.object()->GetSharedMemory(&local_fd,
561 byte_count) != PP_OK) {
558 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory"; 562 DVLOG(1) << "CreateImageData failed: could not GetSharedMemory";
563 return 0;
564 }
559 565
560 #if defined(OS_WIN) 566 #if defined(OS_WIN)
561 *image_handle = dispatcher->ShareHandleWithRemote( 567 *image_handle = dispatcher->ShareHandleWithRemote(
562 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); 568 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false);
563 #elif defined(OS_MACOSX) || defined(OS_ANDROID) 569 #elif defined(OS_MACOSX) || defined(OS_ANDROID)
564 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); 570 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false);
565 #elif defined(OS_POSIX) 571 #elif defined(OS_POSIX)
566 // On X Windows, a non-nacl handle is a SysV shared memory key. 572 // On X Windows, a non-nacl handle is a SysV shared memory key.
567 if (is_nacl_plugin) 573 if (is_nacl_plugin)
568 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); 574 *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false);
569 else 575 else
570 *image_handle = IPC::PlatformFileForTransit(local_fd, false); 576 *image_handle = IPC::PlatformFileForTransit(local_fd, false);
571 #else 577 #else
572 #error Not implemented. 578 #error Not implemented.
573 #endif 579 #endif
574 580
575 return result; 581 return resource.Release();
576 } 582 }
577 583
578 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, 584 void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance,
579 int32_t format, 585 int32_t format,
580 const PP_Size& size, 586 const PP_Size& size,
581 PP_Bool init_to_zero, 587 PP_Bool init_to_zero,
582 HostResource* result, 588 HostResource* result,
583 std::string* image_data_desc, 589 std::string* image_data_desc,
584 ImageHandle* result_image_handle) { 590 ImageHandle* result_image_handle) {
585 PP_ImageDataDesc desc; 591 PP_ImageDataDesc desc;
586 IPC::PlatformFileForTransit image_handle; 592 IPC::PlatformFileForTransit image_handle;
587 uint32_t byte_count; 593 uint32_t byte_count;
588 PP_Resource resource = CreateImageData( 594 PP_Resource resource =
589 instance, 595 CreateImageData(instance,
590 static_cast<PP_ImageDataFormat>(format), 596 static_cast<PP_ImageDataFormat>(format),
591 size, 597 size,
592 true /* init_to_zero */, 598 true /* init_to_zero */,
593 false /* is_nacl_plugin */, 599 false /* is_nacl_plugin */,
594 &desc, &image_handle, &byte_count); 600 &desc, &image_handle, &byte_count);
595 result->SetHostResource(instance, resource); 601 result->SetHostResource(instance, resource);
596 if (resource) { 602 if (resource) {
597 image_data_desc->resize(sizeof(PP_ImageDataDesc)); 603 image_data_desc->resize(sizeof(PP_ImageDataDesc));
598 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); 604 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc));
599 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID) 605 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_ANDROID)
600 *result_image_handle = image_handle; 606 *result_image_handle = image_handle;
601 #else 607 #else
602 // On X Windows ImageHandle is a SysV shared memory key. 608 // On X Windows ImageHandle is a SysV shared memory key.
603 *result_image_handle = image_handle.fd; 609 *result_image_handle = image_handle.fd;
604 #endif 610 #endif
605 } else { 611 } else {
606 image_data_desc->clear(); 612 image_data_desc->clear();
607 *result_image_handle = ImageData::NullHandle(); 613 *result_image_handle = ImageData::NullHandle();
608 } 614 }
609 } 615 }
610 616
611 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( 617 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl(
612 PP_Instance instance, 618 PP_Instance instance,
613 int32_t format, 619 int32_t format,
614 const PP_Size& size, 620 const PP_Size& size,
615 PP_Bool init_to_zero, 621 PP_Bool init_to_zero,
616 HostResource* result, 622 HostResource* result,
617 std::string* image_data_desc, 623 std::string* image_data_desc,
618 ppapi::proxy::SerializedHandle* result_image_handle) { 624 ppapi::proxy::SerializedHandle* result_image_handle) {
619 PP_ImageDataDesc desc; 625 PP_ImageDataDesc desc;
620 IPC::PlatformFileForTransit image_handle; 626 IPC::PlatformFileForTransit image_handle;
621 uint32_t byte_count; 627 uint32_t byte_count;
622 PP_Resource resource = CreateImageData( 628 PP_Resource resource =
623 instance, 629 CreateImageData(instance,
624 static_cast<PP_ImageDataFormat>(format), 630 static_cast<PP_ImageDataFormat>(format),
625 size, 631 size,
626 true /* init_to_zero */, 632 true /* init_to_zero */,
627 true /* is_nacl_plugin */, 633 true /* is_nacl_plugin */,
628 &desc, &image_handle, &byte_count); 634 &desc, &image_handle, &byte_count);
629 635
630 result->SetHostResource(instance, resource); 636 result->SetHostResource(instance, resource);
631 if (resource) { 637 if (resource) {
632 image_data_desc->resize(sizeof(PP_ImageDataDesc)); 638 image_data_desc->resize(sizeof(PP_ImageDataDesc));
633 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); 639 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc));
634 result_image_handle->set_shmem(image_handle, byte_count); 640 result_image_handle->set_shmem(image_handle, byte_count);
635 } else { 641 } else {
636 image_data_desc->clear(); 642 image_data_desc->clear();
637 result_image_handle->set_null_shmem(); 643 result_image_handle->set_null_shmem();
638 } 644 }
(...skipping 17 matching lines...) Expand all
656 // still cached in our process, the proxy still holds a reference so we can 662 // still cached in our process, the proxy still holds a reference so we can
657 // remove the one the renderer just sent is. If the proxy no longer holds a 663 // remove the one the renderer just sent is. If the proxy no longer holds a
658 // reference, we released everything and we should also release the one the 664 // reference, we released everything and we should also release the one the
659 // renderer just sent us. 665 // renderer just sent us.
660 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource( 666 dispatcher()->Send(new PpapiHostMsg_PPBCore_ReleaseResource(
661 API_ID_PPB_CORE, old_image_data)); 667 API_ID_PPB_CORE, old_image_data));
662 } 668 }
663 669
664 } // namespace proxy 670 } // namespace proxy
665 } // namespace ppapi 671 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppapi_messages.h ('k') | ppapi/proxy/resource_creation_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698