RecordedOp.h revision b565df13a9e5c7b1d7d93bdfa4a793752d66d3cc
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
46// Generate OpId enum
47#define IDENTITY_FN(Type) Type,
48namespace RecordedOpId {
49    enum {
50        MAP_OPS(IDENTITY_FN)
51        Count,
52    };
53}
54static_assert(RecordedOpId::BitmapOp == 0,
55        "First index must be zero for LUTs to work");
56
57#define BASE_PARAMS const Rect& unmappedBounds, const Matrix4& localMatrix, const Rect& localClipRect, const SkPaint* paint
58#define BASE_PARAMS_PAINTLESS const Rect& unmappedBounds, const Matrix4& localMatrix, const Rect& localClipRect
59#define SUPER(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClipRect, paint)
60#define SUPER_PAINTLESS(Type) RecordedOp(RecordedOpId::Type, unmappedBounds, localMatrix, localClipRect, nullptr)
61
62struct RecordedOp {
63    /* ID from RecordedOpId - generally used for jumping into function tables */
64    const int opId;
65
66    /* bounds in *local* space, without accounting for DisplayList transformation */
67    const Rect unmappedBounds;
68
69    /* transform in recording space (vs DisplayList origin) */
70    const Matrix4 localMatrix;
71
72    /* clip in recording space */
73    const Rect localClipRect;
74
75    /* optional paint, stored in base object to simplify merging logic */
76    const SkPaint* paint;
77protected:
78    RecordedOp(unsigned int opId, BASE_PARAMS)
79            : opId(opId)
80            , unmappedBounds(unmappedBounds)
81            , localMatrix(localMatrix)
82            , localClipRect(localClipRect)
83            , paint(paint) {}
84};
85
86struct RenderNodeOp : RecordedOp {
87    RenderNodeOp(BASE_PARAMS_PAINTLESS, RenderNode* renderNode)
88            : SUPER_PAINTLESS(RenderNodeOp)
89            , renderNode(renderNode) {}
90    RenderNode * renderNode; // not const, since drawing modifies it (somehow...)
91};
92
93struct BitmapOp : RecordedOp {
94    BitmapOp(BASE_PARAMS, const SkBitmap* bitmap)
95            : SUPER(BitmapOp)
96            , bitmap(bitmap) {}
97    const SkBitmap* bitmap;
98    // TODO: asset atlas/texture id lookup?
99};
100
101struct RectOp : RecordedOp {
102    RectOp(BASE_PARAMS)
103            : SUPER(RectOp) {}
104};
105
106struct SimpleRectsOp : RecordedOp { // Filled, no AA (TODO: better name?)
107    SimpleRectsOp(BASE_PARAMS, Vertex* vertices, size_t vertexCount)
108            : SUPER(SimpleRectsOp)
109            , vertices(vertices)
110            , vertexCount(vertexCount) {}
111    Vertex* vertices;
112    const size_t vertexCount;
113};
114
115}; // namespace uirenderer
116}; // namespace android
117
118#endif // ANDROID_HWUI_RECORDED_OP_H
119