summaryrefslogtreecommitdiffstats
path: root/cc/resources/content_layer_updater.cc
diff options
context:
space:
mode:
authorvangelis@chromium.org <vangelis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 03:30:52 +0000
committervangelis@chromium.org <vangelis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-28 03:30:52 +0000
commit50120f2dae7a44e4549878ae3c77986aa3f0fd0c (patch)
tree9413c5eda77c647e162bf900d48a3d53983a6a23 /cc/resources/content_layer_updater.cc
parentf079ded96e4e9cb99eb018f3eb2a1cdebc9f7dbd (diff)
downloadchromium_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/content_layer_updater.cc')
-rw-r--r--cc/resources/content_layer_updater.cc27
1 files changed, 19 insertions, 8 deletions
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