forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_item_list.h
149 lines (119 loc) · 5.26 KB
/
display_item_list.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
#define CC_PLAYBACK_DISPLAY_ITEM_LIST_H_
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/trace_event/trace_event.h"
#include "cc/base/cc_export.h"
#include "cc/base/contiguous_container.h"
#include "cc/playback/discardable_image_map.h"
#include "cc/playback/display_item.h"
#include "cc/playback/display_item_list_settings.h"
#include "third_party/skia/include/core/SkPicture.h"
#include "ui/gfx/geometry/rect.h"
class SkCanvas;
class SkPictureRecorder;
namespace cc {
class DisplayItem;
class DrawingDisplayItem;
class ImageSerializationProcessor;
namespace proto {
class DisplayItemList;
}
class CC_EXPORT DisplayItemList
: public base::RefCountedThreadSafe<DisplayItemList> {
public:
// Creates a display item list. If picture caching is used, then layer_rect
// specifies the cull rect of the display item list (the picture will not
// exceed this rect). If picture caching is not used, then the given rect can
// be empty.
// TODO(vmpstr): Maybe this cull rect can be part of the settings instead.
static scoped_refptr<DisplayItemList> Create(
const gfx::Rect& layer_rect,
const DisplayItemListSettings& settings);
// Creates a DisplayItemList from a Protobuf.
// TODO(dtrainor): Pass in a list of possible DisplayItems to reuse
// (crbug.com/548434).
static scoped_refptr<DisplayItemList> CreateFromProto(
const proto::DisplayItemList& proto,
ImageSerializationProcessor* image_serialization_processor);
// Creates a Protobuf representing the state of this DisplayItemList.
// TODO(dtrainor): Don't resend DisplayItems that were already serialized
// (crbug.com/548434).
void ToProtobuf(proto::DisplayItemList* proto,
ImageSerializationProcessor* image_serialization_processor);
void Raster(SkCanvas* canvas,
SkPicture::AbortCallback* callback,
const gfx::Rect& canvas_target_playback_rect,
float contents_scale) const;
// This is a fast path for use only if canvas_ is set and
// retain_individual_display_items_ is false. This method also updates
// approximate_op_count_.
void RasterIntoCanvas(const DisplayItem& display_item);
// Because processing happens in this function, all the set up for
// this item should be done via the args, which is why the return
// type needs to be const, to prevent set-after-processing mistakes.
template <typename DisplayItemType, typename... Args>
const DisplayItemType& CreateAndAppendItem(const gfx::Rect& visual_rect,
Args&&... args) {
visual_rects_.push_back(visual_rect);
auto* item = &items_.AllocateAndConstruct<DisplayItemType>(
std::forward<Args>(args)...);
approximate_op_count_ += item->ApproximateOpCount();
ProcessAppendedItem(item);
return *item;
}
// Called after all items are appended, to process the items and, if
// applicable, create an internally cached SkPicture.
void Finalize();
void SetIsSuitableForGpuRasterization(bool is_suitable) {
is_suitable_for_gpu_rasterization_ = is_suitable;
}
bool IsSuitableForGpuRasterization() const;
int ApproximateOpCount() const;
size_t ApproximateMemoryUsage() const;
bool ShouldBeAnalyzedForSolidColor() const;
bool RetainsIndividualDisplayItems() const;
std::unique_ptr<base::trace_event::ConvertableToTraceFormat> AsValue(
bool include_items) const;
void EmitTraceSnapshot() const;
void GenerateDiscardableImagesMetadata();
void GetDiscardableImagesInRect(const gfx::Rect& rect,
float raster_scale,
std::vector<DrawImage>* images);
gfx::Rect VisualRectForTesting(int index) { return visual_rects_[index]; }
private:
DisplayItemList(gfx::Rect layer_rect,
const DisplayItemListSettings& display_list_settings,
bool retain_individual_display_items);
~DisplayItemList();
void ProcessAppendedItem(const DisplayItem* item);
ContiguousContainer<DisplayItem> items_;
// The visual rects associated with each of the display items in the
// display item list. There is one rect per display item, and the
// position in |visual_rects_| matches the position of the item in
// |items_| . These rects are intentionally kept separate
// because they are not needed while walking the |items_| for raster.
std::vector<gfx::Rect> visual_rects_;
sk_sp<SkPicture> picture_;
std::unique_ptr<SkPictureRecorder> recorder_;
const DisplayItemListSettings settings_;
bool retain_individual_display_items_;
gfx::Rect layer_rect_;
bool is_suitable_for_gpu_rasterization_;
int approximate_op_count_;
// Memory usage due to the cached SkPicture.
size_t picture_memory_usage_;
DiscardableImageMap image_map_;
friend class base::RefCountedThreadSafe<DisplayItemList>;
FRIEND_TEST_ALL_PREFIXES(DisplayItemListTest, ApproximateMemoryUsage);
DISALLOW_COPY_AND_ASSIGN(DisplayItemList);
};
} // namespace cc
#endif // CC_PLAYBACK_DISPLAY_ITEM_LIST_H_