blob: e1f260034d33ae2f7bbd5e55d5c945f2a28b6917 [file] [log] [blame]
[email protected]b23c0222012-12-11 02:26:531// 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.
4
[email protected]cc3cfaa2013-03-18 09:05:525#include "cc/layers/picture_image_layer.h"
[email protected]b23c0222012-12-11 02:26:536
avi02a4d172015-12-21 06:14:367#include <stddef.h>
8
vmpstr9dab6fe2016-06-24 02:13:409#include "cc/layers/picture_layer_impl.h"
chrishtrac41ff942017-03-17 05:07:3010#include "cc/paint/drawing_display_item.h"
enne34f6084c2017-02-02 22:39:0811#include "cc/paint/paint_canvas.h"
12#include "cc/paint/paint_recorder.h"
khushalsagar8e17a5b2016-03-31 18:49:3713#include "cc/trees/layer_tree_host.h"
khushalsagar61567792016-09-17 00:13:5814#include "cc/trees/layer_tree_settings.h"
[email protected]b23c0222012-12-11 02:26:5315
16namespace cc {
17
loyso0940d412016-03-14 01:30:3118scoped_refptr<PictureImageLayer> PictureImageLayer::Create() {
19 return make_scoped_refptr(new PictureImageLayer());
[email protected]b23c0222012-12-11 02:26:5320}
21
loyso0940d412016-03-14 01:30:3122PictureImageLayer::PictureImageLayer() : PictureLayer(this) {}
[email protected]b23c0222012-12-11 02:26:5323
[email protected]e617329f2013-03-13 13:05:2124PictureImageLayer::~PictureImageLayer() {
[email protected]8c406cda32013-03-14 16:20:3225 ClearClient();
[email protected]b23c0222012-12-11 02:26:5326}
27
danakj60bc3bc2016-04-09 00:24:4828std::unique_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
[email protected]e617329f2013-03-13 13:05:2129 LayerTreeImpl* tree_impl) {
sunxd936c16d2017-02-10 20:20:3030 auto layer_impl = PictureLayerImpl::Create(tree_impl, id(), mask_type());
vmpstr9dab6fe2016-06-24 02:13:4031 layer_impl->set_is_directly_composited_image(true);
32 return std::move(layer_impl);
[email protected]ab663692013-02-25 19:59:2033}
34
[email protected]ad63b2f2014-08-11 17:39:5435bool PictureImageLayer::HasDrawableContent() const {
vmpstr55c7657ca2017-04-29 00:46:4836 return image_.sk_image() && PictureLayer::HasDrawableContent();
[email protected]ab663692013-02-25 19:59:2037}
38
vmpstr55c7657ca2017-04-29 00:46:4839void PictureImageLayer::SetImage(PaintImage image) {
fmalita386ff1c42015-08-04 04:58:5240 // SetImage() currently gets called whenever there is any
[email protected]b23c0222012-12-11 02:26:5341 // style change that affects the layer even if that change doesn't
42 // affect the actual contents of the image (e.g. a CSS animation).
43 // With this check in place we avoid unecessary texture uploads.
vmpstr55c7657ca2017-04-29 00:46:4844 if (image_ == image)
[email protected]e617329f2013-03-13 13:05:2145 return;
[email protected]b23c0222012-12-11 02:26:5346
danakja04855a2015-11-18 20:39:1047 image_ = std::move(image);
[email protected]ad63b2f2014-08-11 17:39:5448 UpdateDrawsContent(HasDrawableContent());
[email protected]7aba6662013-03-12 10:17:3449 SetNeedsDisplay();
[email protected]b23c0222012-12-11 02:26:5350}
51
chrishtr01539b802015-11-24 08:11:3252gfx::Rect PictureImageLayer::PaintableRegion() {
53 return gfx::Rect(bounds());
54}
55
jbromanc389c8092015-10-15 22:09:4056scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList(
schenney0154bfa2015-02-05 19:46:4957 ContentLayerClient::PaintingControlSetting painting_control) {
vmpstr55c7657ca2017-04-29 00:46:4858 DCHECK(image_.sk_image());
59 DCHECK_GT(image_.sk_image()->width(), 0);
60 DCHECK_GT(image_.sk_image()->height(), 0);
khushalsagar8e17a5b2016-03-31 18:49:3761 DCHECK(layer_tree_host());
[email protected]b23c0222012-12-11 02:26:5362
ennecb0ee5f2017-01-27 20:12:2463 auto display_list = make_scoped_refptr(new DisplayItemList);
jbromanc389c8092015-10-15 22:09:4064
enne34f6084c2017-02-02 22:39:0865 PaintRecorder recorder;
66 PaintCanvas* canvas =
chrishtre8384fa2015-12-03 17:43:2067 recorder.beginRecording(gfx::RectToSkRect(PaintableRegion()));
jbromanc389c8092015-10-15 22:09:4068
vmpstr55c7657ca2017-04-29 00:46:4869 SkScalar content_to_layer_scale_x = SkFloatToScalar(
70 static_cast<float>(bounds().width()) / image_.sk_image()->width());
71 SkScalar content_to_layer_scale_y = SkFloatToScalar(
72 static_cast<float>(bounds().height()) / image_.sk_image()->height());
[email protected]b23c0222012-12-11 02:26:5373 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
74
[email protected]69346b22014-08-11 17:47:1375 // Because Android WebView resourceless software draw mode rasters directly
76 // to the root canvas, this draw must use the kSrcOver_Mode so that
77 // transparent images blend correctly.
vmpstr55c7657ca2017-04-29 00:46:4878 canvas->drawImage(image_, 0, 0);
ajuma979c57f2015-01-14 16:40:2479
wkorman923cfdd2016-08-11 00:04:3380 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
fmalita2d743282016-03-22 13:32:1081 PaintableRegion(), recorder.finishRecordingAsPicture());
jbroman16d628c2015-05-29 20:11:5982
83 display_list->Finalize();
84 return display_list;
ajuma5e77f7d42014-11-27 14:19:1485}
86
[email protected]1d96e032014-03-25 05:59:0887bool PictureImageLayer::FillsBoundsCompletely() const {
[email protected]69346b22014-08-11 17:47:1388 return false;
[email protected]b23c0222012-12-11 02:26:5389}
90
jbroman9f60f1a2015-07-16 21:40:3291size_t PictureImageLayer::GetApproximateUnsharedMemoryUsage() const {
92 return 0;
93}
94
[email protected]b23c0222012-12-11 02:26:5395} // namespace cc