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

Side by Side Diff: cc/picture_image_layer.cc

Issue 12326022: Efficiently handle image layer scaling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handle sublayerTransform and anchor point Created 7 years, 10 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
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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 "cc/picture_image_layer.h" 5 #include "cc/picture_image_layer.h"
6 6
7 #include "cc/picture_image_layer_impl.h"
7 #include "third_party/skia/include/core/SkCanvas.h" 8 #include "third_party/skia/include/core/SkCanvas.h"
8 9
9 namespace cc { 10 namespace cc {
10 11
11 scoped_refptr<PictureImageLayer> PictureImageLayer::create() 12 scoped_refptr<PictureImageLayer> PictureImageLayer::create()
12 { 13 {
13 return make_scoped_refptr(new PictureImageLayer()); 14 return make_scoped_refptr(new PictureImageLayer());
14 } 15 }
15 16
16 PictureImageLayer::PictureImageLayer() 17 PictureImageLayer::PictureImageLayer()
17 : PictureLayer(this) 18 : PictureLayer(this)
18 { 19 {
19 } 20 }
20 21
21 PictureImageLayer::~PictureImageLayer() 22 PictureImageLayer::~PictureImageLayer()
22 { 23 {
23 clearClient(); 24 clearClient();
24 } 25 }
25 26
27 scoped_ptr<LayerImpl> PictureImageLayer::createLayerImpl(
28 LayerTreeImpl* treeImpl) {
29 return PictureImageLayerImpl::create(treeImpl, id()).PassAs<LayerImpl>();
30 }
31
32 bool PictureImageLayer::drawsContent() const {
33 return !bitmap_.isNull() && PictureLayer::drawsContent();
34 }
35
26 void PictureImageLayer::setBitmap(const SkBitmap& bitmap) 36 void PictureImageLayer::setBitmap(const SkBitmap& bitmap)
27 { 37 {
28 // setBitmap() currently gets called whenever there is any 38 // setBitmap() currently gets called whenever there is any
29 // style change that affects the layer even if that change doesn't 39 // style change that affects the layer even if that change doesn't
30 // affect the actual contents of the image (e.g. a CSS animation). 40 // affect the actual contents of the image (e.g. a CSS animation).
31 // With this check in place we avoid unecessary texture uploads. 41 // With this check in place we avoid unecessary texture uploads.
32 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef()) 42 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
33 return; 43 return;
34 44
35 bitmap_ = bitmap; 45 bitmap_ = bitmap;
36 setNeedsDisplay(); 46 setNeedsDisplay();
37 } 47 }
38 48
39 void PictureImageLayer::update(
40 ResourceUpdateQueue& queue,
41 const OcclusionTracker* tracker,
42 RenderingStats* stats) {
43 if (bounds() != bounds_) {
44 // Pictures are recorded in layer space, so if the layer size changes,
45 // then the picture needs to be re-scaled, as a directly composited image
46 // always fills its entire layer bounds. This could be improved by
47 // recording pictures of images at their actual resolution somehow.
48 bounds_ = bounds();
49 setNeedsDisplay();
50 }
51 PictureLayer::update(queue, tracker, stats);
52 }
53
54 void PictureImageLayer::paintContents( 49 void PictureImageLayer::paintContents(
55 SkCanvas* canvas, 50 SkCanvas* canvas,
56 const gfx::Rect& clip, 51 const gfx::Rect& clip,
57 gfx::RectF& opaque) { 52 gfx::RectF& opaque) {
58 if (!bitmap_.width() || !bitmap_.height()) 53 if (!bitmap_.width() || !bitmap_.height())
59 return; 54 return;
60 55
61 SkScalar content_to_layer_scale_x = SkFloatToScalar( 56 // WebImageLayerImpl should always set bounds equaling to the size of the
62 static_cast<float>(bounds().width()) / bitmap_.width()); 57 // bitmap.
63 SkScalar content_to_layer_scale_y = SkFloatToScalar( 58 DCHECK(bounds().width() == bitmap_.width() &&
64 static_cast<float>(bounds().height()) / bitmap_.height()); 59 bounds().height() == bitmap_.height());
65 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
66 60
67 canvas->drawBitmap(bitmap_, 0, 0); 61 canvas->drawBitmap(bitmap_, 0, 0);
68 } 62 }
69 63
70 } // namespace cc 64 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698