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 template <typename DisplayItemType
>
49 DisplayItemType
* CreateAndAppendItem() {
51 needs_process_
= true;
53 ProcessAppendedItemsOnTheFly();
54 return items_
.AllocateAndConstruct
<DisplayItemType
>();
57 // Removes the last item. This cannot be called on lists with cached pictures
58 // (since the data may already have been incorporated into cached picture
62 // Called after all items are appended, to process the items and, if
63 // applicable, create an internally cached SkPicture.
66 bool IsSuitableForGpuRasterization() const;
67 int ApproximateOpCount() const;
68 size_t PictureMemoryUsage() const;
70 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValue(
71 bool include_items
) const;
73 void EmitTraceSnapshot() const;
75 void GatherPixelRefs(const gfx::Size
& grid_cell_size
);
77 // Finds the sidecar for a display item in this list.
78 void* GetSidecar(DisplayItem
* display_item
);
81 DisplayItemList(gfx::Rect layer_rect
,
82 const DisplayItemListSettings
& display_list_settings
,
83 bool retain_individual_display_items
);
84 DisplayItemList(gfx::Rect layer_rect
,
85 const DisplayItemListSettings
& display_list_settings
);
88 // While appending new items, if they are not being retained, this can process
89 // periodically to avoid retaining all the items and processing at the end.
90 void ProcessAppendedItemsOnTheFly();
91 void ProcessAppendedItems();
93 bool ProcessAppendedItemsCalled() const { return !needs_process_
; }
96 bool ProcessAppendedItemsCalled() const { return true; }
99 SidecarListContainer
<DisplayItem
> items_
;
100 skia::RefPtr
<SkPicture
> picture_
;
102 scoped_ptr
<SkPictureRecorder
> recorder_
;
103 skia::RefPtr
<SkCanvas
> canvas_
;
104 bool use_cached_picture_
;
105 bool retain_individual_display_items_
;
107 gfx::Rect layer_rect_
;
108 bool is_suitable_for_gpu_rasterization_
;
109 int approximate_op_count_
;
110 size_t picture_memory_usage_
;
112 scoped_ptr
<PixelRefMap
> pixel_refs_
;
114 friend class base::RefCountedThreadSafe
<DisplayItemList
>;
115 friend class PixelRefMap::Iterator
;
116 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest
, PictureMemoryUsage
);
117 DISALLOW_COPY_AND_ASSIGN(DisplayItemList
);
122 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_