Disable ContentSettingBubbleModelTest.RPHAllow which is flaky.
[chromium-blink-merge.git] / content / renderer / pepper / pepper_platform_image_2d_impl.cc
blob4a0b4f1bc7a3fe74b27ec1bc44ee0fe7ae84735d
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"
12 namespace content {
14 PepperPlatformImage2DImpl::PepperPlatformImage2DImpl(int width,
15 int height,
16 TransportDIB* dib)
17 : width_(width),
18 height_(height),
19 dib_(dib) {
22 // On Mac, we have to tell the browser to free the transport DIB.
23 PepperPlatformImage2DImpl::~PepperPlatformImage2DImpl() {
24 #if defined(OS_MACOSX)
25 if (dib_) {
26 RenderThreadImpl::current()->Send(
27 new ViewHostMsg_FreeTransportDIB(dib_->id()));
29 #endif
32 // static
33 PepperPlatformImage2DImpl* PepperPlatformImage2DImpl::Create(int width,
34 int height) {
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,
48 true,
49 &dib_handle);
50 if (!RenderThreadImpl::current()->Send(msg))
51 return NULL;
52 if (!TransportDIB::is_valid_handle(dib_handle))
53 return NULL;
55 TransportDIB* dib = TransportDIB::CreateWithHandle(dib_handle);
56 #else
57 static int next_dib_id = 0;
58 TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++);
59 if (!dib)
60 return NULL;
61 #endif
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();
73 #if defined(OS_WIN)
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());
79 #endif
82 TransportDIB* PepperPlatformImage2DImpl::GetTransportDIB() const {
83 return dib_.get();
86 } // namespace content