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/picture_pile.h" | 10 #include "cc/resources/picture_pile.h" |
11 #include "cc/trees/layer_tree_impl.h" | 11 #include "cc/trees/layer_tree_impl.h" |
12 #include "third_party/skia/include/core/SkPictureRecorder.h" | 12 #include "third_party/skia/include/core/SkPictureRecorder.h" |
13 #include "ui/gfx/geometry/rect_conversions.h" | 13 #include "ui/gfx/geometry/rect_conversions.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 | 16 |
17 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | 17 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
18 return make_scoped_refptr(new PictureLayer(client)); | 18 return make_scoped_refptr(new PictureLayer(client)); |
19 } | 19 } |
20 | 20 |
21 PictureLayer::PictureLayer(ContentLayerClient* client) | 21 PictureLayer::PictureLayer(ContentLayerClient* client) |
22 : client_(client), | 22 : client_(client), |
23 recording_source_(new PicturePile), | 23 recording_source_(new PicturePile), |
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_last_frame_(can_use_lcd_text()) { | 26 can_use_lcd_text_last_frame_(can_use_lcd_text()), |
| 27 is_mask_(false) { |
| 28 } |
| 29 |
| 30 PictureLayer::PictureLayer(ContentLayerClient* client, |
| 31 scoped_ptr<RecordingSource> source) |
| 32 : PictureLayer(client) { |
| 33 recording_source_ = source.Pass(); |
27 } | 34 } |
28 | 35 |
29 PictureLayer::~PictureLayer() { | 36 PictureLayer::~PictureLayer() { |
30 } | 37 } |
31 | 38 |
32 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 39 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
33 return PictureLayerImpl::Create(tree_impl, id()); | 40 return PictureLayerImpl::Create(tree_impl, id()); |
34 } | 41 } |
35 | 42 |
36 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 43 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
(...skipping 16 matching lines...) Expand all Loading... |
53 // Update may not get called for the layer (if it's not in the viewport | 60 // Update may not get called for the layer (if it's not in the viewport |
54 // for example, even though it has resized making the recording source no | 61 // for example, even though it has resized making the recording source no |
55 // longer valid. In this case just destroy the recording source. | 62 // longer valid. In this case just destroy the recording source. |
56 recording_source_->SetEmptyBounds(); | 63 recording_source_->SetEmptyBounds(); |
57 } | 64 } |
58 | 65 |
59 // Unlike other properties, invalidation must always be set on layer_impl. | 66 // Unlike other properties, invalidation must always be set on layer_impl. |
60 // See PictureLayerImpl::PushPropertiesTo for more details. | 67 // See PictureLayerImpl::PushPropertiesTo for more details. |
61 layer_impl->invalidation_.Clear(); | 68 layer_impl->invalidation_.Clear(); |
62 layer_impl->invalidation_.Swap(&recording_invalidation_); | 69 layer_impl->invalidation_.Swap(&recording_invalidation_); |
63 layer_impl->UpdateRasterSource(recording_source_->CreateRasterSource()); | 70 layer_impl->set_is_mask(is_mask_); |
| 71 scoped_refptr<RasterSource> raster_source = |
| 72 recording_source_->CreateRasterSource(); |
| 73 raster_source->SetBackgoundColor(SafeOpaqueBackgroundColor()); |
| 74 raster_source->SetRequiresClear(!contents_opaque() && |
| 75 !client_->FillsBoundsCompletely()); |
| 76 layer_impl->UpdateRasterSource(raster_source); |
64 } | 77 } |
65 | 78 |
66 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 79 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
67 Layer::SetLayerTreeHost(host); | 80 Layer::SetLayerTreeHost(host); |
68 if (host) { | 81 if (host) { |
69 // TODO(hendrikw): Perhaps use and initialization function to do this work. | |
70 recording_source_->SetMinContentsScale( | 82 recording_source_->SetMinContentsScale( |
71 host->settings().minimum_contents_scale); | 83 host->settings().minimum_contents_scale); |
72 recording_source_->SetTileGridSize(host->settings().default_tile_grid_size); | 84 recording_source_->SetTileGridSize(host->settings().default_tile_grid_size); |
73 recording_source_->SetSlowdownRasterScaleFactor( | 85 recording_source_->SetSlowdownRasterScaleFactor( |
74 host->debug_state().slow_down_raster_scale_factor); | 86 host->debug_state().slow_down_raster_scale_factor); |
75 } | 87 } |
76 } | 88 } |
77 | 89 |
78 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | 90 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { |
79 if (!layer_rect.IsEmpty()) { | 91 if (!layer_rect.IsEmpty()) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 // the full page content must always be provided in the picture layer. | 134 // the full page content must always be provided in the picture layer. |
123 visible_layer_rect = gfx::Rect(layer_size); | 135 visible_layer_rect = gfx::Rect(layer_size); |
124 } | 136 } |
125 | 137 |
126 // UpdateAndExpandInvalidation will give us an invalidation that covers | 138 // UpdateAndExpandInvalidation will give us an invalidation that covers |
127 // anything not explicitly recorded in this frame. We give this region | 139 // anything not explicitly recorded in this frame. We give this region |
128 // to the impl side so that it drops tiles that may not have a recording | 140 // to the impl side so that it drops tiles that may not have a recording |
129 // for them. | 141 // for them. |
130 DCHECK(client_); | 142 DCHECK(client_); |
131 updated |= recording_source_->UpdateAndExpandInvalidation( | 143 updated |= recording_source_->UpdateAndExpandInvalidation( |
132 client_, &recording_invalidation_, SafeOpaqueBackgroundColor(), | 144 client_, &recording_invalidation_, layer_size, visible_layer_rect, |
133 contents_opaque(), client_->FillsBoundsCompletely(), layer_size, | 145 update_source_frame_number_, Picture::RECORD_NORMALLY); |
134 visible_layer_rect, update_source_frame_number_, | |
135 Picture::RECORD_NORMALLY); | |
136 last_updated_visible_content_rect_ = visible_content_rect(); | 146 last_updated_visible_content_rect_ = visible_content_rect(); |
137 | 147 |
138 if (updated) { | 148 if (updated) { |
139 SetNeedsPushProperties(); | 149 SetNeedsPushProperties(); |
140 } else { | 150 } else { |
141 // If this invalidation did not affect the recording source, then it can be | 151 // If this invalidation did not affect the recording source, then it can be |
142 // cleared as an optimization. | 152 // cleared as an optimization. |
143 recording_invalidation_.Clear(); | 153 recording_invalidation_.Clear(); |
144 } | 154 } |
145 | 155 |
146 return updated; | 156 return updated; |
147 } | 157 } |
148 | 158 |
149 void PictureLayer::SetIsMask(bool is_mask) { | 159 void PictureLayer::SetIsMask(bool is_mask) { |
150 recording_source_->SetIsMask(is_mask); | 160 is_mask_ = is_mask; |
151 } | 161 } |
152 | 162 |
153 bool PictureLayer::SupportsLCDText() const { | 163 bool PictureLayer::SupportsLCDText() const { |
154 return true; | 164 return true; |
155 } | 165 } |
156 | 166 |
157 void PictureLayer::UpdateCanUseLCDText() { | 167 void PictureLayer::UpdateCanUseLCDText() { |
158 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) | 168 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) |
159 return; | 169 return; |
160 | 170 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 203 |
194 bool PictureLayer::HasDrawableContent() const { | 204 bool PictureLayer::HasDrawableContent() const { |
195 return client_ && Layer::HasDrawableContent(); | 205 return client_ && Layer::HasDrawableContent(); |
196 } | 206 } |
197 | 207 |
198 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 208 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
199 benchmark->RunOnLayer(this); | 209 benchmark->RunOnLayer(this); |
200 } | 210 } |
201 | 211 |
202 } // namespace cc | 212 } // namespace cc |
OLD | NEW |