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..80cc38dcd3dead824c9087574766442d7e1d8920 100644 |
--- a/content/renderer/pepper/ppb_image_data_impl.cc |
+++ b/content/renderer/pepper/ppb_image_data_impl.cc |
@@ -25,6 +25,19 @@ using ppapi::thunk::PPB_ImageData_API; |
namespace content { |
+namespace { |
+// Returns true if the ImageData shared memory should be allocated in the |
+// browser process for the current platform. |
+bool IsBrowserAllocated() { |
+#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; |
+} |
+} // namespace |
+ |
PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance, |
PPB_ImageData_Shared::ImageDataType type) |
: Resource(ppapi::OBJECT_IS_IMPL, instance), |
@@ -33,7 +46,7 @@ PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance, |
height_(0) { |
switch (type) { |
case PPB_ImageData_Shared::PLATFORM: |
- backend_.reset(new ImageDataPlatformBackend); |
+ backend_.reset(new ImageDataPlatformBackend(IsBrowserAllocated())); |
return; |
case PPB_ImageData_Shared::SIMPLE: |
backend_.reset(new ImageDataSimpleBackend); |
@@ -43,6 +56,15 @@ PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance, |
NOTREACHED(); |
} |
+PPB_ImageData_Impl::PPB_ImageData_Impl(PP_Instance instance, |
+ ForTest) |
+ : Resource(ppapi::OBJECT_IS_IMPL, instance), |
+ format_(PP_IMAGEDATAFORMAT_BGRA_PREMUL), |
+ width_(0), |
+ height_(0) { |
+ backend_.reset(new ImageDataPlatformBackend(false)); |
+} |
+ |
PPB_ImageData_Impl::~PPB_ImageData_Impl() { |
} |
@@ -127,19 +149,22 @@ 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 defined(OS_POSIX) |
+ if (dib_) { |
+ RenderThreadImpl::current()->Send( |
+ new ViewHostMsg_FreeTransportDIB(dib_->id())); |
+ } |
#endif |
+ } |
} |
bool ImageDataPlatformBackend::Init(PPB_ImageData_Impl* impl, |
@@ -152,30 +177,32 @@ 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; |
+ TransportDIB* dib = NULL; |
+ if (is_browser_allocated_) { |
+#if defined(OS_POSIX) |
+ // 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); |
#endif |
+ } else { |
+ static int next_dib_id = 0; |
+ dib = TransportDIB::Create(buffer_size, next_dib_id++); |
+ if (!dib) |
+ return false; |
+ } |
+ DCHECK(dib); |
dib_.reset(dib); |
return true; |
} |