blob: 6a9663412a0086f1aafa0162fa989a02abe987f2 [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
Chris Craik0519c812015-02-11 13:17:06 -080020#include "FloatColor.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080021#include "Matrix.h"
Chris Craik922d3a72015-02-13 17:47:21 -080022#include "Program.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080023#include "Rect.h"
Chris Craik922d3a72015-02-13 17:47:21 -080024#include "SkiaShader.h"
Chris Craik6c15ffa2015-02-02 13:50:55 -080025#include "utils/Macros.h"
26
27#include <GLES2/gl2.h>
28#include <GLES2/gl2ext.h>
Chris Craik03188872015-02-02 18:39:33 -080029#include <SkXfermode.h>
Chris Craik6c15ffa2015-02-02 13:50:55 -080030
31namespace android {
32namespace uirenderer {
33
Chris Craik03188872015-02-02 18:39:33 -080034class Program;
Chris Craik0519c812015-02-11 13:17:06 -080035class RoundRectClipState;
Chris Craik922d3a72015-02-13 17:47:21 -080036class Texture;
Chris Craik03188872015-02-02 18:39:33 -080037
Chris Craik6c15ffa2015-02-02 13:50:55 -080038/*
39 * Enumerates optional vertex attributes
40 *
41 * Position is always enabled by MeshState, these other attributes
42 * are enabled/disabled dynamically based on mesh content.
43 */
Chris Craik53e51e42015-06-01 10:35:35 -070044
45namespace VertexAttribFlags {
46 enum {
47 None = 0,
48 TextureCoord = 1 << 0,
49 Color = 1 << 1,
50 Alpha = 1 << 2,
51 };
Chris Craik6c15ffa2015-02-02 13:50:55 -080052};
Chris Craik53e51e42015-06-01 10:35:35 -070053
54/*
55 * Enumerates transform features
56 */
57namespace TransformFlags {
58 enum {
59 None = 0,
60
61 // offset the eventual drawing matrix by a tiny amount to
62 // disambiguate sampling patterns with non-AA rendering
63 OffsetByFudgeFactor = 1 << 0,
64
65 // Canvas transform isn't applied to the mesh at draw time,
66 //since it's already built in.
Chris Craike4db79d2015-12-22 16:32:23 -080067 MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove for HWUI_NEW_OPS
Chris Craik53e51e42015-06-01 10:35:35 -070068 };
69};
Chris Craik6c15ffa2015-02-02 13:50:55 -080070
71/**
Chris Craik0519c812015-02-11 13:17:06 -080072 * Structure containing all data required to issue an OpenGL draw
Chris Craik6c15ffa2015-02-02 13:50:55 -080073 *
74 * Includes all of the mesh, fill, and GL state required to perform
75 * the operation. Pieces of data are either directly copied into the
76 * structure, or stored as a pointer or GL object reference to data
Chris Craik0519c812015-02-11 13:17:06 -080077 * managed.
78 *
79 * Eventually, a Glop should be able to be drawn multiple times from
80 * a single construction, up until GL context destruction. Currently,
81 * vertex/index/Texture/RoundRectClipState pointers prevent this from
82 * being safe.
Chris Craik6c15ffa2015-02-02 13:50:55 -080083 */
Chris Craik6c15ffa2015-02-02 13:50:55 -080084struct Glop {
sergeyvf42bf3e2016-03-11 13:45:15 -080085 PREVENT_COPY_AND_ASSIGN(Glop);
86public:
87 Glop() { }
Chris Craik6c15ffa2015-02-02 13:50:55 -080088 struct Mesh {
Chris Craik6c15ffa2015-02-02 13:50:55 -080089 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported
Chris Craikef250742015-02-25 17:16:16 -080090
91 // buffer object and void* are mutually exclusive.
92 // Only GL_UNSIGNED_SHORT supported.
93 struct Indices {
94 GLuint bufferObject;
95 const void* indices;
96 } indices;
97
98 // buffer object and void*s are mutually exclusive.
99 // TODO: enforce mutual exclusion with restricted setters and/or unions
100 struct Vertices {
101 GLuint bufferObject;
Chris Craikeb911c22015-03-06 17:30:11 -0800102 int attribFlags;
Chris Craikef250742015-02-25 17:16:16 -0800103 const void* position;
104 const void* texCoord;
105 const void* color;
106 GLsizei stride;
107 } vertices;
108
Chris Craik0519c812015-02-11 13:17:06 -0800109 int elementCount;
Chris Craik0519c812015-02-11 13:17:06 -0800110 TextureVertex mappedVertices[4];
Chris Craik6c15ffa2015-02-02 13:50:55 -0800111 } mesh;
112
113 struct Fill {
114 Program* program;
Chris Craik30036092015-02-12 10:41:39 -0800115
Chris Craikf27133d2015-02-19 09:51:53 -0800116 struct TextureData {
117 Texture* texture;
Chris Craik26bf3422015-02-26 16:28:17 -0800118 GLenum target;
Chris Craikf27133d2015-02-19 09:51:53 -0800119 GLenum filter;
120 GLenum clamp;
Chris Craik26bf3422015-02-26 16:28:17 -0800121 Matrix4* textureTransform;
Chris Craikf27133d2015-02-19 09:51:53 -0800122 } texture;
Chris Craik0519c812015-02-11 13:17:06 -0800123
124 bool colorEnabled;
Chris Craik117bdbc2015-02-05 10:12:38 -0800125 FloatColor color;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800126
Chris Craik117bdbc2015-02-05 10:12:38 -0800127 ProgramDescription::ColorFilterMode filterMode;
128 union Filter {
129 struct Matrix {
130 float matrix[16];
131 float vector[4];
132 } matrix;
133 FloatColor color;
134 } filter;
Chris Craik922d3a72015-02-13 17:47:21 -0800135
136 SkiaShaderData skiaShaderData;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800137 } fill;
138
139 struct Transform {
Chris Craik53e51e42015-06-01 10:35:35 -0700140 // modelView transform, accounting for delta between mesh transform and content of the mesh
141 // often represents x/y offsets within command, or scaling for mesh unit size
Chris Craik6c15ffa2015-02-02 13:50:55 -0800142 Matrix4 modelView;
Chris Craik53e51e42015-06-01 10:35:35 -0700143
144 // Canvas transform of Glop - not necessarily applied to geometry (see flags)
Chris Craik6c15ffa2015-02-02 13:50:55 -0800145 Matrix4 canvas;
Chris Craik53e51e42015-06-01 10:35:35 -0700146 int transformFlags;
147
148 const Matrix4& meshTransform() const {
149 return (transformFlags & TransformFlags::MeshIgnoresCanvasTransform)
150 ? Matrix4::identity() : canvas;
151 }
Chris Craik6c15ffa2015-02-02 13:50:55 -0800152 } transform;
153
sergeyvf42bf3e2016-03-11 13:45:15 -0800154 const RoundRectClipState* roundRectClipState = nullptr;
Chris Craik30036092015-02-12 10:41:39 -0800155
156 /**
157 * Blending to be used by this draw - both GL_NONE if blending is disabled.
158 *
159 * Defined by fill step, but can be force-enabled by presence of kAlpha_Attrib
160 */
Chris Craik6c15ffa2015-02-02 13:50:55 -0800161 struct Blend {
Chris Craik03188872015-02-02 18:39:33 -0800162 GLenum src;
163 GLenum dst;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800164 } blend;
165
Chris Craik70969cc2016-03-30 18:09:17 -0700166#if !HWUI_NEW_OPS
Chris Craik6c15ffa2015-02-02 13:50:55 -0800167 /**
Chris Craik30036092015-02-12 10:41:39 -0800168 * Bounds of the drawing command in layer space. Only mapped into layer
169 * space once GlopBuilder::build() is called.
170 */
sergeyvf42bf3e2016-03-11 13:45:15 -0800171 Rect bounds; // TODO: remove for HWUI_NEW_OPS
Chris Craik70969cc2016-03-30 18:09:17 -0700172#endif
Chris Craik30036092015-02-12 10:41:39 -0800173
174 /**
Chris Craik6c15ffa2015-02-02 13:50:55 -0800175 * Additional render state to enumerate:
176 * - scissor + (bits for whether each of LTRB needed?)
177 * - stencil mode (draw into, mask, count, etc)
178 */
179};
180
181} /* namespace uirenderer */
182} /* namespace android */
183
184#endif // ANDROID_HWUI_GLOP_H