Landing Recent QUIC changes until 8/19/2015 17:00 UTC.
[chromium-blink-merge.git] / cc / playback / display_item_list.h
blob3778b00afbc0bb9918db220f7a62d82d34a37f6c
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"
21 class SkCanvas;
22 class SkPictureRecorder;
24 namespace cc {
26 class DisplayItemListSettings;
28 class CC_EXPORT DisplayItemList
29 : public base::RefCountedThreadSafe<DisplayItemList> {
30 public:
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(
40 gfx::Rect layer_rect,
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() {
55 #if DCHECK_IS_ON()
56 needs_process_ = true;
57 #endif
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
64 // sizes, etc).
65 void RemoveLast();
67 // Called after all items are appended, to process the items and, if
68 // applicable, create an internally cached SkPicture.
69 void Finalize();
71 bool IsSuitableForGpuRasterization() const;
72 int ApproximateOpCount() const;
73 size_t ApproximateMemoryUsage() const;
74 bool ShouldBeAnalyzedForSolidColor() const;
76 bool RetainsIndividualDisplayItems() const;
78 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue(
79 bool include_items) const;
81 void EmitTraceSnapshot() const;
83 void GatherPixelRefs(const gfx::Size& grid_cell_size);
85 // Finds the sidecar for a display item in this list.
86 void* GetSidecar(DisplayItem* display_item);
88 private:
89 DisplayItemList(gfx::Rect layer_rect,
90 const DisplayItemListSettings& display_list_settings,
91 bool retain_individual_display_items);
92 DisplayItemList(gfx::Rect layer_rect,
93 const DisplayItemListSettings& display_list_settings);
94 ~DisplayItemList();
96 // While appending new items, if they are not being retained, this can process
97 // periodically to avoid retaining all the items and processing at the end.
98 void ProcessAppendedItemsOnTheFly();
99 void ProcessAppendedItems();
100 #if DCHECK_IS_ON()
101 bool ProcessAppendedItemsCalled() const { return !needs_process_; }
102 bool needs_process_;
103 #else
104 bool ProcessAppendedItemsCalled() const { return true; }
105 #endif
107 SidecarListContainer<DisplayItem> items_;
108 skia::RefPtr<SkPicture> picture_;
110 scoped_ptr<SkPictureRecorder> recorder_;
111 skia::RefPtr<SkCanvas> canvas_;
112 bool use_cached_picture_;
113 bool retain_individual_display_items_;
115 gfx::Rect layer_rect_;
116 bool all_items_are_suitable_for_gpu_rasterization_;
117 int approximate_op_count_;
119 // Memory usage due to the cached SkPicture.
120 size_t picture_memory_usage_;
122 // Memory usage due to external data held by display items.
123 size_t external_memory_usage_;
125 scoped_ptr<PixelRefMap> pixel_refs_;
127 friend class base::RefCountedThreadSafe<DisplayItemList>;
128 friend class PixelRefMap::Iterator;
129 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage);
130 DISALLOW_COPY_AND_ASSIGN(DisplayItemList);
133 } // namespace cc
135 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_