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

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

Powered by Google App Engine
This is Rietveld 408576698