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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "pipeline/skia/SkiaDisplayList.h"
#include "canvas/CanvasOpBuffer.h"
#include <memory>
#include <variant>
namespace android {
namespace uirenderer {
namespace VectorDrawable {
class Tree;
};
typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
class SkiaDisplayListWrapper {
public:
// Constructs an empty (invalid) DisplayList
explicit SkiaDisplayListWrapper() {}
// Constructs a DisplayList from a SkiaDisplayList
explicit SkiaDisplayListWrapper(std::unique_ptr<skiapipeline::SkiaDisplayList> impl)
: mImpl(std::move(impl)) {}
// Move support
SkiaDisplayListWrapper(SkiaDisplayListWrapper&& other) : mImpl(std::move(other.mImpl)) {}
SkiaDisplayListWrapper& operator=(SkiaDisplayListWrapper&& other) {
mImpl = std::move(other.mImpl);
return *this;
}
// No copy support
SkiaDisplayListWrapper(const SkiaDisplayListWrapper& other) = delete;
SkiaDisplayListWrapper& operator=(const SkiaDisplayListWrapper&) = delete;
void updateChildren(std::function<void(RenderNode*)> updateFn) {
mImpl->updateChildren(std::move(updateFn));
}
[[nodiscard]] explicit operator bool() const {
return mImpl.get() != nullptr;
}
// If true this DisplayList contains a backing content, even if that content is empty
// If false, there this DisplayList is in an "empty" state
[[nodiscard]] bool isValid() const {
return mImpl.get() != nullptr;
}
[[nodiscard]] bool isEmpty() const {
return !hasContent();
}
[[nodiscard]] bool hasContent() const {
return mImpl && !(mImpl->isEmpty());
}
[[nodiscard]] bool hasHolePunches() const {
return mImpl && mImpl->hasHolePunches();
}
[[nodiscard]] bool containsProjectionReceiver() const {
return mImpl && mImpl->containsProjectionReceiver();
}
[[nodiscard]] skiapipeline::SkiaDisplayList* asSkiaDl() {
return mImpl.get();
}
[[nodiscard]] const skiapipeline::SkiaDisplayList* asSkiaDl() const {
return mImpl.get();
}
[[nodiscard]] bool hasVectorDrawables() const {
return mImpl && mImpl->hasVectorDrawables();
}
void clear(RenderNode* owningNode = nullptr) {
if (mImpl && owningNode && mImpl->reuseDisplayList(owningNode)) {
// TODO: This is a bit sketchy to have a unique_ptr temporarily owned twice
// Do something to cleanup reuseDisplayList passing itself to the RenderNode
mImpl.release();
} else {
mImpl = nullptr;
}
}
[[nodiscard]] size_t getUsedSize() const {
return mImpl ? mImpl->getUsedSize() : 0;
}
[[nodiscard]] size_t getAllocatedSize() const {
return mImpl ? mImpl->getAllocatedSize() : 0;
}
void output(std::ostream& output, uint32_t level) const {
if (mImpl) {
mImpl->output(output, level);
}
}
[[nodiscard]] bool hasFunctor() const {
return mImpl && mImpl->hasFunctor();
}
bool prepareListAndChildren(
TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn) {
return mImpl && mImpl->prepareListAndChildren(
observer, info, functorsNeedLayer, std::move(childFn));
}
void syncContents(const WebViewSyncData& data) {
if (mImpl) {
mImpl->syncContents(data);
}
}
[[nodiscard]] bool hasText() const {
return mImpl && mImpl->hasText();
}
void applyColorTransform(ColorTransform transform) {
if (mImpl) {
mImpl->applyColorTransform(transform);
}
}
private:
std::unique_ptr<skiapipeline::SkiaDisplayList> mImpl;
};
/**
* Data structure that holds the list of commands used in display list stream
*/
//using DisplayList = skiapipeline::SkiaDisplayList;
class MultiDisplayList {
private:
using SkiaDisplayList = skiapipeline::SkiaDisplayList;
struct EmptyList {
bool hasText() const { return false; }
void updateChildren(std::function<void(RenderNode*)> updateFn) {}
bool isEmpty() const { return true; }
bool containsProjectionReceiver() const { return false; }
bool hasVectorDrawables() const { return false; }
size_t getUsedSize() const { return 0; }
size_t getAllocatedSize() const { return 0; }
void output(std::ostream& output, uint32_t level) const { }
bool hasFunctor() const { return false; }
bool prepareListAndChildren(
TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn) {
return false;
}
void syncContents(const WebViewSyncData& data) { }
void applyColorTransform(ColorTransform transform) { }
};
std::variant<EmptyList, std::unique_ptr<SkiaDisplayList>, CanvasOpBuffer> mImpls;
template <typename T>
static constexpr T& get(T& t) { return t; }
template <typename T>
static constexpr const T& get(const T& t) { return t; }
template <typename T>
static constexpr T& get(std::unique_ptr<T>& t) { return *t; }
template <typename T>
static constexpr const T& get(const std::unique_ptr<T>& t) { return *t; }
template <typename T>
auto apply(T&& t) {
return std::visit([&t](auto& it) -> auto {
return t(get(it));
}, mImpls);
}
template <typename T>
auto apply(T&& t) const {
return std::visit([&t](const auto& it) -> auto {
return t(get(it));
}, mImpls);
}
public:
// Constructs an empty (invalid) DisplayList
explicit MultiDisplayList() {}
// Constructs a DisplayList from a SkiaDisplayList
explicit MultiDisplayList(std::unique_ptr<SkiaDisplayList> impl)
: mImpls(std::move(impl)) {}
explicit MultiDisplayList(CanvasOpBuffer&& opBuffer) : mImpls(std::move(opBuffer)) {}
// Move support
MultiDisplayList(MultiDisplayList&& other) : mImpls(std::move(other.mImpls)) {}
MultiDisplayList& operator=(MultiDisplayList&& other) {
mImpls = std::move(other.mImpls);
return *this;
}
// No copy support
MultiDisplayList(const MultiDisplayList& other) = delete;
MultiDisplayList& operator=(const MultiDisplayList&) = delete;
void updateChildren(std::function<void(RenderNode*)> updateFn) {
apply([&](auto& it) { it.updateChildren(std::move(updateFn)); });
}
[[nodiscard]] explicit operator bool() const {
return isValid();
}
// If true this DisplayList contains a backing content, even if that content is empty
// If false, there this DisplayList is in an "empty" state
[[nodiscard]] bool isValid() const {
return mImpls.index() != 0;
}
[[nodiscard]] bool isEmpty() const {
return apply([](const auto& it) -> auto { return it.isEmpty(); });
}
[[nodiscard]] bool hasContent() const {
return !isEmpty();
}
[[nodiscard]] bool containsProjectionReceiver() const {
return apply([](const auto& it) -> auto { return it.containsProjectionReceiver(); });
}
[[nodiscard]] SkiaDisplayList* asSkiaDl() {
return std::get<1>(mImpls).get();
}
[[nodiscard]] const SkiaDisplayList* asSkiaDl() const {
return std::get<1>(mImpls).get();
}
[[nodiscard]] bool hasVectorDrawables() const {
return apply([](const auto& it) -> auto { return it.hasVectorDrawables(); });
}
void clear(RenderNode* owningNode = nullptr) {
if (owningNode && mImpls.index() == 1) {
auto& skiaDl = std::get<1>(mImpls);
if (skiaDl->reuseDisplayList(owningNode)) {
skiaDl.release();
}
}
mImpls = EmptyList{};
}
[[nodiscard]] size_t getUsedSize() const {
return apply([](const auto& it) -> auto { return it.getUsedSize(); });
}
[[nodiscard]] size_t getAllocatedSize() const {
return apply([](const auto& it) -> auto { return it.getAllocatedSize(); });
}
void output(std::ostream& output, uint32_t level) const {
apply([&](const auto& it) { it.output(output, level); });
}
[[nodiscard]] bool hasFunctor() const {
return apply([](const auto& it) -> auto { return it.hasFunctor(); });
}
bool prepareListAndChildren(
TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn) {
return apply([&](auto& it) -> auto {
return it.prepareListAndChildren(observer, info, functorsNeedLayer, std::move(childFn));
});
}
void syncContents(const WebViewSyncData& data) {
apply([&](auto& it) { it.syncContents(data); });
}
[[nodiscard]] bool hasText() const {
return apply([](const auto& it) -> auto { return it.hasText(); });
}
void applyColorTransform(ColorTransform transform) {
apply([=](auto& it) { it.applyColorTransform(transform); });
}
[[nodiscard]] CanvasOpBuffer& asOpBuffer() {
return std::get<CanvasOpBuffer>(mImpls);
}
};
// For now stick to the original single-type container to avoid any regressions
using DisplayList = SkiaDisplayListWrapper;
} // namespace uirenderer
} // namespace android
|