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/list_container.h"
14 #include "cc/playback/discardable_image_map.h"
15 #include "cc/playback/display_item.h"
16 #include "skia/ext/refptr.h"
17 #include "third_party/skia/include/core/SkPicture.h"
18 #include "ui/gfx/geometry/rect.h"
21 class SkPictureRecorder
;
25 class DisplayItemListSettings
;
27 class CC_EXPORT DisplayItemList
28 : public base::RefCountedThreadSafe
<DisplayItemList
> {
30 // Creates a display item list. If picture caching is used, then layer_rect
31 // specifies the cull rect of the display item list (the picture will not
32 // exceed this rect). If picture caching is not used, then the given rect can
34 // TODO(vmpstr): Maybe this cull rect can be part of the settings instead.
35 static scoped_refptr
<DisplayItemList
> Create(
36 const gfx::Rect
& layer_rect
,
37 const DisplayItemListSettings
& settings
);
39 void Raster(SkCanvas
* canvas
,
40 SkPicture::AbortCallback
* callback
,
41 const gfx::Rect
& canvas_target_playback_rect
,
42 float contents_scale
) const;
44 // This is a fast path for use only if canvas_ is set and
45 // retain_individual_display_items_ is false. This method also updates
46 // is_suitable_for_gpu_rasterization_ and approximate_op_count_.
47 void RasterIntoCanvas(const DisplayItem
& display_item
);
49 template <typename DisplayItemType
>
50 DisplayItemType
* CreateAndAppendItem() {
52 needs_process_
= true;
54 ProcessAppendedItemsOnTheFly();
55 return items_
.AllocateAndConstruct
<DisplayItemType
>();
58 // Removes the last item. This cannot be called on lists with cached pictures
59 // (since the data may already have been incorporated into cached picture
63 // Called after all items are appended, to process the items and, if
64 // applicable, create an internally cached SkPicture.
67 bool IsSuitableForGpuRasterization() const;
68 int ApproximateOpCount() const;
69 size_t ApproximateMemoryUsage() const;
70 bool ShouldBeAnalyzedForSolidColor() const;
72 bool RetainsIndividualDisplayItems() const;
74 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> AsValue(
75 bool include_items
) const;
77 void EmitTraceSnapshot() const;
79 void GatherDiscardableImages(const gfx::Size
& grid_cell_size
);
82 DisplayItemList(gfx::Rect layer_rect
,
83 const DisplayItemListSettings
& display_list_settings
,
84 bool retain_individual_display_items
);
87 // While appending new items, if they are not being retained, this can process
88 // periodically to avoid retaining all the items and processing at the end.
89 void ProcessAppendedItemsOnTheFly();
90 void ProcessAppendedItems();
92 bool ProcessAppendedItemsCalled() const { return !needs_process_
; }
95 bool ProcessAppendedItemsCalled() const { return true; }
98 ListContainer
<DisplayItem
> items_
;
99 skia::RefPtr
<SkPicture
> picture_
;
101 scoped_ptr
<SkPictureRecorder
> recorder_
;
102 skia::RefPtr
<SkCanvas
> canvas_
;
103 const bool use_cached_picture_
;
104 bool retain_individual_display_items_
;
106 gfx::Rect layer_rect_
;
107 bool is_suitable_for_gpu_rasterization_
;
108 int approximate_op_count_
;
110 // Memory usage due to the cached SkPicture.
111 size_t picture_memory_usage_
;
113 // Memory usage due to external data held by display items.
114 size_t external_memory_usage_
;
116 scoped_ptr
<DiscardableImageMap
> images_
;
118 friend class base::RefCountedThreadSafe
<DisplayItemList
>;
119 friend class DiscardableImageMap::Iterator
;
120 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest
, ApproximateMemoryUsage
);
121 DISALLOW_COPY_AND_ASSIGN(DisplayItemList
);
126 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_