| 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 instrumentation_object_tracker_(id()), | 22 instrumentation_object_tracker_(id()), |
| 23 update_source_frame_number_(-1), | 23 update_source_frame_number_(-1), |
| 24 can_use_lcd_text_last_frame_(can_use_lcd_text()) { | 24 can_use_lcd_text_last_frame_(false), |
| 25 first_update_lcd_text_occured_(false) { |
| 25 } | 26 } |
| 26 | 27 |
| 27 PictureLayer::~PictureLayer() { | 28 PictureLayer::~PictureLayer() { |
| 28 } | 29 } |
| 29 | 30 |
| 30 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 31 scoped_ptr<LayerImpl> PictureLayer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 31 return PictureLayerImpl::Create(tree_impl, id()); | 32 return PictureLayerImpl::Create(tree_impl, id()); |
| 32 } | 33 } |
| 33 | 34 |
| 34 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { | 35 void PictureLayer::PushPropertiesTo(LayerImpl* base_layer) { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // anything not explicitly recorded in this frame. We give this region | 118 // anything not explicitly recorded in this frame. We give this region |
| 118 // 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 |
| 119 // for them. | 120 // for them. |
| 120 DCHECK(client_); | 121 DCHECK(client_); |
| 121 updated |= | 122 updated |= |
| 122 pile_.UpdateAndExpandInvalidation(client_, | 123 pile_.UpdateAndExpandInvalidation(client_, |
| 123 &pile_invalidation_, | 124 &pile_invalidation_, |
| 124 SafeOpaqueBackgroundColor(), | 125 SafeOpaqueBackgroundColor(), |
| 125 contents_opaque(), | 126 contents_opaque(), |
| 126 client_->FillsBoundsCompletely(), | 127 client_->FillsBoundsCompletely(), |
| 128 can_use_lcd_text_last_frame_, |
| 127 layer_size, | 129 layer_size, |
| 128 visible_layer_rect, | 130 visible_layer_rect, |
| 129 update_source_frame_number_, | 131 update_source_frame_number_, |
| 130 Picture::RECORD_NORMALLY, | 132 Picture::RECORD_NORMALLY, |
| 131 rendering_stats_instrumentation()); | 133 rendering_stats_instrumentation()); |
| 132 last_updated_visible_content_rect_ = visible_content_rect(); | 134 last_updated_visible_content_rect_ = visible_content_rect(); |
| 133 | 135 |
| 134 if (updated) { | 136 if (updated) { |
| 135 SetNeedsPushProperties(); | 137 SetNeedsPushProperties(); |
| 136 } else { | 138 } else { |
| 137 // If this invalidation did not affect the pile, then it can be cleared as | 139 // If this invalidation did not affect the pile, then it can be cleared as |
| 138 // an optimization. | 140 // an optimization. |
| 139 pile_invalidation_.Clear(); | 141 pile_invalidation_.Clear(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 return updated; | 144 return updated; |
| 143 } | 145 } |
| 144 | 146 |
| 145 void PictureLayer::SetIsMask(bool is_mask) { | 147 void PictureLayer::SetIsMask(bool is_mask) { |
| 146 pile_.set_is_mask(is_mask); | 148 pile_.set_is_mask(is_mask); |
| 147 } | 149 } |
| 148 | 150 |
| 149 bool PictureLayer::SupportsLCDText() const { | 151 bool PictureLayer::SupportsLCDText() const { |
| 150 return true; | 152 return true; |
| 151 } | 153 } |
| 152 | 154 |
| 153 void PictureLayer::UpdateCanUseLCDText() { | 155 void PictureLayer::UpdateCanUseLCDText() { |
| 154 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) | 156 if (first_update_lcd_text_occured_) { |
| 155 return; | 157 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) |
| 158 return; |
| 159 // LCD text can turn off but never on. |
| 160 if (!can_use_lcd_text_last_frame_) |
| 161 return; |
| 162 } |
| 156 | 163 |
| 157 can_use_lcd_text_last_frame_ = can_use_lcd_text(); | 164 can_use_lcd_text_last_frame_ = can_use_lcd_text(); |
| 158 if (client_) | 165 first_update_lcd_text_occured_ = true; |
| 159 client_->DidChangeLayerCanUseLCDText(); | 166 SetNeedsDisplay(); |
| 160 } | 167 } |
| 161 | 168 |
| 162 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { | 169 skia::RefPtr<SkPicture> PictureLayer::GetPicture() const { |
| 163 // We could either flatten the PicturePile into a single SkPicture, | 170 // We could either flatten the PicturePile into a single SkPicture, |
| 164 // or paint a fresh one depending on what we intend to do with the | 171 // or paint a fresh one depending on what we intend to do with the |
| 165 // picture. For now we just paint a fresh one to get consistent results. | 172 // picture. For now we just paint a fresh one to get consistent results. |
| 166 if (!DrawsContent()) | 173 if (!DrawsContent()) |
| 167 return skia::RefPtr<SkPicture>(); | 174 return skia::RefPtr<SkPicture>(); |
| 168 | 175 |
| 169 int width = bounds().width(); | 176 int width = bounds().width(); |
| 170 int height = bounds().height(); | 177 int height = bounds().height(); |
| 171 | 178 |
| 172 SkPictureRecorder recorder; | 179 SkPictureRecorder recorder; |
| 173 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); | 180 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); |
| 174 client_->PaintContents(canvas, | 181 client_->PaintContents(canvas, |
| 175 gfx::Rect(width, height), | 182 gfx::Rect(width, height), |
| 183 can_use_lcd_text_last_frame_, |
| 184 contents_opaque(), |
| 176 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | 185 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); |
| 177 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 186 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| 178 return picture; | 187 return picture; |
| 179 } | 188 } |
| 180 | 189 |
| 181 bool PictureLayer::IsSuitableForGpuRasterization() const { | 190 bool PictureLayer::IsSuitableForGpuRasterization() const { |
| 182 return pile_.is_suitable_for_gpu_rasterization(); | 191 return pile_.is_suitable_for_gpu_rasterization(); |
| 183 } | 192 } |
| 184 | 193 |
| 185 void PictureLayer::ClearClient() { | 194 void PictureLayer::ClearClient() { |
| 186 client_ = nullptr; | 195 client_ = nullptr; |
| 187 UpdateDrawsContent(HasDrawableContent()); | 196 UpdateDrawsContent(HasDrawableContent()); |
| 188 } | 197 } |
| 189 | 198 |
| 190 bool PictureLayer::HasDrawableContent() const { | 199 bool PictureLayer::HasDrawableContent() const { |
| 191 return client_ && Layer::HasDrawableContent(); | 200 return client_ && Layer::HasDrawableContent(); |
| 192 } | 201 } |
| 193 | 202 |
| 194 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 203 void PictureLayer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 195 benchmark->RunOnLayer(this); | 204 benchmark->RunOnLayer(this); |
| 196 } | 205 } |
| 197 | 206 |
| 198 } // namespace cc | 207 } // namespace cc |
| OLD | NEW |