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

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

Issue 6359005: Mac Pepper: Make Image2D's TransportDIB available to the browser. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/pepper_plugin_delegate_impl.h" 5 #include "chrome/renderer/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/surface/transport_dib.h" 10 #include "app/surface/transport_dib.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 namespace { 62 namespace {
63 63
64 const int32 kDefaultCommandBufferSize = 1024 * 1024; 64 const int32 kDefaultCommandBufferSize = 1024 * 1024;
65 65
66 // Implements the Image2D using a TransportDIB. 66 // Implements the Image2D using a TransportDIB.
67 class PlatformImage2DImpl 67 class PlatformImage2DImpl
68 : public webkit::ppapi::PluginDelegate::PlatformImage2D { 68 : public webkit::ppapi::PluginDelegate::PlatformImage2D {
69 public: 69 public:
70 // This constructor will take ownership of the dib pointer. 70 // This constructor will take ownership of the dib pointer.
71 // On Mac, we assume that the dib is cached by the browser, so on destruction
72 // we'll tell the browser to free it.
71 PlatformImage2DImpl(int width, int height, TransportDIB* dib) 73 PlatformImage2DImpl(int width, int height, TransportDIB* dib)
72 : width_(width), 74 : width_(width),
73 height_(height), 75 height_(height),
74 dib_(dib) { 76 dib_(dib) {
75 } 77 }
76 78
79 #if defined(OS_MACOSX)
80 // On Mac, we have to tell the browser to free the transport DIB.
81 virtual ~PlatformImage2DImpl() {
82 if (dib_.get()) {
83 RenderThread::current()->Send(
84 new ViewHostMsg_FreeTransportDIB(dib_->id()));
85 }
86 }
87 #endif
88
77 virtual skia::PlatformCanvas* Map() { 89 virtual skia::PlatformCanvas* Map() {
78 return dib_->GetPlatformCanvas(width_, height_); 90 return dib_->GetPlatformCanvas(width_, height_);
79 } 91 }
80 92
81 virtual intptr_t GetSharedMemoryHandle(uint32* byte_count) const { 93 virtual intptr_t GetSharedMemoryHandle(uint32* byte_count) const {
82 *byte_count = dib_->size(); 94 *byte_count = dib_->size();
83 #if defined(OS_WIN) 95 #if defined(OS_WIN)
84 return reinterpret_cast<intptr_t>(dib_->handle()); 96 return reinterpret_cast<intptr_t>(dib_->handle());
85 #elif defined(OS_MACOSX) 97 #elif defined(OS_MACOSX)
86 return static_cast<intptr_t>(dib_->handle().fd); 98 return static_cast<intptr_t>(dib_->handle().fd);
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 webkit::ppapi::PluginDelegate::PlatformImage2D* 491 webkit::ppapi::PluginDelegate::PlatformImage2D*
480 PepperPluginDelegateImpl::CreateImage2D(int width, int height) { 492 PepperPluginDelegateImpl::CreateImage2D(int width, int height) {
481 uint32 buffer_size = width * height * 4; 493 uint32 buffer_size = width * height * 4;
482 494
483 // Allocate the transport DIB and the PlatformCanvas pointing to it. 495 // Allocate the transport DIB and the PlatformCanvas pointing to it.
484 #if defined(OS_MACOSX) 496 #if defined(OS_MACOSX)
485 // On the Mac, shared memory has to be created in the browser in order to 497 // On the Mac, shared memory has to be created in the browser in order to
486 // work in the sandbox. Do this by sending a message to the browser 498 // work in the sandbox. Do this by sending a message to the browser
487 // requesting a TransportDIB (see also 499 // requesting a TransportDIB (see also
488 // chrome/renderer/webplugin_delegate_proxy.cc, method 500 // chrome/renderer/webplugin_delegate_proxy.cc, method
489 // WebPluginDelegateProxy::CreateBitmap() for similar code). Note that the 501 // WebPluginDelegateProxy::CreateBitmap() for similar code). The TransportDIB
490 // TransportDIB is _not_ cached in the browser; this is because this memory 502 // is cached in the browser, and is freed (in typical cases) by the
491 // gets flushed by the renderer into another TransportDIB that represents the 503 // PlatformImage2DImpl's destructor.
492 // page, which is then in turn flushed to the screen by the browser process.
493 // When |transport_dib_| goes out of scope in the dtor, all of its shared
494 // memory gets reclaimed.
495 TransportDIB::Handle dib_handle; 504 TransportDIB::Handle dib_handle;
496 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(buffer_size, 505 IPC::Message* msg = new ViewHostMsg_AllocTransportDIB(buffer_size,
497 false, 506 true,
498 &dib_handle); 507 &dib_handle);
499 if (!RenderThread::current()->Send(msg)) 508 if (!RenderThread::current()->Send(msg))
500 return NULL; 509 return NULL;
501 if (!TransportDIB::is_valid(dib_handle)) 510 if (!TransportDIB::is_valid(dib_handle))
502 return NULL; 511 return NULL;
503 512
504 TransportDIB* dib = TransportDIB::Map(dib_handle); 513 TransportDIB* dib = TransportDIB::Map(dib_handle);
505 #else 514 #else
506 static int next_dib_id = 0; 515 static int next_dib_id = 0;
507 TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++); 516 TransportDIB* dib = TransportDIB::Create(buffer_size, next_dib_id++);
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 } 883 }
875 884
876 void PepperPluginDelegateImpl::DidStopLoading() { 885 void PepperPluginDelegateImpl::DidStopLoading() {
877 render_view_->DidStopLoadingForPlugin(); 886 render_view_->DidStopLoadingForPlugin();
878 } 887 }
879 888
880 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) { 889 void PepperPluginDelegateImpl::SetContentRestriction(int restrictions) {
881 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions( 890 render_view_->Send(new ViewHostMsg_UpdateContentRestrictions(
882 render_view_->routing_id(), restrictions)); 891 render_view_->routing_id(), restrictions));
883 } 892 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698