| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "cc/base/cc_export.h" | 16 #include "cc/base/cc_export.h" |
| 17 #include "cc/base/contiguous_container.h" | 17 #include "cc/base/contiguous_container.h" |
| 18 #include "cc/base/rtree.h" |
| 18 #include "cc/playback/discardable_image_map.h" | 19 #include "cc/playback/discardable_image_map.h" |
| 19 #include "cc/playback/display_item.h" | 20 #include "cc/playback/display_item.h" |
| 20 #include "cc/playback/display_item_list_settings.h" | 21 #include "cc/playback/display_item_list_settings.h" |
| 21 #include "skia/ext/refptr.h" | 22 #include "skia/ext/refptr.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 // is_suitable_for_gpu_rasterization_ and 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 // TODO(crbug.com/513016): None of the items might individually trigger a | 74 // TODO(crbug.com/513016): None of the items might individually trigger a |
| 83 // veto even though they collectively have enough "bad" operations that a | 75 // veto even though they collectively have enough "bad" operations that a |
| 84 // corresponding flattened Picture would get vetoed. | 76 // corresponding flattened Picture would get vetoed. |
| 85 is_suitable_for_gpu_rasterization_ &= item->IsSuitableForGpuRasterization(); | 77 all_items_are_suitable_for_gpu_rasterization_ &= |
| 86 ProcessAppendedItem(item); | 78 item->IsSuitableForGpuRasterization(); |
| 87 return *item; | 79 return *item; |
| 88 } | 80 } |
| 89 | 81 |
| 90 // Called after all items are appended, to process the items and, if | 82 // Called after all items are appended, to process the items and, if |
| 91 // applicable, create an internally cached SkPicture. | 83 // applicable, create an internally cached SkPicture. |
| 92 void Finalize(); | 84 void Finalize(); |
| 93 | 85 |
| 94 bool IsSuitableForGpuRasterization() const; | 86 bool IsSuitableForGpuRasterization() const; |
| 95 int ApproximateOpCount() const; | 87 int ApproximateOpCount() const; |
| 96 size_t ApproximateMemoryUsage() const; | 88 size_t ApproximateMemoryUsage() const; |
| 97 bool ShouldBeAnalyzedForSolidColor() const; | 89 bool ShouldBeAnalyzedForSolidColor() const; |
| 98 | 90 |
| 99 bool RetainsIndividualDisplayItems() const; | |
| 100 | |
| 101 scoped_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 91 scoped_ptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
| 102 bool include_items) const; | 92 bool include_items) const; |
| 103 | 93 |
| 104 void EmitTraceSnapshot() const; | 94 void EmitTraceSnapshot() const; |
| 105 | 95 |
| 106 void GenerateDiscardableImagesMetadata(); | 96 void GenerateDiscardableImagesMetadata(); |
| 107 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 97 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 108 float raster_scale, | 98 float raster_scale, |
| 109 std::vector<DrawImage>* images); | 99 std::vector<DrawImage>* images); |
| 110 bool MayHaveDiscardableImages() const; | 100 bool MayHaveDiscardableImages() const; |
| 111 | 101 |
| 112 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } | 102 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } |
| 103 void SetRetainVisualRectsForTesting(bool retain) { |
| 104 retain_visual_rects_ = retain; |
| 105 } |
| 113 | 106 |
| 114 private: | 107 private: |
| 115 DisplayItemList(gfx::Rect layer_rect, | 108 explicit DisplayItemList( |
| 116 const DisplayItemListSettings& display_list_settings, | 109 const DisplayItemListSettings& display_list_settings); |
| 117 bool retain_individual_display_items); | |
| 118 ~DisplayItemList(); | 110 ~DisplayItemList(); |
| 119 | 111 |
| 120 void ProcessAppendedItem(const DisplayItem* item); | 112 void ProcessAppendedItem(const DisplayItem* item); |
| 121 | 113 |
| 114 gfx::Rect GetQueryRect(const gfx::Rect& rect, float scale) const; |
| 115 |
| 116 RTree rtree_; |
| 122 ContiguousContainer<DisplayItem> items_; | 117 ContiguousContainer<DisplayItem> items_; |
| 123 // The visual rects associated with each of the display items in the | 118 // The visual rects associated with each of the display items in the |
| 124 // display item list. There is one rect per display item, and the | 119 // display item list. There is one rect per display item, and the |
| 125 // position in |visual_rects_| matches the position of the item in | 120 // position in |visual_rects_| matches the position of the item in |
| 126 // |items_| . These rects are intentionally kept separate | 121 // |items_| . These rects are intentionally kept separate |
| 127 // because they are not needed while walking the |items_| for raster. | 122 // because they are not needed while walking the |items_| for raster. |
| 128 std::vector<gfx::Rect> visual_rects_; | 123 std::vector<gfx::Rect> visual_rects_; |
| 129 sk_sp<SkPicture> picture_; | 124 bool retain_visual_rects_; |
| 130 | 125 |
| 131 scoped_ptr<SkPictureRecorder> recorder_; | |
| 132 skia::RefPtr<SkCanvas> canvas_; | |
| 133 const DisplayItemListSettings settings_; | 126 const DisplayItemListSettings settings_; |
| 134 bool retain_individual_display_items_; | 127 bool all_items_are_suitable_for_gpu_rasterization_; |
| 135 | |
| 136 gfx::Rect layer_rect_; | |
| 137 bool is_suitable_for_gpu_rasterization_; | |
| 138 int approximate_op_count_; | 128 int approximate_op_count_; |
| 139 | 129 |
| 140 // Memory usage due to the cached SkPicture. | |
| 141 size_t picture_memory_usage_; | |
| 142 | |
| 143 DiscardableImageMap image_map_; | 130 DiscardableImageMap image_map_; |
| 144 | 131 |
| 145 friend class base::RefCountedThreadSafe<DisplayItemList>; | 132 friend class base::RefCountedThreadSafe<DisplayItemList>; |
| 146 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 133 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
| 147 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 134 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
| 148 }; | 135 }; |
| 149 | 136 |
| 150 } // namespace cc | 137 } // namespace cc |
| 151 | 138 |
| 152 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 139 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
| OLD | NEW |