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> |
| 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 DisplayItem; | 31 class DisplayItem; |
| 30 class DrawingDisplayItem; | 32 class DrawingDisplayItem; |
| 31 class ImageSerializationProcessor; | 33 class ImageSerializationProcessor; |
| 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 ImageSerializationProcessor* image_serialization_processor); | 51 ImageSerializationProcessor* image_serialization_processor); |
| 55 | 52 |
| 56 // Creates a Protobuf representing the state of this DisplayItemList. | 53 // Creates a Protobuf representing the state of this DisplayItemList. |
| 57 // TODO(dtrainor): Don't resend DisplayItems that were already serialized | 54 // TODO(dtrainor): Don't resend DisplayItems that were already serialized |
| 58 // (crbug.com/548434). | 55 // (crbug.com/548434). |
| 59 void ToProtobuf(proto::DisplayItemList* proto, | 56 void ToProtobuf(proto::DisplayItemList* proto, |
| 60 ImageSerializationProcessor* image_serialization_processor); | 57 ImageSerializationProcessor* image_serialization_processor); |
| 61 | 58 |
| 62 void Raster(SkCanvas* canvas, | 59 void Raster(SkCanvas* canvas, |
| 63 SkPicture::AbortCallback* callback, | 60 SkPicture::AbortCallback* callback, |
| 64 const gfx::Rect& canvas_target_playback_rect, | 61 const gfx::Rect& canvas_target_playback_rect, |
| 65 float contents_scale) const; | 62 float contents_scale) const; |
| 66 | 63 |
| 67 // This is a fast path for use only if canvas_ is set and | |
| 68 // retain_individual_display_items_ is false. This method also updates | |
| 69 // approximate_op_count_. | |
| 70 void RasterIntoCanvas(const DisplayItem& display_item); | |
| 71 | |
| 72 // Because processing happens in this function, all the set up for | 64 // Because processing happens in this function, all the set up for |
| 73 // this item should be done via the args, which is why the return | 65 // this item should be done via the args, which is why the return |
| 74 // type needs to be const, to prevent set-after-processing mistakes. | 66 // type needs to be const, to prevent set-after-processing mistakes. |
| 75 template <typename DisplayItemType, typename... Args> | 67 template <typename DisplayItemType, typename... Args> |
| 76 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, | 68 const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect, |
| 77 Args&&... args) { | 69 Args&&... args) { |
| 78 visual_rects_.push_back(visual_rect); | 70 visual_rects_.push_back(visual_rect); |
| 79 auto* item = &items_.AllocateAndConstruct<DisplayItemType>( | 71 auto* item = &items_.AllocateAndConstruct<DisplayItemType>( |
| 80 std::forward<Args>(args)...); | 72 std::forward<Args>(args)...); |
| 81 approximate_op_count_ += item->ApproximateOpCount(); | 73 approximate_op_count_ += item->ApproximateOpCount(); |
| 82 ProcessAppendedItem(item); | |
| 83 return *item; | 74 return *item; |
| 84 } | 75 } |
| 85 | 76 |
| 86 // Called after all items are appended, to process the items and, if | 77 // Called after all items are appended, to process the items and, if |
| 87 // applicable, create an internally cached SkPicture. | 78 // applicable, create an internally cached SkPicture. |
| 88 void Finalize(); | 79 void Finalize(); |
| 89 | 80 |
| 90 void SetIsSuitableForGpuRasterization(bool is_suitable) { | 81 void SetIsSuitableForGpuRasterization(bool is_suitable) { |
| 91 is_suitable_for_gpu_rasterization_ = is_suitable; | 82 all_items_are_suitable_for_gpu_rasterization_ = is_suitable; |
| 92 } | 83 } |
| 93 bool IsSuitableForGpuRasterization() const; | 84 bool IsSuitableForGpuRasterization() const; |
| 94 int ApproximateOpCount() const; | 85 int ApproximateOpCount() const; |
| 95 size_t ApproximateMemoryUsage() const; | 86 size_t ApproximateMemoryUsage() const; |
| 96 bool ShouldBeAnalyzedForSolidColor() const; | 87 bool ShouldBeAnalyzedForSolidColor() const; |
| 97 | 88 |
| 98 bool RetainsIndividualDisplayItems() const; | |
| 99 | |
| 100 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 89 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
| 101 bool include_items) const; | 90 bool include_items) const; |
| 102 | 91 |
| 103 void EmitTraceSnapshot() const; | 92 void EmitTraceSnapshot() const; |
| 104 | 93 |
| 105 void GenerateDiscardableImagesMetadata(); | 94 void GenerateDiscardableImagesMetadata(); |
| 106 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 95 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 107 float raster_scale, | 96 float raster_scale, |
| 108 std::vector<DrawImage>* images); | 97 std::vector<DrawImage>* images); |
| 109 | 98 |
| 110 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } | 99 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } |
| 100 void SetRetainVisualRectsForTesting(bool retain) { | |
| 101 retain_visual_rects_ = retain; | |
| 102 } | |
| 111 | 103 |
| 112 private: | 104 private: |
| 113 DisplayItemList(gfx::Rect layer_rect, | 105 explicit DisplayItemList( |
| 114 const DisplayItemListSettings& display_list_settings, | 106 const DisplayItemListSettings& display_list_settings); |
| 115 bool retain_individual_display_items); | |
| 116 ~DisplayItemList(); | 107 ~DisplayItemList(); |
| 117 | 108 |
| 118 void ProcessAppendedItem(const DisplayItem* item); | 109 void ProcessAppendedItem(const DisplayItem* item); |
| 119 | 110 |
| 111 gfx::Rect GetQueryRect(const gfx::Rect& rect, float scale) const; | |
| 112 | |
| 113 RTree rtree_; | |
| 120 ContiguousContainer<DisplayItem> items_; | 114 ContiguousContainer<DisplayItem> items_; |
| 121 // The visual rects associated with each of the display items in the | 115 // The visual rects associated with each of the display items in the |
| 122 // display item list. There is one rect per display item, and the | 116 // display item list. There is one rect per display item, and the |
| 123 // position in |visual_rects_| matches the position of the item in | 117 // position in |visual_rects_| matches the position of the item in |
| 124 // |items_| . These rects are intentionally kept separate | 118 // |items_| . These rects are intentionally kept separate |
| 125 // because they are not needed while walking the |items_| for raster. | 119 // because they are not needed while walking the |items_| for raster. |
| 126 std::vector<gfx::Rect> visual_rects_; | 120 std::vector<gfx::Rect> visual_rects_; |
| 127 sk_sp<SkPicture> picture_; | 121 bool retain_visual_rects_; |
|
vmpstr
2016/06/22 20:14:07
Where are we using this?
wkorman
2016/06/24 19:57:14
In display_item_list_unittest, two main cases:
1.
vmpstr
2016/06/24 20:15:33
Can you put a comment to make it clear that this i
wkorman
2016/06/24 22:39:32
Done.
| |
| 128 | 122 |
| 129 std::unique_ptr<SkPictureRecorder> recorder_; | |
| 130 const DisplayItemListSettings settings_; | 123 const DisplayItemListSettings settings_; |
| 131 bool retain_individual_display_items_; | 124 bool all_items_are_suitable_for_gpu_rasterization_; |
| 132 | |
| 133 gfx::Rect layer_rect_; | |
| 134 bool is_suitable_for_gpu_rasterization_; | |
| 135 int approximate_op_count_; | 125 int approximate_op_count_; |
| 136 | 126 |
| 137 // Memory usage due to the cached SkPicture. | |
| 138 size_t picture_memory_usage_; | |
| 139 | |
| 140 DiscardableImageMap image_map_; | 127 DiscardableImageMap image_map_; |
| 141 | 128 |
| 142 friend class base::RefCountedThreadSafe<DisplayItemList>; | 129 friend class base::RefCountedThreadSafe<DisplayItemList>; |
| 143 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 130 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
| 144 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 131 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
| 145 }; | 132 }; |
| 146 | 133 |
| 147 } // namespace cc | 134 } // namespace cc |
| 148 | 135 |
| 149 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 136 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
| OLD | NEW |