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 #ifndef CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
6 #define CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/trace_event/trace_event.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/base/scoped_ptr_vector.h"
14 #include "cc/base/sidecar_list_container.h"
15 #include "cc/playback/display_item.h"
16 #include "cc/playback/pixel_ref_map.h"
17 #include "skia/ext/refptr.h"
18 #include "third_party/skia/include/core/SkPicture.h"
19 #include "ui/gfx/geometry/rect.h"
22 class SkPictureRecorder
;
26 class DisplayItemListSettings
;
28 class CC_EXPORT DisplayItemList
29 : public base::RefCountedThreadSafe
<DisplayItemList
> {
31 static scoped_refptr
<DisplayItemList
> CreateWithoutCachedPicture(
32 const DisplayItemListSettings
& settings
);
34 // Creates a display item list with the given cull rect (if picture caching
35 // is used). The resulting display list will not support sidecar data.
36 static scoped_refptr
<DisplayItemList
> Create(gfx::Rect layer_rect
,
37 bool use_cached_picture
);
39 static scoped_refptr
<DisplayItemList
> Create(
41 const DisplayItemListSettings
& settings
);
43 void Raster(SkCanvas
* canvas
,
44 SkPicture::AbortCallback
* callback
,
45 const gfx::Rect
& canvas_target_playback_rect
,
46 float contents_scale
) const;
48 // This is a fast path for use only if canvas_ is set and
49 // retain_individual_display_items_ is false. This method also updates
50 // is_suitable_for_gpu_rasterization_ and approximate_op_count_.
51 void RasterIntoCanvas(const DisplayItem
& display_item
);
53 template <typename DisplayItemType
>
54 DisplayItemType
* CreateAndAppendItem() {
56 needs_process_
= true;
58 ProcessAppendedItemsOnTheFly();
59 return items_
.AllocateAndConstruct
<DisplayItemType
>();
62 // Removes the last item. This cannot be called on lists with cached pictures
63 // (since the data may already have been incorporated into cached picture
67 // Called after all items are appended, to process the items and, if
68 // applicable, create an internally cached SkPicture.
71 bool IsSuitableForGpuRasterization() const;
72 int ApproximateOpCount() const;
73 size_t ApproximateMemoryUsage() const;
75 bool RetainsIndividualDisplayItems() const;
77 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValue(
78 bool include_items
) const;
80 void EmitTraceSnapshot() const;
82 void GatherPixelRefs(const gfx::Size
& grid_cell_size
);
84 // Finds the sidecar for a display item in this list.
85 void* GetSidecar(DisplayItem
* display_item
);
88 DisplayItemList(gfx::Rect layer_rect
,
89 const DisplayItemListSettings
& display_list_settings
,
90 bool retain_individual_display_items
);
91 DisplayItemList(gfx::Rect layer_rect
,
92 const DisplayItemListSettings
& display_list_settings
);
95 // While appending new items, if they are not being retained, this can process
96 // periodically to avoid retaining all the items and processing at the end.
97 void ProcessAppendedItemsOnTheFly();
98 void ProcessAppendedItems();
100 bool ProcessAppendedItemsCalled() const { return !needs_process_
; }
103 bool ProcessAppendedItemsCalled() const { return true; }
106 SidecarListContainer
<DisplayItem
> items_
;
107 skia::RefPtr
<SkPicture
> picture_
;
109 scoped_ptr
<SkPictureRecorder
> recorder_
;
110 skia::RefPtr
<SkCanvas
> canvas_
;
111 bool use_cached_picture_
;
112 bool retain_individual_display_items_
;
114 gfx::Rect layer_rect_
;
115 bool all_items_are_suitable_for_gpu_rasterization_
;
116 int approximate_op_count_
;
118 // Memory usage due to the cached SkPicture.
119 size_t picture_memory_usage_
;
121 // Memory usage due to external data held by display items.
122 size_t external_memory_usage_
;
124 scoped_ptr
<PixelRefMap
> pixel_refs_
;
126 friend class base::RefCountedThreadSafe
<DisplayItemList
>;
127 friend class PixelRefMap::Iterator
;
128 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest
, ApproximateMemoryUsage
);
129 DISALLOW_COPY_AND_ASSIGN(DisplayItemList
);
134 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_