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 | |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame^] | 17 | #pragma once |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 18 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 19 | #include "FloatColor.h" |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 20 | #include "Matrix.h" |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 21 | #include "Program.h" |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 22 | #include "Rect.h" |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 23 | #include "SkiaShader.h" |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 24 | #include "utils/Macros.h" |
| 25 | |
| 26 | #include <GLES2/gl2.h> |
| 27 | #include <GLES2/gl2ext.h> |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 28 | #include <SkXfermode.h> |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 33 | class Program; |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 34 | class RoundRectClipState; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 35 | class Texture; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 36 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 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 | */ |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 43 | |
| 44 | namespace VertexAttribFlags { |
| 45 | enum { |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 46 | // Mesh is pure x,y vertex pairs |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 47 | None = 0, |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 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. |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 50 | TextureCoord = 1 << 0, |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 51 | // Mesh has color embedded (to export to varying) |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 52 | Color = 1 << 1, |
Chris Craik | 138c21f | 2016-04-28 16:59:42 -0700 | [diff] [blame] | 53 | // Mesh has alpha embedded (to export to varying) |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 54 | Alpha = 1 << 2, |
| 55 | }; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 56 | }; |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 57 | |
| 58 | /* |
| 59 | * Enumerates transform features |
| 60 | */ |
| 61 | namespace 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, |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame^] | 70 | // since it's already built in. |
Chris Craik | e4db79d | 2015-12-22 16:32:23 -0800 | [diff] [blame] | 71 | MeshIgnoresCanvasTransform = 1 << 1, // TODO: remove for HWUI_NEW_OPS |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 72 | }; |
| 73 | }; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 76 | * Structure containing all data required to issue an OpenGL draw |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 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 |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 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. |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 87 | */ |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 88 | struct Glop { |
sergeyv | f42bf3e | 2016-03-11 13:45:15 -0800 | [diff] [blame] | 89 | PREVENT_COPY_AND_ASSIGN(Glop); |
| 90 | public: |
| 91 | Glop() { } |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 92 | struct Mesh { |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 93 | GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 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; |
Chris Craik | eb911c2 | 2015-03-06 17:30:11 -0800 | [diff] [blame] | 106 | int attribFlags; |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 107 | const void* position; |
| 108 | const void* texCoord; |
| 109 | const void* color; |
| 110 | GLsizei stride; |
| 111 | } vertices; |
| 112 | |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 113 | int elementCount; |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 114 | TextureVertex mappedVertices[4]; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 115 | } mesh; |
| 116 | |
| 117 | struct Fill { |
| 118 | Program* program; |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 119 | |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 120 | struct TextureData { |
| 121 | Texture* texture; |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame] | 122 | GLenum target; |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 123 | GLenum filter; |
| 124 | GLenum clamp; |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame] | 125 | Matrix4* textureTransform; |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 126 | } texture; |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 127 | |
| 128 | bool colorEnabled; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 129 | FloatColor color; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 130 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 131 | ProgramDescription::ColorFilterMode filterMode; |
| 132 | union Filter { |
| 133 | struct Matrix { |
| 134 | float matrix[16]; |
| 135 | float vector[4]; |
| 136 | } matrix; |
| 137 | FloatColor color; |
| 138 | } filter; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 139 | |
| 140 | SkiaShaderData skiaShaderData; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 141 | } fill; |
| 142 | |
| 143 | struct Transform { |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 144 | // modelView transform, accounting for delta between mesh transform and content of the mesh |
| 145 | // 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] | 146 | Matrix4 modelView; |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 147 | |
| 148 | // Canvas transform of Glop - not necessarily applied to geometry (see flags) |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 149 | Matrix4 canvas; |
Chris Craik | 53e51e4 | 2015-06-01 10:35:35 -0700 | [diff] [blame] | 150 | int transformFlags; |
| 151 | |
| 152 | const Matrix4& meshTransform() const { |
| 153 | return (transformFlags & TransformFlags::MeshIgnoresCanvasTransform) |
| 154 | ? Matrix4::identity() : canvas; |
| 155 | } |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 156 | } transform; |
| 157 | |
sergeyv | f42bf3e | 2016-03-11 13:45:15 -0800 | [diff] [blame] | 158 | const RoundRectClipState* roundRectClipState = nullptr; |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Blending to be used by this draw - both GL_NONE if blending is disabled. |
| 162 | * |
| 163 | * Defined by fill step, but can be force-enabled by presence of kAlpha_Attrib |
| 164 | */ |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 165 | struct Blend { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 166 | GLenum src; |
| 167 | GLenum dst; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 168 | } blend; |
| 169 | |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 170 | /** |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 171 | * Additional render state to enumerate: |
| 172 | * - scissor + (bits for whether each of LTRB needed?) |
| 173 | * - stencil mode (draw into, mask, count, etc) |
| 174 | */ |
| 175 | }; |
| 176 | |
| 177 | } /* namespace uirenderer */ |
| 178 | } /* namespace android */ |