| 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 "base/gtest_prod_util.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "cc/base/cc_export.h" | 12 #include "cc/base/cc_export.h" |
| 13 #include "cc/base/contiguous_container.h" | 13 #include "cc/base/contiguous_container.h" |
| 14 #include "cc/base/rtree.h" |
| 14 #include "cc/playback/discardable_image_map.h" | 15 #include "cc/playback/discardable_image_map.h" |
| 15 #include "cc/playback/display_item.h" | 16 #include "cc/playback/display_item.h" |
| 16 #include "cc/playback/display_item_list_settings.h" | 17 #include "cc/playback/display_item_list_settings.h" |
| 17 #include "skia/ext/refptr.h" | 18 #include "skia/ext/refptr.h" |
| 18 #include "third_party/skia/include/core/SkPicture.h" | 19 #include "third_party/skia/include/core/SkPicture.h" |
| 19 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 21 #include "ui/gfx/geometry/rect_conversions.h" |
| 20 | 22 |
| 21 class SkCanvas; | 23 class SkCanvas; |
| 22 class SkPictureRecorder; | 24 class SkPictureRecorder; |
| 23 | 25 |
| 24 namespace cc { | 26 namespace cc { |
| 25 | 27 |
| 26 namespace proto { | 28 namespace proto { |
| 27 class DisplayItemList; | 29 class DisplayItemList; |
| 28 } | 30 } |
| 29 | 31 |
| 30 class CC_EXPORT DisplayItemList | 32 class CC_EXPORT DisplayItemList |
| 31 : public base::RefCountedThreadSafe<DisplayItemList> { | 33 : public base::RefCountedThreadSafe<DisplayItemList> { |
| 32 public: | 34 public: |
| 33 // Creates a display item list. If picture caching is used, then layer_rect | 35 // Creates a display item list. |
| 34 // specifies the cull rect of the display item list (the picture will not | |
| 35 // exceed this rect). If picture caching is not used, then the given rect can | |
| 36 // be empty. | |
| 37 // TODO(vmpstr): Maybe this cull rect can be part of the settings instead. | |
| 38 static scoped_refptr<DisplayItemList> Create( | 36 static scoped_refptr<DisplayItemList> Create( |
| 39 const gfx::Rect& layer_rect, | |
| 40 const DisplayItemListSettings& settings); | 37 const DisplayItemListSettings& settings); |
| 41 | 38 |
| 42 // Creates a DisplayItemList from a Protobuf. | 39 // Creates a DisplayItemList from a Protobuf. |
| 43 // TODO(dtrainor): Pass in a list of possible DisplayItems to reuse | 40 // TODO(dtrainor): Pass in a list of possible DisplayItems to reuse |
| 44 // (crbug.com/548434). | 41 // (crbug.com/548434). |
| 45 static scoped_refptr<DisplayItemList> CreateFromProto( | 42 static scoped_refptr<DisplayItemList> CreateFromProto( |
| 46 const proto::DisplayItemList& proto); | 43 const proto::DisplayItemList& proto); |
| 47 | 44 |
| 48 // Creates a Protobuf representing the state of this DisplayItemList. | 45 // Creates a Protobuf representing the state of this DisplayItemList. |
| 49 // TODO(dtrainor): Don't resend DisplayItems that were already serialized | 46 // TODO(dtrainor): Don't resend DisplayItems that were already serialized |
| 50 // (crbug.com/548434). | 47 // (crbug.com/548434). |
| 51 void ToProtobuf(proto::DisplayItemList* proto); | 48 void ToProtobuf(proto::DisplayItemList* proto); |
| 52 | 49 |
| 53 void Raster(SkCanvas* canvas, | 50 void Raster(SkCanvas* canvas, |
| 54 SkPicture::AbortCallback* callback, | 51 SkPicture::AbortCallback* callback, |
| 55 const gfx::Rect& canvas_target_playback_rect, | 52 const gfx::Rect& canvas_target_playback_rect, |
| 56 float contents_scale) const; | 53 float contents_scale) const; |
| 57 | 54 |
| 58 // This is a fast path for use only if canvas_ is set and | |
| 59 // retain_individual_display_items_ is false. This method also updates | |
| 60 // is_suitable_for_gpu_rasterization_ and approximate_op_count_. | |
| 61 void RasterIntoCanvas(const DisplayItem& display_item); | |
| 62 | |
| 63 template <typename DisplayItemType> | 55 template <typename DisplayItemType> |
| 64 DisplayItemType* CreateAndAppendItem(const gfx::Rect& visual_rect) { | 56 DisplayItemType* CreateAndAppendItem(const gfx::Rect& visual_rect) { |
| 65 #if DCHECK_IS_ON() | 57 #if DCHECK_IS_ON() |
| 66 needs_process_ = true; | 58 needs_finalize_ = true; |
| 67 #endif | 59 #endif |
| 60 // TODO(wkorman): Would be nice to avoid having to do this conversion if |
| 61 // possible. |
| 68 visual_rects_.push_back(visual_rect); | 62 visual_rects_.push_back(visual_rect); |
| 69 ProcessAppendedItemsOnTheFly(); | |
| 70 return &items_.AllocateAndConstruct<DisplayItemType>(); | 63 return &items_.AllocateAndConstruct<DisplayItemType>(); |
| 71 } | 64 } |
| 72 | 65 |
| 73 // Removes the last item. This cannot be called on lists with cached pictures | 66 // Removes the last item. This cannot be called on lists with cached pictures |
| 74 // (since the data may already have been incorporated into cached picture | 67 // (since the data may already have been incorporated into cached picture |
| 75 // sizes, etc). | 68 // sizes, etc). |
| 76 void RemoveLast(); | 69 void RemoveLast(); |
| 77 | 70 |
| 78 // Called after all items are appended, to process the items and, if | 71 // Called after all items are appended, to process the items and, if |
| 79 // applicable, create an internally cached SkPicture. | 72 // applicable, create an internally cached SkPicture. |
| 80 void Finalize(); | 73 void Finalize(); |
| 81 | 74 |
| 82 bool IsSuitableForGpuRasterization() const; | 75 bool IsSuitableForGpuRasterization() const; |
| 83 int ApproximateOpCount() const; | 76 int ApproximateOpCount() const; |
| 84 size_t ApproximateMemoryUsage() const; | 77 size_t ApproximateMemoryUsage() const; |
| 85 bool ShouldBeAnalyzedForSolidColor() const; | 78 bool ShouldBeAnalyzedForSolidColor() const; |
| 86 | 79 |
| 87 bool RetainsIndividualDisplayItems() const; | |
| 88 | |
| 89 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue( | 80 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue( |
| 90 bool include_items) const; | 81 bool include_items) const; |
| 91 | 82 |
| 92 void EmitTraceSnapshot() const; | 83 void EmitTraceSnapshot() const; |
| 93 | 84 |
| 94 void GenerateDiscardableImagesMetadata(); | 85 void GenerateDiscardableImagesMetadata(); |
| 95 void GetDiscardableImagesInRect(const gfx::Rect& rect, | 86 void GetDiscardableImagesInRect(const gfx::Rect& rect, |
| 96 float raster_scale, | 87 float raster_scale, |
| 97 std::vector<DrawImage>* images); | 88 std::vector<DrawImage>* images); |
| 98 | 89 |
| 99 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } | 90 gfx::Rect VisualRectForTesting(int index) { |
| 91 return visual_rects_[index]; |
| 92 } |
| 100 | 93 |
| 101 private: | 94 private: |
| 102 DisplayItemList(gfx::Rect layer_rect, | 95 explicit DisplayItemList( |
| 103 const DisplayItemListSettings& display_list_settings, | 96 const DisplayItemListSettings& display_list_settings); |
| 104 bool retain_individual_display_items); | |
| 105 ~DisplayItemList(); | 97 ~DisplayItemList(); |
| 106 | 98 |
| 107 // While appending new items, if they are not being retained, this can process | |
| 108 // periodically to avoid retaining all the items and processing at the end. | |
| 109 void ProcessAppendedItemsOnTheFly(); | |
| 110 void ProcessAppendedItems(); | |
| 111 #if DCHECK_IS_ON() | 99 #if DCHECK_IS_ON() |
| 112 bool ProcessAppendedItemsCalled() const { return !needs_process_; } | 100 bool FinalizeCalled() const { return !needs_finalize_; } |
| 113 bool needs_process_; | 101 bool needs_finalize_; |
| 114 #else | 102 #else |
| 115 bool ProcessAppendedItemsCalled() const { return true; } | 103 bool FinalizeCalled() const { return true; } |
| 116 #endif | 104 #endif |
| 117 | 105 |
| 106 gfx::Rect GetQueryRect(const gfx::Rect& rect, float scale) const; |
| 107 |
| 108 RTree rtree_; |
| 118 ContiguousContainer<DisplayItem> items_; | 109 ContiguousContainer<DisplayItem> items_; |
| 119 // The visual rects associated with each of the display items in the | 110 // The visual rects associated with each of the display items in the |
| 120 // display item list. There is one rect per display item, and the | 111 // display item list. There is one rect per display item, and the |
| 121 // position in |visual_rects_| matches the position of the item in | 112 // position in |visual_rects_| matches the position of the item in |
| 122 // |items_| . These rects are intentionally kept separate | 113 // |items_| . These rects are intentionally kept separate |
| 123 // because they are not needed while walking the |items_| for raster. | 114 // because they are not needed while walking the |items_| for raster. |
| 124 std::vector<gfx::Rect> visual_rects_; | 115 std::vector<gfx::Rect> visual_rects_; |
| 125 skia::RefPtr<SkPicture> picture_; | 116 skia::RefPtr<SkPicture> picture_; |
| 126 | 117 |
| 127 scoped_ptr<SkPictureRecorder> recorder_; | |
| 128 skia::RefPtr<SkCanvas> canvas_; | |
| 129 const DisplayItemListSettings settings_; | 118 const DisplayItemListSettings settings_; |
| 130 bool retain_individual_display_items_; | 119 bool all_items_are_suitable_for_gpu_rasterization_; |
| 131 | |
| 132 gfx::Rect layer_rect_; | |
| 133 bool is_suitable_for_gpu_rasterization_; | |
| 134 int approximate_op_count_; | 120 int approximate_op_count_; |
| 135 | 121 |
| 136 // Memory usage due to the cached SkPicture. | |
| 137 size_t picture_memory_usage_; | |
| 138 | |
| 139 // Memory usage due to external data held by display items. | 122 // Memory usage due to external data held by display items. |
| 140 size_t external_memory_usage_; | 123 size_t external_memory_usage_; |
| 141 | 124 |
| 142 DiscardableImageMap image_map_; | 125 DiscardableImageMap image_map_; |
| 143 | 126 |
| 144 friend class base::RefCountedThreadSafe<DisplayItemList>; | 127 friend class base::RefCountedThreadSafe<DisplayItemList>; |
| 145 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); | 128 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); |
| 146 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); | 129 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); |
| 147 }; | 130 }; |
| 148 | 131 |
| 149 } // namespace cc | 132 } // namespace cc |
| 150 | 133 |
| 151 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ | 134 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ |
| OLD | NEW |