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

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

Issue 2141233002: cc: Clean up RecordingSource API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 5 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
OLDNEW
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 "base/trace_event/trace_event.h" 8 #include "base/trace_event/trace_event.h"
9 #include "cc/layers/content_layer_client.h" 9 #include "cc/layers/content_layer_client.h"
10 #include "cc/layers/picture_layer_impl.h" 10 #include "cc/layers/picture_layer_impl.h"
11 #include "cc/playback/recording_source.h"
12 #include "cc/proto/cc_conversions.h" 11 #include "cc/proto/cc_conversions.h"
13 #include "cc/proto/gfx_conversions.h" 12 #include "cc/proto/gfx_conversions.h"
14 #include "cc/proto/layer.pb.h" 13 #include "cc/proto/layer.pb.h"
15 #include "cc/trees/layer_tree_host.h" 14 #include "cc/trees/layer_tree_host.h"
16 #include "cc/trees/layer_tree_impl.h" 15 #include "cc/trees/layer_tree_impl.h"
17 #include "third_party/skia/include/core/SkPictureRecorder.h" 16 #include "third_party/skia/include/core/SkPictureRecorder.h"
18 #include "ui/gfx/geometry/rect_conversions.h" 17 #include "ui/gfx/geometry/rect_conversions.h"
19 18
20 namespace cc { 19 namespace cc {
21 20
21 PictureLayerData::PictureLayerData() = default;
22
23 PictureLayerData::~PictureLayerData() = default;
24
25 ContentLayerClientData::ContentLayerClientData() = default;
26
27 ContentLayerClientData::ContentLayerClientData(const ContentLayerClientData&) =
28 default;
29
30 ContentLayerClientData::~ContentLayerClientData() = default;
31
22 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { 32 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
23 return make_scoped_refptr(new PictureLayer(client)); 33 return make_scoped_refptr(new PictureLayer(client));
24 } 34 }
25 35
26 PictureLayer::PictureLayer(ContentLayerClient* client) 36 PictureLayer::PictureLayer(ContentLayerClient* client)
27 : instrumentation_object_tracker_(id()), 37 : instrumentation_object_tracker_(id()),
28 update_source_frame_number_(-1), 38 update_source_frame_number_(-1),
29 is_mask_(false) { 39 is_mask_(false) {
30 inputs_.client = client; 40 inputs_.client = client;
31 } 41 }
32 42
33 PictureLayer::PictureLayer(ContentLayerClient* client, 43 PictureLayer::PictureLayer(ContentLayerClient* client,
34 std::unique_ptr<RecordingSource> source) 44 const PictureLayerData& layer_data,
45 const ContentLayerClientData& client_data)
35 : PictureLayer(client) { 46 : PictureLayer(client) {
36 recording_source_ = std::move(source); 47 layer_data_ = layer_data;
48 client_data_ = client_data;
37 } 49 }
38 50
39 PictureLayer::~PictureLayer() { 51 PictureLayer::~PictureLayer() {
40 } 52 }
41 53
42 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl( 54 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl(
43 LayerTreeImpl* tree_impl) { 55 LayerTreeImpl* tree_impl) {
44 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); 56 return PictureLayerImpl::Create(tree_impl, id(), is_mask_);
45 } 57 }
46 58
47 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { 59 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
48 Layer::PushPropertiesTo(base_layer); 60 Layer::PushPropertiesTo(base_layer);
49 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); 61 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo");
50 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 62 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
51 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. 63 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer.
52 DCHECK_EQ(layer_impl->is_mask(), is_mask_); 64 DCHECK_EQ(layer_impl->is_mask(), is_mask_);
53 DropRecordingSourceContentIfInvalid(); 65 DropRecordingSourceContentIfInvalid();
54 66
55 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor); 67 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor);
56 68
57 // Preserve lcd text settings from the current raster source. 69 // Preserve lcd text settings from the current raster source.
58 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); 70 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText();
59 scoped_refptr<RasterSource> raster_source = 71 scoped_refptr<RasterSource> raster_source =
60 recording_source_->CreateRasterSource(can_use_lcd_text); 72 CreateRasterSource(layer_data_, client_data_, can_use_lcd_text);
61 layer_impl->set_gpu_raster_max_texture_size( 73 layer_impl->set_gpu_raster_max_texture_size(
62 layer_tree_host()->device_viewport_size()); 74 layer_tree_host()->device_viewport_size());
63 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, 75 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_,
64 nullptr); 76 nullptr);
65 DCHECK(last_updated_invalidation_.IsEmpty()); 77 DCHECK(last_updated_invalidation_.IsEmpty());
66 } 78 }
67 79
68 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { 80 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) {
69 Layer::SetLayerTreeHost(host); 81 Layer::SetLayerTreeHost(host);
70 if (!host) 82 if (!host)
71 return; 83 return;
72 84
73 if (!recording_source_) 85 layer_data_ = PictureLayerData();
vmpstr 2016/07/20 22:18:10 What's the difference between this and ResetLayerA
Menglin 2016/07/20 22:39:31 ResetLayerAndClientData() is essentially layer_
vmpstr 2016/07/20 23:55:54 Hmm... It certainly isn't reset if it's only reset
74 recording_source_.reset(new RecordingSource); 86 client_data_ = ContentLayerClientData();
75 recording_source_->SetSlowdownRasterScaleFactor( 87 layer_data_.slow_down_raster_scale_factor_for_debug =
76 host->debug_state().slow_down_raster_scale_factor); 88 host->debug_state().slow_down_raster_scale_factor;
77 // If we need to enable image decode tasks, then we have to generate the 89 // If we need to enable image decode tasks, then we have to generate the
78 // discardable images metadata. 90 // discardable images metadata.
79 const LayerTreeSettings& settings = layer_tree_host()->settings(); 91 const LayerTreeSettings& settings = layer_tree_host()->settings();
80 recording_source_->SetGenerateDiscardableImagesMetadata( 92 SetGenerateDiscardableImagesMetadata(settings.image_decode_tasks_enabled);
81 settings.image_decode_tasks_enabled);
82 } 93 }
83 94
84 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { 95 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) {
85 DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents()); 96 DCHECK(!layer_tree_host() || !layer_tree_host()->in_paint_layer_contents());
86 if (recording_source_) 97 SetNeedsDisplayRectSimple(layer_rect);
vmpstr 2016/07/20 22:18:10 Can this function go away as well and just be repl
Menglin 2016/07/20 22:39:31 we probably want to keep it since the test code us
vmpstr 2016/07/20 23:55:54 Thanks! FWIW, we sometimes have FooInternal when t
87 recording_source_->SetNeedsDisplayRect(layer_rect);
88 Layer::SetNeedsDisplayRect(layer_rect); 98 Layer::SetNeedsDisplayRect(layer_rect);
89 } 99 }
90 100
91 bool PictureLayer::Update() { 101 bool PictureLayer::Update() {
92 update_source_frame_number_ = layer_tree_host()->source_frame_number(); 102 update_source_frame_number_ = layer_tree_host()->source_frame_number();
93 bool updated = Layer::Update(); 103 bool updated = Layer::Update();
94 104
95 gfx::Size layer_size = paint_properties().bounds; 105 gfx::Size layer_size = paint_properties().bounds;
96 106
97 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); 107 SetBackgroundColorSimple(SafeOpaqueBackgroundColor());
98 recording_source_->SetRequiresClear(!contents_opaque() && 108 SetRequiresClear(!contents_opaque() &&
99 !inputs_.client->FillsBoundsCompletely()); 109 !inputs_.client->FillsBoundsCompletely());
100 110
101 TRACE_EVENT1("cc", "PictureLayer::Update", 111 TRACE_EVENT1("cc", "PictureLayer::Update",
102 "source_frame_number", 112 "source_frame_number",
103 layer_tree_host()->source_frame_number()); 113 layer_tree_host()->source_frame_number());
104 devtools_instrumentation::ScopedLayerTreeTask update_layer( 114 devtools_instrumentation::ScopedLayerTreeTask update_layer(
105 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); 115 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id());
106 116
107 // UpdateAndExpandInvalidation will give us an invalidation that covers 117 // UpdateAndExpandInvalidation will give us an invalidation that covers
108 // anything not explicitly recorded in this frame. We give this region 118 // anything not explicitly recorded in this frame. We give this region
109 // to the impl side so that it drops tiles that may not have a recording 119 // to the impl side so that it drops tiles that may not have a recording
110 // for them. 120 // for them.
111 DCHECK(inputs_.client); 121 DCHECK(inputs_.client);
112 updated |= recording_source_->UpdateAndExpandInvalidation( 122 updated |= UpdateAndExpandInvalidation(
113 inputs_.client, &last_updated_invalidation_, layer_size, 123 &last_updated_invalidation_, layer_size, PictureLayer::RECORD_NORMALLY,
vmpstr 2016/07/20 22:18:10 Do we ever pass something other than "RECORD_NORMA
Menglin 2016/07/20 22:39:31 I checked, it always pass RECORD_NORMALLY
114 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); 124 &layer_data_, &client_data_, &invalidation_);
vmpstr 2016/07/20 22:18:10 In general, if we can eliminate some of these para
Menglin 2016/07/20 22:39:31 but that doesn't work in GetPicture, where it rece
vmpstr 2016/07/20 23:55:54 Oh yeah, good point.
115 125
116 if (updated) { 126 if (updated) {
117 SetNeedsPushProperties(); 127 SetNeedsPushProperties();
118 } else { 128 } else {
119 // If this invalidation did not affect the recording source, then it can be 129 // If this invalidation did not affect the recording source, then it can be
120 // cleared as an optimization. 130 // cleared as an optimization.
121 last_updated_invalidation_.Clear(); 131 last_updated_invalidation_.Clear();
122 } 132 }
123 133
124 return updated; 134 return updated;
125 } 135 }
126 136
127 void PictureLayer::SetIsMask(bool is_mask) { 137 void PictureLayer::SetIsMask(bool is_mask) {
128 is_mask_ = is_mask; 138 is_mask_ = is_mask;
129 } 139 }
130 140
131 sk_sp<SkPicture> PictureLayer::GetPicture() const { 141 sk_sp<SkPicture> PictureLayer::GetPicture() const {
132 // We could either flatten the RecordingSource into a single 142 // We could either flatten the RecordingSource into a single
133 // SkPicture, or paint a fresh one depending on what we intend to do with the 143 // SkPicture, or paint a fresh one depending on what we intend to do with the
134 // picture. For now we just paint a fresh one to get consistent results. 144 // picture. For now we just paint a fresh one to get consistent results.
135 if (!DrawsContent()) 145 if (!DrawsContent())
136 return nullptr; 146 return nullptr;
137 147
138 gfx::Size layer_size = bounds(); 148 gfx::Size layer_size = bounds();
139 std::unique_ptr<RecordingSource> recording_source(new RecordingSource);
140 Region recording_invalidation; 149 Region recording_invalidation;
141 recording_source->UpdateAndExpandInvalidation( 150 InvalidationRegion invalidation_regision;
vmpstr 2016/07/20 22:18:10 s/regision/region/
Menglin 2016/07/20 22:39:31 ok
142 inputs_.client, &recording_invalidation, layer_size, 151 PictureLayerData layer_data = PictureLayerData();
143 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); 152 ContentLayerClientData client_data = ContentLayerClientData();
144 153 UpdateAndExpandInvalidation(&recording_invalidation, layer_size,
154 PictureLayer::RECORD_NORMALLY, &layer_data,
155 &client_data, &invalidation_regision);
Menglin 2016/07/20 22:39:31 Here it needs the local variables
vmpstr 2016/07/20 23:55:54 Acknowledged.
145 scoped_refptr<RasterSource> raster_source = 156 scoped_refptr<RasterSource> raster_source =
146 recording_source->CreateRasterSource(false); 157 CreateRasterSource(layer_data, client_data, false);
147 158
148 return raster_source->GetFlattenedPicture(); 159 return raster_source->GetFlattenedPicture();
149 } 160 }
150 161
151 bool PictureLayer::IsSuitableForGpuRasterization() const { 162 bool PictureLayer::IsSuitableForGpuRasterization() const {
152 return recording_source_->IsSuitableForGpuRasterization(); 163 // The display list needs to be created (see: UpdateAndExpandInvalidation)
164 // before checking for suitability. There are cases where an update will not
165 // create a display list (e.g., if the size is empty). We return true in these
166 // cases because the gpu suitability bit sticks false.
167 return !client_data_.display_list ||
168 client_data_.display_list->IsSuitableForGpuRasterization();
153 } 169 }
154 170
155 void PictureLayer::ClearClient() { 171 void PictureLayer::ClearClient() {
156 inputs_.client = nullptr; 172 inputs_.client = nullptr;
157 UpdateDrawsContent(HasDrawableContent()); 173 UpdateDrawsContent(HasDrawableContent());
158 } 174 }
159 175
160 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { 176 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) {
161 if (inputs_.nearest_neighbor == nearest_neighbor) 177 if (inputs_.nearest_neighbor == nearest_neighbor)
162 return; 178 return;
163 179
164 inputs_.nearest_neighbor = nearest_neighbor; 180 inputs_.nearest_neighbor = nearest_neighbor;
165 SetNeedsCommit(); 181 SetNeedsCommit();
166 } 182 }
167 183
168 bool PictureLayer::HasDrawableContent() const { 184 bool PictureLayer::HasDrawableContent() const {
169 return inputs_.client && Layer::HasDrawableContent(); 185 return inputs_.client && Layer::HasDrawableContent();
170 } 186 }
171 187
172 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { 188 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const {
173 proto->set_type(proto::LayerNode::PICTURE_LAYER); 189 proto->set_type(proto::LayerNode::PICTURE_LAYER);
174 } 190 }
175 191
176 void PictureLayer::LayerSpecificPropertiesToProto( 192 void PictureLayer::LayerSpecificPropertiesToProto(
177 proto::LayerProperties* proto) { 193 proto::LayerProperties* proto) {
178 Layer::LayerSpecificPropertiesToProto(proto); 194 Layer::LayerSpecificPropertiesToProto(proto);
179 DropRecordingSourceContentIfInvalid(); 195 DropRecordingSourceContentIfInvalid();
180 196
181 proto::PictureLayerProperties* picture = proto->mutable_picture(); 197 proto::PictureLayerProperties* picture = proto->mutable_picture();
182 recording_source_->ToProtobuf(picture->mutable_recording_source()); 198
199 RectToProto(client_data_.recorded_viewport,
200 picture->mutable_recorded_viewport());
201 SizeToProto(layer_data_.size, picture->mutable_size());
202 picture->set_slow_down_raster_scale_factor_for_debug(
203 layer_data_.slow_down_raster_scale_factor_for_debug);
204 picture->set_generate_discardable_images_metadata(
205 layer_data_.generate_discardable_images_metadata);
206 picture->set_requires_clear(layer_data_.requires_clear);
207 picture->set_is_solid_color(layer_data_.is_solid_color);
208 picture->set_clear_canvas_with_debug_color(
209 layer_data_.clear_canvas_with_debug_color);
210 picture->set_solid_color(static_cast<uint64_t>(layer_data_.solid_color));
211 picture->set_background_color(
212 static_cast<uint64_t>(layer_data_.background_color));
213 if (client_data_.display_list)
214 client_data_.display_list->ToProtobuf(picture->mutable_display_list());
183 215
184 // Add all SkPicture items to the picture cache. 216 // Add all SkPicture items to the picture cache.
185 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); 217 const DisplayItemList* display_list = GetDisplayItemList();
186 if (display_list) { 218 if (display_list) {
187 for (auto it = display_list->begin(); it != display_list->end(); ++it) { 219 for (auto it = display_list->begin(); it != display_list->end(); ++it) {
188 sk_sp<const SkPicture> picture = it->GetPicture(); 220 sk_sp<const SkPicture> picture = it->GetPicture();
189 // Only DrawingDisplayItems have SkPictures. 221 // Only DrawingDisplayItems have SkPictures.
190 if (!picture) 222 if (!picture)
191 continue; 223 continue;
192 224
193 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); 225 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get());
194 } 226 }
195 } 227 }
196 228
197 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); 229 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation());
198 picture->set_is_mask(is_mask_); 230 picture->set_is_mask(is_mask_);
199 picture->set_nearest_neighbor(inputs_.nearest_neighbor); 231 picture->set_nearest_neighbor(inputs_.nearest_neighbor);
200 232
201 picture->set_update_source_frame_number(update_source_frame_number_); 233 picture->set_update_source_frame_number(update_source_frame_number_);
202 234
203 last_updated_invalidation_.Clear(); 235 last_updated_invalidation_.Clear();
204 } 236 }
205 237
206 void PictureLayer::FromLayerSpecificPropertiesProto( 238 void PictureLayer::FromLayerSpecificPropertiesProto(
207 const proto::LayerProperties& proto) { 239 const proto::LayerProperties& proto) {
208 Layer::FromLayerSpecificPropertiesProto(proto); 240 Layer::FromLayerSpecificPropertiesProto(proto);
209 const proto::PictureLayerProperties& picture = proto.picture(); 241 const proto::PictureLayerProperties& picture = proto.picture();
210 // If this is a new layer, ensure it has a recording source. During layer 242 // If this is a new layer, ensure it has a recording source. During layer
211 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but 243 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but
212 // instead the member is set directly, so it needs to be set here explicitly. 244 // instead the member is set directly, so it needs to be set here explicitly.
213 if (!recording_source_) 245 layer_data_ = PictureLayerData();
214 recording_source_.reset(new RecordingSource); 246 client_data_ = ContentLayerClientData();
247 std::vector<uint32_t> used_engine_picture_ids;
215 248
216 std::vector<uint32_t> used_engine_picture_ids; 249 DCHECK(layer_tree_host()->client_picture_cache());
217 recording_source_->FromProtobuf(picture.recording_source(), 250 client_data_.recorded_viewport = ProtoToRect(picture.recorded_viewport());
218 layer_tree_host()->client_picture_cache(), 251 layer_data_.size = ProtoToSize(picture.size());
219 &used_engine_picture_ids); 252 layer_data_.slow_down_raster_scale_factor_for_debug =
253 picture.slow_down_raster_scale_factor_for_debug();
254 layer_data_.generate_discardable_images_metadata =
255 picture.generate_discardable_images_metadata();
256 layer_data_.requires_clear = picture.requires_clear();
257 layer_data_.is_solid_color = picture.is_solid_color();
258 layer_data_.clear_canvas_with_debug_color =
259 picture.clear_canvas_with_debug_color();
260 layer_data_.solid_color = static_cast<SkColor>(picture.solid_color());
261 layer_data_.background_color =
262 static_cast<SkColor>(picture.background_color());
263
264 // This might not exist if the |client_data_.display_list| of the serialized
265 // RecordingSource was null, which can happen if |Clear()| is
266 // called.
267 if (picture.has_display_list()) {
268 client_data_.display_list = DisplayItemList::CreateFromProto(
269 picture.display_list(), layer_tree_host()->client_picture_cache(),
270 &used_engine_picture_ids);
271 FinishDisplayItemListUpdate(&layer_data_, &client_data_);
272 } else {
273 client_data_.display_list = nullptr;
274 }
220 275
221 // Inform picture cache about which SkPictures are now in use. 276 // Inform picture cache about which SkPictures are now in use.
222 for (uint32_t engine_picture_id : used_engine_picture_ids) 277 for (uint32_t engine_picture_id : used_engine_picture_ids)
223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); 278 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id);
224 279
225 Region new_invalidation = RegionFromProto(picture.invalidation()); 280 Region new_invalidation = RegionFromProto(picture.invalidation());
226 last_updated_invalidation_.Swap(&new_invalidation); 281 last_updated_invalidation_.Swap(&new_invalidation);
227 is_mask_ = picture.is_mask(); 282 is_mask_ = picture.is_mask();
228 inputs_.nearest_neighbor = picture.nearest_neighbor(); 283 inputs_.nearest_neighbor = picture.nearest_neighbor();
229 284
230 update_source_frame_number_ = picture.update_source_frame_number(); 285 update_source_frame_number_ = picture.update_source_frame_number();
231 } 286 }
232 287
233 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { 288 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
234 benchmark->RunOnLayer(this); 289 benchmark->RunOnLayer(this);
235 } 290 }
236 291
292 bool PictureLayer::UpdateAndExpandInvalidation(
293 Region* invalidation,
294 const gfx::Size& layer_size,
295 PictureLayer::RecordingMode recording_mode,
296 PictureLayerData* layer_data,
297 ContentLayerClientData* client_data,
298 InvalidationRegion* invalidation_state) const {
299 bool updated = false;
300
301 if (layer_data->size != layer_size)
302 layer_data->size = layer_size;
303
304 invalidation_state->Swap(invalidation);
305 invalidation_state->Clear();
306
307 gfx::Rect new_recorded_viewport = inputs_.client->PaintableRegion();
308 if (new_recorded_viewport != client_data->recorded_viewport) {
309 UpdateInvalidationForNewViewport(client_data->recorded_viewport,
310 new_recorded_viewport, invalidation);
311 client_data->recorded_viewport = new_recorded_viewport;
312 updated = true;
313 }
314
315 if (!updated && !invalidation->Intersects(client_data->recorded_viewport))
316 return false;
317
318 if (invalidation->IsEmpty())
319 return false;
320
321 ContentLayerClient::PaintingControlSetting painting_control =
322 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL;
323
324 switch (recording_mode) {
325 case PictureLayer::RECORD_NORMALLY:
326 // Already setup for normal recording.
327 break;
328 case PictureLayer::RECORD_WITH_PAINTING_DISABLED:
329 painting_control = ContentLayerClient::DISPLAY_LIST_PAINTING_DISABLED;
330 break;
331 case PictureLayer::RECORD_WITH_CACHING_DISABLED:
332 painting_control = ContentLayerClient::DISPLAY_LIST_CACHING_DISABLED;
333 break;
334 case PictureLayer::RECORD_WITH_CONSTRUCTION_DISABLED:
335 painting_control = ContentLayerClient::DISPLAY_LIST_CONSTRUCTION_DISABLED;
336 break;
337 case PictureLayer::RECORD_WITH_SUBSEQUENCE_CACHING_DISABLED:
338 painting_control = ContentLayerClient::SUBSEQUENCE_CACHING_DISABLED;
339 break;
340 case PictureLayer::RECORD_WITH_SK_NULL_CANVAS:
341 case PictureLayer::RECORDING_MODE_COUNT:
342 NOTREACHED();
343 }
344
345 // TODO(vmpstr): Add a slow_down_recording_scale_factor_for_debug_ to be able
346 // to slow down recording.
347 client_data->display_list =
348 inputs_.client->PaintContentsToDisplayList(painting_control);
349 client_data->painter_reported_memory_usage =
350 inputs_.client->GetApproximateUnsharedMemoryUsage();
351
352 FinishDisplayItemListUpdate(layer_data, client_data);
353
354 return true;
355 }
356
357 void PictureLayer::ResetLayerAndClientData() {
358 layer_data_.size = gfx::Size();
359 client_data_.recorded_viewport = gfx::Rect();
360 client_data_.display_list = nullptr;
361 client_data_.painter_reported_memory_usage = 0;
362 layer_data_.is_solid_color = false;
363 }
364
365 void PictureLayer::SetGenerateDiscardableImagesMetadata(
366 bool generate_metadata) {
367 layer_data_.generate_discardable_images_metadata = generate_metadata;
368 }
369
370 void PictureLayer::SetBackgroundColorSimple(SkColor background_color) {
371 layer_data_.background_color = background_color;
372 }
373
374 void PictureLayer::SetRequiresClear(bool requires_clear) {
375 layer_data_.requires_clear = requires_clear;
376 }
377
378 void PictureLayer::SetNeedsDisplayRectSimple(const gfx::Rect& layer_rect) {
379 if (!layer_rect.IsEmpty()) {
380 // Clamp invalidation to the layer bounds.
381 invalidation_.Union(
382 gfx::IntersectRects(layer_rect, gfx::Rect(layer_data_.size)));
383 }
384 }
385
386 gfx::Size PictureLayer::GetSizeInLayerData() const {
387 return layer_data_.size;
388 }
389
390 const DisplayItemList* PictureLayer::GetDisplayItemList() {
391 return client_data_.display_list.get();
392 }
393
394 scoped_refptr<RasterSource> PictureLayer::CreateRasterSource(
395 const PictureLayerData& layer_data,
396 const ContentLayerClientData& client_data,
397 bool can_use_lcd_text) const {
398 return scoped_refptr<RasterSource>(RasterSource::CreateFromDataStruct(
vmpstr 2016/07/20 22:18:10 You don't need to wrap this in scoped_refptr, sinc
399 layer_data, client_data, can_use_lcd_text));
400 }
401
237 void PictureLayer::DropRecordingSourceContentIfInvalid() { 402 void PictureLayer::DropRecordingSourceContentIfInvalid() {
238 int source_frame_number = layer_tree_host()->source_frame_number(); 403 int source_frame_number = layer_tree_host()->source_frame_number();
239 gfx::Size recording_source_bounds = recording_source_->GetSize(); 404 gfx::Size recording_source_bounds = GetSizeInLayerData();
240 405
241 gfx::Size layer_bounds = bounds(); 406 gfx::Size layer_bounds = bounds();
242 if (paint_properties().source_frame_number == source_frame_number) 407 if (paint_properties().source_frame_number == source_frame_number)
243 layer_bounds = paint_properties().bounds; 408 layer_bounds = paint_properties().bounds;
244 409
245 // If update called, then recording source size must match bounds pushed to 410 // If update called, then recording source size must match bounds pushed to
246 // impl layer. 411 // impl layer.
247 DCHECK(update_source_frame_number_ != source_frame_number || 412 DCHECK(update_source_frame_number_ != source_frame_number ||
248 layer_bounds == recording_source_bounds) 413 layer_bounds == recording_source_bounds)
249 << " bounds " << layer_bounds.ToString() << " recording source " 414 << " bounds " << layer_bounds.ToString() << " recording source "
250 << recording_source_bounds.ToString(); 415 << recording_source_bounds.ToString();
251 416
252 if (update_source_frame_number_ != source_frame_number && 417 if (update_source_frame_number_ != source_frame_number &&
253 recording_source_bounds != layer_bounds) { 418 recording_source_bounds != layer_bounds) {
254 // Update may not get called for the layer (if it's not in the viewport 419 // Update may not get called for the layer (if it's not in the viewport
255 // for example), even though it has resized making the recording source no 420 // for example), even though it has resized making the recording source no
256 // longer valid. In this case just destroy the recording source. 421 // longer valid. In this case just destroy the recording source.
257 recording_source_->SetEmptyBounds(); 422 ResetLayerAndClientData();
258 } 423 }
259 } 424 }
260 425
426 void PictureLayer::FinishDisplayItemListUpdate(
427 PictureLayerData* layer_data,
428 ContentLayerClientData* client_data) const {
429 TRACE_EVENT0("cc", "PictureLayer::FinishDisplayItemListUpdate");
430 DetermineIfSolidColor(layer_data, client_data);
431 client_data->display_list->EmitTraceSnapshot();
432 if (layer_data->generate_discardable_images_metadata)
433 client_data->display_list->GenerateDiscardableImagesMetadata();
434 }
435
436 void PictureLayer::DetermineIfSolidColor(
437 PictureLayerData* layer_data,
438 ContentLayerClientData* client_data) const {
439 DCHECK(client_data->display_list);
440 layer_data->is_solid_color = false;
441 layer_data->solid_color = SK_ColorTRANSPARENT;
442
443 if (!client_data->display_list->ShouldBeAnalyzedForSolidColor())
444 return;
445
446 TRACE_EVENT1("cc", "PictureLayer::DetermineIfSolidColor", "opcount",
447 client_data->display_list->ApproximateOpCount());
448 gfx::Size layer_size = layer_data->size;
449 skia::AnalysisCanvas canvas(layer_size.width(), layer_size.height());
450 client_data->display_list->Raster(&canvas, nullptr, gfx::Rect(), 1.f);
451 layer_data->is_solid_color = canvas.GetColorIfSolid(&layer_data->solid_color);
452 }
453
454 void PictureLayer::UpdateInvalidationForNewViewport(
455 const gfx::Rect& old_recorded_viewport,
456 const gfx::Rect& new_recorded_viewport,
457 Region* invalidation) const {
458 // Invalidate newly-exposed and no-longer-exposed areas.
459 Region newly_exposed_region(new_recorded_viewport);
460 newly_exposed_region.Subtract(old_recorded_viewport);
461 invalidation->Union(newly_exposed_region);
462
463 Region no_longer_exposed_region(old_recorded_viewport);
464 no_longer_exposed_region.Subtract(new_recorded_viewport);
465 invalidation->Union(no_longer_exposed_region);
466 }
467
261 } // namespace cc 468 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698