Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: cc/layers/picture_image_layer.cc

Issue 2835373003: Plumb PaintImage to the PictureImageLayer. (Closed)
Patch Set: update Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/picture_image_layer.h ('k') | cc/layers/picture_image_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/picture_image_layer.h" 5 #include "cc/layers/picture_image_layer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "cc/layers/picture_layer_impl.h" 9 #include "cc/layers/picture_layer_impl.h"
10 #include "cc/paint/drawing_display_item.h" 10 #include "cc/paint/drawing_display_item.h"
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 std::unique_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl( 28 std::unique_ptr<LayerImpl> PictureImageLayer::CreateLayerImpl(
29 LayerTreeImpl* tree_impl) { 29 LayerTreeImpl* tree_impl) {
30 auto layer_impl = PictureLayerImpl::Create(tree_impl, id(), mask_type()); 30 auto layer_impl = PictureLayerImpl::Create(tree_impl, id(), mask_type());
31 layer_impl->set_is_directly_composited_image(true); 31 layer_impl->set_is_directly_composited_image(true);
32 return std::move(layer_impl); 32 return std::move(layer_impl);
33 } 33 }
34 34
35 bool PictureImageLayer::HasDrawableContent() const { 35 bool PictureImageLayer::HasDrawableContent() const {
36 return image_ && PictureLayer::HasDrawableContent(); 36 return image_.sk_image() && PictureLayer::HasDrawableContent();
37 } 37 }
38 38
39 void PictureImageLayer::SetImage(sk_sp<const SkImage> image) { 39 void PictureImageLayer::SetImage(PaintImage image) {
40 // SetImage() currently gets called whenever there is any 40 // SetImage() currently gets called whenever there is any
41 // style change that affects the layer even if that change doesn't 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). 42 // affect the actual contents of the image (e.g. a CSS animation).
43 // With this check in place we avoid unecessary texture uploads. 43 // With this check in place we avoid unecessary texture uploads.
44 if (image_.get() == image.get()) 44 if (image_ == image)
45 return; 45 return;
46 46
47 image_ = std::move(image); 47 image_ = std::move(image);
48 UpdateDrawsContent(HasDrawableContent()); 48 UpdateDrawsContent(HasDrawableContent());
49 SetNeedsDisplay(); 49 SetNeedsDisplay();
50 } 50 }
51 51
52 gfx::Rect PictureImageLayer::PaintableRegion() { 52 gfx::Rect PictureImageLayer::PaintableRegion() {
53 return gfx::Rect(bounds()); 53 return gfx::Rect(bounds());
54 } 54 }
55 55
56 scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList( 56 scoped_refptr<DisplayItemList> PictureImageLayer::PaintContentsToDisplayList(
57 ContentLayerClient::PaintingControlSetting painting_control) { 57 ContentLayerClient::PaintingControlSetting painting_control) {
58 DCHECK(image_); 58 DCHECK(image_.sk_image());
59 DCHECK_GT(image_->width(), 0); 59 DCHECK_GT(image_.sk_image()->width(), 0);
60 DCHECK_GT(image_->height(), 0); 60 DCHECK_GT(image_.sk_image()->height(), 0);
61 DCHECK(layer_tree_host()); 61 DCHECK(layer_tree_host());
62 62
63 auto display_list = make_scoped_refptr(new DisplayItemList); 63 auto display_list = make_scoped_refptr(new DisplayItemList);
64 64
65 PaintRecorder recorder; 65 PaintRecorder recorder;
66 PaintCanvas* canvas = 66 PaintCanvas* canvas =
67 recorder.beginRecording(gfx::RectToSkRect(PaintableRegion())); 67 recorder.beginRecording(gfx::RectToSkRect(PaintableRegion()));
68 68
69 SkScalar content_to_layer_scale_x = 69 SkScalar content_to_layer_scale_x = SkFloatToScalar(
70 SkFloatToScalar(static_cast<float>(bounds().width()) / image_->width()); 70 static_cast<float>(bounds().width()) / image_.sk_image()->width());
71 SkScalar content_to_layer_scale_y = 71 SkScalar content_to_layer_scale_y = SkFloatToScalar(
72 SkFloatToScalar(static_cast<float>(bounds().height()) / image_->height()); 72 static_cast<float>(bounds().height()) / image_.sk_image()->height());
73 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y); 73 canvas->scale(content_to_layer_scale_x, content_to_layer_scale_y);
74 74
75 // Because Android WebView resourceless software draw mode rasters directly 75 // Because Android WebView resourceless software draw mode rasters directly
76 // to the root canvas, this draw must use the kSrcOver_Mode so that 76 // to the root canvas, this draw must use the kSrcOver_Mode so that
77 // transparent images blend correctly. 77 // transparent images blend correctly.
78 // TODO(vmpstr): Plumb animation type and completion states to here. 78 canvas->drawImage(image_, 0, 0);
79 canvas->drawImage(PaintImage(image_, PaintImage::AnimationType::UNKNOWN,
80 PaintImage::CompletionState::UNKNOWN),
81 0, 0);
82 79
83 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>( 80 display_list->CreateAndAppendDrawingItem<DrawingDisplayItem>(
84 PaintableRegion(), recorder.finishRecordingAsPicture()); 81 PaintableRegion(), recorder.finishRecordingAsPicture());
85 82
86 display_list->Finalize(); 83 display_list->Finalize();
87 return display_list; 84 return display_list;
88 } 85 }
89 86
90 bool PictureImageLayer::FillsBoundsCompletely() const { 87 bool PictureImageLayer::FillsBoundsCompletely() const {
91 return false; 88 return false;
92 } 89 }
93 90
94 size_t PictureImageLayer::GetApproximateUnsharedMemoryUsage() const { 91 size_t PictureImageLayer::GetApproximateUnsharedMemoryUsage() const {
95 return 0; 92 return 0;
96 } 93 }
97 94
98 } // namespace cc 95 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_image_layer.h ('k') | cc/layers/picture_image_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698