| 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..12550b158718db5fbfbac9c6fb699fb87c20d048 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,44 @@ void DisplayItemList::Raster(SkCanvas* canvas,
|
| }
|
| }
|
|
|
| +void DisplayItemList::ProcessAppendedItemsOnTheFly() {
|
| + if (retain_individual_display_items_)
|
| + return;
|
| + if (items_.size() >= kDefaultNumDisplayItemsToReserve) {
|
| + ProcessAppendedItems();
|
| + // This function exists to keep the |items_| from growing indefinitely if
|
| + // we're not going to store them anyway. So the items better be deleted
|
| + // after |items_| grows too large and we process it.
|
| + DCHECK(items_.empty());
|
| + }
|
| +}
|
| +
|
| +void DisplayItemList::ProcessAppendedItems() {
|
| +#if DCHECK_IS_ON()
|
| + needs_process_ = false;
|
| +#endif
|
| + for (DisplayItem* item : items_) {
|
| + 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 +154,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 +163,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 +179,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 +209,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 +217,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_);
|
|
|