OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 5 #ifndef CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
6 #define CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 6 #define CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
7 | 7 |
8 #include "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
13 #include "cc/base/contiguous_container.h" | 13 #include "cc/base/contiguous_container.h" |
14 #include "cc/playback/discardable_image_map.h" | 14 #include "cc/playback/discardable_image_map.h" |
15 #include "cc/playback/display_item.h" | 15 #include "cc/playback/display_item.h" |
16 #include "cc/playback/display_item_list_settings.h" | 16 #include "cc/playback/display_item_list_settings.h" |
17 #include "skia/ext/refptr.h" | 17 #include "skia/ext/refptr.h" |
18 #include "third_party/skia/include/core/SkPicture.h" | 18 #include "third_party/skia/include/core/SkPicture.h" |
19 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
20 | 20 |
21 class SkCanvas; | 21 class SkCanvas; |
22 class SkPictureRecorder; | 22 class SkPictureRecorder; |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 class DisplayItem; | |
26 class DrawingDisplayItem; | |
27 | 25 |
28 namespace proto { | 26 namespace proto { |
29 class DisplayItemList; | 27 class DisplayItemList; |
30 } | 28 } |
31 | 29 |
32 class CC_EXPORT DisplayItemList | 30 class CC_EXPORT DisplayItemList |
33 : public base::RefCountedThreadSafe<DisplayItemList> { | 31 : public base::RefCountedThreadSafe<DisplayItemList> { |
34 public: | 32 public: |
35 // Creates a display item list. If picture caching is used, then layer_rect | 33 // Creates a display item list. If picture caching is used, then layer_rect |
36 // specifies the cull rect of the display item list (the picture will not | 34 // specifies the cull rect of the display item list (the picture will not |
(...skipping 18 matching lines...) Expand all Loading... |
55 void Raster(SkCanvas* canvas, | 53 void Raster(SkCanvas* canvas, |
56 SkPicture::AbortCallback* callback, | 54 SkPicture::AbortCallback* callback, |
57 const gfx::Rect& canvas_target_playback_rect, | 55 const gfx::Rect& canvas_target_playback_rect, |
58 float contents_scale) const; | 56 float contents_scale) const; |
59 | 57 |
60 // This is a fast path for use only if canvas_ is set and | 58 // This is a fast path for use only if canvas_ is set and |
61 // retain_individual_display_items_ is false. This method also updates | 59 // retain_individual_display_items_ is false. This method also updates |
62 // is_suitable_for_gpu_rasterization_ and approximate_op_count_. | 60 // is_suitable_for_gpu_rasterization_ and approximate_op_count_. |
63 void RasterIntoCanvas(const DisplayItem& display_item); | 61 void RasterIntoCanvas(const DisplayItem& display_item); |
64 | 62 |
65 // Because processing happens in this function, all the set up for | 63 template <typename DisplayItemType> |
66 // this item should be done via the args, which is why the return | 64 DisplayItemType* CreateAndAppendItem(const gfx::Rect& visual_rect) { |
67 // type needs to be const, to prevent set-after-processing mistakes. | 65 #if DCHECK_IS_ON() |
68 template <typename DisplayItemType, typename... Args> | 66 needs_process_ = true; |
69 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, | 67 #endif |
70 const Args&... args) { | |
71 visual_rects_.push_back(visual_rect); | 68 visual_rects_.push_back(visual_rect); |
72 // TODO(enne): This should forward the args. | 69 ProcessAppendedItemsOnTheFly(); |
73 auto* item = &items_.AllocateAndConstruct<DisplayItemType>(args...); | 70 return &items_.AllocateAndConstruct<DisplayItemType>(); |
74 approximate_op_count_ += item->ApproximateOpCount(); | |
75 // TODO(crbug.com/513016): None of the items might individually trigger a | |
76 // veto even though they collectively have enough "bad" operations that a | |
77 // corresponding flattened Picture would get vetoed. | |
78 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); | |
79 ProcessAppendedItem(item); | |
80 return *item; | |
81 } | 71 } |
82 | 72 |
| 73 // Removes the last item. This cannot be called on lists with cached pictures |
| 74 // (since the data may already have been incorporated into cached picture |
| 75 // sizes, etc). |
| 76 void RemoveLast(); |
| 77 |
83 // Called after all items are appended, to process the items and, if | 78 // Called after all items are appended, to process the items and, if |
84 // applicable, create an internally cached SkPicture. | 79 // applicable, create an internally cached SkPicture. |
85 void Finalize(); | 80 void Finalize(); |
86 | 81 |
87 bool IsSuitableForGpuRasterization() const; | 82 bool IsSuitableForGpuRasterization() const; |
88 int ApproximateOpCount() const; | 83 int ApproximateOpCount() const; |
89 size_t ApproximateMemoryUsage() const; | 84 size_t ApproximateMemoryUsage() const; |
90 bool ShouldBeAnalyzedForSolidColor() const; | 85 bool ShouldBeAnalyzedForSolidColor() const; |
91 | 86 |
92 bool RetainsIndividualDisplayItems() const; | 87 bool RetainsIndividualDisplayItems() const; |
93 | 88 |
94 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 89 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
95 bool include_items) const; | 90 bool include_items) const; |
96 | 91 |
97 void EmitTraceSnapshot() const; | 92 void EmitTraceSnapshot() const; |
98 | 93 |
99 void GenerateDiscardableImagesMetadata(); | 94 void GenerateDiscardableImagesMetadata(); |
100 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 95 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
101 float raster_scale, | 96 float raster_scale, |
102 std::vector<DrawImage>* images); | 97 std::vector<DrawImage>* images); |
103 | 98 |
104 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } | 99 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } |
105 | 100 |
106 private: | 101 private: |
107 DisplayItemList(gfx::Rect layer_rect, | 102 DisplayItemList(gfx::Rect layer_rect, |
108 const DisplayItemListSettings& display_list_settings, | 103 const DisplayItemListSettings& display_list_settings, |
109 bool retain_individual_display_items); | 104 bool retain_individual_display_items); |
110 ~DisplayItemList(); | 105 ~DisplayItemList(); |
111 | 106 |
112 void ProcessAppendedItem(const DisplayItem* item); | 107 // While appending new items, if they are not being retained, this can process |
| 108 // periodically to avoid retaining all the items and processing at the end. |
| 109 void ProcessAppendedItemsOnTheFly(); |
| 110 void ProcessAppendedItems(); |
| 111 #if DCHECK_IS_ON() |
| 112 bool ProcessAppendedItemsCalled() const { return !needs_process_; } |
| 113 bool needs_process_; |
| 114 #else |
| 115 bool ProcessAppendedItemsCalled() const { return true; } |
| 116 #endif |
113 | 117 |
114 ContiguousContainer<DisplayItem> items_; | 118 ContiguousContainer<DisplayItem> items_; |
115 // The visual rects associated with each of the display items in the | 119 // The visual rects associated with each of the display items in the |
116 // display item list. There is one rect per display item, and the | 120 // display item list. There is one rect per display item, and the |
117 // position in |visual_rects_| matches the position of the item in | 121 // position in |visual_rects_| matches the position of the item in |
118 // |items_| . These rects are intentionally kept separate | 122 // |items_| . These rects are intentionally kept separate |
119 // because they are not needed while walking the |items_| for raster. | 123 // because they are not needed while walking the |items_| for raster. |
120 std::vector<gfx::Rect> visual_rects_; | 124 std::vector<gfx::Rect> visual_rects_; |
121 skia::RefPtr<SkPicture> picture_; | 125 skia::RefPtr<SkPicture> picture_; |
122 | 126 |
123 scoped_ptr<SkPictureRecorder> recorder_; | 127 scoped_ptr<SkPictureRecorder> recorder_; |
124 skia::RefPtr<SkCanvas> canvas_; | 128 skia::RefPtr<SkCanvas> canvas_; |
125 const DisplayItemListSettings settings_; | 129 const DisplayItemListSettings settings_; |
126 bool retain_individual_display_items_; | 130 bool retain_individual_display_items_; |
127 | 131 |
128 gfx::Rect layer_rect_; | 132 gfx::Rect layer_rect_; |
129 bool is_suitable_for_gpu_rasterization_; | 133 bool is_suitable_for_gpu_rasterization_; |
130 int approximate_op_count_; | 134 int approximate_op_count_; |
131 | 135 |
132 // Memory usage due to the cached SkPicture. | 136 // Memory usage due to the cached SkPicture. |
133 size_t picture_memory_usage_; | 137 size_t picture_memory_usage_; |
134 | 138 |
| 139 // Memory usage due to external data held by display items. |
| 140 size_t external_memory_usage_; |
| 141 |
135 DiscardableImageMap image_map_; | 142 DiscardableImageMap image_map_; |
136 | 143 |
137 friend class base::RefCountedThreadSafe<DisplayItemList>; | 144 friend class base::RefCountedThreadSafe<DisplayItemList>; |
138 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 145 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
139 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 146 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
140 }; | 147 }; |
141 | 148 |
142 } // namespace cc | 149 } // namespace cc |
143 | 150 |
144 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 151 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
OLD | NEW |