| 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/trees/layer_tree_impl.h" | 10 #include "cc/trees/layer_tree_impl.h" |
| 11 #include "third_party/skia/include/core/SkPictureRecorder.h" | 11 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 12 #include "ui/gfx/geometry/rect_conversions.h" | 12 #include "ui/gfx/geometry/rect_conversions.h" |
| 13 | 13 |
| 14 namespace cc { | 14 namespace cc { |
| 15 | 15 |
| 16 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { | 16 scoped_refptr<PictureLayer> PictureLayer::Create(ContentLayerClient* client) { |
| 17 return make_scoped_refptr(new PictureLayer(client)); | 17 return make_scoped_refptr(new PictureLayer(client)); |
| 18 } | 18 } |
| 19 | 19 |
| 20 PictureLayer::PictureLayer(ContentLayerClient* client) | 20 PictureLayer::PictureLayer(ContentLayerClient* client) |
| 21 : client_(client), | 21 : client_(client), |
| 22 pile_(make_scoped_refptr(new PicturePile())), | |
| 23 instrumentation_object_tracker_(id()), | 22 instrumentation_object_tracker_(id()), |
| 24 update_source_frame_number_(-1), | 23 update_source_frame_number_(-1), |
| 25 can_use_lcd_text_last_frame_(can_use_lcd_text()) { | 24 can_use_lcd_text_last_frame_(can_use_lcd_text()) { |
| 26 } | 25 } |
| 27 | 26 |
| 28 PictureLayer::~PictureLayer() { | 27 PictureLayer::~PictureLayer() { |
| 29 } | 28 } |
| 30 | 29 |
| 31 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 30 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 32 return PictureLayerImpl::Create(tree_impl, id()); | 31 return PictureLayerImpl::Create(tree_impl, id()); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 34 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
| 36 Layer::PushPropertiesTo(base_layer); | 35 Layer::PushPropertiesTo(base_layer); |
| 37 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); | 36 PictureLayerImpl* layer_impl = static_cast<PictureLayerImpl*>(base_layer); |
| 38 | 37 |
| 39 if (layer_impl->bounds().IsEmpty()) { | 38 if (layer_impl->bounds().IsEmpty()) { |
| 40 // Update may not get called for an empty layer, so resize here instead. | 39 // Update may not get called for an empty layer, so resize here instead. |
| 41 // Using layer_impl because either bounds() or paint_properties().bounds | 40 // Using layer_impl because either bounds() or paint_properties().bounds |
| 42 // may disagree and either one could have been pushed to layer_impl. | 41 // may disagree and either one could have been pushed to layer_impl. |
| 43 pile_->SetEmptyBounds(); | 42 pile_.SetEmptyBounds(); |
| 44 } else if (update_source_frame_number_ == | 43 } else if (update_source_frame_number_ == |
| 45 layer_tree_host()->source_frame_number()) { | 44 layer_tree_host()->source_frame_number()) { |
| 46 // TODO(ernstm): This DCHECK is only valid as long as the pile's tiling_rect | 45 // TODO(ernstm): This DCHECK is only valid as long as the pile's tiling_rect |
| 47 // is identical to the layer_rect. | 46 // is identical to the layer_rect. |
| 48 // If update called, then pile size must match bounds pushed to impl layer. | 47 // If update called, then pile size must match bounds pushed to impl layer. |
| 49 DCHECK_EQ(layer_impl->bounds().ToString(), pile_->tiling_size().ToString()); | 48 DCHECK_EQ(layer_impl->bounds().ToString(), pile_.tiling_size().ToString()); |
| 50 } | 49 } |
| 51 | 50 |
| 52 // Unlike other properties, invalidation must always be set on layer_impl. | 51 // Unlike other properties, invalidation must always be set on layer_impl. |
| 53 // See PictureLayerImpl::PushPropertiesTo for more details. | 52 // See PictureLayerImpl::PushPropertiesTo for more details. |
| 54 layer_impl->invalidation_.Clear(); | 53 layer_impl->invalidation_.Clear(); |
| 55 layer_impl->invalidation_.Swap(&pile_invalidation_); | 54 layer_impl->invalidation_.Swap(&pile_invalidation_); |
| 56 layer_impl->pile_ = PicturePileImpl::CreateFromOther(pile_.get()); | 55 layer_impl->pile_ = PicturePileImpl::CreateFromOther(&pile_); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { | 58 void PictureLayer::SetLayerTreeHost(LayerTreeHost* host) { |
| 60 Layer::SetLayerTreeHost(host); | 59 Layer::SetLayerTreeHost(host); |
| 61 if (host) { | 60 if (host) { |
| 62 pile_->SetMinContentsScale(host->settings().minimum_contents_scale); | 61 pile_.SetMinContentsScale(host->settings().minimum_contents_scale); |
| 63 pile_->SetTileGridSize(host->settings().default_tile_grid_size); | 62 pile_.SetTileGridSize(host->settings().default_tile_grid_size); |
| 64 pile_->set_slow_down_raster_scale_factor( | 63 pile_.set_slow_down_raster_scale_factor( |
| 65 host->debug_state().slow_down_raster_scale_factor); | 64 host->debug_state().slow_down_raster_scale_factor); |
| 66 pile_->set_show_debug_picture_borders( | 65 pile_.set_show_debug_picture_borders( |
| 67 host->debug_state().show_picture_borders); | 66 host->debug_state().show_picture_borders); |
| 68 } | 67 } |
| 69 } | 68 } |
| 70 | 69 |
| 71 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { | 70 void PictureLayer::SetNeedsDisplayRect(const gfx::Rect& layer_rect) { |
| 72 if (!layer_rect.IsEmpty()) { | 71 if (!layer_rect.IsEmpty()) { |
| 73 // Clamp invalidation to the layer bounds. | 72 // Clamp invalidation to the layer bounds. |
| 74 pending_invalidation_.Union( | 73 pending_invalidation_.Union( |
| 75 gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); | 74 gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); |
| 76 } | 75 } |
| 77 Layer::SetNeedsDisplayRect(layer_rect); | 76 Layer::SetNeedsDisplayRect(layer_rect); |
| 78 } | 77 } |
| 79 | 78 |
| 80 bool PictureLayer::Update(ResourceUpdateQueue* queue, | 79 bool PictureLayer::Update(ResourceUpdateQueue* queue, |
| 81 const OcclusionTracker<Layer>* occlusion) { | 80 const OcclusionTracker<Layer>* occlusion) { |
| 82 update_source_frame_number_ = layer_tree_host()->source_frame_number(); | 81 update_source_frame_number_ = layer_tree_host()->source_frame_number(); |
| 83 bool updated = Layer::Update(queue, occlusion); | 82 bool updated = Layer::Update(queue, occlusion); |
| 84 | 83 |
| 85 { | 84 { |
| 86 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 85 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
| 87 true); | 86 true); |
| 88 UpdateCanUseLCDText(); | 87 UpdateCanUseLCDText(); |
| 89 } | 88 } |
| 90 | 89 |
| 91 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( | 90 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( |
| 92 visible_content_rect(), 1.f / contents_scale_x()); | 91 visible_content_rect(), 1.f / contents_scale_x()); |
| 93 gfx::Size layer_size = paint_properties().bounds; | 92 gfx::Size layer_size = paint_properties().bounds; |
| 94 | 93 |
| 95 if (last_updated_visible_content_rect_ == visible_content_rect() && | 94 if (last_updated_visible_content_rect_ == visible_content_rect() && |
| 96 pile_->tiling_size() == layer_size && pending_invalidation_.IsEmpty()) { | 95 pile_.tiling_size() == layer_size && pending_invalidation_.IsEmpty()) { |
| 97 // Only early out if the visible content rect of this layer hasn't changed. | 96 // Only early out if the visible content rect of this layer hasn't changed. |
| 98 return updated; | 97 return updated; |
| 99 } | 98 } |
| 100 | 99 |
| 101 TRACE_EVENT1("cc", "PictureLayer::Update", | 100 TRACE_EVENT1("cc", "PictureLayer::Update", |
| 102 "source_frame_number", | 101 "source_frame_number", |
| 103 layer_tree_host()->source_frame_number()); | 102 layer_tree_host()->source_frame_number()); |
| 104 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 103 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
| 105 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); | 104 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); |
| 106 | 105 |
| 107 // Calling paint in WebKit can sometimes cause invalidations, so save | 106 // Calling paint in WebKit can sometimes cause invalidations, so save |
| 108 // off the invalidation prior to calling update. | 107 // off the invalidation prior to calling update. |
| 109 pending_invalidation_.Swap(&pile_invalidation_); | 108 pending_invalidation_.Swap(&pile_invalidation_); |
| 110 pending_invalidation_.Clear(); | 109 pending_invalidation_.Clear(); |
| 111 | 110 |
| 112 if (layer_tree_host()->settings().record_full_layer) { | 111 if (layer_tree_host()->settings().record_full_layer) { |
| 113 // Workaround for http://crbug.com/235910 - to retain backwards compat | 112 // Workaround for http://crbug.com/235910 - to retain backwards compat |
| 114 // the full page content must always be provided in the picture layer. | 113 // the full page content must always be provided in the picture layer. |
| 115 visible_layer_rect = gfx::Rect(layer_size); | 114 visible_layer_rect = gfx::Rect(layer_size); |
| 116 } | 115 } |
| 117 | 116 |
| 118 // UpdateAndExpandInvalidation will give us an invalidation that covers | 117 // UpdateAndExpandInvalidation will give us an invalidation that covers |
| 119 // anything not explicitly recorded in this frame. We give this region | 118 // anything not explicitly recorded in this frame. We give this region |
| 120 // to the impl side so that it drops tiles that may not have a recording | 119 // to the impl side so that it drops tiles that may not have a recording |
| 121 // for them. | 120 // for them. |
| 122 DCHECK(client_); | 121 DCHECK(client_); |
| 123 updated |= | 122 updated |= |
| 124 pile_->UpdateAndExpandInvalidation(client_, | 123 pile_.UpdateAndExpandInvalidation(client_, |
| 125 &pile_invalidation_, | 124 &pile_invalidation_, |
| 126 SafeOpaqueBackgroundColor(), | 125 SafeOpaqueBackgroundColor(), |
| 127 contents_opaque(), | 126 contents_opaque(), |
| 128 client_->FillsBoundsCompletely(), | 127 client_->FillsBoundsCompletely(), |
| 129 layer_size, | 128 layer_size, |
| 130 visible_layer_rect, | 129 visible_layer_rect, |
| 131 update_source_frame_number_, | 130 update_source_frame_number_, |
| 132 Picture::RECORD_NORMALLY, | 131 Picture::RECORD_NORMALLY, |
| 133 rendering_stats_instrumentation()); | 132 rendering_stats_instrumentation()); |
| 134 last_updated_visible_content_rect_ = visible_content_rect(); | 133 last_updated_visible_content_rect_ = visible_content_rect(); |
| 135 | 134 |
| 136 if (updated) { | 135 if (updated) { |
| 137 SetNeedsPushProperties(); | 136 SetNeedsPushProperties(); |
| 138 } else { | 137 } else { |
| 139 // If this invalidation did not affect the pile, then it can be cleared as | 138 // If this invalidation did not affect the pile, then it can be cleared as |
| 140 // an optimization. | 139 // an optimization. |
| 141 pile_invalidation_.Clear(); | 140 pile_invalidation_.Clear(); |
| 142 } | 141 } |
| 143 | 142 |
| 144 return updated; | 143 return updated; |
| 145 } | 144 } |
| 146 | 145 |
| 147 void PictureLayer::SetIsMask(bool is_mask) { | 146 void PictureLayer::SetIsMask(bool is_mask) { |
| 148 pile_->set_is_mask(is_mask); | 147 pile_.set_is_mask(is_mask); |
| 149 } | 148 } |
| 150 | 149 |
| 151 bool PictureLayer::SupportsLCDText() const { | 150 bool PictureLayer::SupportsLCDText() const { |
| 152 return true; | 151 return true; |
| 153 } | 152 } |
| 154 | 153 |
| 155 void PictureLayer::UpdateCanUseLCDText() { | 154 void PictureLayer::UpdateCanUseLCDText() { |
| 156 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) | 155 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) |
| 157 return; | 156 return; |
| 158 | 157 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 174 SkPictureRecorder recorder; | 173 SkPictureRecorder recorder; |
| 175 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); | 174 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); |
| 176 client_->PaintContents(canvas, | 175 client_->PaintContents(canvas, |
| 177 gfx::Rect(width, height), | 176 gfx::Rect(width, height), |
| 178 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | 177 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); |
| 179 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 178 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| 180 return picture; | 179 return picture; |
| 181 } | 180 } |
| 182 | 181 |
| 183 bool PictureLayer::IsSuitableForGpuRasterization() const { | 182 bool PictureLayer::IsSuitableForGpuRasterization() const { |
| 184 return pile_->is_suitable_for_gpu_rasterization(); | 183 return pile_.is_suitable_for_gpu_rasterization(); |
| 185 } | 184 } |
| 186 | 185 |
| 187 void PictureLayer::ClearClient() { | 186 void PictureLayer::ClearClient() { |
| 188 client_ = nullptr; | 187 client_ = nullptr; |
| 189 UpdateDrawsContent(HasDrawableContent()); | 188 UpdateDrawsContent(HasDrawableContent()); |
| 190 } | 189 } |
| 191 | 190 |
| 192 bool PictureLayer::HasDrawableContent() const { | 191 bool PictureLayer::HasDrawableContent() const { |
| 193 return client_ && Layer::HasDrawableContent(); | 192 return client_ && Layer::HasDrawableContent(); |
| 194 } | 193 } |
| 195 | 194 |
| 196 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 195 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 197 benchmark->RunOnLayer(this); | 196 benchmark->RunOnLayer(this); |
| 198 } | 197 } |
| 199 | 198 |
| 200 } // namespace cc | 199 } // namespace cc |
| OLD | NEW |