RecordedOp.h revision 6fe991e5e76f9af9dab960100d5768d96d5f4daa
1/*
2 * Copyright (C) 2015 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#ifndef ANDROID_HWUI_RECORDED_OP_H
18#define ANDROID_HWUI_RECORDED_OP_H
19
20#include "utils/LinearAllocator.h"
21#include "Rect.h"
22#include "Matrix.h"
23
24#include "SkXfermode.h"
25
26class SkBitmap;
27class SkPaint;
28
29namespace android {
30namespace uirenderer {
31
32class RenderNode;
33struct Vertex;
34
35/**
36 * The provided macro is executed for each op type in order, with the results separated by commas.
37 *
38 * This serves as the authoritative list of ops, used for generating ID enum, and ID based LUTs.
39 */
40#define MAP_OPS(OP_FN) \
41        OP_FN(BitmapOp) \
42        OP_FN(RectOp) \
43        OP_FN(RenderNodeOp) \
44        OP_FN(SimpleRectsOp) \
45        OP_FN(BeginLayerOp) \
46        OP_FN(EndLayerOp) \
47        OP_FN(LayerOp)
48
49// Generate OpId enum
50#define IDENTITY_FN(Type) Type,
51namespace RecordedOpId {
52    enum {
53        MAP_OPS(IDENTITY_FN)
54        Count,
55    };
56}
57static_assert(RecordedOpId::BitmapOp == 0,
58        "First index must be zero for LUTs to work");
59
60#define BASE_PARAMS const Rect& unmappedBounds, const Matrix4& localMatrix, const Rect& localClipRect, const SkPaint* paint
61#define BASE_PARAMS_PAINTLESS const Rect& unmappedBounds, const Matrix4& localMatrix, const Rect& localClipRect
62#define SUPER(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClipRect, paint)
63#define SUPER_PAINTLESS(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClipRect, nullptr)
64
65struct RecordedOp {
66    /* ID from RecordedOpId - generally used for jumping into function tables */
67    const int opId;
68
69    /* bounds in *local* space, without accounting for DisplayList transformation */
70    const Rect unmappedBounds;
71
72    /* transform in recording space (vs DisplayList origin) */
73    const Matrix4 localMatrix;
74
75    /* clip in recording space */
76    const Rect localClipRect;
77
78    /* optional paint, stored in base object to simplify merging logic */
79    const SkPaint* paint;
80protected:
81    RecordedOp(unsigned int opId, BASE_PARAMS)
82            : opId(opId)
83            , unmappedBounds(unmappedBounds)
84            , localMatrix(localMatrix)
85            , localClipRect(localClipRect)
86            , paint(paint) {}
87};
88
89struct RenderNodeOp : RecordedOp {
90    RenderNodeOp(BASE_PARAMS_PAINTLESS, RenderNode* renderNode)
91            : SUPER_PAINTLESS(RenderNodeOp)
92            , renderNode(renderNode) {}
93    RenderNode * renderNode; // not const, since drawing modifies it (somehow...)
94};
95
96struct BitmapOp : RecordedOp {
97    BitmapOp(BASE_PARAMS, const SkBitmap* bitmap)
98            : SUPER(BitmapOp)
99            , bitmap(bitmap) {}
100    const SkBitmap* bitmap;
101    // TODO: asset atlas/texture id lookup?
102};
103
104struct RectOp : RecordedOp {
105    RectOp(BASE_PARAMS)
106            : SUPER(RectOp) {}
107};
108
109struct SimpleRectsOp : RecordedOp { // Filled, no AA (TODO: better name?)
110    SimpleRectsOp(BASE_PARAMS, Vertex* vertices, size_t vertexCount)
111            : SUPER(SimpleRectsOp)
112            , vertices(vertices)
113            , vertexCount(vertexCount) {}
114    Vertex* vertices;
115    const size_t vertexCount;
116};
117
118/**
119 * Stateful operation! denotes the creation of an off-screen layer,
120 * and that commands following will render into it.
121 */
122struct BeginLayerOp : RecordedOp {
123    BeginLayerOp(BASE_PARAMS)
124            : SUPER(BeginLayerOp) {}
125};
126
127/**
128 * Stateful operation! Denotes end of off-screen layer, and that
129 * commands since last BeginLayerOp should be drawn into parent FBO.
130 *
131 * State in this op is empty, it just serves to signal that a layer has been finished.
132 */
133struct EndLayerOp : RecordedOp {
134    EndLayerOp()
135            : RecordedOp(RecordedOpId::EndLayerOp, Rect(0, 0), Matrix4::identity(), Rect(0, 0), nullptr) {}
136};
137
138struct LayerOp : RecordedOp {
139    LayerOp(BASE_PARAMS)
140            : SUPER(LayerOp) {}
141};
142
143}; // namespace uirenderer
144}; // namespace android
145
146#endif // ANDROID_HWUI_RECORDED_OP_H
147