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

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: 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 : client_(client),
28 instrumentation_object_tracker_(id()), 32 instrumentation_object_tracker_(id()),
29 update_source_frame_number_(-1), 33 update_source_frame_number_(-1),
30 is_mask_(false), 34 is_mask_(false) {}
31 nearest_neighbor_(false) {}
32 35
33 PictureLayer::PictureLayer(ContentLayerClient* client, 36 PictureLayer::PictureLayer(ContentLayerClient* client,
34 std::unique_ptr<RecordingSource> source) 37 std::unique_ptr<RecordingSource> source)
35 : PictureLayer(client) { 38 : PictureLayer(client) {
36 recording_source_ = std::move(source); 39 recording_source_ = std::move(source);
37 } 40 }
38 41
39 PictureLayer::~PictureLayer() { 42 PictureLayer::~PictureLayer() {
40 } 43 }
41 44
42 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl( 45 std::unique_ptr<LayerImpl> PictureLayer::CreateLayerImpl(
43 LayerTreeImpl* tree_impl) { 46 LayerTreeImpl* tree_impl) {
44 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); 47 return PictureLayerImpl::Create(tree_impl, id(), is_mask_);
45 } 48 }
46 49
47 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { 50 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) {
48 Layer::PushPropertiesTo(base_layer); 51 Layer::PushPropertiesTo(base_layer);
49 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); 52 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo");
50 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); 53 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer);
51 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. 54 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer.
52 DCHECK_EQ(layer_impl->is_mask(), is_mask_); 55 DCHECK_EQ(layer_impl->is_mask(), is_mask_);
53 DropRecordingSourceContentIfInvalid(); 56 DropRecordingSourceContentIfInvalid();
54 57
55 layer_impl->SetNearestNeighbor(nearest_neighbor_); 58 layer_impl->SetNearestNeighbor(inputs_.nearest_neighbor_);
56 59
57 // Preserve lcd text settings from the current raster source. 60 // Preserve lcd text settings from the current raster source.
58 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); 61 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText();
59 scoped_refptr<RasterSource> raster_source = 62 scoped_refptr<RasterSource> raster_source =
60 recording_source_->CreateRasterSource(can_use_lcd_text); 63 recording_source_->CreateRasterSource(can_use_lcd_text);
61 layer_impl->set_gpu_raster_max_texture_size( 64 layer_impl->set_gpu_raster_max_texture_size(
62 layer_tree_host()->device_viewport_size()); 65 layer_tree_host()->device_viewport_size());
63 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_, 66 layer_impl->UpdateRasterSource(raster_source, &last_updated_invalidation_,
64 nullptr); 67 nullptr);
65 DCHECK(last_updated_invalidation_.IsEmpty()); 68 DCHECK(last_updated_invalidation_.IsEmpty());
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 bool PictureLayer::IsSuitableForGpuRasterization() const { 154 bool PictureLayer::IsSuitableForGpuRasterization() const {
152 return recording_source_->IsSuitableForGpuRasterization(); 155 return recording_source_->IsSuitableForGpuRasterization();
153 } 156 }
154 157
155 void PictureLayer::ClearClient() { 158 void PictureLayer::ClearClient() {
156 client_ = nullptr; 159 client_ = nullptr;
157 UpdateDrawsContent(HasDrawableContent()); 160 UpdateDrawsContent(HasDrawableContent());
158 } 161 }
159 162
160 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { 163 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) {
161 if (nearest_neighbor_ == nearest_neighbor) 164 if (inputs_.nearest_neighbor_ == nearest_neighbor)
162 return; 165 return;
163 166
164 nearest_neighbor_ = nearest_neighbor; 167 inputs_.nearest_neighbor_ = nearest_neighbor;
165 SetNeedsCommit(); 168 SetNeedsCommit();
166 } 169 }
167 170
168 bool PictureLayer::HasDrawableContent() const { 171 bool PictureLayer::HasDrawableContent() const {
169 return client_ && Layer::HasDrawableContent(); 172 return client_ && Layer::HasDrawableContent();
170 } 173 }
171 174
172 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { 175 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const {
173 proto->set_type(proto::LayerNode::PICTURE_LAYER); 176 proto->set_type(proto::LayerNode::PICTURE_LAYER);
174 } 177 }
(...skipping 14 matching lines...) Expand all
189 // Only DrawingDisplayItems have SkPictures. 192 // Only DrawingDisplayItems have SkPictures.
190 if (!picture) 193 if (!picture)
191 continue; 194 continue;
192 195
193 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); 196 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get());
194 } 197 }
195 } 198 }
196 199
197 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); 200 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation());
198 picture->set_is_mask(is_mask_); 201 picture->set_is_mask(is_mask_);
199 picture->set_nearest_neighbor(nearest_neighbor_); 202 picture->set_nearest_neighbor(inputs_.nearest_neighbor_);
200 203
201 picture->set_update_source_frame_number(update_source_frame_number_); 204 picture->set_update_source_frame_number(update_source_frame_number_);
202 205
203 last_updated_invalidation_.Clear(); 206 last_updated_invalidation_.Clear();
204 } 207 }
205 208
206 void PictureLayer::FromLayerSpecificPropertiesProto( 209 void PictureLayer::FromLayerSpecificPropertiesProto(
207 const proto::LayerProperties& proto) { 210 const proto::LayerProperties& proto) {
208 Layer::FromLayerSpecificPropertiesProto(proto); 211 Layer::FromLayerSpecificPropertiesProto(proto);
209 const proto::PictureLayerProperties& picture = proto.picture(); 212 const proto::PictureLayerProperties& picture = proto.picture();
210 // If this is a new layer, ensure it has a recording source. During layer 213 // If this is a new layer, ensure it has a recording source. During layer
211 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but 214 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but
212 // instead the member is set directly, so it needs to be set here explicitly. 215 // instead the member is set directly, so it needs to be set here explicitly.
213 if (!recording_source_) 216 if (!recording_source_)
214 recording_source_.reset(new RecordingSource); 217 recording_source_.reset(new RecordingSource);
215 218
216 std::vector<uint32_t> used_engine_picture_ids; 219 std::vector<uint32_t> used_engine_picture_ids;
217 recording_source_->FromProtobuf(picture.recording_source(), 220 recording_source_->FromProtobuf(picture.recording_source(),
218 layer_tree_host()->client_picture_cache(), 221 layer_tree_host()->client_picture_cache(),
219 &used_engine_picture_ids); 222 &used_engine_picture_ids);
220 223
221 // Inform picture cache about which SkPictures are now in use. 224 // Inform picture cache about which SkPictures are now in use.
222 for (uint32_t engine_picture_id : used_engine_picture_ids) 225 for (uint32_t engine_picture_id : used_engine_picture_ids)
223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); 226 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id);
224 227
225 Region new_invalidation = RegionFromProto(picture.invalidation()); 228 Region new_invalidation = RegionFromProto(picture.invalidation());
226 last_updated_invalidation_.Swap(&new_invalidation); 229 last_updated_invalidation_.Swap(&new_invalidation);
227 is_mask_ = picture.is_mask(); 230 is_mask_ = picture.is_mask();
228 nearest_neighbor_ = picture.nearest_neighbor(); 231 inputs_.nearest_neighbor_ = picture.nearest_neighbor();
229 232
230 update_source_frame_number_ = picture.update_source_frame_number(); 233 update_source_frame_number_ = picture.update_source_frame_number();
231 } 234 }
232 235
233 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { 236 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
234 benchmark->RunOnLayer(this); 237 benchmark->RunOnLayer(this);
235 } 238 }
236 239
237 void PictureLayer::DropRecordingSourceContentIfInvalid() { 240 void PictureLayer::DropRecordingSourceContentIfInvalid() {
238 int source_frame_number = layer_tree_host()->source_frame_number(); 241 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 && 255 if (update_source_frame_number_ != source_frame_number &&
253 recording_source_bounds != layer_bounds) { 256 recording_source_bounds != layer_bounds) {
254 // Update may not get called for the layer (if it's not in the viewport 257 // 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 258 // for example), even though it has resized making the recording source no
256 // longer valid. In this case just destroy the recording source. 259 // longer valid. In this case just destroy the recording source.
257 recording_source_->SetEmptyBounds(); 260 recording_source_->SetEmptyBounds();
258 } 261 }
259 } 262 }
260 263
261 } // namespace cc 264 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698