blob: b80faeb1a65b8028602543e1fd4e46b0ff5a1f0b [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; }
49};
50
51extern template class OpBuffer<CanvasOpType, CanvasOpContainer>;
52class CanvasOpBuffer final : public OpBuffer<CanvasOpType, CanvasOpContainer> {
53public:
54 template <CanvasOpType T>
55 void push(CanvasOp<T>&& op) {
56 push_container(CanvasOpContainer<T>(std::move(op)));
57 }
58};
59
60} // namespace android::uirenderer