OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CC_RESOURCES_DISPLAY_ITEM_LIST_H_ | |
6 #define CC_RESOURCES_DISPLAY_ITEM_LIST_H_ | |
7 | |
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 // TODO(danakj): Move ListContainer out of cc/quads/ | |
15 #include "cc/quads/list_container.h" | |
16 #include "cc/resources/display_item.h" | |
17 #include "cc/resources/pixel_ref_map.h" | |
18 #include "skia/ext/refptr.h" | |
19 #include "third_party/skia/include/core/SkPicture.h" | |
20 #include "ui/gfx/geometry/rect.h" | |
21 | |
22 class SkCanvas; | |
23 class SkDrawPictureCallback; | |
24 class SkPictureRecorder; | |
25 | |
26 namespace cc { | |
27 | |
28 class CC_EXPORT DisplayItemList | |
29 : public base::RefCountedThreadSafe<DisplayItemList> { | |
30 public: | |
31 static scoped_refptr<DisplayItemList> Create(gfx::Rect layer_rect, | |
32 bool use_cached_picture); | |
33 | |
34 void Raster(SkCanvas* canvas, | |
35 SkDrawPictureCallback* callback, | |
36 float contents_scale) const; | |
37 | |
38 template <typename DisplayItemType> | |
39 DisplayItemType* CreateAndAppendItem() { | |
40 #if DCHECK_IS_ON() | |
41 needs_process_ = true; | |
42 #endif | |
43 ProcessAppendedItemsOnTheFly(); | |
44 return items_.AllocateAndConstruct<DisplayItemType>(); | |
45 } | |
46 | |
47 void ProcessAppendedItems(); | |
48 void CreateAndCacheSkPicture(); | |
49 | |
50 bool IsSuitableForGpuRasterization() const; | |
51 int ApproximateOpCount() const; | |
52 size_t PictureMemoryUsage() const; | |
53 | |
54 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; | |
55 | |
56 void EmitTraceSnapshot() const; | |
57 | |
58 void GatherPixelRefs(const gfx::Size& grid_cell_size); | |
59 | |
60 private: | |
61 DisplayItemList(gfx::Rect layer_rect, | |
62 bool use_cached_picture, | |
63 bool retain_individual_display_items); | |
64 DisplayItemList(gfx::Rect layer_rect, bool use_cached_picture); | |
65 ~DisplayItemList(); | |
66 | |
67 // While appending new items, if they are not being retained, this can process | |
68 // periodically to avoid retaining all the items and processing at the end. | |
69 void ProcessAppendedItemsOnTheFly(); | |
70 #if DCHECK_IS_ON() | |
71 bool ProcessAppendedItemsCalled() const { return !needs_process_; } | |
72 bool needs_process_; | |
73 #else | |
74 bool ProcessAppendedItemsCalled() const { return true; } | |
75 #endif | |
76 | |
77 ListContainer<DisplayItem> items_; | |
78 skia::RefPtr<SkPicture> picture_; | |
79 | |
80 scoped_ptr<SkPictureRecorder> recorder_; | |
81 skia::RefPtr<SkCanvas> canvas_; | |
82 bool use_cached_picture_; | |
83 bool retain_individual_display_items_; | |
84 | |
85 gfx::Rect layer_rect_; | |
86 bool is_suitable_for_gpu_rasterization_; | |
87 int approximate_op_count_; | |
88 size_t picture_memory_usage_; | |
89 | |
90 scoped_ptr<PixelRefMap> pixel_refs_; | |
91 | |
92 friend class base::RefCountedThreadSafe<DisplayItemList>; | |
93 friend class PixelRefMap::Iterator; | |
94 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, PictureMemoryUsage); | |
95 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | |
96 }; | |
97 | |
98 } // namespace cc | |
99 | |
100 #endif // CC_RESOURCES_DISPLAY_ITEM_LIST_H_ | |
OLD | NEW |