Glop.h revision 2a38c42e921451abebb4ee5f5ecd738f1b6b04ed
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#include <SkXfermode.h> 29 30namespace android { 31namespace uirenderer { 32 33class Program; 34class RoundRectClipState; 35class Texture; 36 37/* 38 * Enumerates optional vertex attributes 39 * 40 * Position is always enabled by MeshState, these other attributes 41 * are enabled/disabled dynamically based on mesh content. 42 */ 43 44namespace VertexAttribFlags { 45 enum { 46 // Mesh is pure x,y vertex pairs 47 None = 0, 48 // Mesh has texture coordinates embedded. Note that texture can exist without this flag 49 // being set, if coordinates passed to sampler are determined another way. 50 TextureCoord = 1 << 0, 51 // Mesh has color embedded (to export to varying) 52 Color = 1 << 1, 53 // Mesh has alpha embedded (to export to varying) 54 Alpha = 1 << 2, 55 }; 56}; 57 58/* 59 * Enumerates transform features 60 */ 61namespace TransformFlags { 62 enum { 63 None = 0, 64 65 // offset the eventual drawing matrix by a tiny amount to 66 // disambiguate sampling patterns with non-AA rendering 67 OffsetByFudgeFactor = 1 << 0, 68 69 // Canvas transform isn't applied to the mesh at draw time, 70 // since it's already built in. 71 MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove for HWUI_NEW_OPS 72 }; 73}; 74 75/** 76 * Structure containing all data required to issue an OpenGL draw 77 * 78 * Includes all of the mesh, fill, and GL state required to perform 79 * the operation. Pieces of data are either directly copied into the 80 * structure, or stored as a pointer or GL object reference to data 81 * managed. 82 * 83 * Eventually, a Glop should be able to be drawn multiple times from 84 * a single construction, up until GL context destruction. Currently, 85 * vertex/index/Texture/RoundRectClipState pointers prevent this from 86 * being safe. 87 */ 88struct Glop { 89 PREVENT_COPY_AND_ASSIGN(Glop); 90public: 91 Glop() { } 92 struct Mesh { 93 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported 94 95 // buffer object and void* are mutually exclusive. 96 // Only GL_UNSIGNED_SHORT supported. 97 struct Indices { 98 GLuint bufferObject; 99 const void* indices; 100 } indices; 101 102 // buffer object and void*s are mutually exclusive. 103 // TODO: enforce mutual exclusion with restricted setters and/or unions 104 struct Vertices { 105 GLuint bufferObject; 106 int attribFlags; 107 const void* position; 108 const void* texCoord; 109 const void* color; 110 GLsizei stride; 111 } vertices; 112 113 int elementCount; 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 151 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