| 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 30 matching lines...) Expand all Loading... |
| 41 bool retain_individual_display_items) | 41 bool retain_individual_display_items) |
| 42 : items_(LargestDisplayItemSize(), | 42 : items_(LargestDisplayItemSize(), |
| 43 settings.max_sidecar_size, | 43 settings.max_sidecar_size, |
| 44 kDefaultNumDisplayItemsToReserve, | 44 kDefaultNumDisplayItemsToReserve, |
| 45 settings.sidecar_destroyer), | 45 settings.sidecar_destroyer), |
| 46 use_cached_picture_(settings.use_cached_picture), | 46 use_cached_picture_(settings.use_cached_picture), |
| 47 retain_individual_display_items_(retain_individual_display_items), | 47 retain_individual_display_items_(retain_individual_display_items), |
| 48 layer_rect_(layer_rect), | 48 layer_rect_(layer_rect), |
| 49 is_suitable_for_gpu_rasterization_(true), | 49 is_suitable_for_gpu_rasterization_(true), |
| 50 approximate_op_count_(0), | 50 approximate_op_count_(0), |
| 51 picture_memory_usage_(0) { | 51 picture_memory_usage_(0), |
| 52 external_memory_usage_(0) { |
| 52 #if DCHECK_IS_ON() | 53 #if DCHECK_IS_ON() |
| 53 needs_process_ = false; | 54 needs_process_ = false; |
| 54 #endif | 55 #endif |
| 55 if (use_cached_picture_) { | 56 if (use_cached_picture_) { |
| 56 SkRTreeFactory factory; | 57 SkRTreeFactory factory; |
| 57 recorder_.reset(new SkPictureRecorder()); | 58 recorder_.reset(new SkPictureRecorder()); |
| 58 canvas_ = skia::SharePtr(recorder_->beginRecording( | 59 canvas_ = skia::SharePtr(recorder_->beginRecording( |
| 59 layer_rect_.width(), layer_rect_.height(), &factory)); | 60 layer_rect_.width(), layer_rect_.height(), &factory)); |
| 60 canvas_->translate(-layer_rect_.x(), -layer_rect_.y()); | 61 canvas_->translate(-layer_rect_.x(), -layer_rect_.y()); |
| 61 canvas_->clipRect(gfx::RectToSkRect(layer_rect_)); | 62 canvas_->clipRect(gfx::RectToSkRect(layer_rect_)); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 approximate_op_count_ += item->approximate_op_count(); | 147 approximate_op_count_ += item->approximate_op_count(); |
| 147 | 148 |
| 148 if (use_cached_picture_) { | 149 if (use_cached_picture_) { |
| 149 DCHECK(canvas_); | 150 DCHECK(canvas_); |
| 150 item->Raster(canvas_.get(), gfx::Rect(), NULL); | 151 item->Raster(canvas_.get(), gfx::Rect(), NULL); |
| 151 } | 152 } |
| 152 | 153 |
| 153 if (retain_individual_display_items_) { | 154 if (retain_individual_display_items_) { |
| 154 // Warning: this double-counts SkPicture data if use_cached_picture_ is | 155 // Warning: this double-counts SkPicture data if use_cached_picture_ is |
| 155 // also true. | 156 // also true. |
| 156 picture_memory_usage_ += item->picture_memory_usage(); | 157 external_memory_usage_ += item->external_memory_usage(); |
| 157 } | 158 } |
| 158 } | 159 } |
| 159 | 160 |
| 160 if (!retain_individual_display_items_) | 161 if (!retain_individual_display_items_) |
| 161 items_.clear(); | 162 items_.clear(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { | 165 void DisplayItemList::RasterIntoCanvas(const DisplayItem& item) { |
| 165 DCHECK(canvas_); | 166 DCHECK(canvas_); |
| 166 DCHECK(!retain_individual_display_items_); | 167 DCHECK(!retain_individual_display_items_); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 186 | 187 |
| 187 void DisplayItemList::Finalize() { | 188 void DisplayItemList::Finalize() { |
| 188 ProcessAppendedItems(); | 189 ProcessAppendedItems(); |
| 189 | 190 |
| 190 if (use_cached_picture_) { | 191 if (use_cached_picture_) { |
| 191 // Convert to an SkPicture for faster rasterization. | 192 // Convert to an SkPicture for faster rasterization. |
| 192 DCHECK(use_cached_picture_); | 193 DCHECK(use_cached_picture_); |
| 193 DCHECK(!picture_); | 194 DCHECK(!picture_); |
| 194 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture()); | 195 picture_ = skia::AdoptRef(recorder_->endRecordingAsPicture()); |
| 195 DCHECK(picture_); | 196 DCHECK(picture_); |
| 196 picture_memory_usage_ += | 197 picture_memory_usage_ = |
| 197 SkPictureUtils::ApproximateBytesUsed(picture_.get()); | 198 SkPictureUtils::ApproximateBytesUsed(picture_.get()); |
| 198 recorder_.reset(); | 199 recorder_.reset(); |
| 199 canvas_.clear(); | 200 canvas_.clear(); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 | 203 |
| 203 bool DisplayItemList::IsSuitableForGpuRasterization() const { | 204 bool DisplayItemList::IsSuitableForGpuRasterization() const { |
| 204 DCHECK(ProcessAppendedItemsCalled()); | 205 DCHECK(ProcessAppendedItemsCalled()); |
| 205 // This is more permissive than Picture's implementation, since none of the | 206 // This is more permissive than Picture's implementation, since none of the |
| 206 // items might individually trigger a veto even though they collectively have | 207 // items might individually trigger a veto even though they collectively have |
| 207 // enough "bad" operations that a corresponding Picture would get vetoed. | 208 // enough "bad" operations that a corresponding Picture would get vetoed. |
| 208 return is_suitable_for_gpu_rasterization_; | 209 return is_suitable_for_gpu_rasterization_; |
| 209 } | 210 } |
| 210 | 211 |
| 211 int DisplayItemList::ApproximateOpCount() const { | 212 int DisplayItemList::ApproximateOpCount() const { |
| 212 DCHECK(ProcessAppendedItemsCalled()); | 213 DCHECK(ProcessAppendedItemsCalled()); |
| 213 return approximate_op_count_; | 214 return approximate_op_count_; |
| 214 } | 215 } |
| 215 | 216 |
| 216 size_t DisplayItemList::PictureMemoryUsage() const { | 217 size_t DisplayItemList::ApproximateMemoryUsage() const { |
| 217 DCHECK(ProcessAppendedItemsCalled()); | 218 DCHECK(ProcessAppendedItemsCalled()); |
| 218 // We double-count in this case. Produce zero to avoid being misleading. | 219 // We double-count in this case. Produce zero to avoid being misleading. |
| 219 if (use_cached_picture_ && retain_individual_display_items_) | 220 if (use_cached_picture_ && retain_individual_display_items_) |
| 220 return 0; | 221 return 0; |
| 221 | 222 |
| 222 DCHECK_IMPLIES(use_cached_picture_, picture_); | 223 DCHECK_IMPLIES(use_cached_picture_, picture_); |
| 223 return picture_memory_usage_; | 224 |
| 225 size_t memory_usage = sizeof(*this); |
| 226 |
| 227 // Memory outside this class due to |items_|. |
| 228 memory_usage += items_.GetCapacityInBytes() + external_memory_usage_; |
| 229 |
| 230 // Memory outside this class due to |picture|. |
| 231 memory_usage += picture_memory_usage_; |
| 232 |
| 233 // TODO(jbroman): Does anything else owned by this class substantially |
| 234 // contribute to memory usage? |
| 235 |
| 236 return memory_usage; |
| 224 } | 237 } |
| 225 | 238 |
| 226 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 239 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 227 DisplayItemList::AsValue(bool include_items) const { | 240 DisplayItemList::AsValue(bool include_items) const { |
| 228 DCHECK(ProcessAppendedItemsCalled()); | 241 DCHECK(ProcessAppendedItemsCalled()); |
| 229 scoped_refptr<base::trace_event::TracedValue> state = | 242 scoped_refptr<base::trace_event::TracedValue> state = |
| 230 new base::trace_event::TracedValue(); | 243 new base::trace_event::TracedValue(); |
| 231 | 244 |
| 232 if (include_items) { | 245 if (include_items) { |
| 233 state->BeginArray("params.items"); | 246 state->BeginArray("params.items"); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 return; | 291 return; |
| 279 | 292 |
| 280 pixel_refs_->GatherPixelRefsFromPicture(picture_.get()); | 293 pixel_refs_->GatherPixelRefsFromPicture(picture_.get()); |
| 281 } | 294 } |
| 282 | 295 |
| 283 void* DisplayItemList::GetSidecar(DisplayItem* display_item) { | 296 void* DisplayItemList::GetSidecar(DisplayItem* display_item) { |
| 284 return items_.GetSidecar(display_item); | 297 return items_.GetSidecar(display_item); |
| 285 } | 298 } |
| 286 | 299 |
| 287 } // namespace cc | 300 } // namespace cc |
| OLD | NEW |