roll libyuv to r1437 to resolve msan overread on odd width ARGBToYUY2.
[chromium-blink-merge.git] / cc / playback / display_item_list.h
blob843e0bdde0e64befed3c5cf6dd1f7585ad8d8eef
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 template <typename DisplayItemType>
49 DisplayItemType* CreateAndAppendItem() {
50 #if DCHECK_IS_ON()
51 needs_process_ = true;
52 #endif
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
59 // sizes, etc).
60 void RemoveLast();
62 // Called after all items are appended, to process the items and, if
63 // applicable, create an internally cached SkPicture.
64 void Finalize();
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);
80 private:
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);
86 ~DisplayItemList();
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();
92 #if DCHECK_IS_ON()
93 bool ProcessAppendedItemsCalled() const { return !needs_process_; }
94 bool needs_process_;
95 #else
96 bool ProcessAppendedItemsCalled() const { return true; }
97 #endif
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);
120 } // namespace cc
122 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_