diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 19:46:06 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-23 19:46:06 +0000 |
commit | 1d01ed634bd4a4e3c15d89931aad1bfc62e0b6cd (patch) | |
tree | d0c01b2443bf1cb89824f906848e98426303acec /chrome/renderer | |
parent | db359dc0e51d8b28f6d93ce979cdf6e081f4211c (diff) | |
download | chromium_src-1d01ed634bd4a4e3c15d89931aad1bfc62e0b6cd.zip chromium_src-1d01ed634bd4a4e3c15d89931aad1bfc62e0b6cd.tar.gz chromium_src-1d01ed634bd4a4e3c15d89931aad1bfc62e0b6cd.tar.bz2 |
Add some optimizations to plugin painting.
The simplest one is to disable blending when the plugin is opaque.
The more complicated one is to bypass webkit painting the background of plugins
when we know the plugin to be always on top and also opaque. The always on top
flag is currently set by a new "Private2" API. Bypassing WebKit makes
animations faster.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3421030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60329 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.cc | 17 | ||||
-rw-r--r-- | chrome/renderer/pepper_plugin_delegate_impl.h | 6 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 5 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 2 | ||||
-rw-r--r-- | chrome/renderer/render_widget.cc | 27 | ||||
-rw-r--r-- | chrome/renderer/render_widget.h | 13 |
6 files changed, 65 insertions, 5 deletions
diff --git a/chrome/renderer/pepper_plugin_delegate_impl.cc b/chrome/renderer/pepper_plugin_delegate_impl.cc index 3a866af..5f73ea7 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.cc +++ b/chrome/renderer/pepper_plugin_delegate_impl.cc @@ -53,6 +53,10 @@ class PlatformImage2DImpl : public pepper::PluginDelegate::PlatformImage2D { return reinterpret_cast<intptr_t>(dib_.get()); } + virtual TransportDIB* GetTransportDIB() const { + return dib_.get(); + } + private: int width_; int height_; @@ -520,6 +524,19 @@ void PepperPluginDelegateImpl::ViewFlushedPaint() { } } +bool PepperPluginDelegateImpl::GetBitmapForOptimizedPluginPaint( + gfx::Rect* bounds, + TransportDIB** dib) { + for (std::set<pepper::PluginInstance*>::iterator i = + active_instances_.begin(); + i != active_instances_.end(); ++i) { + pepper::PluginInstance* instance = *i; + if (instance->GetBitmapForOptimizedPluginPaint(bounds, dib)) + return true; + } + return false; +} + void PepperPluginDelegateImpl::InstanceCreated( pepper::PluginInstance* instance) { active_instances_.insert(instance); diff --git a/chrome/renderer/pepper_plugin_delegate_impl.h b/chrome/renderer/pepper_plugin_delegate_impl.h index 19f08b1c..0119148 100644 --- a/chrome/renderer/pepper_plugin_delegate_impl.h +++ b/chrome/renderer/pepper_plugin_delegate_impl.h @@ -29,6 +29,8 @@ class WebFileChooserCompletion; struct WebFileChooserParams; } +class TransportDIB; + class PepperPluginDelegateImpl : public pepper::PluginDelegate, public base::SupportsWeakPtr<PepperPluginDelegateImpl> { @@ -41,6 +43,10 @@ class PepperPluginDelegateImpl void ViewInitiatedPaint(); void ViewFlushedPaint(); + // Called by RenderView to implement the corresponding function in its base + // class RenderWidget (see that for more). + bool GetBitmapForOptimizedPluginPaint(gfx::Rect* bounds, TransportDIB** dib); + // Called by RenderView when ViewMsg_AsyncOpenFile_ACK. void OnAsyncFileOpened(base::PlatformFileError error_code, base::PlatformFile file, diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index ae155e8..98cc445 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -4717,6 +4717,11 @@ void RenderView::DidFlushPaint() { } } +bool RenderView::GetBitmapForOptimizedPluginPaint(gfx::Rect* bounds, + TransportDIB** dib) { + return pepper_delegate_.GetBitmapForOptimizedPluginPaint(bounds, dib); +} + void RenderView::OnClearFocusedNode() { if (webview()) webview()->clearFocusedNode(); diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 01f9655..1a733fe 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -608,6 +608,8 @@ class RenderView : public RenderWidget, const gfx::Rect& resizer_rect); virtual void DidInitiatePaint(); virtual void DidFlushPaint(); + virtual bool GetBitmapForOptimizedPluginPaint(gfx::Rect* bounds, + TransportDIB** dib); virtual void DidHandleKeyEvent(); virtual void DidHandleMouseEvent(const WebKit::WebMouseEvent& event); virtual void OnSetFocus(bool enable); diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index 3252097..95346c3 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -505,11 +505,21 @@ void RenderWidget::DoDeferredUpdate() { gfx::Rect scroll_damage = update.GetScrollDamage(); gfx::Rect bounds = update.GetPaintBounds().Union(scroll_damage); + // A plugin may be able to do an optimized paint. First check this, in which + // case we can skip all of the bitmap generation and regular paint code. + TransportDIB::Id dib_id; + TransportDIB* dib = NULL; std::vector<gfx::Rect> copy_rects; - if (!is_gpu_rendering_active_) { + if (update.scroll_rect.IsEmpty() && + !is_gpu_rendering_active_ && + GetBitmapForOptimizedPluginPaint(&bounds, &dib)) { + copy_rects.push_back(bounds); + dib_id = dib->id(); + } else if (!is_gpu_rendering_active_) { // Compute a buffer for painting and cache it. - scoped_ptr<skia::PlatformCanvas> canvas - (RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, bounds)); + scoped_ptr<skia::PlatformCanvas> canvas( + RenderProcess::current()->GetDrawingCanvas(¤t_paint_buf_, + bounds)); if (!canvas.get()) { NOTREACHED(); return; @@ -538,6 +548,8 @@ void RenderWidget::DoDeferredUpdate() { for (size_t i = 0; i < copy_rects.size(); ++i) PaintRect(copy_rects[i], bounds.origin(), canvas.get()); + + dib_id = current_paint_buf_->id(); } else { // Accelerated compositing path // Begin painting. bool finish = next_paint_is_resize_ack(); @@ -546,8 +558,7 @@ void RenderWidget::DoDeferredUpdate() { // sending an ack to browser process that the paint is complete... ViewHostMsg_UpdateRect_Params params; - params.bitmap = - current_paint_buf_ ? current_paint_buf_->id() : TransportDIB::Id(); + params.bitmap = dib_id; params.bitmap_rect = bounds; params.dx = update.scroll_delta.x(); params.dy = update.scroll_delta.y(); @@ -889,6 +900,12 @@ void RenderWidget::OnSetTextDirection(WebTextDirection direction) { webwidget_->setTextDirection(direction); } +bool RenderWidget::GetBitmapForOptimizedPluginPaint(gfx::Rect* bounds, + TransportDIB** dib) { + // Normal RenderWidgets don't support optimized plugin painting. + return false; +} + void RenderWidget::SetHidden(bool hidden) { if (is_hidden_ == hidden) return; diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h index 7f9e247..61abdee 100644 --- a/chrome/renderer/render_widget.h +++ b/chrome/renderer/render_widget.h @@ -197,6 +197,19 @@ class RenderWidget : public IPC::Channel::Listener, virtual void DidInitiatePaint() {} virtual void DidFlushPaint() {} + // Detects if a suitable opaque plugin covers |*bounds| with no compositing + // necessary. + // + // Returns true if the paint can be handled by just blitting the plugin + // bitmap. In this case, the |*dib| parameter will contain the TransportDIB + // and the |*bounds| will be updated to contain the rect on the page that + // contains the given DIB (this may go off the visible page). + // + // A return value of false means optimized painting can not be used and we + // should continue with the normal painting code path. + virtual bool GetBitmapForOptimizedPluginPaint(gfx::Rect* bounds, + TransportDIB** dib); + // Sets the "hidden" state of this widget. All accesses to is_hidden_ should // use this method so that we can properly inform the RenderThread of our // state. |