Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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/content_layer.h" | 5 #include "cc/layers/content_layer.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "cc/layers/content_layer_client.h" | 10 #include "cc/layers/content_layer_client.h" |
| 11 #include "cc/resources/bitmap_content_layer_updater.h" | 11 #include "cc/resources/bitmap_content_layer_updater.h" |
| 12 #include "cc/resources/bitmap_skpicture_content_layer_updater.h" | 12 #include "cc/resources/bitmap_skpicture_content_layer_updater.h" |
| 13 #include "cc/resources/layer_painter.h" | 13 #include "cc/resources/layer_painter.h" |
| 14 #include "cc/trees/layer_tree_host.h" | 14 #include "cc/trees/layer_tree_host.h" |
| 15 #include "third_party/skia/include/core/SkPictureRecorder.h" | 15 #include "third_party/skia/include/core/SkPictureRecorder.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 ContentLayerPainter::ContentLayerPainter(ContentLayerClient* client) | 19 ContentLayerPainter::ContentLayerPainter(ContentLayerClient* client) |
| 20 : client_(client) {} | 20 : client_(client) {} |
| 21 | 21 |
| 22 scoped_ptr<ContentLayerPainter> ContentLayerPainter::Create( | 22 scoped_ptr<ContentLayerPainter> ContentLayerPainter::Create( |
| 23 ContentLayerClient* client) { | 23 ContentLayerClient* client) { |
| 24 return make_scoped_ptr(new ContentLayerPainter(client)); | 24 return make_scoped_ptr(new ContentLayerPainter(client)); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void ContentLayerPainter::Paint(SkCanvas* canvas, | 27 void ContentLayerPainter::Paint(SkCanvas* canvas, |
| 28 const gfx::Rect& content_rect) { | 28 const gfx::Rect& content_rect, |
| 29 bool can_use_lcd_text, | |
| 30 bool contents_opaque) { | |
| 29 client_->PaintContents(canvas, | 31 client_->PaintContents(canvas, |
| 30 content_rect, | 32 content_rect, |
| 33 can_use_lcd_text, | |
| 34 contents_opaque, | |
| 31 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | 35 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); |
| 32 } | 36 } |
| 33 | 37 |
| 34 scoped_refptr<ContentLayer> ContentLayer::Create(ContentLayerClient* client) { | 38 scoped_refptr<ContentLayer> ContentLayer::Create(ContentLayerClient* client) { |
| 35 return make_scoped_refptr(new ContentLayer(client)); | 39 return make_scoped_refptr(new ContentLayer(client)); |
| 36 } | 40 } |
| 37 | 41 |
| 38 ContentLayer::ContentLayer(ContentLayerClient* client) | 42 ContentLayer::ContentLayer(ContentLayerClient* client) |
| 39 : TiledLayer(), | 43 : TiledLayer(), |
| 40 client_(client), | 44 client_(client), |
| 41 can_use_lcd_text_last_frame_(can_use_lcd_text()) { | 45 can_use_lcd_text_last_frame_(false), |
| 46 first_update_lcd_text_occured_(false) { | |
| 42 } | 47 } |
| 43 | 48 |
| 44 ContentLayer::~ContentLayer() {} | 49 ContentLayer::~ContentLayer() {} |
| 45 | 50 |
| 46 void ContentLayer::ClearClient() { | 51 void ContentLayer::ClearClient() { |
| 47 client_ = nullptr; | 52 client_ = nullptr; |
| 48 UpdateDrawsContent(HasDrawableContent()); | 53 UpdateDrawsContent(HasDrawableContent()); |
| 49 } | 54 } |
| 50 | 55 |
| 51 bool ContentLayer::HasDrawableContent() const { | 56 bool ContentLayer::HasDrawableContent() const { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 layer_tree_host()->GetRendererCapabilities().best_texture_format); | 125 layer_tree_host()->GetRendererCapabilities().best_texture_format); |
| 121 } | 126 } |
| 122 | 127 |
| 123 void ContentLayer::SetContentsOpaque(bool opaque) { | 128 void ContentLayer::SetContentsOpaque(bool opaque) { |
| 124 Layer::SetContentsOpaque(opaque); | 129 Layer::SetContentsOpaque(opaque); |
| 125 if (updater_.get()) | 130 if (updater_.get()) |
| 126 updater_->SetOpaque(opaque); | 131 updater_->SetOpaque(opaque); |
| 127 } | 132 } |
| 128 | 133 |
| 129 void ContentLayer::UpdateCanUseLCDText() { | 134 void ContentLayer::UpdateCanUseLCDText() { |
| 130 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) | 135 if (first_update_lcd_text_occured_) { |
| 131 return; | 136 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) |
| 137 return; | |
| 138 // LCD text can turn off but never on. | |
| 139 if (!can_use_lcd_text_last_frame_) | |
| 140 return; | |
| 141 } | |
| 132 | 142 |
| 133 can_use_lcd_text_last_frame_ = can_use_lcd_text(); | 143 can_use_lcd_text_last_frame_ = can_use_lcd_text(); |
| 134 if (client_) | 144 updater_->SetCanUseLCDText(can_use_lcd_text_last_frame_); |
| 135 client_->DidChangeLayerCanUseLCDText(); | 145 first_update_lcd_text_occured_ = true; |
|
enne (OOO)
2014/11/12 18:51:05
I don't think this can go. The reason this was im
danakj
2014/11/12 18:52:48
Ah okay, makes sense now that I saw the ui::Layer
| |
| 146 SetNeedsDisplay(); | |
| 136 } | 147 } |
| 137 | 148 |
| 138 bool ContentLayer::SupportsLCDText() const { | 149 bool ContentLayer::SupportsLCDText() const { |
| 139 return true; | 150 return true; |
| 140 } | 151 } |
| 141 | 152 |
| 142 skia::RefPtr<SkPicture> ContentLayer::GetPicture() const { | 153 skia::RefPtr<SkPicture> ContentLayer::GetPicture() const { |
| 143 if (!DrawsContent()) | 154 if (!DrawsContent()) |
| 144 return skia::RefPtr<SkPicture>(); | 155 return skia::RefPtr<SkPicture>(); |
| 145 | 156 |
| 146 int width = bounds().width(); | 157 int width = bounds().width(); |
| 147 int height = bounds().height(); | 158 int height = bounds().height(); |
| 148 | 159 |
| 149 SkPictureRecorder recorder; | 160 SkPictureRecorder recorder; |
| 150 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); | 161 SkCanvas* canvas = recorder.beginRecording(width, height, nullptr, 0); |
| 151 client_->PaintContents(canvas, | 162 client_->PaintContents(canvas, |
| 152 gfx::Rect(width, height), | 163 gfx::Rect(width, height), |
| 164 can_use_lcd_text_last_frame_, | |
| 165 contents_opaque(), | |
| 153 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | 166 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); |
| 154 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 167 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
| 155 return picture; | 168 return picture; |
| 156 } | 169 } |
| 157 | 170 |
| 158 void ContentLayer::OnOutputSurfaceCreated() { | 171 void ContentLayer::OnOutputSurfaceCreated() { |
| 159 SetTextureFormat( | 172 SetTextureFormat( |
| 160 layer_tree_host()->GetRendererCapabilities().best_texture_format); | 173 layer_tree_host()->GetRendererCapabilities().best_texture_format); |
| 161 TiledLayer::OnOutputSurfaceCreated(); | 174 TiledLayer::OnOutputSurfaceCreated(); |
| 162 } | 175 } |
| 163 | 176 |
| 164 } // namespace cc | 177 } // namespace cc |
| OLD | NEW |