OLD | NEW |
---|---|
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 "cc/layers/content_layer_client.h" | 8 #include "cc/layers/content_layer_client.h" |
9 #include "cc/layers/picture_layer_impl.h" | 9 #include "cc/layers/picture_layer_impl.h" |
10 #include "cc/playback/display_list_recording_source.h" | 10 #include "cc/playback/display_list_recording_source.h" |
11 #include "cc/proto/cc_conversions.h" | |
12 #include "cc/proto/gfx_conversions.h" | |
13 #include "cc/proto/layer.pb.h" | |
11 #include "cc/trees/layer_tree_host.h" | 14 #include "cc/trees/layer_tree_host.h" |
12 #include "cc/trees/layer_tree_impl.h" | 15 #include "cc/trees/layer_tree_impl.h" |
13 #include "third_party/skia/include/core/SkPictureRecorder.h" | 16 #include "third_party/skia/include/core/SkPictureRecorder.h" |
14 #include "ui/gfx/geometry/rect_conversions.h" | 17 #include "ui/gfx/geometry/rect_conversions.h" |
15 | 18 |
16 namespace cc { | 19 namespace cc { |
17 | 20 |
18 scoped_refptr<PictureLayer> PictureLayer::Create(const LayerSettings& settings, | 21 scoped_refptr<PictureLayer> PictureLayer::Create(const LayerSettings& settings, |
19 ContentLayerClient* client) { | 22 ContentLayerClient* client) { |
20 return make_scoped_refptr(new PictureLayer(settings, client)); | 23 return make_scoped_refptr(new PictureLayer(settings, client)); |
(...skipping 22 matching lines...) Expand all Loading... | |
43 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 46 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
44 return PictureLayerImpl::Create(tree_impl, id(), is_mask_, | 47 return PictureLayerImpl::Create(tree_impl, id(), is_mask_, |
45 new LayerImpl::SyncedScrollOffset); | 48 new LayerImpl::SyncedScrollOffset); |
46 } | 49 } |
47 | 50 |
48 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 51 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
49 Layer::PushPropertiesTo(base_layer); | 52 Layer::PushPropertiesTo(base_layer); |
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 | 56 DropRecordingSourceContentIfInvalid(); |
David Trainor- moved to gerrit
2015/12/16 19:10:59
Moved this up to keep it in the same place as the
| |
54 int source_frame_number = layer_tree_host()->source_frame_number(); | |
55 gfx::Size impl_bounds = layer_impl->bounds(); | |
56 gfx::Size recording_source_bounds = recording_source_->GetSize(); | |
57 | |
58 // If update called, then recording source size must match bounds pushed to | |
59 // impl layer. | |
60 DCHECK(update_source_frame_number_ != source_frame_number || | |
61 impl_bounds == recording_source_bounds) | |
62 << " bounds " << impl_bounds.ToString() << " recording source " | |
63 << recording_source_bounds.ToString(); | |
64 | |
65 if (update_source_frame_number_ != source_frame_number && | |
66 recording_source_bounds != impl_bounds) { | |
67 // Update may not get called for the layer (if it's not in the viewport | |
68 // for example, even though it has resized making the recording source no | |
69 // longer valid. In this case just destroy the recording source. | |
70 recording_source_->SetEmptyBounds(); | |
71 } | |
72 | 57 |
73 layer_impl->SetNearestNeighbor(nearest_neighbor_); | 58 layer_impl->SetNearestNeighbor(nearest_neighbor_); |
74 | 59 |
75 // Preserve lcd text settings from the current raster source. | 60 // Preserve lcd text settings from the current raster source. |
76 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); | 61 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); |
77 scoped_refptr<DisplayListRasterSource> raster_source = | 62 scoped_refptr<DisplayListRasterSource> raster_source = |
78 recording_source_->CreateRasterSource(can_use_lcd_text); | 63 recording_source_->CreateRasterSource(can_use_lcd_text); |
79 layer_impl->set_gpu_raster_max_texture_size( | 64 layer_impl->set_gpu_raster_max_texture_size( |
80 layer_tree_host()->device_viewport_size()); | 65 layer_tree_host()->device_viewport_size()); |
81 layer_impl->UpdateRasterSource(raster_source, invalidation_.region(), | 66 layer_impl->UpdateRasterSource(raster_source, invalidation_.region(), |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
191 return; | 176 return; |
192 | 177 |
193 nearest_neighbor_ = nearest_neighbor; | 178 nearest_neighbor_ = nearest_neighbor; |
194 SetNeedsCommit(); | 179 SetNeedsCommit(); |
195 } | 180 } |
196 | 181 |
197 bool PictureLayer::HasDrawableContent() const { | 182 bool PictureLayer::HasDrawableContent() const { |
198 return client_ && Layer::HasDrawableContent(); | 183 return client_ && Layer::HasDrawableContent(); |
199 } | 184 } |
200 | 185 |
186 void PictureLayer::SetTypeForProtoSerialization(proto::LayerNode* proto) const { | |
187 proto->set_type(proto::LayerType::PICTURE_LAYER); | |
188 } | |
189 | |
190 void PictureLayer::LayerSpecificPropertiesToProto( | |
191 proto::LayerProperties* proto) { | |
192 Layer::LayerSpecificPropertiesToProto(proto); | |
193 DropRecordingSourceContentIfInvalid(); | |
194 | |
195 proto::PictureLayerProperties* picture = proto->mutable_picture(); | |
196 recording_source_->ToProtobuf(picture->mutable_recording_source()); | |
197 RegionToProto(*invalidation_.region(), picture->mutable_invalidation()); | |
198 RectToProto(last_updated_visible_layer_rect_, | |
199 picture->mutable_last_updated_visible_layer_rect()); | |
200 picture->set_is_mask(is_mask_); | |
201 picture->set_nearest_neighbor(nearest_neighbor_); | |
202 | |
203 picture->set_update_source_frame_number(update_source_frame_number_); | |
204 | |
205 invalidation_.Clear(); | |
206 } | |
207 | |
208 void PictureLayer::FromLayerSpecificPropertiesProto( | |
209 const proto::LayerProperties& proto) { | |
210 Layer::FromLayerSpecificPropertiesProto(proto); | |
211 const proto::PictureLayerProperties& picture = proto.picture(); | |
212 recording_source_->FromProtobuf(picture.recording_source()); | |
213 | |
214 Region new_invalidation = RegionFromProto(picture.invalidation()); | |
215 invalidation_.Swap(&new_invalidation); | |
216 last_updated_visible_layer_rect_ = | |
217 ProtoToRect(picture.last_updated_visible_layer_rect()); | |
218 is_mask_ = picture.is_mask(); | |
219 nearest_neighbor_ = picture.nearest_neighbor(); | |
220 | |
221 update_source_frame_number_ = picture.update_source_frame_number(); | |
222 } | |
223 | |
201 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 224 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
202 benchmark->RunOnLayer(this); | 225 benchmark->RunOnLayer(this); |
203 } | 226 } |
204 | 227 |
228 void PictureLayer::DropRecordingSourceContentIfInvalid() { | |
229 int source_frame_number = layer_tree_host()->source_frame_number(); | |
230 gfx::Size recording_source_bounds = recording_source_->GetSize(); | |
231 | |
232 gfx::Size layer_bounds = bounds(); | |
233 if (paint_properties().source_frame_number == source_frame_number) | |
234 layer_bounds = paint_properties().bounds; | |
235 | |
236 // If update called, then recording source size must match bounds pushed to | |
237 // impl layer. | |
238 DCHECK(update_source_frame_number_ != source_frame_number || | |
239 layer_bounds == recording_source_bounds) | |
240 << " bounds " << layer_bounds.ToString() << " recording source " | |
241 << recording_source_bounds.ToString(); | |
242 | |
243 if (update_source_frame_number_ != source_frame_number && | |
244 recording_source_bounds != layer_bounds) { | |
245 // Update may not get called for the layer (if it's not in the viewport | |
246 // for example), even though it has resized making the recording source no | |
247 // longer valid. In this case just destroy the recording source. | |
248 recording_source_->SetEmptyBounds(); | |
249 } | |
250 } | |
251 | |
205 } // namespace cc | 252 } // namespace cc |
OLD | NEW |