OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/playback/display_item_list.h" | 5 #include "cc/playback/display_item_list.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 !settings.use_cached_picture || DisplayItemsTracingEnabled())); | 48 !settings.use_cached_picture || DisplayItemsTracingEnabled())); |
49 } | 49 } |
50 | 50 |
51 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, | 51 DisplayItemList::DisplayItemList(gfx::Rect layer_rect, |
52 const DisplayItemListSettings& settings, | 52 const DisplayItemListSettings& settings, |
53 bool retain_individual_display_items) | 53 bool retain_individual_display_items) |
54 : items_(LargestDisplayItemSize(), kDefaultNumDisplayItemsToReserve), | 54 : items_(LargestDisplayItemSize(), kDefaultNumDisplayItemsToReserve), |
55 use_cached_picture_(settings.use_cached_picture), | 55 use_cached_picture_(settings.use_cached_picture), |
56 retain_individual_display_items_(retain_individual_display_items), | 56 retain_individual_display_items_(retain_individual_display_items), |
57 layer_rect_(layer_rect), | 57 layer_rect_(layer_rect), |
58 all_items_are_suitable_for_gpu_rasterization_(true), | 58 is_suitable_for_gpu_rasterization_(true), |
59 approximate_op_count_(0), | 59 approximate_op_count_(0), |
60 picture_memory_usage_(0), | 60 picture_memory_usage_(0), |
61 external_memory_usage_(0) { | 61 external_memory_usage_(0) { |
62 #if DCHECK_IS_ON() | 62 #if DCHECK_IS_ON() |
63 needs_process_ = false; | 63 needs_process_ = false; |
64 #endif | 64 #endif |
65 if (use_cached_picture_) { | 65 if (use_cached_picture_) { |
66 SkRTreeFactory factory; | 66 SkRTreeFactory factory; |
67 recorder_.reset(new SkPictureRecorder()); | 67 recorder_.reset(new SkPictureRecorder()); |
68 canvas_ = skia::SharePtr(recorder_->beginRecording( | 68 canvas_ = skia::SharePtr(recorder_->beginRecording( |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // after |items_| grows too large and we process it. | 116 // after |items_| grows too large and we process it. |
117 DCHECK(items_.empty()); | 117 DCHECK(items_.empty()); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 void DisplayItemList::ProcessAppendedItems() { | 121 void DisplayItemList::ProcessAppendedItems() { |
122 #if DCHECK_IS_ON() | 122 #if DCHECK_IS_ON() |
123 needs_process_ = false; | 123 needs_process_ = false; |
124 #endif | 124 #endif |
125 for (const DisplayItem* item : items_) { | 125 for (const DisplayItem* item : items_) { |
126 all_items_are_suitable_for_gpu_rasterization_ &= | |
127 item->is_suitable_for_gpu_rasterization(); | |
128 approximate_op_count_ += item->approximate_op_count(); | |
129 | |
130 if (use_cached_picture_) { | 126 if (use_cached_picture_) { |
| 127 // When using a cached picture we will calculate gpu suitability on the |
| 128 // entire cached picture instead of the items. This is more permissive |
| 129 // since none of the items might individually trigger a veto even though |
| 130 // they collectively have enough "bad" operations that a corresponding |
| 131 // Picture would get vetoed. See crbug.com/513016. |
131 DCHECK(canvas_); | 132 DCHECK(canvas_); |
132 item->Raster(canvas_.get(), gfx::Rect(), NULL); | 133 approximate_op_count_ += item->approximate_op_count(); |
| 134 item->Raster(canvas_.get(), gfx::Rect(), nullptr); |
| 135 } else { |
| 136 is_suitable_for_gpu_rasterization_ &= |
| 137 item->is_suitable_for_gpu_rasterization(); |
| 138 approximate_op_count_ += item->approximate_op_count(); |
133 } | 139 } |
134 | 140 |
135 if (retain_individual_display_items_) { | 141 if (retain_individual_display_items_) { |
136 // Warning: this double-counts SkPicture data if use_cached_picture_ is | 142 // Warning: this double-counts SkPicture data if use_cached_picture_ is |
137 // also true. | 143 // also true. |
138 external_memory_usage_ += item->external_memory_usage(); | 144 external_memory_usage_ += item->external_memory_usage(); |
139 } | 145 } |
140 } | 146 } |
141 | 147 |
142 if (!retain_individual_display_items_) | 148 if (!retain_individual_display_items_) |
143 items_.clear(); | 149 items_.clear(); |
144 } | 150 } |
145 | 151 |
146 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { | 152 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { |
147 DCHECK(canvas_); | 153 DCHECK(canvas_); |
148 DCHECK(!retain_individual_display_items_); | 154 DCHECK(!retain_individual_display_items_); |
149 all_items_are_suitable_for_gpu_rasterization_ &= | |
150 item.is_suitable_for_gpu_rasterization(); | |
151 approximate_op_count_ += item.approximate_op_count(); | 155 approximate_op_count_ += item.approximate_op_count(); |
152 | 156 |
153 item.Raster(canvas_.get(), gfx::Rect(), NULL); | 157 item.Raster(canvas_.get(), gfx::Rect(), nullptr); |
154 } | 158 } |
155 | 159 |
156 bool DisplayItemList::RetainsIndividualDisplayItems() const { | 160 bool DisplayItemList::RetainsIndividualDisplayItems() const { |
157 return retain_individual_display_items_; | 161 return retain_individual_display_items_; |
158 } | 162 } |
159 | 163 |
160 void DisplayItemList::RemoveLast() { | 164 void DisplayItemList::RemoveLast() { |
161 // We cannot remove the last item if it has been squashed into a picture. | 165 // We cannot remove the last item if it has been squashed into a picture. |
162 // The last item should not have been handled by ProcessAppendedItems, so we | 166 // The last item should not have been handled by ProcessAppendedItems, so we |
163 // don't need to remove it from approximate_op_count_, etc. | 167 // don't need to remove it from approximate_op_count_, etc. |
164 DCHECK(retain_individual_display_items_); | 168 DCHECK(retain_individual_display_items_); |
165 DCHECK(!use_cached_picture_); | 169 DCHECK(!use_cached_picture_); |
166 items_.RemoveLast(); | 170 items_.RemoveLast(); |
167 } | 171 } |
168 | 172 |
169 void DisplayItemList::Finalize() { | 173 void DisplayItemList::Finalize() { |
170 ProcessAppendedItems(); | 174 ProcessAppendedItems(); |
171 | 175 |
172 if (use_cached_picture_) { | 176 if (use_cached_picture_) { |
173 // Convert to an SkPicture for faster rasterization. | 177 // Convert to an SkPicture for faster rasterization. |
174 DCHECK(use_cached_picture_); | 178 DCHECK(use_cached_picture_); |
175 DCHECK(!picture_); | 179 DCHECK(!picture_); |
176 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture()); | 180 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture()); |
177 DCHECK(picture_); | 181 DCHECK(picture_); |
178 picture_memory_usage_ = | 182 picture_memory_usage_ = |
179 SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 183 SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
180 recorder_.reset(); | 184 recorder_.reset(); |
181 canvas_.clear(); | 185 canvas_.clear(); |
| 186 is_suitable_for_gpu_rasterization_ = |
| 187 picture_->suitableForGpuRasterization(nullptr); |
182 } | 188 } |
183 } | 189 } |
184 | 190 |
185 bool DisplayItemList::IsSuitableForGpuRasterization() const { | 191 bool DisplayItemList::IsSuitableForGpuRasterization() const { |
186 DCHECK(ProcessAppendedItemsCalled()); | 192 DCHECK(ProcessAppendedItemsCalled()); |
187 if (use_cached_picture_) | 193 return is_suitable_for_gpu_rasterization_; |
188 return picture_->suitableForGpuRasterization(NULL); | |
189 | |
190 // This is more permissive than Picture's implementation, since none of the | |
191 // items might individually trigger a veto even though they collectively have | |
192 // enough "bad" operations that a corresponding Picture would get vetoed. See | |
193 // crbug.com/513016. | |
194 return all_items_are_suitable_for_gpu_rasterization_; | |
195 } | 194 } |
196 | 195 |
197 int DisplayItemList::ApproximateOpCount() const { | 196 int DisplayItemList::ApproximateOpCount() const { |
198 DCHECK(ProcessAppendedItemsCalled()); | 197 DCHECK(ProcessAppendedItemsCalled()); |
199 return approximate_op_count_; | 198 return approximate_op_count_; |
200 } | 199 } |
201 | 200 |
202 size_t DisplayItemList::ApproximateMemoryUsage() const { | 201 size_t DisplayItemList::ApproximateMemoryUsage() const { |
203 DCHECK(ProcessAppendedItemsCalled()); | 202 DCHECK(ProcessAppendedItemsCalled()); |
204 // We double-count in this case. Produce zero to avoid being misleading. | 203 // We double-count in this case. Produce zero to avoid being misleading. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 DCHECK(picture_); | 276 DCHECK(picture_); |
278 DCHECK(!images_); | 277 DCHECK(!images_); |
279 images_ = make_scoped_ptr(new DiscardableImageMap(grid_cell_size)); | 278 images_ = make_scoped_ptr(new DiscardableImageMap(grid_cell_size)); |
280 if (!picture_->willPlayBackBitmaps()) | 279 if (!picture_->willPlayBackBitmaps()) |
281 return; | 280 return; |
282 | 281 |
283 images_->GatherImagesFromPicture(picture_.get(), layer_rect_); | 282 images_->GatherImagesFromPicture(picture_.get(), layer_rect_); |
284 } | 283 } |
285 | 284 |
286 } // namespace cc | 285 } // namespace cc |
OLD | NEW |