Mailbox support for texture layers.
[chromium-blink-merge.git] / cc / picture_image_layer.cc
blobb87c6e6d9cbbd0304037a69f7b3626c048b1eb1e
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"
9 namespace cc {
11 scoped_refptr<PictureImageLayer> PictureImageLayer::create()
13 return make_scoped_refptr(new PictureImageLayer());
16 PictureImageLayer::PictureImageLayer()
17 : PictureLayer(this)
21 PictureImageLayer::~PictureImageLayer()
23 clearClient();
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())
33 return;
35 bitmap_ = bitmap;
36 setNeedsDisplay();
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();
51 PictureLayer::update(queue, tracker, stats);
54 void PictureImageLayer::paintContents(
55 SkCanvas* canvas,
56 const gfx::Rect& clip,
57 gfx::RectF& opaque) {
58 if (!bitmap_.width() || !bitmap_.height())
59 return;
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);
70 } // namespace cc