Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: cc/playback/display_item_list.h

Issue 1484163002: Raster display item lists via a visual rect RTree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update test expectations. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 visual_rects_.push_back(visual_rect); 71 visual_rects_.push_back(visual_rect);
80 auto* item = &items_.AllocateAndConstruct<DisplayItemType>( 72 auto* item = &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 is_suitable_for_gpu_rasterization_ = is_suitable; 83 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
111 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; } 100 gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; }
101 void SetRetainVisualRectsForTesting(bool retain) {
102 retain_visual_rects_ = retain;
103 }
112 104
113 ContiguousContainer<DisplayItem>::const_iterator begin() const { 105 ContiguousContainer<DisplayItem>::const_iterator begin() const {
114 return items_.begin(); 106 return items_.begin();
115 } 107 }
116 108
117 ContiguousContainer<DisplayItem>::const_iterator end() const { 109 ContiguousContainer<DisplayItem>::const_iterator end() const {
118 return items_.end(); 110 return items_.end();
119 } 111 }
120 112
121 private: 113 private:
122 DisplayItemList(gfx::Rect layer_rect, 114 explicit DisplayItemList(
123 const DisplayItemListSettings& display_list_settings, 115 const DisplayItemListSettings& display_list_settings);
124 bool retain_individual_display_items);
125 ~DisplayItemList(); 116 ~DisplayItemList();
126 117
127 void ProcessAppendedItem(const DisplayItem* item); 118 void ProcessAppendedItem(const DisplayItem* item);
128 119
120 RTree rtree_;
129 ContiguousContainer<DisplayItem> items_; 121 ContiguousContainer<DisplayItem> items_;
130 // The visual rects associated with each of the display items in the 122 // The visual rects associated with each of the display items in the
131 // display item list. There is one rect per display item, and the 123 // display item list. There is one rect per display item, and the
132 // position in |visual_rects_| matches the position of the item in 124 // position in |visual_rects_| matches the position of the item in
133 // |items_| . These rects are intentionally kept separate 125 // |items_| . These rects are intentionally kept separate
134 // because they are not needed while walking the |items_| for raster. 126 // because they are not needed while walking the |items_| for raster.
135 std::vector<gfx::Rect> visual_rects_; 127 std::vector<gfx::Rect> visual_rects_;
136 sk_sp<SkPicture> picture_; 128 // For testing purposes only. Whether to keep visual rects across calls to
129 // Finalize().
130 bool retain_visual_rects_ = false;
137 131
138 std::unique_ptr<SkPictureRecorder> recorder_;
139 const DisplayItemListSettings settings_; 132 const DisplayItemListSettings settings_;
140 bool retain_individual_display_items_; 133 bool all_items_are_suitable_for_gpu_rasterization_ = true;
141 134 int approximate_op_count_ = 0;
142 gfx::Rect layer_rect_;
143 bool is_suitable_for_gpu_rasterization_;
144 int approximate_op_count_;
145
146 // Memory usage due to the cached SkPicture.
147 size_t picture_memory_usage_;
148 135
149 DiscardableImageMap image_map_; 136 DiscardableImageMap image_map_;
150 137
151 friend class base::RefCountedThreadSafe<DisplayItemList>; 138 friend class base::RefCountedThreadSafe<DisplayItemList>;
152 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage); 139 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage);
153 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); 140 DISALLOW_COPY_AND_ASSIGN(DisplayItemList);
154 }; 141 };
155 142
156 } // namespace cc 143 } // namespace cc
157 144
158 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_ 145 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698