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 | 0519c810 | 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 | 0519c810 | 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 | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 44 | enum class VertexAttribFlags { |
| 45 | kNone = 0, |
| 46 | kTextureCoord = 1 << 0, |
| 47 | kColor = 1 << 1, |
| 48 | kAlpha = 1 << 2, |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 49 | }; |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 50 | MAKE_FLAGS_ENUM(VertexAttribFlags) |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 51 | |
| 52 | /** |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 53 | * Structure containing all data required to issue an OpenGL draw |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 54 | * |
| 55 | * Includes all of the mesh, fill, and GL state required to perform |
| 56 | * the operation. Pieces of data are either directly copied into the |
| 57 | * structure, or stored as a pointer or GL object reference to data |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 58 | * managed. |
| 59 | * |
| 60 | * Eventually, a Glop should be able to be drawn multiple times from |
| 61 | * a single construction, up until GL context destruction. Currently, |
| 62 | * vertex/index/Texture/RoundRectClipState pointers prevent this from |
| 63 | * being safe. |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 64 | */ |
| 65 | // TODO: PREVENT_COPY_AND_ASSIGN(...) or similar |
| 66 | struct Glop { |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 67 | struct Mesh { |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 68 | GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported |
Chris Craik | ef25074 | 2015-02-25 17:16:16 -0800 | [diff] [blame] | 69 | |
| 70 | // buffer object and void* are mutually exclusive. |
| 71 | // Only GL_UNSIGNED_SHORT supported. |
| 72 | struct Indices { |
| 73 | GLuint bufferObject; |
| 74 | const void* indices; |
| 75 | } indices; |
| 76 | |
| 77 | // buffer object and void*s are mutually exclusive. |
| 78 | // TODO: enforce mutual exclusion with restricted setters and/or unions |
| 79 | struct Vertices { |
| 80 | GLuint bufferObject; |
| 81 | VertexAttribFlags flags; |
| 82 | const void* position; |
| 83 | const void* texCoord; |
| 84 | const void* color; |
| 85 | GLsizei stride; |
| 86 | } vertices; |
| 87 | |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 88 | int elementCount; |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 89 | TextureVertex mappedVertices[4]; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 90 | } mesh; |
| 91 | |
| 92 | struct Fill { |
| 93 | Program* program; |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 94 | |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 95 | struct TextureData { |
| 96 | Texture* texture; |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame^] | 97 | GLenum target; |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 98 | GLenum filter; |
| 99 | GLenum clamp; |
Chris Craik | 26bf342 | 2015-02-26 16:28:17 -0800 | [diff] [blame^] | 100 | Matrix4* textureTransform; |
Chris Craik | f27133d | 2015-02-19 09:51:53 -0800 | [diff] [blame] | 101 | } texture; |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 102 | |
| 103 | bool colorEnabled; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 104 | FloatColor color; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 105 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 106 | ProgramDescription::ColorFilterMode filterMode; |
| 107 | union Filter { |
| 108 | struct Matrix { |
| 109 | float matrix[16]; |
| 110 | float vector[4]; |
| 111 | } matrix; |
| 112 | FloatColor color; |
| 113 | } filter; |
Chris Craik | 922d3a7 | 2015-02-13 17:47:21 -0800 | [diff] [blame] | 114 | |
| 115 | SkiaShaderData skiaShaderData; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 116 | } fill; |
| 117 | |
| 118 | struct Transform { |
| 119 | Matrix4 ortho; // TODO: out of op, since this is static per FBO |
| 120 | Matrix4 modelView; |
| 121 | Matrix4 canvas; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 122 | bool fudgingOffset; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 123 | } transform; |
| 124 | |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 125 | const RoundRectClipState* roundRectClipState; |
| 126 | |
| 127 | /** |
| 128 | * Blending to be used by this draw - both GL_NONE if blending is disabled. |
| 129 | * |
| 130 | * Defined by fill step, but can be force-enabled by presence of kAlpha_Attrib |
| 131 | */ |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 132 | struct Blend { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 133 | GLenum src; |
| 134 | GLenum dst; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 135 | } blend; |
| 136 | |
| 137 | /** |
Chris Craik | 3003609 | 2015-02-12 10:41:39 -0800 | [diff] [blame] | 138 | * Bounds of the drawing command in layer space. Only mapped into layer |
| 139 | * space once GlopBuilder::build() is called. |
| 140 | */ |
| 141 | Rect bounds; |
| 142 | |
| 143 | /** |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 144 | * Additional render state to enumerate: |
| 145 | * - scissor + (bits for whether each of LTRB needed?) |
| 146 | * - stencil mode (draw into, mask, count, etc) |
| 147 | */ |
| 148 | }; |
| 149 | |
| 150 | } /* namespace uirenderer */ |
| 151 | } /* namespace android */ |
| 152 | |
| 153 | #endif // ANDROID_HWUI_GLOP_H |