blob: e91c08d5a351304b7d9ba073aa973b34f66e05b6 [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
Chris Craik5e00c7c2016-07-06 16:10:09 -070017#pragma once
Chris Craik6c15ffa2015-02-02 13:50:55 -080018
Chris Craik0519c812015-02-11 13:17:06 -080019#include "FloatColor.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080020#include "Matrix.h"
Chris Craik922d3a72015-02-13 17:47:21 -080021#include "Program.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080022#include "Rect.h"
Chris Craik922d3a72015-02-13 17:47:21 -080023#include "SkiaShader.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080024#include "utils/Macros.h"
25
26#include <GLES2/gl2.h>
27#include <GLES2/gl2ext.h>
28
29namespace android {
30namespace uirenderer {
31
Chris Craik03188872015-02-02 18:39:33 -080032class Program;
Chris Craik0519c812015-02-11 13:17:06 -080033class RoundRectClipState;
Chris Craik922d3a72015-02-13 17:47:21 -080034class Texture;
Chris Craik03188872015-02-02 18:39:33 -080035
Chris Craik6c15ffa2015-02-02 13:50:55 -080036/*
37 * Enumerates optional vertex attributes
38 *
39 * Position is always enabled by MeshState, these other attributes
40 * are enabled/disabled dynamically based on mesh content.
41 */
Chris Craik53e51e42015-06-01 10:35:35 -070042
43namespace VertexAttribFlags {
44 enum {
Chris Craik138c21f2016-04-28 16:59:42 -070045 // Mesh is pure x,y vertex pairs
Chris Craik53e51e42015-06-01 10:35:35 -070046 None = 0,
Chris Craik138c21f2016-04-28 16:59:42 -070047 // Mesh has texture coordinates embedded. Note that texture can exist without this flag
48 // being set, if coordinates passed to sampler are determined another way.
Chris Craik53e51e42015-06-01 10:35:35 -070049 TextureCoord = 1 << 0,
Chris Craik138c21f2016-04-28 16:59:42 -070050 // Mesh has color embedded (to export to varying)
Chris Craik53e51e42015-06-01 10:35:35 -070051 Color = 1 << 1,
Chris Craik138c21f2016-04-28 16:59:42 -070052 // Mesh has alpha embedded (to export to varying)
Chris Craik53e51e42015-06-01 10:35:35 -070053 Alpha = 1 << 2,
54 };
Chris Craik6c15ffa2015-02-02 13:50:55 -080055};
Chris Craik53e51e42015-06-01 10:35:35 -070056
57/*
58 * Enumerates transform features
59 */
60namespace TransformFlags {
61 enum {
62 None = 0,
63
64 // offset the eventual drawing matrix by a tiny amount to
65 // disambiguate sampling patterns with non-AA rendering
66 OffsetByFudgeFactor = 1 << 0,
67
68 // Canvas transform isn't applied to the mesh at draw time,
Chris Craik5e00c7c2016-07-06 16:10:09 -070069 // since it's already built in.
Chris Craike4db79d2015-12-22 16:32:23 -080070 MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove for HWUI_NEW_OPS
Chris Craik53e51e42015-06-01 10:35:35 -070071 };
72};
Chris Craik6c15ffa2015-02-02 13:50:55 -080073
74/**
Chris Craik0519c812015-02-11 13:17:06 -080075 * Structure containing all data required to issue an OpenGL draw
Chris Craik6c15ffa2015-02-02 13:50:55 -080076 *
77 * Includes all of the mesh, fill, and GL state required to perform
78 * the operation. Pieces of data are either directly copied into the
79 * structure, or stored as a pointer or GL object reference to data
Chris Craik0519c812015-02-11 13:17:06 -080080 * managed.
81 *
82 * Eventually, a Glop should be able to be drawn multiple times from
83 * a single construction, up until GL context destruction. Currently,
84 * vertex/index/Texture/RoundRectClipState pointers prevent this from
85 * being safe.
Chris Craik6c15ffa2015-02-02 13:50:55 -080086 */
Chris Craik6c15ffa2015-02-02 13:50:55 -080087struct Glop {
sergeyvf42bf3e2016-03-11 13:45:15 -080088 PREVENT_COPY_AND_ASSIGN(Glop);
89public:
90 Glop() { }
Chris Craik6c15ffa2015-02-02 13:50:55 -080091 struct Mesh {
Chris Craik6c15ffa2015-02-02 13:50:55 -080092 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported
Chris Craikef250742015-02-25 17:16:16 -080093
94 // buffer object and void* are mutually exclusive.
95 // Only GL_UNSIGNED_SHORT supported.
96 struct Indices {
97 GLuint bufferObject;
98 const void* indices;
99 } indices;
100
101 // buffer object and void*s are mutually exclusive.
102 // TODO: enforce mutual exclusion with restricted setters and/or unions
103 struct Vertices {
104 GLuint bufferObject;
Chris Craikeb911c22015-03-06 17:30:11 -0800105 int attribFlags;
Chris Craikef250742015-02-25 17:16:16 -0800106 const void* position;
107 const void* texCoord;
108 const void* color;
109 GLsizei stride;
110 } vertices;
111
Chris Craik0519c812015-02-11 13:17:06 -0800112 int elementCount;
Arunb0a94772017-01-23 11:41:06 +0000113 int vertexCount; // only used for meshes (for glDrawRangeElements)
Chris Craik0519c812015-02-11 13:17:06 -0800114 TextureVertex mappedVertices[4];
Chris Craik6c15ffa2015-02-02 13:50:55 -0800115 } mesh;
116
117 struct Fill {
118 Program* program;
Chris Craik30036092015-02-12 10:41:39 -0800119
Chris Craikf27133d2015-02-19 09:51:53 -0800120 struct TextureData {
121 Texture* texture;
122 GLenum filter;
123 GLenum clamp;
Chris Craik26bf3422015-02-26 16:28:17 -0800124 Matrix4* textureTransform;
Chris Craikf27133d2015-02-19 09:51:53 -0800125 } texture;
Chris Craik0519c812015-02-11 13:17:06 -0800126
127 bool colorEnabled;
Chris Craik117bdbc2015-02-05 10:12:38 -0800128 FloatColor color;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800129
Chris Craik117bdbc2015-02-05 10:12:38 -0800130 ProgramDescription::ColorFilterMode filterMode;
131 union Filter {
132 struct Matrix {
133 float matrix[16];
134 float vector[4];
135 } matrix;
136 FloatColor color;
137 } filter;
Chris Craik922d3a72015-02-13 17:47:21 -0800138
139 SkiaShaderData skiaShaderData;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800140 } fill;
141
142 struct Transform {
Chris Craik53e51e42015-06-01 10:35:35 -0700143 // modelView transform, accounting for delta between mesh transform and content of the mesh
144 // often represents x/y offsets within command, or scaling for mesh unit size
Chris Craik6c15ffa2015-02-02 13:50:55 -0800145 Matrix4 modelView;
Chris Craik53e51e42015-06-01 10:35:35 -0700146
147 // Canvas transform of Glop - not necessarily applied to geometry (see flags)
Chris Craik6c15ffa2015-02-02 13:50:55 -0800148 Matrix4 canvas;
Chris Craik53e51e42015-06-01 10:35:35 -0700149 int transformFlags;
150
151 const Matrix4& meshTransform() const {
152 return (transformFlags & TransformFlags::MeshIgnoresCanvasTransform)
153 ? Matrix4::identity() : canvas;
154 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800155 } transform;
156
sergeyvf42bf3e2016-03-11 13:45:15 -0800157 const RoundRectClipState* roundRectClipState = nullptr;
Chris Craik30036092015-02-12 10:41:39 -0800158
159 /**
160 * Blending to be used by this draw - both GL_NONE if blending is disabled.
161 *
162 * Defined by fill step, but can be force-enabled by presence of kAlpha_Attrib
163 */
Chris Craik6c15ffa2015-02-02 13:50:55 -0800164 struct Blend {
Chris Craik03188872015-02-02 18:39:33 -0800165 GLenum src;
166 GLenum dst;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800167 } blend;
168
Chris Craik30036092015-02-12 10:41:39 -0800169 /**
Chris Craik6c15ffa2015-02-02 13:50:55 -0800170 * Additional render state to enumerate:
171 * - scissor + (bits for whether each of LTRB needed?)
172 * - stencil mode (draw into, mask, count, etc)
173 */
174};
175
176} /* namespace uirenderer */
177} /* namespace android */