blob: 07e079a7d57f38f1e492276c10ae9bfd6adf46df [file] [log] [blame]
John Reck013127b2020-10-29 20:53:51 -04001/*
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
24namespace android::uirenderer {
25
26template <CanvasOpType T>
27struct CanvasOp;
28
29template <CanvasOpType T>
30class CanvasOpContainer {
31private:
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
39public:
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 Reck90b0a1c2020-11-12 12:37:30 -050049 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 Reck013127b2020-10-29 20:53:51 -040053};
54
55extern template class OpBuffer<CanvasOpType, CanvasOpContainer>;
56class CanvasOpBuffer final : public OpBuffer<CanvasOpType, CanvasOpContainer> {
57public:
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