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/content_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) | |
20 : client_(client) {} | |
21 | |
22 scoped_ptr<ContentLayerPainter> ContentLayerPainter::Create( | |
23 ContentLayerClient* client) { | |
24 return make_scoped_ptr(new ContentLayerPainter(client)); | |
25 } | |
26 | |
27 void ContentLayerPainter::Paint(SkCanvas* canvas, | |
28 const gfx::Rect& content_rect, | |
29 gfx::RectF* opaque) { | |
30 client_->PaintContents(canvas, | |
31 content_rect, | |
32 opaque, | |
33 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | |
34 } | |
35 | |
36 scoped_refptr<ContentLayer> ContentLayer::Create(ContentLayerClient* client) { | 19 scoped_refptr<ContentLayer> ContentLayer::Create(ContentLayerClient* client) { |
37 return make_scoped_refptr(new ContentLayer(client)); | 20 return make_scoped_refptr(new ContentLayer(client)); |
38 } | 21 } |
39 | 22 |
40 ContentLayer::ContentLayer(ContentLayerClient* client) | 23 ContentLayer::ContentLayer(ContentLayerClient* client) |
41 : TiledLayer(), | 24 : client_(client), use_lcd_text_(true) { |
42 client_(client), | |
43 can_use_lcd_text_last_frame_(can_use_lcd_text()) { | |
44 } | 25 } |
45 | 26 |
46 ContentLayer::~ContentLayer() {} | 27 ContentLayer::~ContentLayer() {} |
47 | 28 |
48 bool ContentLayer::DrawsContent() const { | 29 bool ContentLayer::DrawsContent() const { |
49 return TiledLayer::DrawsContent() && client_; | 30 return TiledLayer::DrawsContent() && client_; |
50 } | 31 } |
51 | 32 |
52 void ContentLayer::SetLayerTreeHost(LayerTreeHost* host) { | 33 void ContentLayer::SetLayerTreeHost(LayerTreeHost* host) { |
53 TiledLayer::SetLayerTreeHost(host); | 34 TiledLayer::SetLayerTreeHost(host); |
(...skipping 17 matching lines...) Expand all Loading... |
71 TiledLayer::SetTexturePriorities(priority_calc); | 52 TiledLayer::SetTexturePriorities(priority_calc); |
72 } | 53 } |
73 | 54 |
74 bool ContentLayer::Update(ResourceUpdateQueue* queue, | 55 bool ContentLayer::Update(ResourceUpdateQueue* queue, |
75 const OcclusionTracker<Layer>* occlusion) { | 56 const OcclusionTracker<Layer>* occlusion) { |
76 { | 57 { |
77 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, | 58 base::AutoReset<bool> ignore_set_needs_commit(&ignore_set_needs_commit_, |
78 true); | 59 true); |
79 | 60 |
80 CreateUpdaterIfNeeded(); | 61 CreateUpdaterIfNeeded(); |
81 UpdateCanUseLCDText(); | 62 UpdateUseLCDText(); |
82 } | 63 } |
83 | 64 |
84 bool updated = TiledLayer::Update(queue, occlusion); | 65 bool updated = TiledLayer::Update(queue, occlusion); |
85 return updated; | 66 return updated; |
86 } | 67 } |
87 | 68 |
88 bool ContentLayer::NeedMoreUpdates() { | 69 bool ContentLayer::NeedMoreUpdates() { |
89 return NeedsIdlePaint(); | 70 return NeedsIdlePaint(); |
90 } | 71 } |
91 | 72 |
92 LayerUpdater* ContentLayer::Updater() const { | 73 LayerUpdater* ContentLayer::Updater() const { |
93 return updater_.get(); | 74 return updater_.get(); |
94 } | 75 } |
95 | 76 |
96 void ContentLayer::CreateUpdaterIfNeeded() { | 77 void ContentLayer::CreateUpdaterIfNeeded() { |
97 if (updater_.get()) | 78 if (updater_.get()) |
98 return; | 79 return; |
99 scoped_ptr<LayerPainter> painter = | 80 scoped_ptr<ContentLayerPainter> painter = |
100 ContentLayerPainter::Create(client_).PassAs<LayerPainter>(); | 81 ContentLayerPainter::Create(client_); |
101 if (layer_tree_host()->settings().per_tile_painting_enabled) { | 82 if (layer_tree_host()->settings().per_tile_painting_enabled) { |
102 updater_ = BitmapSkPictureContentLayerUpdater::Create( | 83 updater_ = BitmapSkPictureContentLayerUpdater::Create( |
103 painter.Pass(), | 84 painter.Pass(), |
104 rendering_stats_instrumentation(), | 85 rendering_stats_instrumentation(), |
105 id()); | 86 id()); |
106 } else { | 87 } else { |
107 updater_ = BitmapContentLayerUpdater::Create( | 88 updater_ = BitmapContentLayerUpdater::Create( |
108 painter.Pass(), | 89 painter.Pass(), |
109 rendering_stats_instrumentation(), | 90 rendering_stats_instrumentation(), |
110 id()); | 91 id()); |
111 } | 92 } |
112 updater_->SetOpaque(contents_opaque()); | 93 updater_->SetOpaque(contents_opaque()); |
113 if (client_) | 94 if (client_) |
114 updater_->SetFillsBoundsCompletely(client_->FillsBoundsCompletely()); | 95 updater_->SetFillsBoundsCompletely(client_->FillsBoundsCompletely()); |
| 96 updater_->set_can_use_lcd_text(use_lcd_text_); |
115 | 97 |
116 SetTextureFormat( | 98 SetTextureFormat( |
117 layer_tree_host()->GetRendererCapabilities().best_texture_format); | 99 layer_tree_host()->GetRendererCapabilities().best_texture_format); |
118 } | 100 } |
119 | 101 |
120 void ContentLayer::SetContentsOpaque(bool opaque) { | 102 void ContentLayer::SetContentsOpaque(bool opaque) { |
121 Layer::SetContentsOpaque(opaque); | 103 Layer::SetContentsOpaque(opaque); |
122 if (updater_.get()) | 104 if (updater_.get()) |
123 updater_->SetOpaque(opaque); | 105 updater_->SetOpaque(opaque); |
124 } | 106 } |
125 | 107 |
126 void ContentLayer::UpdateCanUseLCDText() { | 108 void ContentLayer::UpdateUseLCDText() { |
127 if (can_use_lcd_text_last_frame_ == can_use_lcd_text()) | 109 if (use_lcd_text_ == can_use_lcd_text()) |
128 return; | 110 return; |
129 | 111 |
130 can_use_lcd_text_last_frame_ = can_use_lcd_text(); | 112 // LCD text starts out enabled and can only be disabled. |
131 if (client_) | 113 if (!use_lcd_text_) |
132 client_->DidChangeLayerCanUseLCDText(); | 114 return; |
| 115 |
| 116 use_lcd_text_ = can_use_lcd_text(); |
| 117 updater_->set_can_use_lcd_text(use_lcd_text_); |
| 118 if (client_->PaintsLCDText()) |
| 119 SetNeedsDisplay(); |
133 } | 120 } |
134 | 121 |
135 bool ContentLayer::SupportsLCDText() const { | 122 bool ContentLayer::SupportsLCDText() const { |
136 return true; | 123 return true; |
137 } | 124 } |
138 | 125 |
139 skia::RefPtr<SkPicture> ContentLayer::GetPicture() const { | 126 skia::RefPtr<SkPicture> ContentLayer::GetPicture() const { |
140 if (!DrawsContent()) | 127 if (!DrawsContent()) |
141 return skia::RefPtr<SkPicture>(); | 128 return skia::RefPtr<SkPicture>(); |
142 | 129 |
143 int width = bounds().width(); | 130 int width = bounds().width(); |
144 int height = bounds().height(); | 131 int height = bounds().height(); |
145 gfx::RectF opaque; | 132 gfx::RectF opaque; |
146 | 133 |
147 SkPictureRecorder recorder; | 134 SkPictureRecorder recorder; |
148 SkCanvas* canvas = recorder.beginRecording(width, height, NULL, 0); | 135 SkCanvas* canvas = recorder.beginRecording(width, height, NULL, 0); |
149 client_->PaintContents(canvas, | 136 client_->PaintContents(canvas, |
150 gfx::Rect(width, height), | 137 gfx::Rect(width, height), |
| 138 use_lcd_text_, |
151 &opaque, | 139 &opaque, |
152 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); | 140 ContentLayerClient::GRAPHICS_CONTEXT_ENABLED); |
153 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); | 141 skia::RefPtr<SkPicture> picture = skia::AdoptRef(recorder.endRecording()); |
154 return picture; | 142 return picture; |
155 } | 143 } |
156 | 144 |
157 void ContentLayer::OnOutputSurfaceCreated() { | 145 void ContentLayer::OnOutputSurfaceCreated() { |
158 SetTextureFormat( | 146 SetTextureFormat( |
159 layer_tree_host()->GetRendererCapabilities().best_texture_format); | 147 layer_tree_host()->GetRendererCapabilities().best_texture_format); |
160 TiledLayer::OnOutputSurfaceCreated(); | 148 TiledLayer::OnOutputSurfaceCreated(); |
161 } | 149 } |
162 | 150 |
163 } // namespace cc | 151 } // namespace cc |
OLD | NEW |