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
3 // found in the LICENSE file.
5 #include "cc/picture_image_layer.h"
7 #include "third_party/skia/include/core/SkCanvas.h"
11 scoped_refptr
<PictureImageLayer
> PictureImageLayer::create()
13 return make_scoped_refptr(new PictureImageLayer());
16 PictureImageLayer::PictureImageLayer()
21 PictureImageLayer::~PictureImageLayer()
26 void PictureImageLayer::setBitmap(const SkBitmap
& bitmap
)
28 // setBitmap() currently gets called whenever there is any
29 // 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).
31 // With this check in place we avoid unecessary texture uploads.
32 if (bitmap
.pixelRef() && bitmap
.pixelRef() == bitmap_
.pixelRef())
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.
51 PictureLayer::update(queue
, tracker
, stats
);
54 void PictureImageLayer::paintContents(
56 const gfx::Rect
& clip
,
58 if (!bitmap_
.width() || !bitmap_
.height())
61 SkScalar content_to_layer_scale_x
= SkFloatToScalar(
62 static_cast<float>(bounds().width()) / bitmap_
.width());
63 SkScalar content_to_layer_scale_y
= SkFloatToScalar(
64 static_cast<float>(bounds().height()) / bitmap_
.height());
65 canvas
->scale(content_to_layer_scale_x
, content_to_layer_scale_y
);
67 canvas
->drawBitmap(bitmap_
, 0, 0);