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

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

Issue 2131233003: cc: Clean up PictureLayer API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move client to internal struct and nit 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" 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::Inputs::Inputs() : nearest_neighbor(false) {}
23
24 PictureLayer::Inputs::~Inputs() {}
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 : client_(client), 31 : instrumentation_object_tracker_(id()),
28 instrumentation_object_tracker_(id()),
29 update_source_frame_number_(-1), 32 update_source_frame_number_(-1),
30 is_mask_(false), 33 is_mask_(false) {
31 nearest_neighbor_(false) {} 34 inputs_.client = client;
35 }
32 36
33 PictureLayer::PictureLayer(ContentLayerClient* client, 37 PictureLayer::PictureLayer(ContentLayerClient* client,
34 std::unique_ptr<RecordingSource> source) 38 std::unique_ptr<RecordingSource> source)
35 : PictureLayer(client) { 39 : PictureLayer(client) {
36 recording_source_ = std::move(source); 40 recording_source_ = std::move(source);
37 } 41 }
38 42
39 PictureLayer::~PictureLayer() { 43 PictureLayer::~PictureLayer() {
40 } 44 }
41 45
42 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl( 46 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl(
43 LayerTreeImpl* tree_impl) { 47 LayerTreeImpl* tree_impl) {
44 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); 48 return PictureLayerImpl::Create(tree_impl, id(), is_mask_);
45 } 49 }
46 50
47 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { 51 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
48 Layer::PushPropertiesTo(base_layer); 52 Layer::PushPropertiesTo(base_layer);
49 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); 53 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo");
50 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 54 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
51 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. 55 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer.
52 DCHECK_EQ(layer_impl->is_mask(), is_mask_); 56 DCHECK_EQ(layer_impl->is_mask(), is_mask_);
53 DropRecordingSourceContentIfInvalid(); 57 DropRecordingSourceContentIfInvalid();
54 58
55 layer_impl->SetNearestNeighbor(nearest_neighbor_); 59 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor);
56 60
57 // Preserve lcd text settings from the current raster source. 61 // Preserve lcd text settings from the current raster source.
58 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); 62 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText();
59 scoped_refptr<RasterSource> raster_source = 63 scoped_refptr<RasterSource> raster_source =
60 recording_source_->CreateRasterSource(can_use_lcd_text); 64 recording_source_->CreateRasterSource(can_use_lcd_text);
61 layer_impl->set_gpu_raster_max_texture_size( 65 layer_impl->set_gpu_raster_max_texture_size(
62 layer_tree_host()->device_viewport_size()); 66 layer_tree_host()->device_viewport_size());
63 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, 67 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_,
64 nullptr); 68 nullptr);
65 DCHECK(last_updated_invalidation_.IsEmpty()); 69 DCHECK(last_updated_invalidation_.IsEmpty());
(...skipping 23 matching lines...) Expand all
89 } 93 }
90 94
91 bool PictureLayer::Update() { 95 bool PictureLayer::Update() {
92 update_source_frame_number_ = layer_tree_host()->source_frame_number(); 96 update_source_frame_number_ = layer_tree_host()->source_frame_number();
93 bool updated = Layer::Update(); 97 bool updated = Layer::Update();
94 98
95 gfx::Size layer_size = paint_properties().bounds; 99 gfx::Size layer_size = paint_properties().bounds;
96 100
97 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); 101 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor());
98 recording_source_->SetRequiresClear(!contents_opaque() && 102 recording_source_->SetRequiresClear(!contents_opaque() &&
99 !client_->FillsBoundsCompletely()); 103 !inputs_.client->FillsBoundsCompletely());
100 104
101 TRACE_EVENT1("cc", "PictureLayer::Update", 105 TRACE_EVENT1("cc", "PictureLayer::Update",
102 "source_frame_number", 106 "source_frame_number",
103 layer_tree_host()->source_frame_number()); 107 layer_tree_host()->source_frame_number());
104 devtools_instrumentation::ScopedLayerTreeTask update_layer( 108 devtools_instrumentation::ScopedLayerTreeTask update_layer(
105 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); 109 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id());
106 110
107 // UpdateAndExpandInvalidation will give us an invalidation that covers 111 // UpdateAndExpandInvalidation will give us an invalidation that covers
108 // anything not explicitly recorded in this frame. We give this region 112 // 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 113 // to the impl side so that it drops tiles that may not have a recording
110 // for them. 114 // for them.
111 DCHECK(client_); 115 DCHECK(inputs_.client);
112 updated |= recording_source_->UpdateAndExpandInvalidation( 116 updated |= recording_source_->UpdateAndExpandInvalidation(
113 client_, &last_updated_invalidation_, layer_size, 117 inputs_.client, &last_updated_invalidation_, layer_size,
114 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); 118 update_source_frame_number_, RecordingSource::RECORD_NORMALLY);
115 119
116 if (updated) { 120 if (updated) {
117 SetNeedsPushProperties(); 121 SetNeedsPushProperties();
118 } else { 122 } else {
119 // If this invalidation did not affect the recording source, then it can be 123 // If this invalidation did not affect the recording source, then it can be
120 // cleared as an optimization. 124 // cleared as an optimization.
121 last_updated_invalidation_.Clear(); 125 last_updated_invalidation_.Clear();
122 } 126 }
123 127
124 return updated; 128 return updated;
125 } 129 }
126 130
127 void PictureLayer::SetIsMask(bool is_mask) { 131 void PictureLayer::SetIsMask(bool is_mask) {
128 is_mask_ = is_mask; 132 is_mask_ = is_mask;
129 } 133 }
130 134
131 sk_sp<SkPicture> PictureLayer::GetPicture() const { 135 sk_sp<SkPicture> PictureLayer::GetPicture() const {
132 // We could either flatten the RecordingSource into a single 136 // 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 137 // 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. 138 // picture. For now we just paint a fresh one to get consistent results.
135 if (!DrawsContent()) 139 if (!DrawsContent())
136 return nullptr; 140 return nullptr;
137 141
138 gfx::Size layer_size = bounds(); 142 gfx::Size layer_size = bounds();
139 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); 143 std::unique_ptr<RecordingSource> recording_source(new RecordingSource);
140 Region recording_invalidation; 144 Region recording_invalidation;
141 recording_source->UpdateAndExpandInvalidation( 145 recording_source->UpdateAndExpandInvalidation(
142 client_, &recording_invalidation, layer_size, update_source_frame_number_, 146 inputs_.client, &recording_invalidation, layer_size,
143 RecordingSource::RECORD_NORMALLY); 147 update_source_frame_number_, RecordingSource::RECORD_NORMALLY);
144 148
145 scoped_refptr<RasterSource> raster_source = 149 scoped_refptr<RasterSource> raster_source =
146 recording_source->CreateRasterSource(false); 150 recording_source->CreateRasterSource(false);
147 151
148 return raster_source->GetFlattenedPicture(); 152 return raster_source->GetFlattenedPicture();
149 } 153 }
150 154
151 bool PictureLayer::IsSuitableForGpuRasterization() const { 155 bool PictureLayer::IsSuitableForGpuRasterization() const {
152 return recording_source_->IsSuitableForGpuRasterization(); 156 return recording_source_->IsSuitableForGpuRasterization();
153 } 157 }
154 158
155 void PictureLayer::ClearClient() { 159 void PictureLayer::ClearClient() {
156 client_ = nullptr; 160 inputs_.client = nullptr;
157 UpdateDrawsContent(HasDrawableContent()); 161 UpdateDrawsContent(HasDrawableContent());
158 } 162 }
159 163
160 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { 164 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) {
161 if (nearest_neighbor_ == nearest_neighbor) 165 if (inputs_.nearest_neighbor == nearest_neighbor)
162 return; 166 return;
163 167
164 nearest_neighbor_ = nearest_neighbor; 168 inputs_.nearest_neighbor = nearest_neighbor;
165 SetNeedsCommit(); 169 SetNeedsCommit();
166 } 170 }
167 171
168 bool PictureLayer::HasDrawableContent() const { 172 bool PictureLayer::HasDrawableContent() const {
169 return client_ && Layer::HasDrawableContent(); 173 return inputs_.client && Layer::HasDrawableContent();
170 } 174 }
171 175
172 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { 176 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const {
173 proto->set_type(proto::LayerNode::PICTURE_LAYER); 177 proto->set_type(proto::LayerNode::PICTURE_LAYER);
174 } 178 }
175 179
176 void PictureLayer::LayerSpecificPropertiesToProto( 180 void PictureLayer::LayerSpecificPropertiesToProto(
177 proto::LayerProperties* proto) { 181 proto::LayerProperties* proto) {
178 Layer::LayerSpecificPropertiesToProto(proto); 182 Layer::LayerSpecificPropertiesToProto(proto);
179 DropRecordingSourceContentIfInvalid(); 183 DropRecordingSourceContentIfInvalid();
180 184
181 proto::PictureLayerProperties* picture = proto->mutable_picture(); 185 proto::PictureLayerProperties* picture = proto->mutable_picture();
182 recording_source_->ToProtobuf(picture->mutable_recording_source()); 186 recording_source_->ToProtobuf(picture->mutable_recording_source());
183 187
184 // Add all SkPicture items to the picture cache. 188 // Add all SkPicture items to the picture cache.
185 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); 189 const DisplayItemList* display_list = recording_source_->GetDisplayItemList();
186 if (display_list) { 190 if (display_list) {
187 for (auto it = display_list->begin(); it != display_list->end(); ++it) { 191 for (auto it = display_list->begin(); it != display_list->end(); ++it) {
188 sk_sp<const SkPicture> picture = it->GetPicture(); 192 sk_sp<const SkPicture> picture = it->GetPicture();
189 // Only DrawingDisplayItems have SkPictures. 193 // Only DrawingDisplayItems have SkPictures.
190 if (!picture) 194 if (!picture)
191 continue; 195 continue;
192 196
193 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); 197 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get());
194 } 198 }
195 } 199 }
196 200
197 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); 201 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation());
198 picture->set_is_mask(is_mask_); 202 picture->set_is_mask(is_mask_);
199 picture->set_nearest_neighbor(nearest_neighbor_); 203 picture->set_nearest_neighbor(inputs_.nearest_neighbor);
200 204
201 picture->set_update_source_frame_number(update_source_frame_number_); 205 picture->set_update_source_frame_number(update_source_frame_number_);
202 206
203 last_updated_invalidation_.Clear(); 207 last_updated_invalidation_.Clear();
204 } 208 }
205 209
206 void PictureLayer::FromLayerSpecificPropertiesProto( 210 void PictureLayer::FromLayerSpecificPropertiesProto(
207 const proto::LayerProperties& proto) { 211 const proto::LayerProperties& proto) {
208 Layer::FromLayerSpecificPropertiesProto(proto); 212 Layer::FromLayerSpecificPropertiesProto(proto);
209 const proto::PictureLayerProperties& picture = proto.picture(); 213 const proto::PictureLayerProperties& picture = proto.picture();
210 // If this is a new layer, ensure it has a recording source. During layer 214 // If this is a new layer, ensure it has a recording source. During layer
211 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but 215 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but
212 // instead the member is set directly, so it needs to be set here explicitly. 216 // instead the member is set directly, so it needs to be set here explicitly.
213 if (!recording_source_) 217 if (!recording_source_)
214 recording_source_.reset(new RecordingSource); 218 recording_source_.reset(new RecordingSource);
215 219
216 std::vector<uint32_t> used_engine_picture_ids; 220 std::vector<uint32_t> used_engine_picture_ids;
217 recording_source_->FromProtobuf(picture.recording_source(), 221 recording_source_->FromProtobuf(picture.recording_source(),
218 layer_tree_host()->client_picture_cache(), 222 layer_tree_host()->client_picture_cache(),
219 &used_engine_picture_ids); 223 &used_engine_picture_ids);
220 224
221 // Inform picture cache about which SkPictures are now in use. 225 // Inform picture cache about which SkPictures are now in use.
222 for (uint32_t engine_picture_id : used_engine_picture_ids) 226 for (uint32_t engine_picture_id : used_engine_picture_ids)
223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); 227 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id);
224 228
225 Region new_invalidation = RegionFromProto(picture.invalidation()); 229 Region new_invalidation = RegionFromProto(picture.invalidation());
226 last_updated_invalidation_.Swap(&new_invalidation); 230 last_updated_invalidation_.Swap(&new_invalidation);
227 is_mask_ = picture.is_mask(); 231 is_mask_ = picture.is_mask();
228 nearest_neighbor_ = picture.nearest_neighbor(); 232 inputs_.nearest_neighbor = picture.nearest_neighbor();
229 233
230 update_source_frame_number_ = picture.update_source_frame_number(); 234 update_source_frame_number_ = picture.update_source_frame_number();
231 } 235 }
232 236
233 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { 237 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
234 benchmark->RunOnLayer(this); 238 benchmark->RunOnLayer(this);
235 } 239 }
236 240
237 void PictureLayer::DropRecordingSourceContentIfInvalid() { 241 void PictureLayer::DropRecordingSourceContentIfInvalid() {
238 int source_frame_number = layer_tree_host()->source_frame_number(); 242 int source_frame_number = layer_tree_host()->source_frame_number();
(...skipping 13 matching lines...) Expand all
252 if (update_source_frame_number_ != source_frame_number && 256 if (update_source_frame_number_ != source_frame_number &&
253 recording_source_bounds != layer_bounds) { 257 recording_source_bounds != layer_bounds) {
254 // Update may not get called for the layer (if it's not in the viewport 258 // 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 259 // for example), even though it has resized making the recording source no
256 // longer valid. In this case just destroy the recording source. 260 // longer valid. In this case just destroy the recording source.
257 recording_source_->SetEmptyBounds(); 261 recording_source_->SetEmptyBounds();
258 } 262 }
259 } 263 }
260 264
261 } // namespace cc 265 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698