diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-07 23:55:35 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-07 23:55:35 +0000 |
commit | e55badb64f610fa03504471ca8edd997a9d3f1b4 (patch) | |
tree | 18337beb82a19166cee0166faf9338124d5d6e78 /chrome/renderer | |
parent | 3d7a219946c1f718357d15cddb954cda5f2c92eb (diff) | |
download | chromium_src-e55badb64f610fa03504471ca8edd997a9d3f1b4.zip chromium_src-e55badb64f610fa03504471ca8edd997a9d3f1b4.tar.gz chromium_src-e55badb64f610fa03504471ca8edd997a9d3f1b4.tar.bz2 |
Partially implement the new pepper API in Chrome. This is not actually hooked
up, which will require some changes in render_view as well as the plugin list.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/1697008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 78 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 27 |
2 files changed, 105 insertions, 0 deletions
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc new file mode 100644 index 0000000..acfb9c8 --- /dev/null +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -0,0 +1,78 @@ +// Copyright (c) 2010 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. + +#include "chrome/renderer/pepper_plugin_delegate_impl.h" + +#include "app/surface/transport_dib.h" +#include "base/scoped_ptr.h" + +namespace { + +// Implements the Image2D using a TransportDIB. +class PlatformImage2DImpl : public pepper::PluginDelegate::PlatformImage2D { + public: + // This constructor will take ownership of the dib pointer. + PlatformImage2DImpl(int width, int height, TransportDIB* dib) + : width_(width), + height_(height), + dib_(dib) { + } + + virtual skia::PlatformCanvas* Map() { + return dib_->GetPlatformCanvas(width_, height_); + } + + virtual intptr_t GetSharedMemoryHandle() const { + return dib_->handle(); + } + + private: + int width_; + int height_; + scoped_ptr<TransportDIB> dib_; + + DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl); +}; + +} // namespace + +PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view) + : render_view_(render_view) { +} + +pepper::PluginDelegate::PlatformImage2D* +PepperPluginDelegateImpl::CreateImage2D(int width, int height) { + uint32 buffer_size = width * height * 4; + + // Allocate the transport DIB and the PlatformCanvas pointing to it. +#if defined(OS_MACOSX) + // 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). Note that the + // TransportDIB is _not_ cached in the browser; this is because this memory + // gets flushed by the renderer into another TransportDIB that represents the + // page, which is then in turn flushed to the screen by the browser process. + // When |transport_dib_| goes out of scope in the dtor, all of its shared + // memory gets reclaimed. + TransportDIB::Handle dib_handle; + IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(buffer_size, + false, + &dib_handle); + if (!RenderThread::current()->Send(msg)) + return NULL; + if (!TransportDIB::is_valid(dib_handle)) + return NULL; + + TransportDIB* dib = TransportDIB::Map(dib_handle); +#else + static int next_dib_id = 0; + TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++); + if (!dib) + return NULL; +#endif + + return new PlatformImage2DImpl(width, height, dib); +} diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h new file mode 100644 index 0000000..6f54a91 --- /dev/null +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -0,0 +1,27 @@ +// Copyright (c) 2010 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. + +#ifndef CHROME_RENDERER_PEPPER_PLUGIN_DELEGATE_IMPL_H_ +#define CHROME_RENDERER_PEPPER_PLUGIN_DELEGATE_IMPL_H_ + +#include "base/basictypes.h" +#include "webkit/glue/plugins/pepper_plugin_delegate.h" + +class RenderView; + +class PepperPluginDelegateImpl : public pepper::PluginDelegate { + public: + explicit PepperPluginDelegateImpl(RenderView* render_view); + + // pepper::PluginDelegate implementation. + virtual PlatformImage2D* CreateImage2D(int width, int height); + + private: + // Pointer to the RenderView that owns us. + RenderView* render_view_; + + DISALLOW_COPY_AND_ASSIGN(PepperPluginDelegateImpl); +}; + +#endif // CHROME_RENDERER_PEPPER_PLUGIN_DELEGATE_IMPL_H_ |