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 <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // retain_individual_display_items_ is false. This method also updates | 69 // retain_individual_display_items_ is false. This method also updates |
70 // approximate_op_count_. | 70 // approximate_op_count_. |
71 void RasterIntoCanvas(const DisplayItem& display_item); | 71 void RasterIntoCanvas(const DisplayItem& display_item); |
72 | 72 |
73 // Because processing happens in this function, all the set up for | 73 // Because processing happens in this function, all the set up for |
74 // this item should be done via the args, which is why the return | 74 // this item should be done via the args, which is why the return |
75 // type needs to be const, to prevent set-after-processing mistakes. | 75 // type needs to be const, to prevent set-after-processing mistakes. |
76 template <typename DisplayItemType, typename... Args> | 76 template <typename DisplayItemType, typename... Args> |
77 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, | 77 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, |
78 Args&&... args) { | 78 Args&&... args) { |
79 visual_rects_.push_back(visual_rect); | 79 inputs_.visual_rects.push_back(visual_rect); |
80 auto* item = &items_.AllocateAndConstruct<DisplayItemType>( | 80 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( |
81 std::forward<Args>(args)...); | 81 std::forward<Args>(args)...); |
82 approximate_op_count_ += item->ApproximateOpCount(); | 82 approximate_op_count_ += item->ApproximateOpCount(); |
83 ProcessAppendedItem(item); | 83 ProcessAppendedItem(item); |
84 return *item; | 84 return *item; |
85 } | 85 } |
86 | 86 |
87 // Called after all items are appended, to process the items and, if | 87 // Called after all items are appended, to process the items and, if |
88 // applicable, create an internally cached SkPicture. | 88 // applicable, create an internally cached SkPicture. |
89 void Finalize(); | 89 void Finalize(); |
90 | 90 |
91 void SetIsSuitableForGpuRasterization(bool is_suitable) { | 91 void SetIsSuitableForGpuRasterization(bool is_suitable) { |
92 is_suitable_for_gpu_rasterization_ = is_suitable; | 92 inputs_.is_suitable_for_gpu_rasterization = is_suitable; |
93 } | 93 } |
94 bool IsSuitableForGpuRasterization() const; | 94 bool IsSuitableForGpuRasterization() const; |
95 int ApproximateOpCount() const; | 95 int ApproximateOpCount() const; |
96 size_t ApproximateMemoryUsage() const; | 96 size_t ApproximateMemoryUsage() const; |
97 bool ShouldBeAnalyzedForSolidColor() const; | 97 bool ShouldBeAnalyzedForSolidColor() const; |
98 | 98 |
99 bool RetainsIndividualDisplayItems() const; | 99 bool RetainsIndividualDisplayItems() const; |
100 | 100 |
101 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 101 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
102 bool include_items) const; | 102 bool include_items) const; |
103 | 103 |
104 void EmitTraceSnapshot() const; | 104 void EmitTraceSnapshot() const; |
105 | 105 |
106 void GenerateDiscardableImagesMetadata(); | 106 void GenerateDiscardableImagesMetadata(); |
107 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 107 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
108 float raster_scale, | 108 float raster_scale, |
109 std::vector<DrawImage>* images); | 109 std::vector<DrawImage>* images); |
110 | 110 |
111 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } | 111 gfx::Rect VisualRectForTesting(int index) { |
| 112 return inputs_.visual_rects[index]; |
| 113 } |
112 | 114 |
113 ContiguousContainer<DisplayItem>::const_iterator begin() const { | 115 ContiguousContainer<DisplayItem>::const_iterator begin() const { |
114 return items_.begin(); | 116 return inputs_.items.begin(); |
115 } | 117 } |
116 | 118 |
117 ContiguousContainer<DisplayItem>::const_iterator end() const { | 119 ContiguousContainer<DisplayItem>::const_iterator end() const { |
118 return items_.end(); | 120 return inputs_.items.end(); |
119 } | 121 } |
120 | 122 |
121 private: | 123 private: |
122 DisplayItemList(gfx::Rect layer_rect, | 124 DisplayItemList(gfx::Rect layer_rect, |
123 const DisplayItemListSettings& display_list_settings, | 125 const DisplayItemListSettings& display_list_settings, |
124 bool retain_individual_display_items); | 126 bool retain_individual_display_items); |
125 ~DisplayItemList(); | 127 ~DisplayItemList(); |
126 | 128 |
127 void ProcessAppendedItem(const DisplayItem* item); | 129 void ProcessAppendedItem(const DisplayItem* item); |
128 | 130 |
129 ContiguousContainer<DisplayItem> items_; | |
130 // The visual rects associated with each of the display items in the | |
131 // display item list. There is one rect per display item, and the | |
132 // position in |visual_rects_| matches the position of the item in | |
133 // |items_| . These rects are intentionally kept separate | |
134 // because they are not needed while walking the |items_| for raster. | |
135 std::vector<gfx::Rect> visual_rects_; | |
136 sk_sp<SkPicture> picture_; | 131 sk_sp<SkPicture> picture_; |
137 | 132 |
138 std::unique_ptr<SkPictureRecorder> recorder_; | 133 std::unique_ptr<SkPictureRecorder> recorder_; |
139 const DisplayItemListSettings settings_; | 134 |
140 bool retain_individual_display_items_; | 135 bool retain_individual_display_items_; |
141 | |
142 gfx::Rect layer_rect_; | |
143 bool is_suitable_for_gpu_rasterization_; | |
144 int approximate_op_count_; | 136 int approximate_op_count_; |
145 | 137 |
146 // Memory usage due to the cached SkPicture. | 138 // Memory usage due to the cached SkPicture. |
147 size_t picture_memory_usage_; | 139 size_t picture_memory_usage_; |
148 | 140 |
149 DiscardableImageMap image_map_; | 141 DiscardableImageMap image_map_; |
150 | 142 |
| 143 struct Inputs { |
| 144 Inputs(gfx::Rect layer_rect, const DisplayItemListSettings& settings); |
| 145 ~Inputs(); |
| 146 |
| 147 ContiguousContainer<DisplayItem> items; |
| 148 // The visual rects associated with each of the display items in the |
| 149 // display item list. There is one rect per display item, and the |
| 150 // position in |visual_rects| matches the position of the item in |
| 151 // |items| . These rects are intentionally kept separate |
| 152 // because they are not needed while walking the |items| for raster. |
| 153 std::vector<gfx::Rect> visual_rects; |
| 154 |
| 155 const DisplayItemListSettings settings; |
| 156 gfx::Rect layer_rect; |
| 157 bool is_suitable_for_gpu_rasterization; |
| 158 }; |
| 159 |
| 160 Inputs inputs_; |
| 161 |
151 friend class base::RefCountedThreadSafe<DisplayItemList>; | 162 friend class base::RefCountedThreadSafe<DisplayItemList>; |
152 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 163 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
153 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 164 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
154 }; | 165 }; |
155 | 166 |
156 } // namespace cc | 167 } // namespace cc |
157 | 168 |
158 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 169 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
OLD | NEW |