Glop.h revision 30036092b40badecbe64d9c2bff4850132147f78
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#ifndef ANDROID_HWUI_GLOP_H 18#define ANDROID_HWUI_GLOP_H 19 20#include "FloatColor.h" 21#include "Matrix.h" 22#include "Rect.h" 23#include "utils/Macros.h" 24 25#include <GLES2/gl2.h> 26#include <GLES2/gl2ext.h> 27#include <SkXfermode.h> 28 29namespace android { 30namespace uirenderer { 31 32class Program; 33class RoundRectClipState; 34 35/* 36 * Enumerates optional vertex attributes 37 * 38 * Position is always enabled by MeshState, these other attributes 39 * are enabled/disabled dynamically based on mesh content. 40 */ 41enum VertexAttribFlags { 42 kNone_Attrib = 0, 43 kTextureCoord_Attrib = 1 << 0, 44 kColor_Attrib = 1 << 1, 45 kAlpha_Attrib = 1 << 2, 46}; 47 48/** 49 * Structure containing all data required to issue an OpenGL draw 50 * 51 * Includes all of the mesh, fill, and GL state required to perform 52 * the operation. Pieces of data are either directly copied into the 53 * structure, or stored as a pointer or GL object reference to data 54 * managed. 55 * 56 * Eventually, a Glop should be able to be drawn multiple times from 57 * a single construction, up until GL context destruction. Currently, 58 * vertex/index/Texture/RoundRectClipState pointers prevent this from 59 * being safe. 60 */ 61// TODO: PREVENT_COPY_AND_ASSIGN(...) or similar 62struct Glop { 63 /* 64 * Stores mesh - vertex and index data. 65 * 66 * buffer objects and void*s are mutually exclusive 67 * indices are optional, currently only GL_UNSIGNED_SHORT supported 68 */ 69 struct Mesh { 70 VertexAttribFlags vertexFlags; 71 GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported 72 GLuint vertexBufferObject; 73 GLuint indexBufferObject; 74 const void* vertices; 75 const void* indices; 76 int elementCount; 77 GLsizei stride; 78 GLvoid* texCoordOffset; 79 TextureVertex mappedVertices[4]; 80 } mesh; 81 82 struct Fill { 83 Program* program; 84 85 Texture* texture; 86 GLenum textureFilter; 87 GLenum textureClamp; 88 89 bool colorEnabled; 90 FloatColor color; 91 92 /* TODO 93 union shader { 94 //... 95 }; TODO 96 */ 97 ProgramDescription::ColorFilterMode filterMode; 98 union Filter { 99 struct Matrix { 100 float matrix[16]; 101 float vector[4]; 102 } matrix; 103 FloatColor color; 104 } filter; 105 } fill; 106 107 struct Transform { 108 Matrix4 ortho; // TODO: out of op, since this is static per FBO 109 Matrix4 modelView; 110 Matrix4 canvas; 111 bool fudgingOffset; 112 } transform; 113 114 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 */ 121 struct Blend { 122 GLenum src; 123 GLenum dst; 124 } blend; 125 126 /** 127 * 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 /** 133 * 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 143