| 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_for_update_(true) { | 26 can_use_lcd_text_last_frame_(can_use_lcd_text()) { |
| 27 } | 27 } |
| 28 | 28 |
| 29 PictureLayer::PictureLayer(ContentLayerClient* client, | 29 PictureLayer::PictureLayer(ContentLayerClient* client, |
| 30 scoped_ptr<RecordingSource> source) | 30 scoped_ptr<RecordingSource> source) |
| 31 : PictureLayer(client) { | 31 : PictureLayer(client) { |
| 32 recording_source_ = source.Pass(); | 32 recording_source_ = source.Pass(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 PictureLayer::~PictureLayer() { | 35 PictureLayer::~PictureLayer() { |
| 36 } | 36 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); | 88 gfx::IntersectRects(layer_rect, gfx::Rect(bounds()))); |
| 89 } | 89 } |
| 90 Layer::SetNeedsDisplayRect(layer_rect); | 90 Layer::SetNeedsDisplayRect(layer_rect); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool PictureLayer::Update(ResourceUpdateQueue* queue, | 93 bool PictureLayer::Update(ResourceUpdateQueue* queue, |
| 94 const OcclusionTracker<Layer>* occlusion) { | 94 const OcclusionTracker<Layer>* occlusion) { |
| 95 update_source_frame_number_ = layer_tree_host()->source_frame_number(); | 95 update_source_frame_number_ = layer_tree_host()->source_frame_number(); |
| 96 bool updated = Layer::Update(queue, occlusion); | 96 bool updated = Layer::Update(queue, occlusion); |
| 97 | 97 |
| 98 bool can_use_lcd_text_changed = UpdateCanUseLCDText(); | 98 { |
| 99 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
| 100 true); |
| 101 UpdateCanUseLCDText(); |
| 102 } |
| 99 | 103 |
| 100 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( | 104 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( |
| 101 visible_content_rect(), 1.f / contents_scale_x()); | 105 visible_content_rect(), 1.f / contents_scale_x()); |
| 102 gfx::Size layer_size = paint_properties().bounds; | 106 gfx::Size layer_size = paint_properties().bounds; |
| 103 | 107 |
| 104 if (last_updated_visible_content_rect_ == visible_content_rect() && | 108 if (last_updated_visible_content_rect_ == visible_content_rect() && |
| 105 recording_source_->GetSize() == layer_size && !can_use_lcd_text_changed && | 109 recording_source_->GetSize() == layer_size && |
| 106 pending_invalidation_.IsEmpty()) { | 110 pending_invalidation_.IsEmpty()) { |
| 107 // Only early out if the visible content rect of this layer hasn't changed. | 111 // Only early out if the visible content rect of this layer hasn't changed. |
| 108 return updated; | 112 return updated; |
| 109 } | 113 } |
| 110 | 114 |
| 111 TRACE_EVENT1("cc", "PictureLayer::Update", | 115 TRACE_EVENT1("cc", "PictureLayer::Update", |
| 112 "source_frame_number", | 116 "source_frame_number", |
| 113 layer_tree_host()->source_frame_number()); | 117 layer_tree_host()->source_frame_number()); |
| 114 devtools_instrumentation::ScopedLayerTreeTask update_layer( | 118 devtools_instrumentation::ScopedLayerTreeTask update_layer( |
| 115 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); | 119 devtools_instrumentation::kUpdateLayer, id(), layer_tree_host()->id()); |
| 116 | 120 |
| 117 // Calling paint in WebKit can sometimes cause invalidations, so save | 121 // Calling paint in WebKit can sometimes cause invalidations, so save |
| 118 // off the invalidation prior to calling update. | 122 // off the invalidation prior to calling update. |
| 119 pending_invalidation_.Swap(&recording_invalidation_); | 123 pending_invalidation_.Swap(&recording_invalidation_); |
| 120 pending_invalidation_.Clear(); | 124 pending_invalidation_.Clear(); |
| 121 | 125 |
| 122 if (layer_tree_host()->settings().record_full_layer) { | 126 if (layer_tree_host()->settings().record_full_layer) { |
| 123 // Workaround for http://crbug.com/235910 - to retain backwards compat | 127 // Workaround for http://crbug.com/235910 - to retain backwards compat |
| 124 // the full page content must always be provided in the picture layer. | 128 // the full page content must always be provided in the picture layer. |
| 125 visible_layer_rect = gfx::Rect(layer_size); | 129 visible_layer_rect = gfx::Rect(layer_size); |
| 126 } | 130 } |
| 127 | 131 |
| 128 // UpdateAndExpandInvalidation will give us an invalidation that covers | 132 // UpdateAndExpandInvalidation will give us an invalidation that covers |
| 129 // anything not explicitly recorded in this frame. We give this region | 133 // anything not explicitly recorded in this frame. We give this region |
| 130 // to the impl side so that it drops tiles that may not have a recording | 134 // to the impl side so that it drops tiles that may not have a recording |
| 131 // for them. | 135 // for them. |
| 132 DCHECK(client_); | 136 DCHECK(client_); |
| 133 updated |= recording_source_->UpdateAndExpandInvalidation( | 137 updated |= recording_source_->UpdateAndExpandInvalidation( |
| 134 client_, &recording_invalidation_, SafeOpaqueBackgroundColor(), | 138 client_, &recording_invalidation_, SafeOpaqueBackgroundColor(), |
| 135 contents_opaque(), client_->FillsBoundsCompletely(), | 139 contents_opaque(), client_->FillsBoundsCompletely(), layer_size, |
| 136 can_use_lcd_text_for_update_, layer_size, visible_layer_rect, | 140 visible_layer_rect, update_source_frame_number_, |
| 137 update_source_frame_number_, Picture::RECORD_NORMALLY); | 141 Picture::RECORD_NORMALLY); |
| 138 last_updated_visible_content_rect_ = visible_content_rect(); | 142 last_updated_visible_content_rect_ = visible_content_rect(); |
| 139 | 143 |
| 140 if (updated) { | 144 if (updated) { |
| 141 SetNeedsPushProperties(); | 145 SetNeedsPushProperties(); |
| 142 } else { | 146 } else { |
| 143 // If this invalidation did not affect the recording source, then it can be | 147 // If this invalidation did not affect the recording source, then it can be |
| 144 // cleared as an optimization. | 148 // cleared as an optimization. |
| 145 recording_invalidation_.Clear(); | 149 recording_invalidation_.Clear(); |
| 146 } | 150 } |
| 147 | 151 |
| 148 return updated; | 152 return updated; |
| 149 } | 153 } |
| 150 | 154 |
| 151 void PictureLayer::SetIsMask(bool is_mask) { | 155 void PictureLayer::SetIsMask(bool is_mask) { |
| 152 recording_source_->SetIsMask(is_mask); | 156 recording_source_->SetIsMask(is_mask); |
| 153 } | 157 } |
| 154 | 158 |
| 155 bool PictureLayer::SupportsLCDText() const { | 159 bool PictureLayer::SupportsLCDText() const { |
| 156 return true; | 160 return true; |
| 157 } | 161 } |
| 158 | 162 |
| 159 bool PictureLayer::UpdateCanUseLCDText() { | 163 void PictureLayer::UpdateCanUseLCDText() { |
| 160 if (!can_use_lcd_text_for_update_) | 164 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) |
| 161 return false; // Don't allow the LCD text state to change once disabled. | 165 return; |
| 162 if (can_use_lcd_text_for_update_ == can_use_lcd_text()) | |
| 163 return false; | |
| 164 | 166 |
| 165 can_use_lcd_text_for_update_ = can_use_lcd_text(); | 167 can_use_lcd_text_last_frame_ = can_use_lcd_text(); |
| 166 return true; | 168 if (client_) |
| 169 client_->DidChangeLayerCanUseLCDText(); |
| 167 } | 170 } |
| 168 | 171 |
| 169 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { | 172 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { |
| 170 // We could either flatten the RecordingSource into a single SkPicture, | 173 // We could either flatten the RecordingSource into a single SkPicture, |
| 171 // or paint a fresh one depending on what we intend to do with the | 174 // or paint a fresh one depending on what we intend to do with the |
| 172 // picture. For now we just paint a fresh one to get consistent results. | 175 // picture. For now we just paint a fresh one to get consistent results. |
| 173 if (!DrawsContent()) | 176 if (!DrawsContent()) |
| 174 return skia::RefPtr<SkPicture>(); | 177 return skia::RefPtr<SkPicture>(); |
| 175 | 178 |
| 176 int width = bounds().width(); | 179 int width = bounds().width(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 196 | 199 |
| 197 bool PictureLayer::HasDrawableContent() const { | 200 bool PictureLayer::HasDrawableContent() const { |
| 198 return client_ && Layer::HasDrawableContent(); | 201 return client_ && Layer::HasDrawableContent(); |
| 199 } | 202 } |
| 200 | 203 |
| 201 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 204 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 202 benchmark->RunOnLayer(this); | 205 benchmark->RunOnLayer(this); |
| 203 } | 206 } |
| 204 | 207 |
| 205 } // namespace cc | 208 } // namespace cc |
| OLD | NEW |