blob: 3aa5b4bf72f8ea9cefcb5bcde137f86b7d1431f4 [file] [log] [blame]
Chris Craik0776a602013-02-14 15:36:01 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Chris Craik5e00c7c2016-07-06 16:10:09 -070017#pragma once
Chris Craik0776a602013-02-14 15:36:01 -080018
John Reck844516c2021-01-13 10:59:10 -050019#include "pipeline/skia/SkiaDisplayList.h"
20
John Reckbe671952021-01-13 22:39:32 -050021#include <memory>
22
Chris Craik0776a602013-02-14 15:36:01 -080023namespace android {
24namespace uirenderer {
25
Doris Liu67ce99b2016-05-17 16:50:31 -070026namespace VectorDrawable {
27class Tree;
28};
29typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot;
30
Doris Liu1d8e1942016-03-02 15:16:28 -080031/**
John Reck44fd8d22014-02-26 11:00:11 -080032 * Data structure that holds the list of commands used in display list stream
Chris Craik0776a602013-02-14 15:36:01 -080033 */
John Reckbe671952021-01-13 22:39:32 -050034//using DisplayList = skiapipeline::SkiaDisplayList;
35class DisplayList {
36public:
37 // Constructs an empty (invalid) DisplayList
38 explicit DisplayList() {}
39
40 // Constructs a DisplayList from a SkiaDisplayList
41 explicit DisplayList(std::unique_ptr<skiapipeline::SkiaDisplayList> impl)
42 : mImpl(std::move(impl)) {}
43
44 // Move support
45 DisplayList(DisplayList&& other) : mImpl(std::move(other.mImpl)) {}
46 DisplayList& operator=(DisplayList&& other) {
47 mImpl = std::move(other.mImpl);
48 return *this;
49 }
50
51 // No copy support
52 DisplayList(const DisplayList& other) = delete;
53 DisplayList& operator=(const DisplayList&) = delete;
54
55 void updateChildren(std::function<void(RenderNode*)> updateFn) {
56 mImpl->updateChildren(std::move(updateFn));
57 }
58
59 [[nodiscard]] explicit operator bool() const {
60 return mImpl.get() != nullptr;
61 }
62
63 // If true this DisplayList contains a backing content, even if that content is empty
64 // If false, there this DisplayList is in an "empty" state
65 [[nodiscard]] bool isValid() const {
66 return mImpl.get() != nullptr;
67 }
68
69 [[nodiscard]] bool isEmpty() const {
70 return !hasContent();
71 }
72
73 [[nodiscard]] bool hasContent() const {
74 return mImpl && !(mImpl->isEmpty());
75 }
76
77 [[nodiscard]] bool containsProjectionReceiver() const {
78 return mImpl && mImpl->containsProjectionReceiver();
79 }
80
81 [[nodiscard]] skiapipeline::SkiaDisplayList* asSkiaDl() {
82 return mImpl.get();
83 }
84
85 [[nodiscard]] const skiapipeline::SkiaDisplayList* asSkiaDl() const {
86 return mImpl.get();
87 }
88
89 [[nodiscard]] bool hasVectorDrawables() const {
90 return mImpl && mImpl->hasVectorDrawables();
91 }
92
93 void clear(RenderNode* owningNode = nullptr) {
94 if (mImpl && owningNode && mImpl->reuseDisplayList(owningNode)) {
95 // TODO: This is a bit sketchy to have a unique_ptr temporarily owned twice
96 // Do something to cleanup reuseDisplayList passing itself to the RenderNode
97 mImpl.release();
98 } else {
99 mImpl = nullptr;
100 }
101 }
102
103 [[nodiscard]] size_t getUsedSize() const {
104 return mImpl ? mImpl->getUsedSize() : 0;
105 }
106
107 [[nodiscard]] size_t getAllocatedSize() const {
108 return mImpl ? mImpl->getAllocatedSize() : 0;
109 }
110
111 void output(std::ostream& output, uint32_t level) const {
112 if (mImpl) {
113 mImpl->output(output, level);
114 }
115 }
116
117 [[nodiscard]] bool hasFunctor() const {
118 return mImpl && mImpl->hasFunctor();
119 }
120
121 bool prepareListAndChildren(
122 TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer,
123 std::function<void(RenderNode*, TreeObserver&, TreeInfo&, bool)> childFn) {
124 return mImpl && mImpl->prepareListAndChildren(
125 observer, info, functorsNeedLayer, std::move(childFn));
126 }
127
128 void syncContents(const WebViewSyncData& data) {
129 if (mImpl) {
130 mImpl->syncContents(data);
131 }
132 }
133
134 [[nodiscard]] bool hasText() const {
135 return mImpl && mImpl->hasText();
136 }
137
138 void applyColorTransform(ColorTransform transform) {
139 if (mImpl) {
140 mImpl->mDisplayList.applyColorTransform(transform);
141 }
142 }
143
144private:
145 std::unique_ptr<skiapipeline::SkiaDisplayList> mImpl;
146};
Chris Craik0776a602013-02-14 15:36:01 -0800147
Chris Blume7b8a8082018-11-30 15:51:58 -0800148} // namespace uirenderer
149} // namespace android