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 "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/layers/recording_source.h" | 11 #include "cc/layers/recording_source.h" |
12 #include "cc/paint/paint_record.h" | 12 #include "cc/paint/paint_record.h" |
13 #include "cc/trees/layer_tree_host.h" | 13 #include "cc/trees/layer_tree_host.h" |
14 #include "cc/trees/layer_tree_impl.h" | 14 #include "cc/trees/layer_tree_impl.h" |
| 15 #include "cc/trees/transform_node.h" |
15 #include "ui/gfx/geometry/rect_conversions.h" | 16 #include "ui/gfx/geometry/rect_conversions.h" |
16 | 17 |
17 namespace cc { | 18 namespace cc { |
18 | 19 |
19 PictureLayer::PictureLayerInputs::PictureLayerInputs() = default; | 20 PictureLayer::PictureLayerInputs::PictureLayerInputs() = default; |
20 | 21 |
21 PictureLayer::PictureLayerInputs::~PictureLayerInputs() = default; | 22 PictureLayer::PictureLayerInputs::~PictureLayerInputs() = default; |
22 | 23 |
23 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | 24 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
24 return make_scoped_refptr(new PictureLayer(client)); | 25 return make_scoped_refptr(new PictureLayer(client)); |
(...skipping 22 matching lines...) Expand all Loading... |
47 | 48 |
48 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 49 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
49 Layer::PushPropertiesTo(base_layer); | 50 Layer::PushPropertiesTo(base_layer); |
50 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); | 51 TRACE_EVENT0("cc", "PictureLayer::PushPropertiesTo"); |
51 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 52 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
52 // TODO(danakj): Make mask_type_ a constructor parameter for PictureLayer. | 53 // TODO(danakj): Make mask_type_ a constructor parameter for PictureLayer. |
53 DCHECK_EQ(layer_impl->mask_type(), mask_type()); | 54 DCHECK_EQ(layer_impl->mask_type(), mask_type()); |
54 DropRecordingSourceContentIfInvalid(); | 55 DropRecordingSourceContentIfInvalid(); |
55 | 56 |
56 layer_impl->SetNearestNeighbor(picture_layer_inputs_.nearest_neighbor); | 57 layer_impl->SetNearestNeighbor(picture_layer_inputs_.nearest_neighbor); |
| 58 layer_impl->SetUseTransformedRasterization( |
| 59 ShouldUseTransformedRasterization()); |
57 | 60 |
58 // Preserve lcd text settings from the current raster source. | 61 // Preserve lcd text settings from the current raster source. |
59 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); | 62 bool can_use_lcd_text = layer_impl->RasterSourceUsesLCDText(); |
60 scoped_refptr<RasterSource> raster_source = | 63 scoped_refptr<RasterSource> raster_source = |
61 recording_source_->CreateRasterSource(can_use_lcd_text); | 64 recording_source_->CreateRasterSource(can_use_lcd_text); |
62 layer_impl->set_gpu_raster_max_texture_size( | 65 layer_impl->set_gpu_raster_max_texture_size( |
63 layer_tree_host()->device_viewport_size()); | 66 layer_tree_host()->device_viewport_size()); |
64 layer_impl->UpdateRasterSource(std::move(raster_source), | 67 layer_impl->UpdateRasterSource(std::move(raster_source), |
65 &last_updated_invalidation_, nullptr); | 68 &last_updated_invalidation_, nullptr); |
66 DCHECK(last_updated_invalidation_.IsEmpty()); | 69 DCHECK(last_updated_invalidation_.IsEmpty()); |
(...skipping 26 matching lines...) Expand all Loading... |
93 recording_source_->SetNeedsDisplayRect(layer_rect); | 96 recording_source_->SetNeedsDisplayRect(layer_rect); |
94 Layer::SetNeedsDisplayRect(layer_rect); | 97 Layer::SetNeedsDisplayRect(layer_rect); |
95 } | 98 } |
96 | 99 |
97 bool PictureLayer::Update() { | 100 bool PictureLayer::Update() { |
98 update_source_frame_number_ = layer_tree_host()->SourceFrameNumber(); | 101 update_source_frame_number_ = layer_tree_host()->SourceFrameNumber(); |
99 bool updated = Layer::Update(); | 102 bool updated = Layer::Update(); |
100 | 103 |
101 gfx::Size layer_size = paint_properties().bounds; | 104 gfx::Size layer_size = paint_properties().bounds; |
102 | 105 |
103 recording_source_->SetBackgroundColor(SafeOpaqueBackgroundColor()); | 106 // When transformed rasterization is used, we try to match the rendering |
| 107 // without a compositing layer, thus we don't over draw background to fill |
| 108 // snapped edges. |
| 109 SkColor background_color = ShouldUseTransformedRasterization() |
| 110 ? SK_ColorTRANSPARENT |
| 111 : SafeOpaqueBackgroundColor(); |
| 112 recording_source_->SetBackgroundColor(background_color); |
104 recording_source_->SetRequiresClear( | 113 recording_source_->SetRequiresClear( |
105 !contents_opaque() && | 114 !contents_opaque() && |
106 !picture_layer_inputs_.client->FillsBoundsCompletely()); | 115 !picture_layer_inputs_.client->FillsBoundsCompletely()); |
107 | 116 |
108 TRACE_EVENT1("cc", "PictureLayer::Update", "source_frame_number", | 117 TRACE_EVENT1("cc", "PictureLayer::Update", "source_frame_number", |
109 layer_tree_host()->SourceFrameNumber()); | 118 layer_tree_host()->SourceFrameNumber()); |
110 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 119 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
111 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->GetId()); | 120 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->GetId()); |
112 | 121 |
113 // UpdateAndExpandInvalidation will give us an invalidation that covers | 122 // UpdateAndExpandInvalidation will give us an invalidation that covers |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } | 200 } |
192 | 201 |
193 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { | 202 void PictureLayer::SetNearestNeighbor(bool nearest_neighbor) { |
194 if (picture_layer_inputs_.nearest_neighbor == nearest_neighbor) | 203 if (picture_layer_inputs_.nearest_neighbor == nearest_neighbor) |
195 return; | 204 return; |
196 | 205 |
197 picture_layer_inputs_.nearest_neighbor = nearest_neighbor; | 206 picture_layer_inputs_.nearest_neighbor = nearest_neighbor; |
198 SetNeedsCommit(); | 207 SetNeedsCommit(); |
199 } | 208 } |
200 | 209 |
| 210 void PictureLayer::SetAllowTransformedRasterization(bool allowed) { |
| 211 if (picture_layer_inputs_.allow_transformed_rasterization == allowed) |
| 212 return; |
| 213 |
| 214 picture_layer_inputs_.allow_transformed_rasterization = allowed; |
| 215 SetNeedsCommit(); |
| 216 } |
| 217 |
201 bool PictureLayer::HasDrawableContent() const { | 218 bool PictureLayer::HasDrawableContent() const { |
202 return picture_layer_inputs_.client && Layer::HasDrawableContent(); | 219 return picture_layer_inputs_.client && Layer::HasDrawableContent(); |
203 } | 220 } |
204 | 221 |
205 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 222 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
206 benchmark->RunOnLayer(this); | 223 benchmark->RunOnLayer(this); |
207 } | 224 } |
208 | 225 |
209 void PictureLayer::DropRecordingSourceContentIfInvalid() { | 226 void PictureLayer::DropRecordingSourceContentIfInvalid() { |
210 int source_frame_number = layer_tree_host()->SourceFrameNumber(); | 227 int source_frame_number = layer_tree_host()->SourceFrameNumber(); |
(...skipping 15 matching lines...) Expand all Loading... |
226 // Update may not get called for the layer (if it's not in the viewport | 243 // Update may not get called for the layer (if it's not in the viewport |
227 // for example), even though it has resized making the recording source no | 244 // for example), even though it has resized making the recording source no |
228 // longer valid. In this case just destroy the recording source. | 245 // longer valid. In this case just destroy the recording source. |
229 recording_source_->SetEmptyBounds(); | 246 recording_source_->SetEmptyBounds(); |
230 picture_layer_inputs_.recorded_viewport = gfx::Rect(); | 247 picture_layer_inputs_.recorded_viewport = gfx::Rect(); |
231 picture_layer_inputs_.display_list = nullptr; | 248 picture_layer_inputs_.display_list = nullptr; |
232 picture_layer_inputs_.painter_reported_memory_usage = 0; | 249 picture_layer_inputs_.painter_reported_memory_usage = 0; |
233 } | 250 } |
234 } | 251 } |
235 | 252 |
| 253 bool PictureLayer::ShouldUseTransformedRasterization() const { |
| 254 if (!picture_layer_inputs_.allow_transformed_rasterization) |
| 255 return false; |
| 256 |
| 257 const TransformTree& transform_tree = |
| 258 layer_tree_host()->property_trees()->transform_tree; |
| 259 DCHECK(!transform_tree.needs_update()); |
| 260 if (transform_tree.Node(transform_tree_index()) |
| 261 ->to_screen_is_potentially_animated) |
| 262 return false; |
| 263 |
| 264 const gfx::Transform& to_screen = |
| 265 transform_tree.ToScreen(transform_tree_index()); |
| 266 if (!to_screen.IsScaleOrTranslation()) |
| 267 return false; |
| 268 |
| 269 float origin_x = |
| 270 to_screen.matrix().getFloat(0, 3) + offset_to_transform_parent().x(); |
| 271 float origin_y = |
| 272 to_screen.matrix().getFloat(1, 3) + offset_to_transform_parent().y(); |
| 273 if (origin_x - floorf(origin_x) == 0.f && origin_y - floorf(origin_y) == 0.f) |
| 274 return false; |
| 275 |
| 276 return true; |
| 277 } |
| 278 |
236 const DisplayItemList* PictureLayer::GetDisplayItemList() { | 279 const DisplayItemList* PictureLayer::GetDisplayItemList() { |
237 return picture_layer_inputs_.display_list.get(); | 280 return picture_layer_inputs_.display_list.get(); |
238 } | 281 } |
239 | 282 |
240 } // namespace cc | 283 } // namespace cc |
OLD | NEW |