Chromium Code Reviews| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 const gfx::Rect& canvas_target_playback_rect, | 63 const gfx::Rect& canvas_target_playback_rect, |
| 64 float contents_scale) const; | 64 float contents_scale) const; |
| 65 | 65 |
| 66 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; | 66 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; |
| 67 | 67 |
| 68 // This is a fast path for use only if canvas_ is set and | 68 // This is a fast path for use only if canvas_ is set and |
| 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 these CreateAndAppend functions, all the set |
| 74 // this item should be done via the args, which is why the return | 74 // up for the item should be done via the args, which is why the return type |
| 75 // type needs to be const, to prevent set-after-processing mistakes. | 75 // 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& CreateAndAppendPairedBeginItem(Args&&... args) { |
| 78 Args&&... args) { | 78 size_t item_index = inputs_.visual_rects.size(); |
| 79 inputs_.visual_rects.push_back(gfx::Rect()); | |
| 80 inputs_.begin_item_indices.push_back(item_index); | |
| 81 | |
| 82 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); | |
| 83 } | |
| 84 | |
| 85 template <typename DisplayItemType, typename... Args> | |
| 86 const DisplayItemType& CreateAndAppendPairedEndItem(Args&&... args) { | |
| 87 size_t last_begin_index = inputs_.begin_item_indices.back(); | |
|
vmpstr
2016/08/10 19:47:31
DCHECK(!inputs_.begin_item_indices.empty());
wkorman
2016/08/10 21:04:25
Done.
| |
| 88 inputs_.begin_item_indices.pop_back(); | |
| 89 | |
| 90 // Ending bounds match the starting bounds. | |
| 91 inputs_.visual_rects.push_back(inputs_.visual_rects[last_begin_index]); | |
| 92 | |
| 93 // The block that ended needs to be included in the bounds of the enclosing | |
| 94 // block. | |
| 95 GrowCurrentBeginItemVisualRect(inputs_.visual_rects[last_begin_index]); | |
|
vmpstr
2016/08/10 19:47:31
I think inputs_.visual_rects.back() is cleaner. Ei
wkorman
2016/08/10 21:04:25
Neither seems equivalent to existing logic:
1. bac
vmpstr
2016/08/10 21:09:43
Err, yeah you're right. You can ignore my comment.
| |
| 96 | |
| 97 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); | |
| 98 } | |
| 99 | |
| 100 template <typename DisplayItemType, typename... Args> | |
| 101 const DisplayItemType& CreateAndAppendDrawingItem( | |
| 102 const gfx::Rect& visual_rect, | |
| 103 Args&&... args) { | |
| 79 inputs_.visual_rects.push_back(visual_rect); | 104 inputs_.visual_rects.push_back(visual_rect); |
| 80 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( | 105 GrowCurrentBeginItemVisualRect(visual_rect); |
| 81 std::forward<Args>(args)...); | 106 |
| 82 approximate_op_count_ += item->ApproximateOpCount(); | 107 return AllocateAndConstruct<DisplayItemType>(std::forward<Args>(args)...); |
| 83 ProcessAppendedItem(item); | |
| 84 return *item; | |
| 85 } | 108 } |
| 86 | 109 |
| 87 // Called after all items are appended, to process the items and, if | 110 // Called after all items are appended, to process the items and, if |
| 88 // applicable, create an internally cached SkPicture. | 111 // applicable, create an internally cached SkPicture. |
| 89 void Finalize(); | 112 void Finalize(); |
| 90 | 113 |
| 91 void SetIsSuitableForGpuRasterization(bool is_suitable) { | 114 void SetIsSuitableForGpuRasterization(bool is_suitable) { |
| 92 inputs_.is_suitable_for_gpu_rasterization = is_suitable; | 115 inputs_.is_suitable_for_gpu_rasterization = is_suitable; |
| 93 } | 116 } |
| 94 bool IsSuitableForGpuRasterization() const; | 117 bool IsSuitableForGpuRasterization() const; |
| 95 int ApproximateOpCount() const; | 118 int ApproximateOpCount() const; |
| 96 size_t ApproximateMemoryUsage() const; | 119 size_t ApproximateMemoryUsage() const; |
| 97 bool ShouldBeAnalyzedForSolidColor() const; | 120 bool ShouldBeAnalyzedForSolidColor() const; |
| 98 | 121 |
| 99 bool RetainsIndividualDisplayItems() const; | 122 bool RetainsIndividualDisplayItems() const; |
| 100 | 123 |
| 101 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 124 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
| 102 bool include_items) const; | 125 bool include_items) const; |
| 103 | 126 |
| 104 void EmitTraceSnapshot() const; | 127 void EmitTraceSnapshot() const; |
| 105 | 128 |
| 106 void GenerateDiscardableImagesMetadata(); | 129 void GenerateDiscardableImagesMetadata(); |
| 107 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 130 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 108 float raster_scale, | 131 float raster_scale, |
| 109 std::vector<DrawImage>* images); | 132 std::vector<DrawImage>* images); |
| 110 | 133 |
| 134 size_t size() const { return inputs_.items.size(); } | |
| 135 | |
| 111 gfx::Rect VisualRectForTesting(int index) { | 136 gfx::Rect VisualRectForTesting(int index) { |
| 112 return inputs_.visual_rects[index]; | 137 return inputs_.visual_rects[index]; |
| 113 } | 138 } |
| 114 | 139 |
| 115 ContiguousContainer<DisplayItem>::const_iterator begin() const { | 140 ContiguousContainer<DisplayItem>::const_iterator begin() const { |
| 116 return inputs_.items.begin(); | 141 return inputs_.items.begin(); |
| 117 } | 142 } |
| 118 | 143 |
| 119 ContiguousContainer<DisplayItem>::const_iterator end() const { | 144 ContiguousContainer<DisplayItem>::const_iterator end() const { |
| 120 return inputs_.items.end(); | 145 return inputs_.items.end(); |
| 121 } | 146 } |
| 122 | 147 |
| 123 private: | 148 private: |
| 124 DisplayItemList(gfx::Rect layer_rect, | 149 DisplayItemList(gfx::Rect layer_rect, |
| 125 const DisplayItemListSettings& display_list_settings, | 150 const DisplayItemListSettings& display_list_settings, |
| 126 bool retain_individual_display_items); | 151 bool retain_individual_display_items); |
| 127 ~DisplayItemList(); | 152 ~DisplayItemList(); |
| 128 | 153 |
| 154 // If we're currently within a paired display item block, unions the | |
| 155 // given visual rect with the begin display item's visual rect. | |
| 156 void GrowCurrentBeginItemVisualRect(const gfx::Rect& visual_rect); | |
| 129 void ProcessAppendedItem(const DisplayItem* item); | 157 void ProcessAppendedItem(const DisplayItem* item); |
| 130 | 158 |
| 159 template <typename DisplayItemType, typename... Args> | |
| 160 const DisplayItemType& AllocateAndConstruct(Args&&... args) { | |
| 161 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( | |
| 162 std::forward<Args>(args)...); | |
| 163 approximate_op_count_ += item->ApproximateOpCount(); | |
| 164 ProcessAppendedItem(item); | |
| 165 return *item; | |
| 166 } | |
| 167 | |
| 131 sk_sp<SkPicture> picture_; | 168 sk_sp<SkPicture> picture_; |
| 132 | 169 |
| 133 std::unique_ptr<SkPictureRecorder> recorder_; | 170 std::unique_ptr<SkPictureRecorder> recorder_; |
| 134 | 171 |
| 135 bool retain_individual_display_items_; | 172 bool retain_individual_display_items_; |
| 136 int approximate_op_count_; | 173 int approximate_op_count_; |
| 137 | 174 |
| 138 // Memory usage due to the cached SkPicture. | 175 // Memory usage due to the cached SkPicture. |
| 139 size_t picture_memory_usage_; | 176 size_t picture_memory_usage_; |
| 140 | 177 |
| 141 DiscardableImageMap image_map_; | 178 DiscardableImageMap image_map_; |
| 142 | 179 |
| 143 struct Inputs { | 180 struct Inputs { |
| 144 Inputs(gfx::Rect layer_rect, const DisplayItemListSettings& settings); | 181 Inputs(gfx::Rect layer_rect, const DisplayItemListSettings& settings); |
| 145 ~Inputs(); | 182 ~Inputs(); |
| 146 | 183 |
| 147 ContiguousContainer<DisplayItem> items; | 184 ContiguousContainer<DisplayItem> items; |
| 148 // The visual rects associated with each of the display items in the | 185 // 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 | 186 // display item list. There is one rect per display item, and the |
| 150 // position in |visual_rects| matches the position of the item in | 187 // position in |visual_rects| matches the position of the item in |
| 151 // |items| . These rects are intentionally kept separate | 188 // |items| . These rects are intentionally kept separate |
| 152 // because they are not needed while walking the |items| for raster. | 189 // because they are not needed while walking the |items| for raster. |
| 153 std::vector<gfx::Rect> visual_rects; | 190 std::vector<gfx::Rect> visual_rects; |
| 154 | 191 std::vector<size_t> begin_item_indices; |
| 155 const DisplayItemListSettings settings; | 192 const DisplayItemListSettings settings; |
| 156 gfx::Rect layer_rect; | 193 gfx::Rect layer_rect; |
| 157 bool is_suitable_for_gpu_rasterization; | 194 bool is_suitable_for_gpu_rasterization; |
| 158 }; | 195 }; |
| 159 | 196 |
| 160 Inputs inputs_; | 197 Inputs inputs_; |
| 161 | 198 |
| 162 friend class base::RefCountedThreadSafe<DisplayItemList>; | 199 friend class base::RefCountedThreadSafe<DisplayItemList>; |
| 163 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 200 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
| 164 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 201 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
| 165 }; | 202 }; |
| 166 | 203 |
| 167 } // namespace cc | 204 } // namespace cc |
| 168 | 205 |
| 169 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 206 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
| OLD | NEW |