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/resources/display_list_recording_source.h" | 10 #include "cc/resources/display_list_recording_source.h" |
11 #include "cc/resources/picture_pile.h" | 11 #include "cc/resources/picture_pile.h" |
12 #include "cc/trees/layer_tree_impl.h" | 12 #include "cc/trees/layer_tree_impl.h" |
13 #include "third_party/skia/include/core/SkPictureRecorder.h" | 13 #include "third_party/skia/include/core/SkPictureRecorder.h" |
14 #include "ui/gfx/geometry/rect_conversions.h" | 14 #include "ui/gfx/geometry/rect_conversions.h" |
15 | 15 |
16 namespace cc { | 16 namespace cc { |
17 | 17 |
18 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | 18 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
19 return make_scoped_refptr(new PictureLayer(client)); | 19 return make_scoped_refptr(new PictureLayer(client)); |
20 } | 20 } |
21 | 21 |
22 PictureLayer::PictureLayer(ContentLayerClient* client) | 22 PictureLayer::PictureLayer(ContentLayerClient* client) |
23 : client_(client), | 23 : client_(client), |
24 instrumentation_object_tracker_(id()), | 24 instrumentation_object_tracker_(id()), |
25 update_source_frame_number_(-1), | 25 update_source_frame_number_(-1), |
26 can_use_lcd_text_for_update_(true), | 26 can_use_lcd_text_for_update_(true), |
27 is_mask_(false) { | 27 is_mask_(false), |
| 28 nearest_neighbor_(false) { |
28 } | 29 } |
29 | 30 |
30 PictureLayer::PictureLayer(ContentLayerClient* client, | 31 PictureLayer::PictureLayer(ContentLayerClient* client, |
31 scoped_ptr<RecordingSource> source) | 32 scoped_ptr<RecordingSource> source) |
32 : PictureLayer(client) { | 33 : PictureLayer(client) { |
33 recording_source_ = source.Pass(); | 34 recording_source_ = source.Pass(); |
34 } | 35 } |
35 | 36 |
36 PictureLayer::~PictureLayer() { | 37 PictureLayer::~PictureLayer() { |
37 } | 38 } |
38 | 39 |
39 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 40 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
40 return PictureLayerImpl::Create(tree_impl, id()); | 41 return PictureLayerImpl::Create(tree_impl, id(), is_mask_); |
41 } | 42 } |
42 | 43 |
43 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 44 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
44 Layer::PushPropertiesTo(base_layer); | 45 Layer::PushPropertiesTo(base_layer); |
45 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 46 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
| 47 // TODO(danakj): Make is_mask_ a constructor parameter for PictureLayer. |
| 48 DCHECK_EQ(layer_impl->is_mask_, is_mask_); |
46 | 49 |
47 int source_frame_number = layer_tree_host()->source_frame_number(); | 50 int source_frame_number = layer_tree_host()->source_frame_number(); |
48 gfx::Size impl_bounds = layer_impl->bounds(); | 51 gfx::Size impl_bounds = layer_impl->bounds(); |
49 gfx::Size recording_source_bounds = recording_source_->GetSize(); | 52 gfx::Size recording_source_bounds = recording_source_->GetSize(); |
50 | 53 |
51 // If update called, then recording source size must match bounds pushed to | 54 // If update called, then recording source size must match bounds pushed to |
52 // impl layer. | 55 // impl layer. |
53 DCHECK_IMPLIES(update_source_frame_number_ == source_frame_number, | 56 DCHECK_IMPLIES(update_source_frame_number_ == source_frame_number, |
54 impl_bounds == recording_source_bounds) | 57 impl_bounds == recording_source_bounds) |
55 << " bounds " << impl_bounds.ToString() << " recording source " | 58 << " bounds " << impl_bounds.ToString() << " recording source " |
56 << recording_source_bounds.ToString(); | 59 << recording_source_bounds.ToString(); |
57 | 60 |
58 if (update_source_frame_number_ != source_frame_number && | 61 if (update_source_frame_number_ != source_frame_number && |
59 recording_source_bounds != impl_bounds) { | 62 recording_source_bounds != impl_bounds) { |
60 // Update may not get called for the layer (if it's not in the viewport | 63 // Update may not get called for the layer (if it's not in the viewport |
61 // for example, even though it has resized making the recording source no | 64 // for example, even though it has resized making the recording source no |
62 // longer valid. In this case just destroy the recording source. | 65 // longer valid. In this case just destroy the recording source. |
63 recording_source_->SetEmptyBounds(); | 66 recording_source_->SetEmptyBounds(); |
64 } | 67 } |
65 | 68 |
66 // Unlike other properties, invalidation must always be set on layer_impl. | 69 layer_impl->SetNearestNeighbor(nearest_neighbor_); |
67 // See PictureLayerImpl::PushPropertiesTo for more details. | 70 |
68 layer_impl->invalidation_.Clear(); | |
69 layer_impl->invalidation_.Swap(&recording_invalidation_); | |
70 layer_impl->set_is_mask(is_mask_); | |
71 scoped_refptr<RasterSource> raster_source = | 71 scoped_refptr<RasterSource> raster_source = |
72 recording_source_->CreateRasterSource(); | 72 recording_source_->CreateRasterSource(); |
73 raster_source->SetBackgoundColor(SafeOpaqueBackgroundColor()); | 73 raster_source->SetBackgoundColor(SafeOpaqueBackgroundColor()); |
74 raster_source->SetRequiresClear(!contents_opaque() && | 74 raster_source->SetRequiresClear(!contents_opaque() && |
75 !client_->FillsBoundsCompletely()); | 75 !client_->FillsBoundsCompletely()); |
76 layer_impl->UpdateRasterSource(raster_source); | 76 layer_impl->UpdateRasterSource(raster_source, &recording_invalidation_, |
| 77 nullptr); |
| 78 DCHECK(recording_invalidation_.IsEmpty()); |
77 } | 79 } |
78 | 80 |
79 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 81 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
80 Layer::SetLayerTreeHost(host); | 82 Layer::SetLayerTreeHost(host); |
81 if (host) { | 83 if (host) { |
82 if (!recording_source_) { | 84 if (!recording_source_) { |
83 if (host->settings().use_display_lists) { | 85 if (host->settings().use_display_lists) { |
84 recording_source_.reset(new DisplayListRecordingSource); | 86 recording_source_.reset(new DisplayListRecordingSource); |
85 } else { | 87 } else { |
86 recording_source_.reset(new PicturePile); | 88 recording_source_.reset(new PicturePile); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 201 |
200 bool PictureLayer::IsSuitableForGpuRasterization() const { | 202 bool PictureLayer::IsSuitableForGpuRasterization() const { |
201 return recording_source_->IsSuitableForGpuRasterization(); | 203 return recording_source_->IsSuitableForGpuRasterization(); |
202 } | 204 } |
203 | 205 |
204 void PictureLayer::ClearClient() { | 206 void PictureLayer::ClearClient() { |
205 client_ = nullptr; | 207 client_ = nullptr; |
206 UpdateDrawsContent(HasDrawableContent()); | 208 UpdateDrawsContent(HasDrawableContent()); |
207 } | 209 } |
208 | 210 |
| 211 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { |
| 212 if (nearest_neighbor_ == nearest_neighbor) |
| 213 return; |
| 214 |
| 215 nearest_neighbor_ = nearest_neighbor; |
| 216 SetNeedsCommit(); |
| 217 } |
| 218 |
209 bool PictureLayer::HasDrawableContent() const { | 219 bool PictureLayer::HasDrawableContent() const { |
210 return client_ && Layer::HasDrawableContent(); | 220 return client_ && Layer::HasDrawableContent(); |
211 } | 221 } |
212 | 222 |
213 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 223 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
214 benchmark->RunOnLayer(this); | 224 benchmark->RunOnLayer(this); |
215 } | 225 } |
216 | 226 |
217 } // namespace cc | 227 } // namespace cc |
OLD | NEW |