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