Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 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 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 20 | #include "FloatColor.h" |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 21 | #include "Matrix.h" |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 22 | #include "Program.h" |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 23 | #include "Rect.h" |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 24 | #include "SkiaShader.h" |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 25 | #include "utils/Macros.h" |
| 26 | |
| 27 | #include <GLES2/gl2.h> |
| 28 | #include <GLES2/gl2ext.h> |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 29 | #include <SkXfermode.h> |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | namespace uirenderer { |
| 33 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 34 | class Program; |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 35 | class RoundRectClipState; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 36 | class Texture; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 37 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 38 | /* |
| 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 Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 44 | |
| 45 | namespace VertexAttribFlags { |
| 46 | enum { |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 47 | // Mesh is pure x,y vertex pairs |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 48 | None = 0, |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 49 | // Mesh has texture coordinates embedded. Note that texture can exist without this flag |
| 50 | // being set, if coordinates passed to sampler are determined another way. |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 51 | TextureCoord = 1 << 0, |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 52 | // Mesh has color embedded (to export to varying) |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 53 | Color = 1 << 1, |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 54 | // Mesh has alpha embedded (to export to varying) |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 55 | Alpha = 1 << 2, |
| 56 | }; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 57 | }; |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Enumerates transform features |
| 61 | */ |
| 62 | namespace TransformFlags { |
| 63 | enum { |
| 64 | None = 0, |
| 65 | |
| 66 | // offset the eventual drawing matrix by a tiny amount to |
| 67 | // disambiguate sampling patterns with non-AA rendering |
| 68 | OffsetByFudgeFactor = 1 << 0, |
| 69 | |
| 70 | // Canvas transform isn't applied to the mesh at draw time, |
| 71 | //since it's already built in. |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 72 | MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove for HWUI_NEW_OPS |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 73 | }; |
| 74 | }; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 75 | |
| 76 | /** |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 77 | * Structure containing all data required to issue an OpenGL draw |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 78 | * |
| 79 | * Includes all of the mesh, fill, and GL state required to perform |
| 80 | * the operation. Pieces of data are either directly copied into the |
| 81 | * structure, or stored as a pointer or GL object reference to data |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 82 | * managed. |
| 83 | * |
| 84 | * Eventually, a Glop should be able to be drawn multiple times from |
| 85 | * a single construction, up until GL context destruction. Currently, |
| 86 | * vertex/index/Texture/RoundRectClipState pointers prevent this from |
| 87 | * being safe. |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 88 | */ |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 89 | struct Glop { |
sergeyv | f42bf3e | 2016-03-11 13:45:15 -0800 | [diff] [blame] | 90 | PREVENT_COPY_AND_ASSIGN(Glop); |
| 91 | public: |
| 92 | Glop() { } |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 93 | struct Mesh { |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 94 | GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 95 | |
| 96 | // buffer object and void* are mutually exclusive. |
| 97 | // Only GL_UNSIGNED_SHORT supported. |
| 98 | struct Indices { |
| 99 | GLuint bufferObject; |
| 100 | const void* indices; |
| 101 | } indices; |
| 102 | |
| 103 | // buffer object and void*s are mutually exclusive. |
| 104 | // TODO: enforce mutual exclusion with restricted setters and/or unions |
| 105 | struct Vertices { |
| 106 | GLuint bufferObject; |
Chris Craik | eb911c2 | 2015-03-06 17:30:11 -0800 | [diff] [blame] | 107 | int attribFlags; |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 108 | const void* position; |
| 109 | const void* texCoord; |
| 110 | const void* color; |
| 111 | GLsizei stride; |
| 112 | } vertices; |
| 113 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 114 | int elementCount; |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 115 | TextureVertex mappedVertices[4]; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 116 | } mesh; |
| 117 | |
| 118 | struct Fill { |
| 119 | Program* program; |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 120 | |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 121 | struct TextureData { |
| 122 | Texture* texture; |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame] | 123 | GLenum target; |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 124 | GLenum filter; |
| 125 | GLenum clamp; |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame] | 126 | Matrix4* textureTransform; |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 127 | } texture; |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 128 | |
| 129 | bool colorEnabled; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 130 | FloatColor color; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 131 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 132 | ProgramDescription::ColorFilterMode filterMode; |
| 133 | union Filter { |
| 134 | struct Matrix { |
| 135 | float matrix[16]; |
| 136 | float vector[4]; |
| 137 | } matrix; |
| 138 | FloatColor color; |
| 139 | } filter; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 140 | |
| 141 | SkiaShaderData skiaShaderData; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 142 | } fill; |
| 143 | |
| 144 | struct Transform { |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 145 | // modelView transform, accounting for delta between mesh transform and content of the mesh |
| 146 | // often represents x/y offsets within command, or scaling for mesh unit size |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 147 | Matrix4 modelView; |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 148 | |
| 149 | // Canvas transform of Glop - not necessarily applied to geometry (see flags) |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 150 | Matrix4 canvas; |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 151 | int transformFlags; |
| 152 | |
| 153 | const Matrix4& meshTransform() const { |
| 154 | return (transformFlags & TransformFlags::MeshIgnoresCanvasTransform) |
| 155 | ? Matrix4::identity() : canvas; |
| 156 | } |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 157 | } transform; |
| 158 | |
sergeyv | f42bf3e | 2016-03-11 13:45:15 -0800 | [diff] [blame] | 159 | const RoundRectClipState* roundRectClipState = nullptr; |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * Blending to be used by this draw - both GL_NONE if blending is disabled. |
| 163 | * |
| 164 | * Defined by fill step, but can be force-enabled by presence of kAlpha_Attrib |
| 165 | */ |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 166 | struct Blend { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 167 | GLenum src; |
| 168 | GLenum dst; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 169 | } blend; |
| 170 | |
Chris Craik | 70969cc | 2016-03-30 18:09:17 -0700 | [diff] [blame] | 171 | #if !HWUI_NEW_OPS |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 172 | /** |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 173 | * Bounds of the drawing command in layer space. Only mapped into layer |
| 174 | * space once GlopBuilder::build() is called. |
| 175 | */ |
sergeyv | f42bf3e | 2016-03-11 13:45:15 -0800 | [diff] [blame] | 176 | Rect bounds; // TODO: remove for HWUI_NEW_OPS |
Chris Craik | 70969cc | 2016-03-30 18:09:17 -0700 | [diff] [blame] | 177 | #endif |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 178 | |
| 179 | /** |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 180 | * Additional render state to enumerate: |
| 181 | * - scissor + (bits for whether each of LTRB needed?) |
| 182 | * - stencil mode (draw into, mask, count, etc) |
| 183 | */ |
| 184 | }; |
| 185 | |
| 186 | } /* namespace uirenderer */ |
| 187 | } /* namespace android */ |
| 188 | |
| 189 | #endif // ANDROID_HWUI_GLOP_H |