John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 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 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <SkMatrix.h> |
| 20 | |
| 21 | #include "CanvasOpTypes.h" |
| 22 | #include "OpBuffer.h" |
| 23 | |
| 24 | namespace android::uirenderer { |
| 25 | |
| 26 | template <CanvasOpType T> |
| 27 | struct CanvasOp; |
| 28 | |
| 29 | template <CanvasOpType T> |
| 30 | class CanvasOpContainer { |
| 31 | private: |
| 32 | BE_OPBUFFERS_FRIEND(); |
| 33 | |
| 34 | OpBufferItemHeader<CanvasOpType> header; |
| 35 | // TODO: Figure out some magic to make this not be here when it's identity (or not used) |
| 36 | SkMatrix mTransform; |
| 37 | CanvasOp<T> mImpl; |
| 38 | |
| 39 | public: |
| 40 | CanvasOpContainer(CanvasOp<T>&& impl, const SkMatrix& transform = SkMatrix::I()) |
| 41 | : mTransform(transform), mImpl(std::move(impl)) {} |
| 42 | |
| 43 | uint32_t size() const { return header.size; } |
| 44 | CanvasOpType type() const { return header.type; } |
| 45 | |
| 46 | const SkMatrix& transform() const { return mTransform; } |
| 47 | |
| 48 | CanvasOp<T>* operator->() noexcept { return &mImpl; } |
John Reck | 90b0a1c | 2020-11-12 12:37:30 -0500 | [diff] [blame] | 49 | const CanvasOp<T>* operator->() const noexcept { return &mImpl; } |
| 50 | |
| 51 | CanvasOp<T>& op() noexcept { return mImpl; } |
| 52 | const CanvasOp<T>& op() const noexcept { return mImpl; } |
John Reck | 013127b | 2020-10-29 20:53:51 -0400 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | extern template class OpBuffer<CanvasOpType, CanvasOpContainer>; |
| 56 | class CanvasOpBuffer final : public OpBuffer<CanvasOpType, CanvasOpContainer> { |
| 57 | public: |
| 58 | template <CanvasOpType T> |
| 59 | void push(CanvasOp<T>&& op) { |
| 60 | push_container(CanvasOpContainer<T>(std::move(op))); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | } // namespace android::uirenderer |