Chromium Code Reviews| Index: content/renderer/pepper/ppb_image_data_impl.cc |
| diff --git a/content/renderer/pepper/ppb_image_data_impl.cc b/content/renderer/pepper/ppb_image_data_impl.cc |
| index 57cdc92bf28feac2a3b10bec6fd1160121868e38..fcf8131d37d60642cbb7ee75ac7788c42d9608fb 100644 |
| --- a/content/renderer/pepper/ppb_image_data_impl.cc |
| +++ b/content/renderer/pepper/ppb_image_data_impl.cc |
| @@ -26,16 +26,19 @@ using ppapi::thunk::PPB_ImageData_API; |
| namespace content { |
| PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance, |
| - PPB_ImageData_Shared::ImageDataType type) |
| + PPB_ImageData_Shared::ImageDataType type, |
| + bool is_browser_allocated) |
|
bbudge
2013/11/11 12:24:06
Couldn't we just call IsBrowserAllocated on the ty
bbudge
2013/11/11 19:09:15
Never mind, I realized this is the whole point of
|
| : Resource(ppapi::OBJECT_IS_IMPL, instance), |
| format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), |
| width_(0), |
| height_(0) { |
| switch (type) { |
| case PPB_ImageData_Shared::PLATFORM: |
| - backend_.reset(new ImageDataPlatformBackend); |
| + backend_.reset(new ImageDataPlatformBackend(is_browser_allocated)); |
| return; |
| case PPB_ImageData_Shared::SIMPLE: |
| + DCHECK(!is_browser_allocated) << |
| + "PPB_ImageData_Shared::SIMPLE is always allocated in the renderer."; |
| backend_.reset(new ImageDataSimpleBackend); |
| return; |
| // No default: so that we get a compiler warning if any types are added. |
| @@ -46,6 +49,18 @@ PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance, |
| PPB_ImageData_Impl::~PPB_ImageData_Impl() { |
| } |
| +// static |
| +bool PPB_ImageData_Impl::IsBrowserAllocated(ImageDataType format) { |
| + if (format == PPB_ImageData_Shared::SIMPLE) |
| + return false; |
| +#if defined(OS_POSIX) && !defined(TOOLKIT_GTK) && !defined(OS_ANDROID) |
| + // On the Mac, shared memory has to be created in the browser in order to |
| + // work in the sandbox. |
| + return true; |
| +#endif |
| + return false; |
| +} |
| + |
| bool PPB_ImageData_Impl::Init(PP_ImageDataFormat format, |
| int width, int height, |
| bool init_to_zero) { |
| @@ -71,7 +86,7 @@ PP_Resource PPB_ImageData_Impl::Create(PP_Instance instance, |
| const PP_Size& size, |
| PP_Bool init_to_zero) { |
| scoped_refptr<PPB_ImageData_Impl> |
| - data(new PPB_ImageData_Impl(instance, type)); |
| + data(new PPB_ImageData_Impl(instance, type, IsBrowserAllocated(type))); |
| if (!data->Init(format, size.width, size.height, !!init_to_zero)) |
| return 0; |
| return data->GetReference(); |
| @@ -127,19 +142,20 @@ const SkBitmap* PPB_ImageData_Impl::GetMappedBitmap() const { |
| // ImageDataPlatformBackend ---------------------------------------------------- |
| -ImageDataPlatformBackend::ImageDataPlatformBackend() |
| +ImageDataPlatformBackend::ImageDataPlatformBackend(bool is_browser_allocated) |
| : width_(0), |
| - height_(0) { |
| + height_(0), |
| + is_browser_allocated_(is_browser_allocated) { |
| } |
| // On POSIX, we have to tell the browser to free the transport DIB. |
| ImageDataPlatformBackend::~ImageDataPlatformBackend() { |
| -#if defined(OS_POSIX) && !defined(TOOLKIT_GTK) && !defined(OS_ANDROID) |
| - if (dib_) { |
| - RenderThreadImpl::current()->Send( |
| - new ViewHostMsg_FreeTransportDIB(dib_->id())); |
| + if (is_browser_allocated_) { |
| + if (dib_) { |
| + RenderThreadImpl::current()->Send( |
| + new ViewHostMsg_FreeTransportDIB(dib_->id())); |
| + } |
| } |
| -#endif |
| } |
| bool ImageDataPlatformBackend::Init(PPB_ImageData_Impl* impl, |
| @@ -152,30 +168,29 @@ bool ImageDataPlatformBackend::Init(PPB_ImageData_Impl* impl, |
| uint32 buffer_size = width_ * height_ * 4; |
| // Allocate the transport DIB and the PlatformCanvas pointing to it. |
| -#if defined(OS_POSIX) && !defined(TOOLKIT_GTK) && !defined(OS_ANDROID) |
| - // On the Mac, shared memory has to be created in the browser in order to |
| - // work in the sandbox. Do this by sending a message to the browser |
| - // requesting a TransportDIB (see also |
| - // chrome/renderer/webplugin_delegate_proxy.cc, method |
| - // WebPluginDelegateProxy::CreateBitmap() for similar code). The TransportDIB |
| - // is cached in the browser, and is freed (in typical cases) by the |
| - // TransportDIB's destructor. |
| - TransportDIB::Handle dib_handle; |
| - IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(buffer_size, |
| - true, |
| - &dib_handle); |
| - if (!RenderThreadImpl::current()->Send(msg)) |
| - return false; |
| - if (!TransportDIB::is_valid_handle(dib_handle)) |
| - return false; |
| - |
| - TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle); |
| -#else |
| - static int next_dib_id = 0; |
| - TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++); |
| - if (!dib) |
| - return false; |
| -#endif |
| + TransportDIB* dib = NULL; |
| + if (is_browser_allocated_) { |
| + // Allocate the image data by sending a message to the browser requesting a |
| + // TransportDIB (see also chrome/renderer/webplugin_delegate_proxy.cc, |
| + // method WebPluginDelegateProxy::CreateBitmap() for similar code). The |
| + // TransportDIB is cached in the browser, and is freed (in typical cases) by |
| + // the TransportDIB's destructor. |
| + TransportDIB::Handle dib_handle; |
| + IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(buffer_size, |
| + true, |
| + &dib_handle); |
| + if (!RenderThreadImpl::current()->Send(msg)) |
| + return false; |
| + if (!TransportDIB::is_valid_handle(dib_handle)) |
| + return false; |
| + |
| + dib = TransportDIB::CreateWithHandle(dib_handle); |
| + } else { |
| + static int next_dib_id = 0; |
| + dib = TransportDIB::Create(buffer_size, next_dib_id++); |
| + if (!dib) |
| + return false; |
| + } |
| dib_.reset(dib); |
| return true; |
| } |