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

Unified Diff: cc/picture_image_layer.cc

Issue 11516005: cc: Handle directly composited images in impl-side painting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix windows Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/picture_image_layer.h ('k') | webkit/compositor_bindings/web_image_layer_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/picture_image_layer.cc
diff --git a/cc/picture_image_layer.cc b/cc/picture_image_layer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b87c6e6d9cbbd0304037a69f7b3626c048b1eb1e
--- /dev/null
+++ b/cc/picture_image_layer.cc
@@ -0,0 +1,70 @@
+// Copyright 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/picture_image_layer.h"
+
+#include "third_party/skia/include/core/SkCanvas.h"
+
+namespace cc {
+
+scoped_refptr<PictureImageLayer> PictureImageLayer::create()
+{
+ return make_scoped_refptr(new PictureImageLayer());
+}
+
+PictureImageLayer::PictureImageLayer()
+ : PictureLayer(this)
+{
+}
+
+PictureImageLayer::~PictureImageLayer()
+{
+ clearClient();
+}
+
+void PictureImageLayer::setBitmap(const SkBitmap& bitmap)
+{
+ // setBitmap() currently gets called whenever there is any
+ // style change that affects the layer even if that change doesn't
+ // affect the actual contents of the image (e.g. a CSS animation).
+ // With this check in place we avoid unecessary texture uploads.
+ if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
+ return;
+
+ bitmap_ = bitmap;
+ setNeedsDisplay();
+}
+
+void PictureImageLayer::update(
+ ResourceUpdateQueue& queue,
+ const OcclusionTracker* tracker,
+ RenderingStats& stats) {
+ if (bounds() != bounds_) {
+ // Pictures are recorded in layer space, so if the layer size changes,
+ // then the picture needs to be re-scaled, as a directly composited image
+ // always fills its entire layer bounds. This could be improved by
+ // recording pictures of images at their actual resolution somehow.
+ bounds_ = bounds();
+ setNeedsDisplay();
+ }
+ PictureLayer::update(queue, tracker, stats);
+}
+
+void PictureImageLayer::paintContents(
+ SkCanvas* canvas,
+ const gfx::Rect& clip,
+ gfx::RectF& opaque) {
+ if (!bitmap_.width() || !bitmap_.height())
+ return;
+
+ SkScalar content_to_layer_scale_x = SkFloatToScalar(
+ static_cast<float>(bounds().width()) / bitmap_.width());
+ SkScalar content_to_layer_scale_y = SkFloatToScalar(
+ static_cast<float>(bounds().height()) / bitmap_.height());
+ canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
+
+ canvas->drawBitmap(bitmap_, 0, 0);
+}
+
+} // namespace cc
« no previous file with comments | « cc/picture_image_layer.h ('k') | webkit/compositor_bindings/web_image_layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698