Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / cc / playback / display_item_list.h
blobe85fe1058c6cc5f14926d58c23186dbf9756799b
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
3 // found in the LICENSE file.
5 #ifndef CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
6 #define CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
8 #include "base/gtest_prod_util.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/trace_event/trace_event.h"
12 #include "cc/base/cc_export.h"
13 #include "cc/base/list_container.h"
14 #include "cc/playback/discardable_image_map.h"
15 #include "cc/playback/display_item.h"
16 #include "skia/ext/refptr.h"
17 #include "third_party/skia/include/core/SkPicture.h"
18 #include "ui/gfx/geometry/rect.h"
20 class SkCanvas;
21 class SkPictureRecorder;
23 namespace cc {
25 class DisplayItemListSettings;
27 class CC_EXPORT DisplayItemList
28 : public base::RefCountedThreadSafe<DisplayItemList> {
29 public:
30 static scoped_refptr<DisplayItemList> CreateWithoutCachedPicture(
31 const DisplayItemListSettings& settings);
33 // Creates a display item list with the given cull rect (if picture caching
34 // is used).
35 static scoped_refptr<DisplayItemList> Create(gfx::Rect layer_rect,
36 bool use_cached_picture);
38 static scoped_refptr<DisplayItemList> Create(
39 gfx::Rect layer_rect,
40 const DisplayItemListSettings& settings);
42 void Raster(SkCanvas* canvas,
43 SkPicture::AbortCallback* callback,
44 const gfx::Rect& canvas_target_playback_rect,
45 float contents_scale) const;
47 // This is a fast path for use only if canvas_ is set and
48 // retain_individual_display_items_ is false. This method also updates
49 // is_suitable_for_gpu_rasterization_ and approximate_op_count_.
50 void RasterIntoCanvas(const DisplayItem& display_item);
52 template <typename DisplayItemType>
53 DisplayItemType* CreateAndAppendItem() {
54 #if DCHECK_IS_ON()
55 needs_process_ = true;
56 #endif
57 ProcessAppendedItemsOnTheFly();
58 return items_.AllocateAndConstruct<DisplayItemType>();
61 // Removes the last item. This cannot be called on lists with cached pictures
62 // (since the data may already have been incorporated into cached picture
63 // sizes, etc).
64 void RemoveLast();
66 // Called after all items are appended, to process the items and, if
67 // applicable, create an internally cached SkPicture.
68 void Finalize();
70 bool IsSuitableForGpuRasterization() const;
71 int ApproximateOpCount() const;
72 size_t ApproximateMemoryUsage() const;
73 bool ShouldBeAnalyzedForSolidColor() const;
75 bool RetainsIndividualDisplayItems() const;
77 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsValue(
78 bool include_items) const;
80 void EmitTraceSnapshot() const;
82 void GatherDiscardableImages(const gfx::Size& grid_cell_size);
84 private:
85 DisplayItemList(gfx::Rect layer_rect,
86 const DisplayItemListSettings& display_list_settings,
87 bool retain_individual_display_items);
88 DisplayItemList(gfx::Rect layer_rect,
89 const DisplayItemListSettings& display_list_settings);
90 ~DisplayItemList();
92 // While appending new items, if they are not being retained, this can process
93 // periodically to avoid retaining all the items and processing at the end.
94 void ProcessAppendedItemsOnTheFly();
95 void ProcessAppendedItems();
96 #if DCHECK_IS_ON()
97 bool ProcessAppendedItemsCalled() const { return !needs_process_; }
98 bool needs_process_;
99 #else
100 bool ProcessAppendedItemsCalled() const { return true; }
101 #endif
103 ListContainer<DisplayItem> items_;
104 skia::RefPtr<SkPicture> picture_;
106 scoped_ptr<SkPictureRecorder> recorder_;
107 skia::RefPtr<SkCanvas> canvas_;
108 bool use_cached_picture_;
109 bool retain_individual_display_items_;
111 gfx::Rect layer_rect_;
112 bool all_items_are_suitable_for_gpu_rasterization_;
113 int approximate_op_count_;
115 // Memory usage due to the cached SkPicture.
116 size_t picture_memory_usage_;
118 // Memory usage due to external data held by display items.
119 size_t external_memory_usage_;
121 scoped_ptr<DiscardableImageMap> images_;
123 friend class base::RefCountedThreadSafe<DisplayItemList>;
124 friend class DiscardableImageMap::Iterator;
125 FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage);
126 DISALLOW_COPY_AND_ASSIGN(DisplayItemList);
129 } // namespace cc
131 #endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_