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
3 // found in the LICENSE file.
5 #include "content/renderer/pepper/pepper_platform_image_2d_impl.h"
7 #include "build/build_config.h"
8 #include "content/common/view_messages.h"
9 #include "content/renderer/render_thread_impl.h"
10 #include "ui/surface/transport_dib.h"
14 PepperPlatformImage2DImpl::PepperPlatformImage2DImpl(int width
,
22 // On Mac, we have to tell the browser to free the transport DIB.
23 PepperPlatformImage2DImpl::~PepperPlatformImage2DImpl() {
24 #if defined(OS_MACOSX)
26 RenderThreadImpl::current()->Send(
27 new ViewHostMsg_FreeTransportDIB(dib_
->id()));
33 PepperPlatformImage2DImpl
* PepperPlatformImage2DImpl::Create(int width
,
35 uint32 buffer_size
= width
* height
* 4;
37 // Allocate the transport DIB and the PlatformCanvas pointing to it.
38 #if defined(OS_MACOSX)
39 // On the Mac, shared memory has to be created in the browser in order to
40 // work in the sandbox. Do this by sending a message to the browser
41 // requesting a TransportDIB (see also
42 // chrome/renderer/webplugin_delegate_proxy.cc, method
43 // WebPluginDelegateProxy::CreateBitmap() for similar code). The TransportDIB
44 // is cached in the browser, and is freed (in typical cases) by the
45 // PepperPlatformImage2DImpl's destructor.
46 TransportDIB::Handle dib_handle
;
47 IPC::Message
* msg
= new ViewHostMsg_AllocTransportDIB(buffer_size
,
50 if (!RenderThreadImpl::current()->Send(msg
))
52 if (!TransportDIB::is_valid_handle(dib_handle
))
55 TransportDIB
* dib
= TransportDIB::CreateWithHandle(dib_handle
);
57 static int next_dib_id
= 0;
58 TransportDIB
* dib
= TransportDIB::Create(buffer_size
, next_dib_id
++);
63 return new PepperPlatformImage2DImpl(width
, height
, dib
);
66 SkCanvas
* PepperPlatformImage2DImpl::Map() {
67 return dib_
->GetPlatformCanvas(width_
, height_
);
70 intptr_t PepperPlatformImage2DImpl::GetSharedMemoryHandle(
71 uint32
* byte_count
) const {
72 *byte_count
= dib_
->size();
74 return reinterpret_cast<intptr_t>(dib_
->handle());
75 #elif defined(OS_MACOSX) || defined(OS_ANDROID)
76 return static_cast<intptr_t>(dib_
->handle().fd
);
77 #elif defined(OS_POSIX)
78 return static_cast<intptr_t>(dib_
->handle());
82 TransportDIB
* PepperPlatformImage2DImpl::GetTransportDIB() const {
86 } // namespace content