diff options
author | vangelis@chromium.org <vangelis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-28 03:30:52 +0000 |
---|---|---|
committer | vangelis@chromium.org <vangelis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-28 03:30:52 +0000 |
commit | 50120f2dae7a44e4549878ae3c77986aa3f0fd0c (patch) | |
tree | 9413c5eda77c647e162bf900d48a3d53983a6a23 /cc/resources | |
parent | f079ded96e4e9cb99eb018f3eb2a1cdebc9f7dbd (diff) | |
download | chromium_src-50120f2dae7a44e4549878ae3c77986aa3f0fd0c.zip chromium_src-50120f2dae7a44e4549878ae3c77986aa3f0fd0c.tar.gz chromium_src-50120f2dae7a44e4549878ae3c77986aa3f0fd0c.tar.bz2 |
Skip clearing the canvas before painting the contents of opaque layers
The SkCanvas doesn't need to be cleared before painting the layer contents
if the layer is known to be opaque (e.g. the root layer). Bypassing the clear
gives a sizeable perf boost.
This patch also switches to calling clear() instead of drawRect() for clearing the canvas pixels as clear has been shown to be significantly faster.
BUG=279612
Review URL: https://chromiumcodereview.appspot.com/23484005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@219894 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/resources')
-rw-r--r-- | cc/resources/bitmap_content_layer_updater.cc | 12 | ||||
-rw-r--r-- | cc/resources/content_layer_updater.cc | 27 | ||||
-rw-r--r-- | cc/resources/content_layer_updater.h | 9 | ||||
-rw-r--r-- | cc/resources/skpicture_content_layer_updater.cc | 9 | ||||
-rw-r--r-- | cc/resources/skpicture_content_layer_updater.h | 7 |
5 files changed, 35 insertions, 29 deletions
diff --git a/cc/resources/bitmap_content_layer_updater.cc b/cc/resources/bitmap_content_layer_updater.cc index 3d90eb0..75b99c5 100644 --- a/cc/resources/bitmap_content_layer_updater.cc +++ b/cc/resources/bitmap_content_layer_updater.cc @@ -43,8 +43,7 @@ BitmapContentLayerUpdater::BitmapContentLayerUpdater( scoped_ptr<LayerPainter> painter, RenderingStatsInstrumentation* stats_instrumentation, int layer_id) - : ContentLayerUpdater(painter.Pass(), stats_instrumentation, layer_id), - opaque_(false) {} + : ContentLayerUpdater(painter.Pass(), stats_instrumentation, layer_id) {} BitmapContentLayerUpdater::~BitmapContentLayerUpdater() {} @@ -67,13 +66,13 @@ void BitmapContentLayerUpdater::PrepareToUpdate( devtools_instrumentation::kPaintSetup, layer_id_); canvas_size_ = content_rect.size(); canvas_ = skia::AdoptRef(skia::CreateBitmapCanvas( - canvas_size_.width(), canvas_size_.height(), opaque_)); + canvas_size_.width(), canvas_size_.height(), layer_is_opaque_)); } base::TimeTicks start_time = rendering_stats_instrumentation_->StartRecording(); PaintContents(canvas_.get(), - content_rect, + content_rect.origin(), contents_width_scale, contents_height_scale, resulting_opaque_rect); @@ -108,11 +107,12 @@ void BitmapContentLayerUpdater::ReduceMemoryUsage() { } void BitmapContentLayerUpdater::SetOpaque(bool opaque) { - if (opaque != opaque_) { + if (opaque != layer_is_opaque_) { canvas_.clear(); canvas_size_ = gfx::Size(); } - opaque_ = opaque; + + ContentLayerUpdater::SetOpaque(opaque); } } // namespace cc diff --git a/cc/resources/content_layer_updater.cc b/cc/resources/content_layer_updater.cc index c9c2ecc..50ea86b 100644 --- a/cc/resources/content_layer_updater.cc +++ b/cc/resources/content_layer_updater.cc @@ -9,6 +9,7 @@ #include "cc/debug/rendering_stats_instrumentation.h" #include "cc/resources/layer_painter.h" #include "third_party/skia/include/core/SkCanvas.h" +#include "third_party/skia/include/core/SkDevice.h" #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkRect.h" #include "third_party/skia/include/core/SkScalar.h" @@ -23,7 +24,8 @@ ContentLayerUpdater::ContentLayerUpdater( int layer_id) : rendering_stats_instrumentation_(stats_instrumentation), layer_id_(layer_id), - painter_(painter.Pass()) {} + painter_(painter.Pass()), + layer_is_opaque_(false) {} ContentLayerUpdater::~ContentLayerUpdater() {} @@ -33,14 +35,17 @@ void ContentLayerUpdater::set_rendering_stats_instrumentation( } void ContentLayerUpdater::PaintContents(SkCanvas* canvas, - gfx::Rect content_rect, + gfx::Point origin, float contents_width_scale, float contents_height_scale, gfx::Rect* resulting_opaque_rect) { TRACE_EVENT0("cc", "ContentLayerUpdater::PaintContents"); canvas->save(); - canvas->translate(SkFloatToScalar(-content_rect.x()), - SkFloatToScalar(-content_rect.y())); + canvas->translate(SkFloatToScalar(-origin.x()), + SkFloatToScalar(-origin.y())); + + SkDevice* device = canvas->getDevice(); + gfx::Rect content_rect(origin, gfx::Size(device->width(), device->height())); gfx::Rect layer_rect = content_rect; @@ -52,12 +57,14 @@ void ContentLayerUpdater::PaintContents(SkCanvas* canvas, content_rect, 1.f / contents_width_scale, 1.f / contents_height_scale); } - SkPaint paint; - paint.setAntiAlias(false); - paint.setXfermodeMode(SkXfermode::kClear_Mode); SkRect layer_sk_rect = SkRect::MakeXYWH( layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()); - canvas->drawRect(layer_sk_rect, paint); + + // If the layer has opaque contents then there is no need to + // clear the canvas before painting. + if (!layer_is_opaque_) + canvas->clear(SK_ColorTRANSPARENT); + canvas->clipRect(layer_sk_rect); gfx::RectF opaque_layer_rect; @@ -71,4 +78,8 @@ void ContentLayerUpdater::PaintContents(SkCanvas* canvas, content_rect_ = content_rect; } +void ContentLayerUpdater::SetOpaque(bool opaque) { + layer_is_opaque_ = opaque; +} + } // namespace cc diff --git a/cc/resources/content_layer_updater.h b/cc/resources/content_layer_updater.h index 6c8dee3..6959526 100644 --- a/cc/resources/content_layer_updater.h +++ b/cc/resources/content_layer_updater.h @@ -22,6 +22,7 @@ class RenderingStatsInstrumentation; class CC_EXPORT ContentLayerUpdater : public LayerUpdater { public: void set_rendering_stats_instrumentation(RenderingStatsInstrumentation* rsi); + virtual void SetOpaque(bool) OVERRIDE; protected: ContentLayerUpdater(scoped_ptr<LayerPainter> painter, @@ -30,12 +31,14 @@ class CC_EXPORT ContentLayerUpdater : public LayerUpdater { virtual ~ContentLayerUpdater(); void PaintContents(SkCanvas* canvas, - gfx::Rect content_rect, + gfx::Point origin, float contents_width_scale, float contents_height_scale, gfx::Rect* resulting_opaque_rect); gfx::Rect content_rect() const { return content_rect_; } + bool layer_is_opaque() const { return layer_is_opaque_; } + RenderingStatsInstrumentation* rendering_stats_instrumentation_; int layer_id_; @@ -43,6 +46,10 @@ class CC_EXPORT ContentLayerUpdater : public LayerUpdater { gfx::Rect content_rect_; scoped_ptr<LayerPainter> painter_; + protected: + // True when it is known that all output pixels will be opaque. + bool layer_is_opaque_; + DISALLOW_COPY_AND_ASSIGN(ContentLayerUpdater); }; diff --git a/cc/resources/skpicture_content_layer_updater.cc b/cc/resources/skpicture_content_layer_updater.cc index e44dbc2..79769bc 100644 --- a/cc/resources/skpicture_content_layer_updater.cc +++ b/cc/resources/skpicture_content_layer_updater.cc @@ -17,8 +17,7 @@ SkPictureContentLayerUpdater::SkPictureContentLayerUpdater( scoped_ptr<LayerPainter> painter, RenderingStatsInstrumentation* stats_instrumentation, int layer_id) - : ContentLayerUpdater(painter.Pass(), stats_instrumentation, layer_id), - layer_is_opaque_(false) {} + : ContentLayerUpdater(painter.Pass(), stats_instrumentation, layer_id) {} SkPictureContentLayerUpdater::~SkPictureContentLayerUpdater() {} @@ -33,7 +32,7 @@ void SkPictureContentLayerUpdater::PrepareToUpdate( base::TimeTicks start_time = rendering_stats_instrumentation_->StartRecording(); PaintContents(canvas, - content_rect, + content_rect.origin(), contents_width_scale, contents_height_scale, resulting_opaque_rect); @@ -49,8 +48,4 @@ void SkPictureContentLayerUpdater::DrawPicture(SkCanvas* canvas) { canvas->drawPicture(picture_); } -void SkPictureContentLayerUpdater::SetOpaque(bool opaque) { - layer_is_opaque_ = opaque; -} - } // namespace cc diff --git a/cc/resources/skpicture_content_layer_updater.h b/cc/resources/skpicture_content_layer_updater.h index 41a9f01..511d8ee 100644 --- a/cc/resources/skpicture_content_layer_updater.h +++ b/cc/resources/skpicture_content_layer_updater.h @@ -20,9 +20,6 @@ class LayerPainter; // FrameBufferSkPictureContentLayerUpdater are two examples of such // implementations. class SkPictureContentLayerUpdater : public ContentLayerUpdater { - public: - virtual void SetOpaque(bool opaque) OVERRIDE; - protected: SkPictureContentLayerUpdater( scoped_ptr<LayerPainter> painter, @@ -37,13 +34,9 @@ class SkPictureContentLayerUpdater : public ContentLayerUpdater { gfx::Rect* resulting_opaque_rect) OVERRIDE; void DrawPicture(SkCanvas* canvas); - bool layer_is_opaque() const { return layer_is_opaque_; } - private: // Recording canvas. SkPicture picture_; - // True when it is known that all output pixels will be opaque. - bool layer_is_opaque_; DISALLOW_COPY_AND_ASSIGN(SkPictureContentLayerUpdater); }; |