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

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

Issue 2185973005: cc: Move solid color scrollbar layer data in a seperate struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: .. 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
« no previous file with comments | « cc/layers/picture_layer.h ('k') | cc/layers/picture_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 : instrumentation_object_tracker_(id()), 27 : instrumentation_object_tracker_(id()),
28 update_source_frame_number_(-1), 28 update_source_frame_number_(-1),
29 is_mask_(false) { 29 is_mask_(false) {
30 inputs_.client = client; 30 picture_layer_inputs_.client = client;
31 } 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(inputs_.nearest_neighbor); 55 layer_impl->SetNearestNeighbor(picture_layer_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 22 matching lines...) Expand all
88 Layer::SetNeedsDisplayRect(layer_rect); 88 Layer::SetNeedsDisplayRect(layer_rect);
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(
99 !inputs_.client->FillsBoundsCompletely()); 99 !contents_opaque() &&
100 !picture_layer_inputs_.client->FillsBoundsCompletely());
100 101
101 TRACE_EVENT1("cc", "PictureLayer::Update", 102 TRACE_EVENT1("cc", "PictureLayer::Update",
102 "source_frame_number", 103 "source_frame_number",
103 layer_tree_host()->source_frame_number()); 104 layer_tree_host()->source_frame_number());
104 devtools_instrumentation::ScopedLayerTreeTask update_layer( 105 devtools_instrumentation::ScopedLayerTreeTask update_layer(
105 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); 106 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id());
106 107
107 // UpdateAndExpandInvalidation will give us an invalidation that covers 108 // UpdateAndExpandInvalidation will give us an invalidation that covers
108 // anything not explicitly recorded in this frame. We give this region 109 // 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 110 // to the impl side so that it drops tiles that may not have a recording
110 // for them. 111 // for them.
111 DCHECK(inputs_.client); 112 DCHECK(picture_layer_inputs_.client);
112 updated |= recording_source_->UpdateAndExpandInvalidation( 113 updated |= recording_source_->UpdateAndExpandInvalidation(
113 inputs_.client, &last_updated_invalidation_, layer_size, 114 picture_layer_inputs_.client, &last_updated_invalidation_, layer_size,
114 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); 115 update_source_frame_number_, RecordingSource::RECORD_NORMALLY);
115 116
116 if (updated) { 117 if (updated) {
117 SetNeedsPushProperties(); 118 SetNeedsPushProperties();
118 } else { 119 } else {
119 // If this invalidation did not affect the recording source, then it can be 120 // If this invalidation did not affect the recording source, then it can be
120 // cleared as an optimization. 121 // cleared as an optimization.
121 last_updated_invalidation_.Clear(); 122 last_updated_invalidation_.Clear();
122 } 123 }
123 124
124 return updated; 125 return updated;
125 } 126 }
126 127
127 void PictureLayer::SetIsMask(bool is_mask) { 128 void PictureLayer::SetIsMask(bool is_mask) {
128 is_mask_ = is_mask; 129 is_mask_ = is_mask;
129 } 130 }
130 131
131 sk_sp<SkPicture> PictureLayer::GetPicture() const { 132 sk_sp<SkPicture> PictureLayer::GetPicture() const {
132 // We could either flatten the RecordingSource into a single 133 // 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 134 // 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. 135 // picture. For now we just paint a fresh one to get consistent results.
135 if (!DrawsContent()) 136 if (!DrawsContent())
136 return nullptr; 137 return nullptr;
137 138
138 gfx::Size layer_size = bounds(); 139 gfx::Size layer_size = bounds();
139 std::unique_ptr<RecordingSource> recording_source(new RecordingSource); 140 std::unique_ptr<RecordingSource> recording_source(new RecordingSource);
140 Region recording_invalidation; 141 Region recording_invalidation;
141 recording_source->UpdateAndExpandInvalidation( 142 recording_source->UpdateAndExpandInvalidation(
142 inputs_.client, &recording_invalidation, layer_size, 143 picture_layer_inputs_.client, &recording_invalidation, layer_size,
143 update_source_frame_number_, RecordingSource::RECORD_NORMALLY); 144 update_source_frame_number_, RecordingSource::RECORD_NORMALLY);
144 145
145 scoped_refptr<RasterSource> raster_source = 146 scoped_refptr<RasterSource> raster_source =
146 recording_source->CreateRasterSource(false); 147 recording_source->CreateRasterSource(false);
147 148
148 return raster_source->GetFlattenedPicture(); 149 return raster_source->GetFlattenedPicture();
149 } 150 }
150 151
151 bool PictureLayer::IsSuitableForGpuRasterization() const { 152 bool PictureLayer::IsSuitableForGpuRasterization() const {
152 return recording_source_->IsSuitableForGpuRasterization(); 153 return recording_source_->IsSuitableForGpuRasterization();
153 } 154 }
154 155
155 void PictureLayer::ClearClient() { 156 void PictureLayer::ClearClient() {
156 inputs_.client = nullptr; 157 picture_layer_inputs_.client = nullptr;
157 UpdateDrawsContent(HasDrawableContent()); 158 UpdateDrawsContent(HasDrawableContent());
158 } 159 }
159 160
160 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { 161 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) {
161 if (inputs_.nearest_neighbor == nearest_neighbor) 162 if (picture_layer_inputs_.nearest_neighbor == nearest_neighbor)
162 return; 163 return;
163 164
164 inputs_.nearest_neighbor = nearest_neighbor; 165 picture_layer_inputs_.nearest_neighbor = nearest_neighbor;
165 SetNeedsCommit(); 166 SetNeedsCommit();
166 } 167 }
167 168
168 bool PictureLayer::HasDrawableContent() const { 169 bool PictureLayer::HasDrawableContent() const {
169 return inputs_.client && Layer::HasDrawableContent(); 170 return picture_layer_inputs_.client && Layer::HasDrawableContent();
170 } 171 }
171 172
172 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { 173 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const {
173 proto->set_type(proto::LayerNode::PICTURE_LAYER); 174 proto->set_type(proto::LayerNode::PICTURE_LAYER);
174 } 175 }
175 176
176 void PictureLayer::LayerSpecificPropertiesToProto( 177 void PictureLayer::LayerSpecificPropertiesToProto(
177 proto::LayerProperties* proto) { 178 proto::LayerProperties* proto) {
178 Layer::LayerSpecificPropertiesToProto(proto); 179 Layer::LayerSpecificPropertiesToProto(proto);
179 DropRecordingSourceContentIfInvalid(); 180 DropRecordingSourceContentIfInvalid();
180 181
181 proto::PictureLayerProperties* picture = proto->mutable_picture(); 182 proto::PictureLayerProperties* picture = proto->mutable_picture();
182 recording_source_->ToProtobuf(picture->mutable_recording_source()); 183 recording_source_->ToProtobuf(picture->mutable_recording_source());
183 184
184 // Add all SkPicture items to the picture cache. 185 // Add all SkPicture items to the picture cache.
185 const DisplayItemList* display_list = recording_source_->GetDisplayItemList(); 186 const DisplayItemList* display_list = recording_source_->GetDisplayItemList();
186 if (display_list) { 187 if (display_list) {
187 for (auto it = display_list->begin(); it != display_list->end(); ++it) { 188 for (auto it = display_list->begin(); it != display_list->end(); ++it) {
188 sk_sp<const SkPicture> picture = it->GetPicture(); 189 sk_sp<const SkPicture> picture = it->GetPicture();
189 // Only DrawingDisplayItems have SkPictures. 190 // Only DrawingDisplayItems have SkPictures.
190 if (!picture) 191 if (!picture)
191 continue; 192 continue;
192 193
193 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get()); 194 layer_tree_host()->engine_picture_cache()->MarkUsed(picture.get());
194 } 195 }
195 } 196 }
196 197
197 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation()); 198 RegionToProto(last_updated_invalidation_, picture->mutable_invalidation());
198 picture->set_is_mask(is_mask_); 199 picture->set_is_mask(is_mask_);
199 picture->set_nearest_neighbor(inputs_.nearest_neighbor); 200 picture->set_nearest_neighbor(picture_layer_inputs_.nearest_neighbor);
200 201
201 picture->set_update_source_frame_number(update_source_frame_number_); 202 picture->set_update_source_frame_number(update_source_frame_number_);
202 203
203 last_updated_invalidation_.Clear(); 204 last_updated_invalidation_.Clear();
204 } 205 }
205 206
206 void PictureLayer::FromLayerSpecificPropertiesProto( 207 void PictureLayer::FromLayerSpecificPropertiesProto(
207 const proto::LayerProperties& proto) { 208 const proto::LayerProperties& proto) {
208 Layer::FromLayerSpecificPropertiesProto(proto); 209 Layer::FromLayerSpecificPropertiesProto(proto);
209 const proto::PictureLayerProperties& picture = proto.picture(); 210 const proto::PictureLayerProperties& picture = proto.picture();
210 // If this is a new layer, ensure it has a recording source. During layer 211 // If this is a new layer, ensure it has a recording source. During layer
211 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but 212 // hierarchy deserialization, ::SetLayerTreeHost(...) is not called, but
212 // instead the member is set directly, so it needs to be set here explicitly. 213 // instead the member is set directly, so it needs to be set here explicitly.
213 if (!recording_source_) 214 if (!recording_source_)
214 recording_source_.reset(new RecordingSource); 215 recording_source_.reset(new RecordingSource);
215 216
216 std::vector<uint32_t> used_engine_picture_ids; 217 std::vector<uint32_t> used_engine_picture_ids;
217 recording_source_->FromProtobuf(picture.recording_source(), 218 recording_source_->FromProtobuf(picture.recording_source(),
218 layer_tree_host()->client_picture_cache(), 219 layer_tree_host()->client_picture_cache(),
219 &used_engine_picture_ids); 220 &used_engine_picture_ids);
220 221
221 // Inform picture cache about which SkPictures are now in use. 222 // Inform picture cache about which SkPictures are now in use.
222 for (uint32_t engine_picture_id : used_engine_picture_ids) 223 for (uint32_t engine_picture_id : used_engine_picture_ids)
223 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id); 224 layer_tree_host()->client_picture_cache()->MarkUsed(engine_picture_id);
224 225
225 Region new_invalidation = RegionFromProto(picture.invalidation()); 226 Region new_invalidation = RegionFromProto(picture.invalidation());
226 last_updated_invalidation_.Swap(&new_invalidation); 227 last_updated_invalidation_.Swap(&new_invalidation);
227 is_mask_ = picture.is_mask(); 228 is_mask_ = picture.is_mask();
228 inputs_.nearest_neighbor = picture.nearest_neighbor(); 229 picture_layer_inputs_.nearest_neighbor = picture.nearest_neighbor();
229 230
230 update_source_frame_number_ = picture.update_source_frame_number(); 231 update_source_frame_number_ = picture.update_source_frame_number();
231 } 232 }
232 233
233 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { 234 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) {
234 benchmark->RunOnLayer(this); 235 benchmark->RunOnLayer(this);
235 } 236 }
236 237
237 void PictureLayer::DropRecordingSourceContentIfInvalid() { 238 void PictureLayer::DropRecordingSourceContentIfInvalid() {
238 int source_frame_number = layer_tree_host()->source_frame_number(); 239 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 && 253 if (update_source_frame_number_ != source_frame_number &&
253 recording_source_bounds != layer_bounds) { 254 recording_source_bounds != layer_bounds) {
254 // Update may not get called for the layer (if it's not in the viewport 255 // 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 256 // for example), even though it has resized making the recording source no
256 // longer valid. In this case just destroy the recording source. 257 // longer valid. In this case just destroy the recording source.
257 recording_source_->SetEmptyBounds(); 258 recording_source_->SetEmptyBounds();
258 } 259 }
259 } 260 }
260 261
261 } // namespace cc 262 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/picture_layer.h ('k') | cc/layers/picture_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698