OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_layer.h" | 5 #include "cc/layers/picture_layer.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "cc/layers/content_layer_client.h" | 8 #include "cc/layers/content_layer_client.h" |
9 #include "cc/layers/picture_layer_impl.h" | 9 #include "cc/layers/picture_layer_impl.h" |
10 #include "cc/trees/layer_tree_impl.h" | 10 #include "cc/trees/layer_tree_impl.h" |
11 #include "third_party/skia/include/core/SkPictureRecorder.h" | 11 #include "third_party/skia/include/core/SkPictureRecorder.h" |
12 #include "ui/gfx/geometry/rect_conversions.h" | 12 #include "ui/gfx/geometry/rect_conversions.h" |
13 | 13 |
14 namespace cc { | 14 namespace cc { |
15 | 15 |
16 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | 16 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
17 return make_scoped_refptr(new PictureLayer(client)); | 17 return make_scoped_refptr(new PictureLayer(client)); |
18 } | 18 } |
19 | 19 |
20 PictureLayer::PictureLayer(ContentLayerClient* client) | 20 PictureLayer::PictureLayer(ContentLayerClient* client) |
21 : client_(client), | 21 : client_(client), |
22 pile_(make_scoped_refptr(new PicturePile())), | |
23 instrumentation_object_tracker_(id()), | 22 instrumentation_object_tracker_(id()), |
24 update_source_frame_number_(-1), | 23 update_source_frame_number_(-1), |
25 can_use_lcd_text_last_frame_(can_use_lcd_text()) { | 24 can_use_lcd_text_last_frame_(can_use_lcd_text()) { |
26 } | 25 } |
27 | 26 |
28 PictureLayer::~PictureLayer() { | 27 PictureLayer::~PictureLayer() { |
29 } | 28 } |
30 | 29 |
31 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 30 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
32 return PictureLayerImpl::Create(tree_impl, id()); | 31 return PictureLayerImpl::Create(tree_impl, id()); |
33 } | 32 } |
34 | 33 |
35 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 34 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
36 Layer::PushPropertiesTo(base_layer); | 35 Layer::PushPropertiesTo(base_layer); |
37 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 36 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
38 | 37 |
39 if (layer_impl->bounds().IsEmpty()) { | 38 if (layer_impl->bounds().IsEmpty()) { |
40 // Update may not get called for an empty layer, so resize here instead. | 39 // Update may not get called for an empty layer, so resize here instead. |
41 // Using layer_impl because either bounds() or paint_properties().bounds | 40 // Using layer_impl because either bounds() or paint_properties().bounds |
42 // may disagree and either one could have been pushed to layer_impl. | 41 // may disagree and either one could have been pushed to layer_impl. |
43 pile_->SetEmptyBounds(); | 42 pile_.SetEmptyBounds(); |
44 } else { | 43 } else { |
45 // If update called, then pile size must match bounds pushed to impl layer. | 44 // If update called, then pile size must match bounds pushed to impl layer. |
46 DCHECK_IMPLIES( | 45 DCHECK_IMPLIES( |
47 update_source_frame_number_ == layer_tree_host()->source_frame_number(), | 46 update_source_frame_number_ == layer_tree_host()->source_frame_number(), |
48 layer_impl->bounds().ToString() == pile_->tiling_size().ToString()); | 47 layer_impl->bounds().ToString() == pile_.tiling_size().ToString()); |
49 } | 48 } |
50 | 49 |
51 // Unlike other properties, invalidation must always be set on layer_impl. | 50 // Unlike other properties, invalidation must always be set on layer_impl. |
52 // See PictureLayerImpl::PushPropertiesTo for more details. | 51 // See PictureLayerImpl::PushPropertiesTo for more details. |
53 layer_impl->invalidation_.Clear(); | 52 layer_impl->invalidation_.Clear(); |
54 layer_impl->invalidation_.Swap(&pile_invalidation_); | 53 layer_impl->invalidation_.Swap(&pile_invalidation_); |
55 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get()); | 54 layer_impl->pile_ = PicturePileImpl::CreateFromOther(&pile_); |
56 } | 55 } |
57 | 56 |
58 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 57 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
59 Layer::SetLayerTreeHost(host); | 58 Layer::SetLayerTreeHost(host); |
60 if (host) { | 59 if (host) { |
61 pile_->SetMinContentsScale(host->settings().minimum_contents_scale); | 60 pile_.SetMinContentsScale(host->settings().minimum_contents_scale); |
62 pile_->SetTileGridSize(host->settings().default_tile_grid_size); | 61 pile_.SetTileGridSize(host->settings().default_tile_grid_size); |
63 pile_->set_slow_down_raster_scale_factor( | 62 pile_.set_slow_down_raster_scale_factor( |
64 host->debug_state().slow_down_raster_scale_factor); | 63 host->debug_state().slow_down_raster_scale_factor); |
65 pile_->set_show_debug_picture_borders( | 64 pile_.set_show_debug_picture_borders( |
66 host->debug_state().show_picture_borders); | 65 host->debug_state().show_picture_borders); |
67 } | 66 } |
68 } | 67 } |
69 | 68 |
70 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | 69 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { |
71 if (!layer_rect.IsEmpty()) { | 70 if (!layer_rect.IsEmpty()) { |
72 // Clamp invalidation to the layer bounds. | 71 // Clamp invalidation to the layer bounds. |
73 pending_invalidation_.Union( | 72 pending_invalidation_.Union( |
74 gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); | 73 gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); |
75 } | 74 } |
76 Layer::SetNeedsDisplayRect(layer_rect); | 75 Layer::SetNeedsDisplayRect(layer_rect); |
77 } | 76 } |
78 | 77 |
79 bool PictureLayer::Update(ResourceUpdateQueue* queue, | 78 bool PictureLayer::Update(ResourceUpdateQueue* queue, |
80 const OcclusionTracker<Layer>* occlusion) { | 79 const OcclusionTracker<Layer>* occlusion) { |
81 update_source_frame_number_ = layer_tree_host()->source_frame_number(); | 80 update_source_frame_number_ = layer_tree_host()->source_frame_number(); |
82 bool updated = Layer::Update(queue, occlusion); | 81 bool updated = Layer::Update(queue, occlusion); |
83 | 82 |
84 { | 83 { |
85 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 84 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
86 true); | 85 true); |
87 UpdateCanUseLCDText(); | 86 UpdateCanUseLCDText(); |
88 } | 87 } |
89 | 88 |
90 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( | 89 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( |
91 visible_content_rect(), 1.f / contents_scale_x()); | 90 visible_content_rect(), 1.f / contents_scale_x()); |
92 gfx::Size layer_size = paint_properties().bounds; | 91 gfx::Size layer_size = paint_properties().bounds; |
93 | 92 |
94 if (last_updated_visible_content_rect_ == visible_content_rect() && | 93 if (last_updated_visible_content_rect_ == visible_content_rect() && |
95 pile_->tiling_size() == layer_size && pending_invalidation_.IsEmpty()) { | 94 pile_.tiling_size() == layer_size && pending_invalidation_.IsEmpty()) { |
96 // Only early out if the visible content rect of this layer hasn't changed. | 95 // Only early out if the visible content rect of this layer hasn't changed. |
97 return updated; | 96 return updated; |
98 } | 97 } |
99 | 98 |
100 TRACE_EVENT1("cc", "PictureLayer::Update", | 99 TRACE_EVENT1("cc", "PictureLayer::Update", |
101 "source_frame_number", | 100 "source_frame_number", |
102 layer_tree_host()->source_frame_number()); | 101 layer_tree_host()->source_frame_number()); |
103 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 102 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
104 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); | 103 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); |
105 | 104 |
106 // Calling paint in WebKit can sometimes cause invalidations, so save | 105 // Calling paint in WebKit can sometimes cause invalidations, so save |
107 // off the invalidation prior to calling update. | 106 // off the invalidation prior to calling update. |
108 pending_invalidation_.Swap(&pile_invalidation_); | 107 pending_invalidation_.Swap(&pile_invalidation_); |
109 pending_invalidation_.Clear(); | 108 pending_invalidation_.Clear(); |
110 | 109 |
111 if (layer_tree_host()->settings().record_full_layer) { | 110 if (layer_tree_host()->settings().record_full_layer) { |
112 // Workaround for http://crbug.com/235910 - to retain backwards compat | 111 // Workaround for http://crbug.com/235910 - to retain backwards compat |
113 // the full page content must always be provided in the picture layer. | 112 // the full page content must always be provided in the picture layer. |
114 visible_layer_rect = gfx::Rect(layer_size); | 113 visible_layer_rect = gfx::Rect(layer_size); |
115 } | 114 } |
116 | 115 |
117 // UpdateAndExpandInvalidation will give us an invalidation that covers | 116 // UpdateAndExpandInvalidation will give us an invalidation that covers |
118 // anything not explicitly recorded in this frame. We give this region | 117 // anything not explicitly recorded in this frame. We give this region |
119 // to the impl side so that it drops tiles that may not have a recording | 118 // to the impl side so that it drops tiles that may not have a recording |
120 // for them. | 119 // for them. |
121 DCHECK(client_); | 120 DCHECK(client_); |
122 updated |= | 121 updated |= |
123 pile_->UpdateAndExpandInvalidation(client_, | 122 pile_.UpdateAndExpandInvalidation(client_, |
124 &pile_invalidation_, | 123 &pile_invalidation_, |
125 SafeOpaqueBackgroundColor(), | 124 SafeOpaqueBackgroundColor(), |
126 contents_opaque(), | 125 contents_opaque(), |
127 client_->FillsBoundsCompletely(), | 126 client_->FillsBoundsCompletely(), |
128 layer_size, | 127 layer_size, |
129 visible_layer_rect, | 128 visible_layer_rect, |
130 update_source_frame_number_, | 129 update_source_frame_number_, |
131 Picture::RECORD_NORMALLY, | 130 Picture::RECORD_NORMALLY, |
132 rendering_stats_instrumentation()); | 131 rendering_stats_instrumentation()); |
133 last_updated_visible_content_rect_ = visible_content_rect(); | 132 last_updated_visible_content_rect_ = visible_content_rect(); |
134 | 133 |
135 if (updated) { | 134 if (updated) { |
136 SetNeedsPushProperties(); | 135 SetNeedsPushProperties(); |
137 } else { | 136 } else { |
138 // If this invalidation did not affect the pile, then it can be cleared as | 137 // If this invalidation did not affect the pile, then it can be cleared as |
139 // an optimization. | 138 // an optimization. |
140 pile_invalidation_.Clear(); | 139 pile_invalidation_.Clear(); |
141 } | 140 } |
142 | 141 |
143 return updated; | 142 return updated; |
144 } | 143 } |
145 | 144 |
146 void PictureLayer::SetIsMask(bool is_mask) { | 145 void PictureLayer::SetIsMask(bool is_mask) { |
147 pile_->set_is_mask(is_mask); | 146 pile_.set_is_mask(is_mask); |
148 } | 147 } |
149 | 148 |
150 bool PictureLayer::SupportsLCDText() const { | 149 bool PictureLayer::SupportsLCDText() const { |
151 return true; | 150 return true; |
152 } | 151 } |
153 | 152 |
154 void PictureLayer::UpdateCanUseLCDText() { | 153 void PictureLayer::UpdateCanUseLCDText() { |
155 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) | 154 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) |
156 return; | 155 return; |
157 | 156 |
(...skipping 15 matching lines...) Expand all Loading... |
173 SkPictureRecorder recorder; | 172 SkPictureRecorder recorder; |
174 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); | 173 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); |
175 client_->PaintContents(canvas, | 174 client_->PaintContents(canvas, |
176 gfx::Rect(width, height), | 175 gfx::Rect(width, height), |
177 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | 176 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); |
178 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 177 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
179 return picture; | 178 return picture; |
180 } | 179 } |
181 | 180 |
182 bool PictureLayer::IsSuitableForGpuRasterization() const { | 181 bool PictureLayer::IsSuitableForGpuRasterization() const { |
183 return pile_->is_suitable_for_gpu_rasterization(); | 182 return pile_.is_suitable_for_gpu_rasterization(); |
184 } | 183 } |
185 | 184 |
186 void PictureLayer::ClearClient() { | 185 void PictureLayer::ClearClient() { |
187 client_ = nullptr; | 186 client_ = nullptr; |
188 UpdateDrawsContent(HasDrawableContent()); | 187 UpdateDrawsContent(HasDrawableContent()); |
189 } | 188 } |
190 | 189 |
191 bool PictureLayer::HasDrawableContent() const { | 190 bool PictureLayer::HasDrawableContent() const { |
192 return client_ && Layer::HasDrawableContent(); | 191 return client_ && Layer::HasDrawableContent(); |
193 } | 192 } |
194 | 193 |
195 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 194 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
196 benchmark->RunOnLayer(this); | 195 benchmark->RunOnLayer(this); |
197 } | 196 } |
198 | 197 |
199 } // namespace cc | 198 } // namespace cc |
OLD | NEW |