blob: 6eca468ded8a904186907ba0d8ef7a874cb006ae [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 */
44enum VertexAttribFlags {
Chris Craik117bdbc2015-02-05 10:12:38 -080045 kNone_Attrib = 0,
Chris Craik6c15ffa2015-02-02 13:50:55 -080046 kTextureCoord_Attrib = 1 << 0,
47 kColor_Attrib = 1 << 1,
48 kAlpha_Attrib = 1 << 2,
49};
50
51/**
Chris Craik0519c812015-02-11 13:17:06 -080052 * Structure containing all data required to issue an OpenGL draw
Chris Craik6c15ffa2015-02-02 13:50:55 -080053 *
54 * Includes all of the mesh, fill, and GL state required to perform
55 * the operation. Pieces of data are either directly copied into the
56 * structure, or stored as a pointer or GL object reference to data
Chris Craik0519c812015-02-11 13:17:06 -080057 * managed.
58 *
59 * Eventually, a Glop should be able to be drawn multiple times from
60 * a single construction, up until GL context destruction. Currently,
61 * vertex/index/Texture/RoundRectClipState pointers prevent this from
62 * being safe.
Chris Craik6c15ffa2015-02-02 13:50:55 -080063 */
64// TODO: PREVENT_COPY_AND_ASSIGN(...) or similar
65struct Glop {
Chris Craik117bdbc2015-02-05 10:12:38 -080066 /*
67 * Stores mesh - vertex and index data.
68 *
69 * buffer objects and void*s are mutually exclusive
Chris Craik2ab95d72015-02-06 15:25:51 -080070 * indices are optional, currently only GL_UNSIGNED_SHORT supported
Chris Craik117bdbc2015-02-05 10:12:38 -080071 */
Chris Craik6c15ffa2015-02-02 13:50:55 -080072 struct Mesh {
Chris Craik03188872015-02-02 18:39:33 -080073 VertexAttribFlags vertexFlags;
Chris Craik6c15ffa2015-02-02 13:50:55 -080074 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported
Chris Craik03188872015-02-02 18:39:33 -080075 GLuint vertexBufferObject;
76 GLuint indexBufferObject;
Chris Craik117bdbc2015-02-05 10:12:38 -080077 const void* vertices;
78 const void* indices;
Chris Craik0519c812015-02-11 13:17:06 -080079 int elementCount;
Chris Craik6c15ffa2015-02-02 13:50:55 -080080 GLsizei stride;
Chris Craik0519c812015-02-11 13:17:06 -080081 GLvoid* texCoordOffset;
82 TextureVertex mappedVertices[4];
Chris Craik6c15ffa2015-02-02 13:50:55 -080083 } mesh;
84
85 struct Fill {
86 Program* program;
Chris Craik30036092015-02-12 10:41:39 -080087
Chris Craik0519c812015-02-11 13:17:06 -080088 Texture* texture;
89 GLenum textureFilter;
Chris Craik30036092015-02-12 10:41:39 -080090 GLenum textureClamp;
Chris Craik0519c812015-02-11 13:17:06 -080091
92 bool colorEnabled;
Chris Craik117bdbc2015-02-05 10:12:38 -080093 FloatColor color;
Chris Craik6c15ffa2015-02-02 13:50:55 -080094
Chris Craik117bdbc2015-02-05 10:12:38 -080095 ProgramDescription::ColorFilterMode filterMode;
96 union Filter {
97 struct Matrix {
98 float matrix[16];
99 float vector[4];
100 } matrix;
101 FloatColor color;
102 } filter;
Chris Craik922d3a72015-02-13 17:47:21 -0800103
104 SkiaShaderData skiaShaderData;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800105 } fill;
106
107 struct Transform {
108 Matrix4 ortho; // TODO: out of op, since this is static per FBO
109 Matrix4 modelView;
110 Matrix4 canvas;
Chris Craik117bdbc2015-02-05 10:12:38 -0800111 bool fudgingOffset;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800112 } transform;
113
Chris Craik30036092015-02-12 10:41:39 -0800114 const RoundRectClipState* roundRectClipState;
115
116 /**
117 * Blending to be used by this draw - both GL_NONE if blending is disabled.
118 *
119 * Defined by fill step, but can be force-enabled by presence of kAlpha_Attrib
120 */
Chris Craik6c15ffa2015-02-02 13:50:55 -0800121 struct Blend {
Chris Craik03188872015-02-02 18:39:33 -0800122 GLenum src;
123 GLenum dst;
Chris Craik6c15ffa2015-02-02 13:50:55 -0800124 } blend;
125
126 /**
Chris Craik30036092015-02-12 10:41:39 -0800127 * Bounds of the drawing command in layer space. Only mapped into layer
128 * space once GlopBuilder::build() is called.
129 */
130 Rect bounds;
131
132 /**
Chris Craik6c15ffa2015-02-02 13:50:55 -0800133 * Additional render state to enumerate:
134 * - scissor + (bits for whether each of LTRB needed?)
135 * - stencil mode (draw into, mask, count, etc)
136 */
137};
138
139} /* namespace uirenderer */
140} /* namespace android */
141
142#endif // ANDROID_HWUI_GLOP_H