diff options
Diffstat (limited to 'ppapi/proxy')
-rw-r--r-- | ppapi/proxy/ppapi_messages.h | 8 | ||||
-rw-r--r-- | ppapi/proxy/ppb_buffer_proxy.cc | 3 | ||||
-rw-r--r-- | ppapi/proxy/ppb_buffer_proxy.h | 3 | ||||
-rw-r--r-- | ppapi/proxy/ppb_image_data_proxy.cc | 114 | ||||
-rw-r--r-- | ppapi/proxy/ppb_image_data_proxy.h | 27 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.cc | 11 | ||||
-rw-r--r-- | ppapi/proxy/resource_creation_proxy.h | 4 |
7 files changed, 155 insertions, 15 deletions
diff --git a/ppapi/proxy/ppapi_messages.h b/ppapi/proxy/ppapi_messages.h index b57e8eb..16cc01b 100644 --- a/ppapi/proxy/ppapi_messages.h +++ b/ppapi/proxy/ppapi_messages.h @@ -909,6 +909,14 @@ IPC_SYNC_MESSAGE_ROUTED4_3(PpapiHostMsg_PPBImageData_Create, ppapi::HostResource /* result_resource */, std::string /* image_data_desc */, ppapi::proxy::ImageHandle /* result */) +IPC_SYNC_MESSAGE_ROUTED4_3(PpapiHostMsg_PPBImageData_CreateNaCl, + PP_Instance /* instance */, + int32 /* format */, + PP_Size /* size */, + PP_Bool /* init_to_zero */, + ppapi::HostResource /* result_resource */, + std::string /* image_data_desc */, + base::SharedMemoryHandle /* result */) // PPB_Instance. IPC_SYNC_MESSAGE_ROUTED1_1(PpapiHostMsg_PPBInstance_GetWindowObject, diff --git a/ppapi/proxy/ppb_buffer_proxy.cc b/ppapi/proxy/ppb_buffer_proxy.cc index 03a57d5..6c4561d 100644 --- a/ppapi/proxy/ppb_buffer_proxy.cc +++ b/ppapi/proxy/ppb_buffer_proxy.cc @@ -29,7 +29,6 @@ Buffer::Buffer(const HostResource& resource, : Resource(OBJECT_IS_PROXY, resource), shm_(shm_handle, false), size_(size), - mapped_data_(NULL), map_count_(0) { } @@ -47,7 +46,7 @@ PP_Bool Buffer::Describe(uint32_t* size_in_bytes) { } PP_Bool Buffer::IsMapped() { - return PP_FromBool(!!mapped_data_); + return PP_FromBool(map_count_ > 0); } void* Buffer::Map() { diff --git a/ppapi/proxy/ppb_buffer_proxy.h b/ppapi/proxy/ppb_buffer_proxy.h index 08a2753..cc8f598 100644 --- a/ppapi/proxy/ppb_buffer_proxy.h +++ b/ppapi/proxy/ppb_buffer_proxy.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,7 +36,6 @@ class Buffer : public thunk::PPB_Buffer_API, public Resource { private: base::SharedMemory shm_; uint32_t size_; - void* mapped_data_; int map_count_; DISALLOW_COPY_AND_ASSIGN(Buffer); diff --git a/ppapi/proxy/ppb_image_data_proxy.cc b/ppapi/proxy/ppb_image_data_proxy.cc index a92d599..2eecc0ff 100644 --- a/ppapi/proxy/ppb_image_data_proxy.cc +++ b/ppapi/proxy/ppb_image_data_proxy.cc @@ -13,6 +13,7 @@ #include "ppapi/c/pp_completion_callback.h" #include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_resource.h" +#include "ppapi/proxy/host_dispatcher.h" #include "ppapi/proxy/plugin_dispatcher.h" #include "ppapi/proxy/plugin_resource_tracker.h" #include "ppapi/proxy/ppapi_messages.h" @@ -29,21 +30,30 @@ namespace ppapi { namespace proxy { +#if !defined(OS_NACL) ImageData::ImageData(const HostResource& resource, const PP_ImageDataDesc& desc, ImageHandle handle) : Resource(OBJECT_IS_PROXY, resource), desc_(desc) { -#if defined(OS_NACL) - // TODO(brettw) implement NaCl ImageData. This will involve just - // memory-mapping the handle as raw memory rather than as a transport DIB. - NOTIMPLEMENTED(); -#elif defined(OS_WIN) +#if defined(OS_WIN) transport_dib_.reset(TransportDIB::CreateWithHandle(handle)); #else transport_dib_.reset(TransportDIB::Map(handle)); -#endif +#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) { } +#endif // !defined(OS_NACL) ImageData::~ImageData() { } @@ -59,7 +69,9 @@ PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { void* ImageData::Map() { #if defined(OS_NACL) - NOTIMPLEMENTED(); + if (map_count_++ == 0) + shm_.Map(size_); + return shm_.memory(); #else if (!mapped_canvas_.get()) { mapped_canvas_.reset(transport_dib_->GetPlatformCanvas(desc_.size.width, @@ -77,7 +89,8 @@ void* ImageData::Map() { void ImageData::Unmap() { #if defined(OS_NACL) - NOTIMPLEMENTED(); + if (--map_count_ == 0) + shm_.Unmap(); #else // TODO(brettw) have a way to unmap a TransportDIB. Currently this isn't // possible since deleting the TransportDIB also frees all the handles. @@ -100,6 +113,15 @@ skia::PlatformCanvas* ImageData::GetPlatformCanvas() { #endif } +SkCanvas* ImageData::GetCanvas() { +#if defined(OS_NACL) + return NULL; // No canvas in NaCl. +#else + return mapped_canvas_.get(); +#endif +} + +#if !defined(OS_NACL) // static ImageHandle ImageData::NullHandle() { #if defined(OS_WIN) @@ -120,6 +142,7 @@ ImageHandle ImageData::HandleFromInt(int32_t i) { return static_cast<ImageHandle>(i); #endif } +#endif // !defined(OS_NACL) PPB_ImageData_Proxy::PPB_ImageData_Proxy(Dispatcher* dispatcher) : InterfaceProxy(dispatcher) { @@ -139,10 +162,17 @@ PP_Resource PPB_ImageData_Proxy::CreateProxyResource(PP_Instance instance, HostResource result; std::string image_data_desc; +#if defined(OS_NACL) + base::SharedMemoryHandle image_handle = base::SharedMemory::NULLHandle(); + dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateNaCl( + kApiID, instance, format, size, init_to_zero, + &result, &image_data_desc, &image_handle)); +#else ImageHandle image_handle = ImageData::NullHandle(); dispatcher->Send(new PpapiHostMsg_PPBImageData_Create( kApiID, instance, format, size, init_to_zero, &result, &image_data_desc, &image_handle)); +#endif if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc)) return 0; @@ -158,6 +188,8 @@ bool PPB_ImageData_Proxy::OnMessageReceived(const IPC::Message& msg) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PPB_ImageData_Proxy, msg) IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnHostMsgCreate) + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_CreateNaCl, + OnHostMsgCreateNaCl) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -170,6 +202,11 @@ void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, HostResource* result, std::string* image_data_desc, ImageHandle* result_image_handle) { +#if defined(OS_NACL) + // This message should never be received in untrusted code. To minimize the + // size of the IRT, we just don't handle it. + return; +#else *result_image_handle = ImageData::NullHandle(); thunk::EnterResourceCreation enter(instance); @@ -200,8 +237,67 @@ void PPB_ImageData_Proxy::OnHostMsgCreate(PP_Instance instance, *result_image_handle = dispatcher()->ShareHandleWithRemote(ih, false); #else *result_image_handle = ImageData::HandleFromInt(handle); -#endif +#endif // defined(OS_WIN) + } +#endif // defined(OS_NACL) +} + +void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( + PP_Instance instance, + int32_t format, + const PP_Size& size, + PP_Bool init_to_zero, + HostResource* result, + std::string* image_data_desc, + base::SharedMemoryHandle* result_image_handle) { +#if defined(OS_NACL) + // This message should never be received in untrusted code. To minimize the + // size of the IRT, we just don't handle it. + return; +#else + *result_image_handle = base::SharedMemory::NULLHandle(); + HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); + if (!dispatcher) + return; + + thunk::EnterResourceCreation enter(instance); + if (enter.failed()) + return; + + PP_Resource resource = enter.functions()->CreateImageDataNaCl( + instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); + if (!resource) + return; + result->SetHostResource(instance, resource); + + // Get the description, it's just serialized as a string. + thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_resource( + resource, false); + if (enter_resource.failed()) + return; + PP_ImageDataDesc desc; + if (enter_resource.object()->Describe(&desc) == PP_TRUE) { + image_data_desc->resize(sizeof(PP_ImageDataDesc)); + memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); } + int local_fd; + uint32_t byte_count; + if (enter_resource.object()->GetSharedMemory(&local_fd, &byte_count) != PP_OK) + return; + + // TODO(dmichael): Change trusted interface to return a PP_FileHandle, those + // casts are ugly. + base::PlatformFile platform_file = +#if defined(OS_WIN) + reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); +#elif defined(OS_POSIX) + local_fd; +#else + #error Not implemented. +#endif // defined(OS_WIN) + *result_image_handle = + dispatcher->ShareHandleWithRemote(platform_file, false); +#endif // defined(OS_NACL) } } // namespace proxy diff --git a/ppapi/proxy/ppb_image_data_proxy.h b/ppapi/proxy/ppb_image_data_proxy.h index 0fcb72a..ee80cc0 100644 --- a/ppapi/proxy/ppb_image_data_proxy.h +++ b/ppapi/proxy/ppb_image_data_proxy.h @@ -6,6 +6,7 @@ #define PPAPI_PPB_IMAGE_DATA_PROXY_H_ #include "base/memory/scoped_ptr.h" +#include "base/shared_memory.h" #include "build/build_config.h" #include "ppapi/c/pp_bool.h" #include "ppapi/c/pp_completion_callback.h" @@ -32,9 +33,19 @@ class ImageData : public ppapi::Resource, public ppapi::thunk::PPB_ImageData_API, public ppapi::PPB_ImageData_Shared { public: +#if !defined(OS_NACL) ImageData(const ppapi::HostResource& resource, const PP_ImageDataDesc& desc, ImageHandle handle); +#else + // In NaCl, we only allow creating an ImageData using a SharedMemoryHandle. + // ImageHandle can differ by host platform. We need something that is + // more consistent across platforms for NaCl, so that we can communicate to + // the host OS in a consistent way. + ImageData(const ppapi::HostResource& resource, + const PP_ImageDataDesc& desc, + const base::SharedMemoryHandle& handle); +#endif virtual ~ImageData(); // Resource overrides. @@ -46,17 +57,22 @@ class ImageData : public ppapi::Resource, virtual void Unmap() OVERRIDE; virtual int32_t GetSharedMemory(int* handle, uint32_t* byte_count) OVERRIDE; virtual skia::PlatformCanvas* GetPlatformCanvas() OVERRIDE; + virtual SkCanvas* GetCanvas() OVERRIDE; const PP_ImageDataDesc& desc() const { return desc_; } +#if !defined(OS_NACL) static ImageHandle NullHandle(); static ImageHandle HandleFromInt(int32_t i); +#endif private: PP_ImageDataDesc desc_; #if defined(OS_NACL) - // TODO(brettw) implement this (see .cc file). + base::SharedMemory shm_; + uint32 size_; + int map_count_; #else scoped_ptr<TransportDIB> transport_dib_; @@ -83,7 +99,7 @@ class PPB_ImageData_Proxy : public InterfaceProxy { static const ApiID kApiID = API_ID_PPB_IMAGE_DATA; private: - // Message handler. + // Message handlers. void OnHostMsgCreate(PP_Instance instance, int32_t format, const PP_Size& size, @@ -91,6 +107,13 @@ class PPB_ImageData_Proxy : public InterfaceProxy { HostResource* result, std::string* image_data_desc, ImageHandle* result_image_handle); + void OnHostMsgCreateNaCl(PP_Instance instance, + int32_t format, + const PP_Size& size, + PP_Bool init_to_zero, + HostResource* result, + std::string* image_data_desc, + base::SharedMemoryHandle* result_image_handle); DISALLOW_COPY_AND_ASSIGN(PPB_ImageData_Proxy); }; diff --git a/ppapi/proxy/resource_creation_proxy.cc b/ppapi/proxy/resource_creation_proxy.cc index 51dd334..7061dc1 100644 --- a/ppapi/proxy/resource_creation_proxy.cc +++ b/ppapi/proxy/resource_creation_proxy.cc @@ -189,6 +189,17 @@ PP_Resource ResourceCreationProxy::CreateImageData(PP_Instance instance, init_to_zero); } +PP_Resource ResourceCreationProxy::CreateImageDataNaCl( + PP_Instance instance, + PP_ImageDataFormat format, + const PP_Size& size, + PP_Bool init_to_zero) { + // These really only are different on the host side. On the plugin side, we + // always request a "platform" ImageData if we're trusted, or a "NaCl" one + // if we're untrusted (see PPB_ImageData_Proxy::CreateProxyResource()). + return CreateImageData(instance, format, size, init_to_zero); +} + PP_Resource ResourceCreationProxy::CreateGraphics2D(PP_Instance instance, const PP_Size& size, PP_Bool is_always_opaque) { diff --git a/ppapi/proxy/resource_creation_proxy.h b/ppapi/proxy/resource_creation_proxy.h index dbc8989..5bfb560d 100644 --- a/ppapi/proxy/resource_creation_proxy.h +++ b/ppapi/proxy/resource_creation_proxy.h @@ -98,6 +98,10 @@ class ResourceCreationProxy : public InterfaceProxy, PP_ImageDataFormat format, const PP_Size& size, PP_Bool init_to_zero) OVERRIDE; + virtual PP_Resource CreateImageDataNaCl(PP_Instance instance, + PP_ImageDataFormat format, + const PP_Size& size, + PP_Bool init_to_zero) OVERRIDE; virtual PP_Resource CreateGraphics2D(PP_Instance pp_instance, const PP_Size& size, PP_Bool is_always_opaque) OVERRIDE; |