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
3 // found in the LICENSE file.
5 #include "cc/resources/display_item_list.h"
7 #include "base/debug/trace_event.h"
8 #include "base/debug/trace_event_argument.h"
9 #include "third_party/skia/include/core/SkCanvas.h"
13 DisplayItemList::DisplayItemList()
14 : is_suitable_for_gpu_rasterization_(true), approximate_op_count_(0) {
17 scoped_refptr
<DisplayItemList
> DisplayItemList::Create() {
18 return make_scoped_refptr(new DisplayItemList());
21 DisplayItemList::~DisplayItemList() {
24 void DisplayItemList::Raster(SkCanvas
* canvas
,
25 SkDrawPictureCallback
* callback
,
26 float contents_scale
) const {
28 canvas
->scale(contents_scale
, contents_scale
);
29 for (size_t i
= 0; i
< items_
.size(); ++i
) {
30 items_
[i
]->Raster(canvas
, callback
);
35 void DisplayItemList::AppendItem(scoped_ptr
<DisplayItem
> item
) {
36 is_suitable_for_gpu_rasterization_
&= item
->IsSuitableForGpuRasterization();
37 approximate_op_count_
+= item
->ApproximateOpCount();
38 items_
.push_back(item
.Pass());
41 bool DisplayItemList::IsSuitableForGpuRasterization() const {
42 // This is more permissive than Picture's implementation, since none of the
43 // items might individually trigger a veto even though they collectively have
44 // enough "bad" operations that a corresponding Picture would get vetoed.
45 return is_suitable_for_gpu_rasterization_
;
48 int DisplayItemList::ApproximateOpCount() const {
49 return approximate_op_count_
;
52 size_t DisplayItemList::PictureMemoryUsage() const {
53 size_t total_size
= 0;
55 for (const auto& item
: items_
) {
56 total_size
+= item
->PictureMemoryUsage();
62 scoped_refptr
<base::debug::ConvertableToTraceFormat
> DisplayItemList::AsValue()
64 scoped_refptr
<base::debug::TracedValue
> state
=
65 new base::debug::TracedValue();
67 // TODO(ajuma): Include the value of each item.
68 state
->SetInteger("length", items_
.size());
72 void DisplayItemList::EmitTraceSnapshot() const {
73 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID(
74 TRACE_DISABLED_BY_DEFAULT("cc.debug") "," TRACE_DISABLED_BY_DEFAULT(
75 "devtools.timeline.picture"),
76 "cc::DisplayItemList", this, AsValue());