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