Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: chrome/renderer/pepper_plugin_delegate_impl.cc

Issue 1697008: New Pepper API implementation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/pepper_plugin_delegate_impl.h ('k') | webkit/glue/plugins/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "chrome/renderer/pepper_plugin_delegate_impl.h"
6
7 #include "app/surface/transport_dib.h"
8 #include "base/scoped_ptr.h"
9
10 namespace {
11
12 // Implements the Image2D using a TransportDIB.
13 class PlatformImage2DImpl : public pepper::PluginDelegate::PlatformImage2D {
14 public:
15 // This constructor will take ownership of the dib pointer.
16 PlatformImage2DImpl(int width, int height, TransportDIB* dib)
17 : width_(width),
18 height_(height),
19 dib_(dib) {
20 }
21
22 virtual skia::PlatformCanvas* Map() {
23 return dib_->GetPlatformCanvas(width_, height_);
24 }
25
26 virtual intptr_t GetSharedMemoryHandle() const {
27 return dib_->handle();
28 }
29
30 private:
31 int width_;
32 int height_;
33 scoped_ptr<TransportDIB> dib_;
34
35 DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl);
36 };
37
38 } // namespace
39
40 PepperPluginDelegateImpl::PepperPluginDelegateImpl(RenderView* render_view)
41 : render_view_(render_view) {
42 }
43
44 pepper::PluginDelegate::PlatformImage2D*
45 PepperPluginDelegateImpl::CreateImage2D(int width, int height) {
46 uint32 buffer_size = width * height * 4;
47
48 // Allocate the transport DIB and the PlatformCanvas pointing to it.
49 #if defined(OS_MACOSX)
50 // On the Mac, shared memory has to be created in the browser in order to
51 // work in the sandbox. Do this by sending a message to the browser
52 // requesting a TransportDIB (see also
53 // chrome/renderer/webplugin_delegate_proxy.cc, method
54 // WebPluginDelegateProxy::CreateBitmap() for similar code). Note that the
55 // TransportDIB is _not_ cached in the browser; this is because this memory
56 // gets flushed by the renderer into another TransportDIB that represents the
57 // page, which is then in turn flushed to the screen by the browser process.
58 // When |transport_dib_| goes out of scope in the dtor, all of its shared
59 // memory gets reclaimed.
60 TransportDIB::Handle dib_handle;
61 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(buffer_size,
62 false,
63 &dib_handle);
64 if (!RenderThread::current()->Send(msg))
65 return NULL;
66 if (!TransportDIB::is_valid(dib_handle))
67 return NULL;
68
69 TransportDIB* dib = TransportDIB::Map(dib_handle);
70 #else
71 static int next_dib_id = 0;
72 TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++);
73 if (!dib)
74 return NULL;
75 #endif
76
77 return new PlatformImage2DImpl(width, height, dib);
78 }
OLDNEW
« no previous file with comments | « chrome/renderer/pepper_plugin_delegate_impl.h ('k') | webkit/glue/plugins/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698