[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 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. | ||||
4 | |||||
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 5 | #include "cc/layers/picture_image_layer.h" |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 6 | |
avi | 02a4d17 | 2015-12-21 06:14:36 | [diff] [blame] | 7 | #include <stddef.h> |
8 | |||||
vmpstr | 9dab6fe | 2016-06-24 02:13:40 | [diff] [blame] | 9 | #include "cc/layers/picture_layer_impl.h" |
chrishtr | ac41ff94 | 2017-03-17 05:07:30 | [diff] [blame] | 10 | #include "cc/paint/drawing_display_item.h" |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 11 | #include "cc/paint/paint_canvas.h" |
12 | #include "cc/paint/paint_recorder.h" | ||||
khushalsagar | 8e17a5b | 2016-03-31 18:49:37 | [diff] [blame] | 13 | #include "cc/trees/layer_tree_host.h" |
khushalsagar | 6156779 | 2016-09-17 00:13:58 | [diff] [blame] | 14 | #include "cc/trees/layer_tree_settings.h" |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 15 | |
16 | namespace cc { | ||||
17 | |||||
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 18 | scoped_refptr<PictureImageLayer> PictureImageLayer::Create() { |
19 | return make_scoped_refptr(new PictureImageLayer()); | ||||
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 20 | } |
21 | |||||
loyso | 0940d41 | 2016-03-14 01:30:31 | [diff] [blame] | 22 | PictureImageLayer::PictureImageLayer() : PictureLayer(this) {} |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 23 | |
[email protected] | e617329f | 2013-03-13 13:05:21 | [diff] [blame] | 24 | PictureImageLayer::~PictureImageLayer() { |
[email protected] | 8c406cda3 | 2013-03-14 16:20:32 | [diff] [blame] | 25 | ClearClient(); |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 26 | } |
27 | |||||
danakj | 60bc3bc | 2016-04-09 00:24:48 | [diff] [blame] | 28 | std::unique_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl( |
[email protected] | e617329f | 2013-03-13 13:05:21 | [diff] [blame] | 29 | LayerTreeImpl* tree_impl) { |
sunxd | 936c16d | 2017-02-10 20:20:30 | [diff] [blame] | 30 | auto layer_impl = PictureLayerImpl::Create(tree_impl, id(), mask_type()); |
vmpstr | 9dab6fe | 2016-06-24 02:13:40 | [diff] [blame] | 31 | layer_impl->set_is_directly_composited_image(true); |
32 | return std::move(layer_impl); | ||||
[email protected] | ab66369 | 2013-02-25 19:59:20 | [diff] [blame] | 33 | } |
34 | |||||
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 35 | bool PictureImageLayer::HasDrawableContent() const { |
vmpstr | 55c7657ca | 2017-04-29 00:46:48 | [diff] [blame] | 36 | return image_.sk_image() && PictureLayer::HasDrawableContent(); |
[email protected] | ab66369 | 2013-02-25 19:59:20 | [diff] [blame] | 37 | } |
38 | |||||
vmpstr | 55c7657ca | 2017-04-29 00:46:48 | [diff] [blame] | 39 | void PictureImageLayer::SetImage(PaintImage image) { |
fmalita | 386ff1c4 | 2015-08-04 04:58:52 | [diff] [blame] | 40 | // SetImage() currently gets called whenever there is any |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 41 | // 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. | ||||
vmpstr | 55c7657ca | 2017-04-29 00:46:48 | [diff] [blame] | 44 | if (image_ == image) |
[email protected] | e617329f | 2013-03-13 13:05:21 | [diff] [blame] | 45 | return; |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 46 | |
danakj | a04855a | 2015-11-18 20:39:10 | [diff] [blame] | 47 | image_ = std::move(image); |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 48 | UpdateDrawsContent(HasDrawableContent()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 49 | SetNeedsDisplay(); |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 50 | } |
51 | |||||
chrishtr | 01539b80 | 2015-11-24 08:11:32 | [diff] [blame] | 52 | gfx::Rect PictureImageLayer::PaintableRegion() { |
53 | return gfx::Rect(bounds()); | ||||
54 | } | ||||
55 | |||||
jbroman | c389c809 | 2015-10-15 22:09:40 | [diff] [blame] | 56 | scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( |
schenney | 0154bfa | 2015-02-05 19:46:49 | [diff] [blame] | 57 | ContentLayerClient::PaintingControlSetting painting_control) { |
vmpstr | 55c7657ca | 2017-04-29 00:46:48 | [diff] [blame] | 58 | DCHECK(image_.sk_image()); |
59 | DCHECK_GT(image_.sk_image()->width(), 0); | ||||
60 | DCHECK_GT(image_.sk_image()->height(), 0); | ||||
khushalsagar | 8e17a5b | 2016-03-31 18:49:37 | [diff] [blame] | 61 | DCHECK(layer_tree_host()); |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 62 | |
enne | cb0ee5f | 2017-01-27 20:12:24 | [diff] [blame] | 63 | auto display_list = make_scoped_refptr(new DisplayItemList); |
jbroman | c389c809 | 2015-10-15 22:09:40 | [diff] [blame] | 64 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 65 | PaintRecorder recorder; |
66 | PaintCanvas* canvas = | ||||
chrishtr | e8384fa | 2015-12-03 17:43:20 | [diff] [blame] | 67 | recorder.beginRecording(gfx::RectToSkRect(PaintableRegion())); |
jbroman | c389c809 | 2015-10-15 22:09:40 | [diff] [blame] | 68 | |
vmpstr | 55c7657ca | 2017-04-29 00:46:48 | [diff] [blame] | 69 | 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] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 73 | canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y); |
74 | |||||
[email protected] | 69346b2 | 2014-08-11 17:47:13 | [diff] [blame] | 75 | // 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. | ||||
vmpstr | 55c7657ca | 2017-04-29 00:46:48 | [diff] [blame] | 78 | canvas->drawImage(image_, 0, 0); |
ajuma | 979c57f | 2015-01-14 16:40:24 | [diff] [blame] | 79 | |
wkorman | 923cfdd | 2016-08-11 00:04:33 | [diff] [blame] | 80 | display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( |
fmalita | 2d74328 | 2016-03-22 13:32:10 | [diff] [blame] | 81 | PaintableRegion(), recorder.finishRecordingAsPicture()); |
jbroman | 16d628c | 2015-05-29 20:11:59 | [diff] [blame] | 82 | |
83 | display_list->Finalize(); | ||||
84 | return display_list; | ||||
ajuma | 5e77f7d4 | 2014-11-27 14:19:14 | [diff] [blame] | 85 | } |
86 | |||||
[email protected] | 1d96e03 | 2014-03-25 05:59:08 | [diff] [blame] | 87 | bool PictureImageLayer::FillsBoundsCompletely() const { |
[email protected] | 69346b2 | 2014-08-11 17:47:13 | [diff] [blame] | 88 | return false; |
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 89 | } |
90 | |||||
jbroman | 9f60f1a | 2015-07-16 21:40:32 | [diff] [blame] | 91 | size_t PictureImageLayer::GetApproximateUnsharedMemoryUsage() const { |
92 | return 0; | ||||
93 | } | ||||
94 | |||||
[email protected] | b23c022 | 2012-12-11 02:26:53 | [diff] [blame] | 95 | } // namespace cc |