Connect PPAPI IPC channels for non-SFI mode.
[chromium-blink-merge.git] / cc / layers / picture_image_layer.cc
blob127560d496146f107cf53b177a2f06b9e5f1dd27
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/layers/picture_image_layer.h"
7 #include "cc/layers/picture_image_layer_impl.h"
8 #include "third_party/skia/include/core/SkCanvas.h"
10 namespace cc {
12 scoped_refptr<PictureImageLayer> PictureImageLayer::Create() {
13 return make_scoped_refptr(new PictureImageLayer());
16 PictureImageLayer::PictureImageLayer() : PictureLayer(this) {}
18 PictureImageLayer::~PictureImageLayer() {
19 ClearClient();
22 scoped_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
23 LayerTreeImpl* tree_impl) {
24 return PictureImageLayerImpl::Create(tree_impl, id()).PassAs<LayerImpl>();
27 bool PictureImageLayer::DrawsContent() const {
28 return !bitmap_.isNull() && PictureLayer::DrawsContent();
31 void PictureImageLayer::SetBitmap(const SkBitmap& bitmap) {
32 // SetBitmap() currently gets called whenever there is any
33 // style change that affects the layer even if that change doesn't
34 // affect the actual contents of the image (e.g. a CSS animation).
35 // With this check in place we avoid unecessary texture uploads.
36 if (bitmap.pixelRef() && bitmap.pixelRef() == bitmap_.pixelRef())
37 return;
39 bitmap_ = bitmap;
40 SetNeedsDisplay();
43 void PictureImageLayer::PaintContents(SkCanvas* canvas,
44 const gfx::Rect& clip,
45 gfx::RectF* opaque) {
46 if (!bitmap_.width() || !bitmap_.height())
47 return;
49 SkScalar content_to_layer_scale_x =
50 SkFloatToScalar(static_cast<float>(bounds().width()) / bitmap_.width());
51 SkScalar content_to_layer_scale_y =
52 SkFloatToScalar(static_cast<float>(bounds().height()) / bitmap_.height());
53 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
55 canvas->drawBitmap(bitmap_, 0, 0);
58 } // namespace cc