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

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

Issue 1123983002: cc: Use a ListContainer for DisplayItemList to reduce allocations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: displaylistcontainer: fixdcheck Created 5 years, 7 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
« no previous file with comments | « cc/resources/compositing_display_item.cc ('k') | cc/resources/display_item_list.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_RESOURCES_DISPLAY_ITEM_LIST_H_ 5 #ifndef CC_RESOURCES_DISPLAY_ITEM_LIST_H_
6 #define CC_RESOURCES_DISPLAY_ITEM_LIST_H_ 6 #define CC_RESOURCES_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/scoped_ptr_vector.h" 13 #include "cc/base/scoped_ptr_vector.h"
14 // TODO(danakj): Move ListContainer out of cc/quads/
15 #include "cc/quads/list_container.h"
14 #include "cc/resources/display_item.h" 16 #include "cc/resources/display_item.h"
15 #include "cc/resources/pixel_ref_map.h" 17 #include "cc/resources/pixel_ref_map.h"
16 #include "skia/ext/refptr.h" 18 #include "skia/ext/refptr.h"
17 #include "third_party/skia/include/core/SkPicture.h" 19 #include "third_party/skia/include/core/SkPicture.h"
18 #include "ui/gfx/geometry/rect.h" 20 #include "ui/gfx/geometry/rect.h"
19 21
20 class SkCanvas; 22 class SkCanvas;
21 class SkDrawPictureCallback; 23 class SkDrawPictureCallback;
22 class SkPictureRecorder; 24 class SkPictureRecorder;
23 25
24 namespace cc { 26 namespace cc {
25 27
26 class CC_EXPORT DisplayItemList 28 class CC_EXPORT DisplayItemList
27 : public base::RefCountedThreadSafe<DisplayItemList> { 29 : public base::RefCountedThreadSafe<DisplayItemList> {
28 public: 30 public:
29 static scoped_refptr<DisplayItemList> Create(gfx::Rect layer_rect, 31 static scoped_refptr<DisplayItemList> Create(gfx::Rect layer_rect,
30 bool use_cached_picture); 32 bool use_cached_picture);
31 33
32 void Raster(SkCanvas* canvas, 34 void Raster(SkCanvas* canvas,
33 SkDrawPictureCallback* callback, 35 SkDrawPictureCallback* callback,
34 float contents_scale) const; 36 float contents_scale) const;
35 37
36 void AppendItem(scoped_ptr<DisplayItem> item); 38 template <typename DisplayItemType>
39 DisplayItemType* CreateAndAppendItem() {
40 #if DCHECK_IS_ON()
41 needs_process_ = true;
42 #endif
43 ProcessAppendedItemsOnTheFly();
44 return items_.AllocateAndConstruct<DisplayItemType>();
45 }
37 46
47 void ProcessAppendedItems();
38 void CreateAndCacheSkPicture(); 48 void CreateAndCacheSkPicture();
39 49
40 bool IsSuitableForGpuRasterization() const; 50 bool IsSuitableForGpuRasterization() const;
41 int ApproximateOpCount() const; 51 int ApproximateOpCount() const;
42 size_t PictureMemoryUsage() const; 52 size_t PictureMemoryUsage() const;
43 53
44 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const; 54 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue() const;
45 55
46 void EmitTraceSnapshot() const; 56 void EmitTraceSnapshot() const;
47 57
48 void GatherPixelRefs(const gfx::Size& grid_cell_size); 58 void GatherPixelRefs(const gfx::Size& grid_cell_size);
49 59
50 private: 60 private:
51 DisplayItemList(gfx::Rect layer_rect, 61 DisplayItemList(gfx::Rect layer_rect,
52 bool use_cached_picture, 62 bool use_cached_picture,
53 bool retain_individual_display_items); 63 bool retain_individual_display_items);
54 DisplayItemList(gfx::Rect layer_rect, bool use_cached_picture); 64 DisplayItemList(gfx::Rect layer_rect, bool use_cached_picture);
55 ~DisplayItemList(); 65 ~DisplayItemList();
56 ScopedPtrVector<DisplayItem> items_; 66
67 // While appending new items, if they are not being retained, this can process
68 // periodically to avoid retaining all the items and processing at the end.
69 void ProcessAppendedItemsOnTheFly();
70 #if DCHECK_IS_ON()
71 bool ProcessAppendedItemsCalled() const { return !needs_process_; }
72 bool needs_process_;
73 #else
74 bool ProcessAppendedItemsCalled() const { return true; }
75 #endif
76
77 ListContainer<DisplayItem> items_;
57 skia::RefPtr<SkPicture> picture_; 78 skia::RefPtr<SkPicture> picture_;
58 79
59 scoped_ptr<SkPictureRecorder> recorder_; 80 scoped_ptr<SkPictureRecorder> recorder_;
60 skia::RefPtr<SkCanvas> canvas_; 81 skia::RefPtr<SkCanvas> canvas_;
61 bool use_cached_picture_; 82 bool use_cached_picture_;
62 bool retain_individual_display_items_; 83 bool retain_individual_display_items_;
63 84
64 gfx::Rect layer_rect_; 85 gfx::Rect layer_rect_;
65 bool is_suitable_for_gpu_rasterization_; 86 bool is_suitable_for_gpu_rasterization_;
66 int approximate_op_count_; 87 int approximate_op_count_;
67 size_t picture_memory_usage_; 88 size_t picture_memory_usage_;
68 89
69 scoped_ptr<PixelRefMap> pixel_refs_; 90 scoped_ptr<PixelRefMap> pixel_refs_;
70 91
71 friend class base::RefCountedThreadSafe<DisplayItemList>; 92 friend class base::RefCountedThreadSafe<DisplayItemList>;
72 friend class PixelRefMap::Iterator; 93 friend class PixelRefMap::Iterator;
73 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, PictureMemoryUsage); 94 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, PictureMemoryUsage);
74 DISALLOW_COPY_AND_ASSIGN(DisplayItemList); 95 DISALLOW_COPY_AND_ASSIGN(DisplayItemList);
75 }; 96 };
76 97
77 } // namespace cc 98 } // namespace cc
78 99
79 #endif // CC_RESOURCES_DISPLAY_ITEM_LIST_H_ 100 #endif // CC_RESOURCES_DISPLAY_ITEM_LIST_H_
OLDNEW
« no previous file with comments | « cc/resources/compositing_display_item.cc ('k') | cc/resources/display_item_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698