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

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: fix failed compositor_unittests Created 4 years, 4 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" 11 #include "cc/playback/recording_source.h"
12 #include "cc/proto/cc_conversions.h" 12 #include "cc/proto/cc_conversions.h"
13 #include "cc/proto/gfx_conversions.h" 13 #include "cc/proto/gfx_conversions.h"
14 #include "cc/proto/layer.pb.h" 14 #include "cc/proto/layer.pb.h"
15 #include "cc/trees/layer_tree_host.h" 15 #include "cc/trees/layer_tree_host.h"
16 #include "cc/trees/layer_tree_impl.h" 16 #include "cc/trees/layer_tree_impl.h"
17 #include "third_party/skia/include/core/SkPictureRecorder.h" 17 #include "third_party/skia/include/core/SkPictureRecorder.h"
18 #include "ui/gfx/geometry/rect_conversions.h" 18 #include "ui/gfx/geometry/rect_conversions.h"
19 19
20 namespace cc { 20 namespace cc {
21 21
22 PictureLayer::PictureLayerInputs::PictureLayerInputs() = default;
23
24 PictureLayer::PictureLayerInputs::~PictureLayerInputs() = default;
25
22 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { 26 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) {
23 return make_scoped_refptr(new PictureLayer(client)); 27 return make_scoped_refptr(new PictureLayer(client));
24 } 28 }
25 29
26 PictureLayer::PictureLayer(ContentLayerClient* client) 30 PictureLayer::PictureLayer(ContentLayerClient* client)
27 : instrumentation_object_tracker_(id()), 31 : instrumentation_object_tracker_(id()),
28 update_source_frame_number_(-1), 32 update_source_frame_number_(-1),
29 is_mask_(false) { 33 is_mask_(false) {
30 picture_layer_inputs_.client = client; 34 picture_layer_inputs_.client = client;
31 } 35 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 "source_frame_number", 107 "source_frame_number",
104 layer_tree_host()->source_frame_number()); 108 layer_tree_host()->source_frame_number());
105 devtools_instrumentation::ScopedLayerTreeTask update_layer( 109 devtools_instrumentation::ScopedLayerTreeTask update_layer(
106 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); 110 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id());
107 111
108 // UpdateAndExpandInvalidation will give us an invalidation that covers 112 // UpdateAndExpandInvalidation will give us an invalidation that covers
109 // anything not explicitly recorded in this frame. We give this region 113 // anything not explicitly recorded in this frame. We give this region
110 // to the impl side so that it drops tiles that may not have a recording 114 // to the impl side so that it drops tiles that may not have a recording
111 // for them. 115 // for them.
112 DCHECK(picture_layer_inputs_.client); 116 DCHECK(picture_layer_inputs_.client);
117
118 picture_layer_inputs_.recorded_viewport =
119 picture_layer_inputs_.client->PaintableRegion();
120
113 updated |= recording_source_->UpdateAndExpandInvalidation( 121 updated |= recording_source_->UpdateAndExpandInvalidation(
114 picture_layer_inputs_.client, &last_updated_invalidation_, layer_size, 122 picture_layer_inputs_.client, &last_updated_invalidation_, layer_size,
115 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); 123 picture_layer_inputs_.recorded_viewport);
116 124
117 if (updated) { 125 if (updated) {
126 picture_layer_inputs_.display_list =
127 picture_layer_inputs_.client->PaintContentsToDisplayList(
128 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
129 picture_layer_inputs_.painter_reported_memory_usage =
130 picture_layer_inputs_.client->GetApproximateUnsharedMemoryUsage();
131 recording_source_->UpdateDisplayItemList(
132 picture_layer_inputs_.display_list,
133 picture_layer_inputs_.painter_reported_memory_usage);
118 SetNeedsPushProperties(); 134 SetNeedsPushProperties();
119 } else { 135 } else {
120 // If this invalidation did not affect the recording source, then it can be 136 // If this invalidation did not affect the recording source, then it can be
121 // cleared as an optimization. 137 // cleared as an optimization.
122 last_updated_invalidation_.Clear(); 138 last_updated_invalidation_.Clear();
123 } 139 }
124 140
125 return updated; 141 return updated;
126 } 142 }
127 143
128 void PictureLayer::SetIsMask(bool is_mask) { 144 void PictureLayer::SetIsMask(bool is_mask) {
129 is_mask_ = is_mask; 145 is_mask_ = is_mask;
130 } 146 }
131 147
132 sk_sp<SkPicture> PictureLayer::GetPicture() const { 148 sk_sp<SkPicture> PictureLayer::GetPicture() const {
133 // We could either flatten the RecordingSource into a single 149 // We could either flatten the RecordingSource into a single
134 // SkPicture, or paint a fresh one depending on what we intend to do with the 150 // SkPicture, or paint a fresh one depending on what we intend to do with the
135 // picture. For now we just paint a fresh one to get consistent results. 151 // picture. For now we just paint a fresh one to get consistent results.
136 if (!DrawsContent()) 152 if (!DrawsContent())
137 return nullptr; 153 return nullptr;
138 154
139 gfx::Size layer_size = bounds(); 155 gfx::Size layer_size = bounds();
140 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); 156 RecordingSource recording_source;
141 Region recording_invalidation; 157 Region recording_invalidation;
142 recording_source->UpdateAndExpandInvalidation( 158
159 gfx::Rect new_recorded_viewport =
160 picture_layer_inputs_.client->PaintableRegion();
161 scoped_refptr<DisplayItemList> display_list =
162 picture_layer_inputs_.client->PaintContentsToDisplayList(
163 ContentLayerClient::PAINTING_BEHAVIOR_NORMAL);
164 size_t painter_reported_memory_usage =
165 picture_layer_inputs_.client->GetApproximateUnsharedMemoryUsage();
166
167 recording_source.UpdateAndExpandInvalidation(
143 picture_layer_inputs_.client, &recording_invalidation, layer_size, 168 picture_layer_inputs_.client, &recording_invalidation, layer_size,
144 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); 169 new_recorded_viewport);
170 recording_source.UpdateDisplayItemList(display_list,
171 painter_reported_memory_usage);
145 172
146 scoped_refptr<RasterSource> raster_source = 173 scoped_refptr<RasterSource> raster_source =
147 recording_source->CreateRasterSource(false); 174 recording_source.CreateRasterSource(false);
148 175
149 return raster_source->GetFlattenedPicture(); 176 return raster_source->GetFlattenedPicture();
150 } 177 }
151 178
152 bool PictureLayer::IsSuitableForGpuRasterization() const { 179 bool PictureLayer::IsSuitableForGpuRasterization() const {
153 return recording_source_->IsSuitableForGpuRasterization(); 180 // The display list needs to be created (see: UpdateAndExpandInvalidation)
181 // before checking for suitability. There are cases where an update will not
182 // create a display list (e.g., if the size is empty). We return true in these
183 // cases because the gpu suitability bit sticks false.
184 return !picture_layer_inputs_.display_list ||
185 picture_layer_inputs_.display_list->IsSuitableForGpuRasterization();
154 } 186 }
155 187
156 void PictureLayer::ClearClient() { 188 void PictureLayer::ClearClient() {
157 picture_layer_inputs_.client = nullptr; 189 picture_layer_inputs_.client = nullptr;
158 UpdateDrawsContent(HasDrawableContent()); 190 UpdateDrawsContent(HasDrawableContent());
159 } 191 }
160 192
161 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { 193 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) {
162 if (picture_layer_inputs_.nearest_neighbor == nearest_neighbor) 194 if (picture_layer_inputs_.nearest_neighbor == nearest_neighbor)
163 return; 195 return;
(...skipping 11 matching lines...) Expand all
175 } 207 }
176 208
177 void PictureLayer::LayerSpecificPropertiesToProto( 209 void PictureLayer::LayerSpecificPropertiesToProto(
178 proto::LayerProperties* proto) { 210 proto::LayerProperties* proto) {
179 Layer::LayerSpecificPropertiesToProto(proto); 211 Layer::LayerSpecificPropertiesToProto(proto);
180 DropRecordingSourceContentIfInvalid(); 212 DropRecordingSourceContentIfInvalid();
181 213
182 proto::PictureLayerProperties* picture = proto->mutable_picture(); 214 proto::PictureLayerProperties* picture = proto->mutable_picture();
183 recording_source_->ToProtobuf(picture->mutable_recording_source()); 215 recording_source_->ToProtobuf(picture->mutable_recording_source());
184 216
185 // Add all SkPicture items to the picture cache. 217 RectToProto(picture_layer_inputs_.recorded_viewport,
186 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); 218 picture->mutable_recorded_viewport());
187 if (display_list) { 219 if (picture_layer_inputs_.display_list) {
188 for (auto it = display_list->begin(); it != display_list->end(); ++it) { 220 picture_layer_inputs_.display_list->ToProtobuf(
189 sk_sp<const SkPicture> picture = it->GetPicture(); 221 picture->mutable_display_list());
222 for (const auto& item : *picture_layer_inputs_.display_list) {
223 sk_sp<const SkPicture> picture = item.GetPicture();
190 // Only DrawingDisplayItems have SkPictures. 224 // Only DrawingDisplayItems have SkPictures.
191 if (!picture) 225 if (!picture)
192 continue; 226 continue;
193 227
194 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); 228 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get());
195 } 229 }
196 } 230 }
197 231
198 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); 232 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation());
199 picture->set_is_mask(is_mask_); 233 picture->set_is_mask(is_mask_);
200 picture->set_nearest_neighbor(picture_layer_inputs_.nearest_neighbor); 234 picture->set_nearest_neighbor(picture_layer_inputs_.nearest_neighbor);
201 235
202 picture->set_update_source_frame_number(update_source_frame_number_); 236 picture->set_update_source_frame_number(update_source_frame_number_);
203 237
204 last_updated_invalidation_.Clear(); 238 last_updated_invalidation_.Clear();
205 } 239 }
206 240
207 void PictureLayer::FromLayerSpecificPropertiesProto( 241 void PictureLayer::FromLayerSpecificPropertiesProto(
208 const proto::LayerProperties& proto) { 242 const proto::LayerProperties& proto) {
209 Layer::FromLayerSpecificPropertiesProto(proto); 243 Layer::FromLayerSpecificPropertiesProto(proto);
210 const proto::PictureLayerProperties& picture = proto.picture(); 244 const proto::PictureLayerProperties& picture = proto.picture();
211 // If this is a new layer, ensure it has a recording source. During layer 245 // If this is a new layer, ensure it has a recording source. During layer
212 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but 246 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but
213 // instead the member is set directly, so it needs to be set here explicitly. 247 // instead the member is set directly, so it needs to be set here explicitly.
214 if (!recording_source_) 248 if (!recording_source_)
215 recording_source_.reset(new RecordingSource); 249 recording_source_.reset(new RecordingSource);
216 250
217 std::vector<uint32_t> used_engine_picture_ids; 251 std::vector<uint32_t> used_engine_picture_ids;
252
253 picture_layer_inputs_.recorded_viewport =
254 ProtoToRect(picture.recorded_viewport());
255
256 ClientPictureCache* client_picture_cache =
257 layer_tree_host()->client_picture_cache();
258 DCHECK(client_picture_cache);
259 // This might not exist if the |input_.display_list| of the serialized
260 // RecordingSource was null, which can happen if |Clear()| is
261 // called.
262 if (picture.has_display_list()) {
263 picture_layer_inputs_.display_list = DisplayItemList::CreateFromProto(
264 picture.display_list(), client_picture_cache, &used_engine_picture_ids);
265 } else {
266 picture_layer_inputs_.display_list = nullptr;
267 }
268
218 recording_source_->FromProtobuf(picture.recording_source(), 269 recording_source_->FromProtobuf(picture.recording_source(),
219 layer_tree_host()->client_picture_cache(), 270 picture_layer_inputs_.display_list);
220 &used_engine_picture_ids);
221 271
222 // Inform picture cache about which SkPictures are now in use. 272 // Inform picture cache about which SkPictures are now in use.
223 for (uint32_t engine_picture_id : used_engine_picture_ids) 273 for (uint32_t engine_picture_id : used_engine_picture_ids)
224 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); 274 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id);
225 275
226 Region new_invalidation = RegionFromProto(picture.invalidation()); 276 Region new_invalidation = RegionFromProto(picture.invalidation());
227 last_updated_invalidation_.Swap(&new_invalidation); 277 last_updated_invalidation_.Swap(&new_invalidation);
228 is_mask_ = picture.is_mask(); 278 is_mask_ = picture.is_mask();
229 picture_layer_inputs_.nearest_neighbor = picture.nearest_neighbor(); 279 picture_layer_inputs_.nearest_neighbor = picture.nearest_neighbor();
230 280
(...skipping 18 matching lines...) Expand all
249 layer_bounds == recording_source_bounds) 299 layer_bounds == recording_source_bounds)
250 << " bounds " << layer_bounds.ToString() << " recording source " 300 << " bounds " << layer_bounds.ToString() << " recording source "
251 << recording_source_bounds.ToString(); 301 << recording_source_bounds.ToString();
252 302
253 if (update_source_frame_number_ != source_frame_number && 303 if (update_source_frame_number_ != source_frame_number &&
254 recording_source_bounds != layer_bounds) { 304 recording_source_bounds != layer_bounds) {
255 // Update may not get called for the layer (if it's not in the viewport 305 // Update may not get called for the layer (if it's not in the viewport
256 // for example), even though it has resized making the recording source no 306 // for example), even though it has resized making the recording source no
257 // longer valid. In this case just destroy the recording source. 307 // longer valid. In this case just destroy the recording source.
258 recording_source_->SetEmptyBounds(); 308 recording_source_->SetEmptyBounds();
309 picture_layer_inputs_.recorded_viewport = gfx::Rect();
310 picture_layer_inputs_.display_list = nullptr;
311 picture_layer_inputs_.painter_reported_memory_usage = 0;
259 } 312 }
260 } 313 }
261 314
315 const DisplayItemList* PictureLayer::GetDisplayItemList() {
316 return picture_layer_inputs_.display_list.get();
317 }
318
262 } // namespace cc 319 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698