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 #pragma once 18 19 #include "FloatColor.h" 20 #include "Matrix.h" 21 #include "Program.h" 22 #include "Rect.h" 23 #include "SkiaShader.h" 24 #include "utils/Macros.h" 25 26 #include <GLES2/gl2.h> 27 #include <GLES2/gl2ext.h> 28 29 namespace android { 30 namespace uirenderer { 31 32 class Program; 33 class RoundRectClipState; 34 class Texture; 35 36 /* 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 */ 42 43 namespace VertexAttribFlags { 44 enum { 45 // Mesh is pure x,y vertex pairs 46 None = 0, 47 // 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. 49 TextureCoord = 1 << 0, 50 // Mesh has color embedded (to export to varying) 51 Color = 1 << 1, 52 // Mesh has alpha embedded (to export to varying) 53 Alpha = 1 << 2, 54 }; 55 }; 56 57 /* 58 * Enumerates transform features 59 */ 60 namespace 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, 69 // since it's already built in. 70 MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove for HWUI_NEW_OPS 71 }; 72 }; 73 74 /** 75 * Structure containing all data required to issue an OpenGL draw 76 * 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 80 * 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. 86 */ 87 struct Glop { 88 PREVENT_COPY_AND_ASSIGN(Glop); 89 public: GlopGlop90 Glop() { } 91 struct Mesh { 92 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported 93 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; 105 int attribFlags; 106 const void* position; 107 const void* texCoord; 108 const void* color; 109 GLsizei stride; 110 } vertices; 111 112 int elementCount; 113 int vertexCount; // only used for meshes (for glDrawRangeElements) 114 TextureVertex mappedVertices[4]; 115 } mesh; 116 117 struct Fill { 118 Program* program; 119 120 struct TextureData { 121 Texture* texture; 122 GLenum filter; 123 GLenum clamp; 124 Matrix4* textureTransform; 125 } texture; 126 127 bool colorEnabled; 128 FloatColor color; 129 130 ProgramDescription::ColorFilterMode filterMode; 131 union Filter { 132 struct Matrix { 133 float matrix[16]; 134 float vector[4]; 135 } matrix; 136 FloatColor color; 137 } filter; 138 139 SkiaShaderData skiaShaderData; 140 } fill; 141 142 struct Transform { 143 // 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 145 Matrix4 modelView; 146 147 // Canvas transform of Glop - not necessarily applied to geometry (see flags) 148 Matrix4 canvas; 149 int transformFlags; 150 meshTransformGlop::Transform151 const Matrix4& meshTransform() const { 152 return (transformFlags & TransformFlags::MeshIgnoresCanvasTransform) 153 ? Matrix4::identity() : canvas; 154 } 155 } transform; 156 157 const RoundRectClipState* roundRectClipState = nullptr; 158 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 */ 164 struct Blend { 165 GLenum src; 166 GLenum dst; 167 } blend; 168 169 /** 170 * 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 */ 178