Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 1 | /* |
| 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 Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 17 | #pragma once |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 18 | |
John Reck | 844516c | 2021-01-13 10:59:10 -0500 | [diff] [blame] | 19 | #include "pipeline/skia/SkiaDisplayList.h" |
| 20 | |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame^] | 21 | #include <memory> |
| 22 | |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
Doris Liu | 67ce99b | 2016-05-17 16:50:31 -0700 | [diff] [blame] | 26 | namespace VectorDrawable { |
| 27 | class Tree; |
| 28 | }; |
| 29 | typedef uirenderer::VectorDrawable::Tree VectorDrawableRoot; |
| 30 | |
Doris Liu | 1d8e194 | 2016-03-02 15:16:28 -0800 | [diff] [blame] | 31 | /** |
John Reck | 44fd8d2 | 2014-02-26 11:00:11 -0800 | [diff] [blame] | 32 | * Data structure that holds the list of commands used in display list stream |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 33 | */ |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame^] | 34 | //using DisplayList = skiapipeline::SkiaDisplayList; |
| 35 | class DisplayList { |
| 36 | public: |
| 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 | |
| 144 | private: |
| 145 | std::unique_ptr<skiapipeline::SkiaDisplayList> mImpl; |
| 146 | }; |
Chris Craik | 0776a60 | 2013-02-14 15:36:01 -0800 | [diff] [blame] | 147 | |
Chris Blume | 7b8a808 | 2018-11-30 15:51:58 -0800 | [diff] [blame] | 148 | } // namespace uirenderer |
| 149 | } // namespace android |