| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "cc/base/cc_export.h" | 17 #include "cc/base/cc_export.h" |
| 18 #include "cc/base/contiguous_container.h" | 18 #include "cc/base/contiguous_container.h" |
| 19 #include "cc/base/rtree.h" |
| 19 #include "cc/playback/discardable_image_map.h" | 20 #include "cc/playback/discardable_image_map.h" |
| 20 #include "cc/playback/display_item.h" | 21 #include "cc/playback/display_item.h" |
| 21 #include "cc/playback/display_item_list_settings.h" | 22 #include "cc/playback/display_item_list_settings.h" |
| 22 #include "third_party/skia/include/core/SkPicture.h" | 23 #include "third_party/skia/include/core/SkPicture.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
| 25 #include "ui/gfx/geometry/rect_conversions.h" |
| 24 | 26 |
| 25 class SkCanvas; | 27 class SkCanvas; |
| 26 class SkPictureRecorder; | 28 class SkPictureRecorder; |
| 27 | 29 |
| 28 namespace cc { | 30 namespace cc { |
| 29 class ClientPictureCache; | 31 class ClientPictureCache; |
| 30 class DisplayItem; | 32 class DisplayItem; |
| 31 class DrawingDisplayItem; | 33 class DrawingDisplayItem; |
| 32 | 34 |
| 33 namespace proto { | 35 namespace proto { |
| 34 class DisplayItemList; | 36 class DisplayItemList; |
| 35 } | 37 } |
| 36 | 38 |
| 37 class CC_EXPORT DisplayItemList | 39 class CC_EXPORT DisplayItemList |
| 38 : public base::RefCountedThreadSafe<DisplayItemList> { | 40 : public base::RefCountedThreadSafe<DisplayItemList> { |
| 39 public: | 41 public: |
| 40 // Creates a display item list. If picture caching is used, then layer_rect | 42 // Creates a display item list. |
| 41 // specifies the cull rect of the display item list (the picture will not | |
| 42 // exceed this rect). If picture caching is not used, then the given rect can | |
| 43 // be empty. | |
| 44 // TODO(vmpstr): Maybe this cull rect can be part of the settings instead. | |
| 45 static scoped_refptr<DisplayItemList> Create( | 43 static scoped_refptr<DisplayItemList> Create( |
| 46 const gfx::Rect& layer_rect, | |
| 47 const DisplayItemListSettings& settings); | 44 const DisplayItemListSettings& settings); |
| 48 | 45 |
| 49 // Creates a DisplayItemList from a Protobuf. | 46 // Creates a DisplayItemList from a Protobuf. |
| 50 // TODO(dtrainor): Pass in a list of possible DisplayItems to reuse | 47 // TODO(dtrainor): Pass in a list of possible DisplayItems to reuse |
| 51 // (crbug.com/548434). | 48 // (crbug.com/548434). |
| 52 static scoped_refptr<DisplayItemList> CreateFromProto( | 49 static scoped_refptr<DisplayItemList> CreateFromProto( |
| 53 const proto::DisplayItemList& proto, | 50 const proto::DisplayItemList& proto, |
| 54 ClientPictureCache* client_picture_cache, | 51 ClientPictureCache* client_picture_cache, |
| 55 std::vector<uint32_t>* used_engine_picture_ids); | 52 std::vector<uint32_t>* used_engine_picture_ids); |
| 56 | 53 |
| 57 // Creates a Protobuf representing the state of this DisplayItemList. | 54 // Creates a Protobuf representing the state of this DisplayItemList. |
| 58 void ToProtobuf(proto::DisplayItemList* proto); | 55 void ToProtobuf(proto::DisplayItemList* proto); |
| 59 | 56 |
| 60 // TODO(trchen): Deprecated. Apply clip and scale on the canvas instead. | 57 // TODO(trchen): Deprecated. Apply clip and scale on the canvas instead. |
| 61 void Raster(SkCanvas* canvas, | 58 void Raster(SkCanvas* canvas, |
| 62 SkPicture::AbortCallback* callback, | 59 SkPicture::AbortCallback* callback, |
| 63 const gfx::Rect& canvas_target_playback_rect, | 60 const gfx::Rect& canvas_target_playback_rect, |
| 64 float contents_scale) const; | 61 float contents_scale) const; |
| 65 | 62 |
| 66 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; | 63 void Raster(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; |
| 67 | 64 |
| 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 | |
| 70 // approximate_op_count_. | |
| 71 void RasterIntoCanvas(const DisplayItem& display_item); | |
| 72 | |
| 73 // Because processing happens in this function, all the set up for | 65 // 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 | 66 // 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. | 67 // type needs to be const, to prevent set-after-processing mistakes. |
| 76 template <typename DisplayItemType, typename... Args> | 68 template <typename DisplayItemType, typename... Args> |
| 77 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, | 69 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, |
| 78 Args&&... args) { | 70 Args&&... args) { |
| 79 inputs_.visual_rects.push_back(visual_rect); | 71 inputs_.visual_rects.push_back(visual_rect); |
| 80 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( | 72 auto* item = &inputs_.items.AllocateAndConstruct<DisplayItemType>( |
| 81 std::forward<Args>(args)...); | 73 std::forward<Args>(args)...); |
| 82 approximate_op_count_ += item->ApproximateOpCount(); | 74 approximate_op_count_ += item->ApproximateOpCount(); |
| 83 ProcessAppendedItem(item); | |
| 84 return *item; | 75 return *item; |
| 85 } | 76 } |
| 86 | 77 |
| 87 // 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 |
| 88 // applicable, create an internally cached SkPicture. | 79 // applicable, create an internally cached SkPicture. |
| 89 void Finalize(); | 80 void Finalize(); |
| 90 | 81 |
| 91 void SetIsSuitableForGpuRasterization(bool is_suitable) { | 82 void SetIsSuitableForGpuRasterization(bool is_suitable) { |
| 92 inputs_.is_suitable_for_gpu_rasterization = is_suitable; | 83 inputs_.all_items_are_suitable_for_gpu_rasterization = is_suitable; |
| 93 } | 84 } |
| 94 bool IsSuitableForGpuRasterization() const; | 85 bool IsSuitableForGpuRasterization() const; |
| 95 int ApproximateOpCount() const; | 86 int ApproximateOpCount() const; |
| 96 size_t ApproximateMemoryUsage() const; | 87 size_t ApproximateMemoryUsage() const; |
| 97 bool ShouldBeAnalyzedForSolidColor() const; | 88 bool ShouldBeAnalyzedForSolidColor() const; |
| 98 | 89 |
| 99 bool RetainsIndividualDisplayItems() const; | |
| 100 | |
| 101 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 90 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
| 102 bool include_items) const; | 91 bool include_items) const; |
| 103 | 92 |
| 104 void EmitTraceSnapshot() const; | 93 void EmitTraceSnapshot() const; |
| 105 | 94 |
| 106 void GenerateDiscardableImagesMetadata(); | 95 void GenerateDiscardableImagesMetadata(); |
| 107 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 96 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 108 float raster_scale, | 97 float raster_scale, |
| 109 std::vector<DrawImage>* images); | 98 std::vector<DrawImage>* images); |
| 110 | 99 |
| 100 void SetRetainVisualRectsForTesting(bool retain) { |
| 101 retain_visual_rects_ = retain; |
| 102 } |
| 103 |
| 111 gfx::Rect VisualRectForTesting(int index) { | 104 gfx::Rect VisualRectForTesting(int index) { |
| 112 return inputs_.visual_rects[index]; | 105 return inputs_.visual_rects[index]; |
| 113 } | 106 } |
| 114 | 107 |
| 115 ContiguousContainer<DisplayItem>::const_iterator begin() const { | 108 ContiguousContainer<DisplayItem>::const_iterator begin() const { |
| 116 return inputs_.items.begin(); | 109 return inputs_.items.begin(); |
| 117 } | 110 } |
| 118 | 111 |
| 119 ContiguousContainer<DisplayItem>::const_iterator end() const { | 112 ContiguousContainer<DisplayItem>::const_iterator end() const { |
| 120 return inputs_.items.end(); | 113 return inputs_.items.end(); |
| 121 } | 114 } |
| 122 | 115 |
| 123 private: | 116 private: |
| 124 DisplayItemList(gfx::Rect layer_rect, | 117 explicit DisplayItemList( |
| 125 const DisplayItemListSettings& display_list_settings, | 118 const DisplayItemListSettings& display_list_settings); |
| 126 bool retain_individual_display_items); | |
| 127 ~DisplayItemList(); | 119 ~DisplayItemList(); |
| 128 | 120 |
| 129 void ProcessAppendedItem(const DisplayItem* item); | 121 void ProcessAppendedItem(const DisplayItem* item); |
| 130 | 122 |
| 131 sk_sp<SkPicture> picture_; | 123 RTree rtree_; |
| 124 // For testing purposes only. Whether to keep visual rects across calls to |
| 125 // Finalize(). |
| 126 bool retain_visual_rects_ = false; |
| 132 | 127 |
| 133 std::unique_ptr<SkPictureRecorder> recorder_; | 128 int approximate_op_count_ = 0; |
| 134 | |
| 135 bool retain_individual_display_items_; | |
| 136 int approximate_op_count_; | |
| 137 | |
| 138 // Memory usage due to the cached SkPicture. | |
| 139 size_t picture_memory_usage_; | |
| 140 | 129 |
| 141 DiscardableImageMap image_map_; | 130 DiscardableImageMap image_map_; |
| 142 | 131 |
| 143 struct Inputs { | 132 struct Inputs { |
| 144 Inputs(gfx::Rect layer_rect, const DisplayItemListSettings& settings); | 133 explicit Inputs(const DisplayItemListSettings& settings); |
| 145 ~Inputs(); | 134 ~Inputs(); |
| 146 | 135 |
| 147 ContiguousContainer<DisplayItem> items; | 136 ContiguousContainer<DisplayItem> items; |
| 148 // The visual rects associated with each of the display items in the | 137 // 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 | 138 // display item list. There is one rect per display item, and the |
| 150 // position in |visual_rects| matches the position of the item in | 139 // position in |visual_rects| matches the position of the item in |
| 151 // |items| . These rects are intentionally kept separate | 140 // |items| . These rects are intentionally kept separate |
| 152 // because they are not needed while walking the |items| for raster. | 141 // because they are not needed while walking the |items| for raster. |
| 153 std::vector<gfx::Rect> visual_rects; | 142 std::vector<gfx::Rect> visual_rects; |
| 154 | 143 |
| 155 const DisplayItemListSettings settings; | 144 const DisplayItemListSettings settings; |
| 156 gfx::Rect layer_rect; | 145 bool all_items_are_suitable_for_gpu_rasterization = true; |
| 157 bool is_suitable_for_gpu_rasterization; | |
| 158 }; | 146 }; |
| 159 | 147 |
| 160 Inputs inputs_; | 148 Inputs inputs_; |
| 161 | 149 |
| 162 friend class base::RefCountedThreadSafe<DisplayItemList>; | 150 friend class base::RefCountedThreadSafe<DisplayItemList>; |
| 163 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 151 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
| 164 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 152 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
| 165 }; | 153 }; |
| 166 | 154 |
| 167 } // namespace cc | 155 } // namespace cc |
| 168 | 156 |
| 169 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 157 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
| OLD | NEW |