blob: 730d9dfe57dd16dfd434cb6882135ce58e0fc69e [file] [log] [blame]
Chris Craik6c15ffa2015-02-02 13:50:55 -08001/*
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_GLOP_H
18#define ANDROID_HWUI_GLOP_H
19
20#include "Matrix.h"
21#include "Rect.h"
22#include "utils/Macros.h"
23
24#include <GLES2/gl2.h>
25#include <GLES2/gl2ext.h>
26
27namespace android {
28namespace uirenderer {
29
30/*
31 * Enumerates optional vertex attributes
32 *
33 * Position is always enabled by MeshState, these other attributes
34 * are enabled/disabled dynamically based on mesh content.
35 */
36enum VertexAttribFlags {
37 // NOTE: position attribute always enabled
38 kTextureCoord_Attrib = 1 << 0,
39 kColor_Attrib = 1 << 1,
40 kAlpha_Attrib = 1 << 2,
41};
42
43/**
44 * Structure containing all data required to issue a single OpenGL draw
45 *
46 * Includes all of the mesh, fill, and GL state required to perform
47 * the operation. Pieces of data are either directly copied into the
48 * structure, or stored as a pointer or GL object reference to data
49 * managed
50 */
51// TODO: PREVENT_COPY_AND_ASSIGN(...) or similar
52struct Glop {
53 Rect bounds;
54
55 struct Mesh {
56 VertexAttribFlags vertexFlags = static_cast<VertexAttribFlags>(0);
57 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported
58 GLuint vertexBufferObject = 0;
59 GLuint indexBufferObject = 0;
60 int vertexCount;
61 GLsizei stride;
62 } mesh;
63
64 struct Fill {
65 Program* program;
66 GLuint shaderId;
67 GLuint textureId;
68
69 struct Color {
70 float a, r, g, b;
71 } color;
72
73 /* TODO
74 union shader {
75 //...
76 }; TODO
77 union filter {
78 //color
79 //matrix + vector
80 };
81 */
82 } fill;
83
84 struct Transform {
85 Matrix4 ortho; // TODO: out of op, since this is static per FBO
86 Matrix4 modelView;
87 Matrix4 canvas;
88 bool offset;
89 } transform;
90
91 struct Blend {
92 static const SkXfermode::Mode kDisable =
93 static_cast<SkXfermode::Mode>(SkXfermode::kLastMode + 1);
94 SkXfermode::Mode mode;
95 bool swapSrcDst;
96 } blend;
97
98 /**
99 * Additional render state to enumerate:
100 * - scissor + (bits for whether each of LTRB needed?)
101 * - stencil mode (draw into, mask, count, etc)
102 */
103};
104
105} /* namespace uirenderer */
106} /* namespace android */
107
108#endif // ANDROID_HWUI_GLOP_H