Index: cc/resources/display_item_list.cc |
diff --git a/cc/resources/display_item_list.cc b/cc/resources/display_item_list.cc |
index 69bdd03a87474207a764abe851fb3585ab759184..8be064229c630b70269db2cacae4051c6c0f943d 100644 |
--- a/cc/resources/display_item_list.cc |
+++ b/cc/resources/display_item_list.cc |
@@ -12,6 +12,7 @@ |
#include "cc/debug/picture_debug_util.h" |
#include "cc/debug/traced_picture.h" |
#include "cc/debug/traced_value.h" |
+#include "cc/resources/largest_display_item.h" |
#include "third_party/skia/include/core/SkCanvas.h" |
#include "third_party/skia/include/core/SkDrawPictureCallback.h" |
#include "third_party/skia/include/core/SkPictureRecorder.h" |
@@ -31,18 +32,24 @@ bool PictureTracingEnabled() { |
return tracing_enabled; |
} |
+const int kDefaultNumDisplayItemsToReserve = 100; |
+ |
} // namespace |
DisplayItemList::DisplayItemList(gfx::Rect layer_rect, |
bool use_cached_picture, |
bool retain_individual_display_items) |
- : recorder_(new SkPictureRecorder()), |
+ : items_(LargestDisplayItemSize(), kDefaultNumDisplayItemsToReserve), |
+ recorder_(new SkPictureRecorder()), |
use_cached_picture_(use_cached_picture), |
retain_individual_display_items_(retain_individual_display_items), |
layer_rect_(layer_rect), |
is_suitable_for_gpu_rasterization_(true), |
approximate_op_count_(0), |
picture_memory_usage_(0) { |
+#if DCHECK_IS_ON() |
+ needs_process_ = false; |
+#endif |
if (use_cached_picture_) { |
SkRTreeFactory factory; |
recorder_.reset(new SkPictureRecorder()); |
@@ -72,12 +79,12 @@ DisplayItemList::~DisplayItemList() { |
void DisplayItemList::Raster(SkCanvas* canvas, |
SkDrawPictureCallback* callback, |
float contents_scale) const { |
+ DCHECK(ProcessAppendedItemsCalled()); |
if (!use_cached_picture_) { |
canvas->save(); |
canvas->scale(contents_scale, contents_scale); |
- for (size_t i = 0; i < items_.size(); ++i) { |
- items_[i]->Raster(canvas, callback); |
- } |
+ for (auto* item : items_) |
+ item->Raster(canvas, callback); |
canvas->restore(); |
} else { |
DCHECK(picture_); |
@@ -99,7 +106,32 @@ void DisplayItemList::Raster(SkCanvas* canvas, |
} |
} |
+void DisplayItemList::ProcessAppendedItems() { |
+#if DCHECK_IS_ON() |
+ needs_process_ = false; |
+#endif |
+ for (DisplayItem* item : items_) { |
ajuma
2015/05/06 15:49:48
With this post-processing approach, the ListContai
|
+ is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); |
+ approximate_op_count_ += item->ApproximateOpCount(); |
+ |
+ if (use_cached_picture_) { |
+ DCHECK(canvas_); |
+ item->Raster(canvas_.get(), NULL); |
+ } |
+ |
+ if (retain_individual_display_items_) { |
+ // Warning: this double-counts SkPicture data if use_cached_picture_ is |
+ // also true. |
+ picture_memory_usage_ += item->PictureMemoryUsage(); |
+ } |
+ } |
+ |
+ if (!retain_individual_display_items_) |
+ items_.clear(); |
+} |
+ |
void DisplayItemList::CreateAndCacheSkPicture() { |
+ DCHECK(ProcessAppendedItemsCalled()); |
// Convert to an SkPicture for faster rasterization. |
DCHECK(use_cached_picture_); |
DCHECK(!picture_); |
@@ -110,24 +142,8 @@ void DisplayItemList::CreateAndCacheSkPicture() { |
canvas_.clear(); |
} |
-void DisplayItemList::AppendItem(scoped_ptr<DisplayItem> item) { |
- is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); |
- approximate_op_count_ += item->ApproximateOpCount(); |
- |
- if (use_cached_picture_) { |
- DCHECK(canvas_); |
- item->Raster(canvas_.get(), NULL); |
- } |
- |
- if (retain_individual_display_items_) { |
- // Warning: this double-counts SkPicture data if use_cached_picture_ is also |
- // true. |
- picture_memory_usage_ += item->PictureMemoryUsage(); |
- items_.push_back(item.Pass()); |
- } |
-} |
- |
bool DisplayItemList::IsSuitableForGpuRasterization() const { |
+ DCHECK(ProcessAppendedItemsCalled()); |
// This is more permissive than Picture's implementation, since none of the |
// items might individually trigger a veto even though they collectively have |
// enough "bad" operations that a corresponding Picture would get vetoed. |
@@ -135,10 +151,12 @@ bool DisplayItemList::IsSuitableForGpuRasterization() const { |
} |
int DisplayItemList::ApproximateOpCount() const { |
+ DCHECK(ProcessAppendedItemsCalled()); |
return approximate_op_count_; |
} |
size_t DisplayItemList::PictureMemoryUsage() const { |
+ DCHECK(ProcessAppendedItemsCalled()); |
// We double-count in this case. Produce zero to avoid being misleading. |
if (use_cached_picture_ && retain_individual_display_items_) |
return 0; |
@@ -149,6 +167,7 @@ size_t DisplayItemList::PictureMemoryUsage() const { |
scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
DisplayItemList::AsValue() const { |
+ DCHECK(ProcessAppendedItemsCalled()); |
scoped_refptr<base::trace_event::TracedValue> state = |
new base::trace_event::TracedValue(); |
@@ -178,6 +197,7 @@ DisplayItemList::AsValue() const { |
} |
void DisplayItemList::EmitTraceSnapshot() const { |
+ DCHECK(ProcessAppendedItemsCalled()); |
TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( |
TRACE_DISABLED_BY_DEFAULT("cc.debug.picture") "," |
TRACE_DISABLED_BY_DEFAULT("devtools.timeline.picture"), |
@@ -185,6 +205,7 @@ void DisplayItemList::EmitTraceSnapshot() const { |
} |
void DisplayItemList::GatherPixelRefs(const gfx::Size& grid_cell_size) { |
+ DCHECK(ProcessAppendedItemsCalled()); |
// This should be only called once, and only after CreateAndCacheSkPicture. |
DCHECK(picture_); |
DCHECK(!pixel_refs_); |