Chromium Code Reviews| Index: ppapi/proxy/ppb_image_data_proxy.cc |
| diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc |
| index 999ab8187e96fc1f5e6d9c8273e7262a3b4a8d00..bb0b7cd7aa83eb4d67f792391e651aef3282adcb 100644 |
| --- a/ppapi/proxy/ppb_image_data_proxy.cc |
| +++ b/ppapi/proxy/ppb_image_data_proxy.cc |
| @@ -307,32 +307,12 @@ void ImageDataCache::OnTimer(PP_Instance instance) { |
| // ImageData ------------------------------------------------------------------- |
| -#if !defined(OS_NACL) |
| ImageData::ImageData(const HostResource& resource, |
| - const PP_ImageDataDesc& desc, |
| - ImageHandle handle) |
| + const PP_ImageDataDesc& desc) |
| : Resource(OBJECT_IS_PROXY, resource), |
| desc_(desc), |
| is_candidate_for_reuse_(false) { |
| -#if defined(OS_WIN) |
| - transport_dib_.reset(TransportDIB::CreateWithHandle(handle)); |
| -#else |
| - transport_dib_.reset(TransportDIB::Map(handle)); |
| -#endif // defined(OS_WIN) |
| } |
| -#else // !defined(OS_NACL) |
| - |
| -ImageData::ImageData(const HostResource& resource, |
| - const PP_ImageDataDesc& desc, |
| - const base::SharedMemoryHandle& handle) |
| - : Resource(OBJECT_IS_PROXY, resource), |
| - desc_(desc), |
| - shm_(handle, false /* read_only */), |
| - size_(desc.size.width * desc.size.height * 4), |
| - map_count_(0), |
| - is_candidate_for_reuse_(false) { |
| -} |
| -#endif // else, !defined(OS_NACL) |
| ImageData::~ImageData() { |
| } |
| @@ -358,12 +338,44 @@ PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { |
| return PP_TRUE; |
| } |
| -void* ImageData::Map() { |
| -#if defined(OS_NACL) |
| - if (map_count_++ == 0) |
| - shm_.Map(size_); |
| - return shm_.memory(); |
| +int32_t ImageData::GetSharedMemory(int* /* handle */, |
| + uint32_t* /* byte_count */) { |
| + // Not supported in the proxy (this method is for actually implementing the |
| + // proxy in the host). |
| + return PP_ERROR_NOACCESS; |
| +} |
| + |
| +void ImageData::SetIsCandidateForReuse() { |
| + is_candidate_for_reuse_ = true; |
| +} |
| + |
| +void ImageData::RecycleToPlugin(bool zero_contents) { |
| + is_candidate_for_reuse_ = false; |
| + if (zero_contents) { |
| + void* data = Map(); |
| + memset(data, 0, desc_.stride * desc_.size.height); |
| + Unmap(); |
| + } |
| +} |
| + |
| +// PlatformImageData ----------------------------------------------------------- |
| + |
| +#if !defined(OS_NACL) |
| +PlatformImageData::PlatformImageData(const HostResource& resource, |
| + const PP_ImageDataDesc& desc, |
| + ImageHandle handle) |
| + : ImageData(resource, desc) { |
| +#if defined(OS_WIN) |
| + transport_dib_.reset(TransportDIB::CreateWithHandle(handle)); |
| #else |
| + transport_dib_.reset(TransportDIB::Map(handle)); |
| +#endif // defined(OS_WIN) |
| +} |
| + |
| +PlatformImageData::~PlatformImageData() { |
| +} |
| + |
| +void* PlatformImageData::Map() { |
| if (!mapped_canvas_.get()) { |
| mapped_canvas_.reset(transport_dib_->GetPlatformCanvas(desc_.size.width, |
| desc_.size.height)); |
| @@ -375,59 +387,24 @@ void* ImageData::Map() { |
| bitmap.lockPixels(); |
| return bitmap.getAddr(0, 0); |
| -#endif |
| } |
| -void ImageData::Unmap() { |
| -#if defined(OS_NACL) |
| - if (--map_count_ == 0) |
| - shm_.Unmap(); |
| -#else |
| +void PlatformImageData::Unmap() { |
| // TODO(brettw) have a way to unmap a TransportDIB. Currently this isn't |
| // possible since deleting the TransportDIB also frees all the handles. |
| // We need to add a method to TransportDIB to release the handles. |
| -#endif |
| -} |
| - |
| -int32_t ImageData::GetSharedMemory(int* /* handle */, |
| - uint32_t* /* byte_count */) { |
| - // Not supported in the proxy (this method is for actually implementing the |
| - // proxy in the host). |
| - return PP_ERROR_NOACCESS; |
| } |
| -SkCanvas* ImageData::GetPlatformCanvas() { |
| -#if defined(OS_NACL) |
| - return NULL; // No canvas in NaCl. |
| -#else |
| +SkCanvas* PlatformImageData::GetPlatformCanvas() { |
| return mapped_canvas_.get(); |
| -#endif |
| } |
| -SkCanvas* ImageData::GetCanvas() { |
| -#if defined(OS_NACL) |
| - return NULL; // No canvas in NaCl. |
| -#else |
| +SkCanvas* PlatformImageData::GetCanvas() { |
| return mapped_canvas_.get(); |
| -#endif |
| -} |
| - |
| -void ImageData::SetIsCandidateForReuse() { |
| - is_candidate_for_reuse_ = true; |
| -} |
| - |
| -void ImageData::RecycleToPlugin(bool zero_contents) { |
| - is_candidate_for_reuse_ = false; |
| - if (zero_contents) { |
| - void* data = Map(); |
| - memset(data, 0, desc_.stride * desc_.size.height); |
| - Unmap(); |
| - } |
| } |
| -#if !defined(OS_NACL) |
| // static |
| -ImageHandle ImageData::NullHandle() { |
| +ImageHandle PlatformImageData::NullHandle() { |
| #if defined(OS_WIN) |
| return NULL; |
| #elif defined(TOOLKIT_GTK) |
| @@ -437,7 +414,7 @@ ImageHandle ImageData::NullHandle() { |
| #endif |
| } |
| -ImageHandle ImageData::HandleFromInt(int32_t i) { |
| +ImageHandle PlatformImageData::HandleFromInt(int32_t i) { |
| #if defined(OS_WIN) |
| return reinterpret_cast<ImageHandle>(i); |
| #elif defined(TOOLKIT_GTK) |
| @@ -448,6 +425,39 @@ ImageHandle ImageData::HandleFromInt(int32_t i) { |
| } |
| #endif // !defined(OS_NACL) |
| +// SimpleImageData ------------------------------------------------------------- |
| + |
| +SimpleImageData::SimpleImageData(const HostResource& resource, |
| + const PP_ImageDataDesc& desc, |
| + const base::SharedMemoryHandle& handle) |
| + : ImageData(resource, desc), |
| + shm_(handle, false /* read_only */), |
| + size_(desc.size.width * desc.size.height * 4), |
| + map_count_(0) { |
| +} |
| + |
| +SimpleImageData::~SimpleImageData() { |
| +} |
| + |
| +void* SimpleImageData::Map() { |
| + if (map_count_++ == 0) |
| + shm_.Map(size_); |
| + return shm_.memory(); |
| +} |
| + |
| +void SimpleImageData::Unmap() { |
| + if (--map_count_ == 0) |
| + shm_.Unmap(); |
| +} |
| + |
| +SkCanvas* SimpleImageData::GetPlatformCanvas() { |
| + return NULL; // No canvas available. |
| +} |
| + |
| +SkCanvas* SimpleImageData::GetCanvas() { |
| + return NULL; // No canvas available. |
| +} |
| + |
| // PPB_ImageData_Proxy --------------------------------------------------------- |
| PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher) |
| @@ -461,7 +471,8 @@ PPB_ImageData_Proxy::~PPB_ImageData_Proxy() { |
| PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance, |
| PP_ImageDataFormat format, |
| const PP_Size& size, |
| - PP_Bool init_to_zero) { |
| + PP_Bool init_to_zero, |
| + PP_Bool platform) { |
| PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| if (!dispatcher) |
| return 0; |
| @@ -477,39 +488,37 @@ PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance, |
| } |
| HostResource result; |
| - std::string image_data_desc; |
| + PP_ImageDataDesc desc; |
| #if defined(OS_NACL) |
|
dmichael (off chromium)
2013/06/10 18:07:29
I think you want to change to checking platform at
bbudge
2013/06/10 23:28:37
Good catch.
|
| ppapi::proxy::SerializedHandle image_handle_wrapper; |
| - dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateNaCl( |
| + dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateSimple( |
| kApiID, instance, format, size, init_to_zero, |
| - &result, &image_data_desc, &image_handle_wrapper)); |
| + &result, &desc, &image_handle_wrapper)); |
| if (!image_handle_wrapper.is_shmem()) |
| return 0; |
| base::SharedMemoryHandle image_handle = image_handle_wrapper.shmem(); |
| + if (!result.is_null()) |
| + return (new SimpleImageData(result, desc, image_handle))->GetReference(); |
| #else |
| - ImageHandle image_handle = ImageData::NullHandle(); |
| - dispatcher->Send(new PpapiHostMsg_PPBImageData_Create( |
| + ImageHandle image_handle = PlatformImageData::NullHandle(); |
| + dispatcher->Send(new PpapiHostMsg_PPBImageData_CreatePlatform( |
| kApiID, instance, format, size, init_to_zero, |
| - &result, &image_data_desc, &image_handle)); |
| + &result, &desc, &image_handle)); |
| + if (!result.is_null()) |
| + return (new PlatformImageData(result, desc, image_handle))->GetReference(); |
| #endif |
| - if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc)) |
| - return 0; |
| - |
| - // We serialize the PP_ImageDataDesc just by copying to a string. |
| - PP_ImageDataDesc desc; |
| - memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); |
| - |
| - return (new ImageData(result, desc, image_handle))->GetReference(); |
| + return 0; |
| } |
| bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg) |
| #if !defined(OS_NACL) |
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate) |
| - IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreateNaCl, |
| - OnHostMsgCreateNaCl) |
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreatePlatform, |
| + OnHostMsgCreatePlatform) |
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreateSimple, |
| + OnHostMsgCreateSimple) |
| #endif |
| IPC_MESSAGE_HANDLER(PpapiMsg_PPBImageData_NotifyUnusedImageData, |
| OnPluginMsgNotifyUnusedImageData) |
| @@ -526,7 +535,7 @@ PP_Resource PPB_ImageData_Proxy::CreateImageData( |
| PP_ImageDataFormat format, |
| const PP_Size& size, |
| bool init_to_zero, |
| - bool is_nacl_plugin, |
| + bool platform, |
| PP_ImageDataDesc* desc, |
| IPC::PlatformFileForTransit* image_handle, |
| uint32_t* byte_count) { |
| @@ -541,11 +550,11 @@ PP_Resource PPB_ImageData_Proxy::CreateImageData( |
| PP_Bool pp_init_to_zero = init_to_zero ? PP_TRUE : PP_FALSE; |
| ppapi::ScopedPPResource resource( |
| ppapi::ScopedPPResource::PassRef(), |
| - is_nacl_plugin ? |
| - enter.functions()->CreateImageDataNaCl(instance, format, &size, |
| - pp_init_to_zero) : |
| - enter.functions()->CreateImageData(instance, format, &size, |
| - pp_init_to_zero)); |
| + platform ? |
| + enter.functions()->CreateImageDataPlatform(instance, format, &size, |
| + pp_init_to_zero) : |
| + enter.functions()->CreateImageDataSimple(instance, format, &size, |
| + pp_init_to_zero)); |
| if (!resource.get()) |
| return 0; |
| @@ -567,11 +576,13 @@ PP_Resource PPB_ImageData_Proxy::CreateImageData( |
| *image_handle = dispatcher->ShareHandleWithRemote( |
| reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)), false); |
| #elif defined(TOOLKIT_GTK) |
| - // On X Windows, a non-nacl handle is a SysV shared memory key. |
| - if (is_nacl_plugin) |
| - *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
| - else |
| + // On X Windows, a PlatformImageData is backed by a SysV shared memory key, |
| + // so embed that in a fake PlatformFileForTransit and don't share it across |
| + // processes. |
| + if (platform) |
| *image_handle = IPC::PlatformFileForTransit(local_fd, false); |
| + else |
| + *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
| #elif defined(OS_POSIX) |
| *image_handle = dispatcher->ShareHandleWithRemote(local_fd, false); |
| #else |
| @@ -581,14 +592,14 @@ PP_Resource PPB_ImageData_Proxy::CreateImageData( |
| return resource.Release(); |
| } |
| -void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, |
| - int32_t format, |
| - const PP_Size& size, |
| - PP_Bool init_to_zero, |
| - HostResource* result, |
| - std::string* image_data_desc, |
| - ImageHandle* result_image_handle) { |
| - PP_ImageDataDesc desc; |
| +void PPB_ImageData_Proxy::OnHostMsgCreatePlatform( |
| + PP_Instance instance, |
| + int32_t format, |
| + const PP_Size& size, |
| + PP_Bool init_to_zero, |
| + HostResource* result, |
| + PP_ImageDataDesc* desc, |
| + ImageHandle* result_image_handle) { |
| IPC::PlatformFileForTransit image_handle; |
| uint32_t byte_count; |
| PP_Resource resource = |
| @@ -596,12 +607,10 @@ void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, |
| static_cast<PP_ImageDataFormat>(format), |
| size, |
| true /* init_to_zero */, |
| - false /* is_nacl_plugin */, |
| - &desc, &image_handle, &byte_count); |
| + true /* platform */, |
| + desc, &image_handle, &byte_count); |
| result->SetHostResource(instance, resource); |
| if (resource) { |
| - image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
| - memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
| #if defined(TOOLKIT_GTK) |
| // On X Windows ImageHandle is a SysV shared memory key. |
| *result_image_handle = image_handle.fd; |
| @@ -609,20 +618,18 @@ void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, |
| *result_image_handle = image_handle; |
| #endif |
| } else { |
| - image_data_desc->clear(); |
| - *result_image_handle = ImageData::NullHandle(); |
| + *result_image_handle = PlatformImageData::NullHandle(); |
| } |
| } |
| -void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( |
| +void PPB_ImageData_Proxy::OnHostMsgCreateSimple( |
| PP_Instance instance, |
| int32_t format, |
| const PP_Size& size, |
| PP_Bool init_to_zero, |
| HostResource* result, |
| - std::string* image_data_desc, |
| + PP_ImageDataDesc* desc, |
| ppapi::proxy::SerializedHandle* result_image_handle) { |
| - PP_ImageDataDesc desc; |
| IPC::PlatformFileForTransit image_handle; |
| uint32_t byte_count; |
| PP_Resource resource = |
| @@ -630,16 +637,13 @@ void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( |
| static_cast<PP_ImageDataFormat>(format), |
| size, |
| true /* init_to_zero */, |
| - true /* is_nacl_plugin */, |
| - &desc, &image_handle, &byte_count); |
| + false /* platform */, |
| + desc, &image_handle, &byte_count); |
| result->SetHostResource(instance, resource); |
| if (resource) { |
| - image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
| - memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
| result_image_handle->set_shmem(image_handle, byte_count); |
| } else { |
| - image_data_desc->clear(); |
| result_image_handle->set_null_shmem(); |
| } |
| } |