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" |
| 22 | #include "Rect.h" |
| 23 | #include "utils/Macros.h" |
| 24 | |
| 25 | #include <GLES2/gl2.h> |
| 26 | #include <GLES2/gl2ext.h> |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 27 | #include <SkXfermode.h> |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace uirenderer { |
| 31 | |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 32 | class Program; |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame^] | 33 | class RoundRectClipState; |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 34 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 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 | */ |
| 41 | enum VertexAttribFlags { |
| 42 | // NOTE: position attribute always enabled |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 43 | kNone_Attrib = 0, |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 44 | kTextureCoord_Attrib = 1 << 0, |
| 45 | kColor_Attrib = 1 << 1, |
| 46 | kAlpha_Attrib = 1 << 2, |
| 47 | }; |
| 48 | |
| 49 | /** |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame^] | 50 | * Structure containing all data required to issue an OpenGL draw |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 51 | * |
| 52 | * Includes all of the mesh, fill, and GL state required to perform |
| 53 | * the operation. Pieces of data are either directly copied into the |
| 54 | * structure, or stored as a pointer or GL object reference to data |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame^] | 55 | * managed. |
| 56 | * |
| 57 | * Eventually, a Glop should be able to be drawn multiple times from |
| 58 | * a single construction, up until GL context destruction. Currently, |
| 59 | * vertex/index/Texture/RoundRectClipState pointers prevent this from |
| 60 | * being safe. |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 61 | */ |
| 62 | // TODO: PREVENT_COPY_AND_ASSIGN(...) or similar |
| 63 | struct Glop { |
| 64 | Rect bounds; |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame^] | 65 | const RoundRectClipState* roundRectClipState; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 66 | |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 67 | /* |
| 68 | * Stores mesh - vertex and index data. |
| 69 | * |
| 70 | * buffer objects and void*s are mutually exclusive |
Chris Craik | 2ab95d7 | 2015-02-06 15:25:51 -0800 | [diff] [blame] | 71 | * indices are optional, currently only GL_UNSIGNED_SHORT supported |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 72 | */ |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 73 | struct Mesh { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 74 | VertexAttribFlags vertexFlags; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 75 | GLuint primitiveMode; // GL_TRIANGLES and GL_TRIANGLE_STRIP supported |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 76 | GLuint vertexBufferObject; |
| 77 | GLuint indexBufferObject; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 78 | const void* vertices; |
| 79 | const void* indices; |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame^] | 80 | int elementCount; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 81 | GLsizei stride; |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame^] | 82 | GLvoid* texCoordOffset; |
| 83 | TextureVertex mappedVertices[4]; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 84 | } mesh; |
| 85 | |
| 86 | struct Fill { |
| 87 | Program* program; |
Chris Craik | 0519c810 | 2015-02-11 13:17:06 -0800 | [diff] [blame^] | 88 | Texture* texture; |
| 89 | GLenum textureFilter; |
| 90 | |
| 91 | bool colorEnabled; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 92 | FloatColor color; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 93 | |
| 94 | /* TODO |
| 95 | union shader { |
| 96 | //... |
| 97 | }; TODO |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 98 | */ |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 99 | ProgramDescription::ColorFilterMode filterMode; |
| 100 | union Filter { |
| 101 | struct Matrix { |
| 102 | float matrix[16]; |
| 103 | float vector[4]; |
| 104 | } matrix; |
| 105 | FloatColor color; |
| 106 | } filter; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 107 | } fill; |
| 108 | |
| 109 | struct Transform { |
| 110 | Matrix4 ortho; // TODO: out of op, since this is static per FBO |
| 111 | Matrix4 modelView; |
| 112 | Matrix4 canvas; |
Chris Craik | 117bdbc | 2015-02-05 10:12:38 -0800 | [diff] [blame] | 113 | bool fudgingOffset; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 114 | } transform; |
| 115 | |
| 116 | struct Blend { |
Chris Craik | 0318887 | 2015-02-02 18:39:33 -0800 | [diff] [blame] | 117 | GLenum src; |
| 118 | GLenum dst; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 119 | } blend; |
| 120 | |
| 121 | /** |
| 122 | * Additional render state to enumerate: |
| 123 | * - scissor + (bits for whether each of LTRB needed?) |
| 124 | * - stencil mode (draw into, mask, count, etc) |
| 125 | */ |
| 126 | }; |
| 127 | |
| 128 | } /* namespace uirenderer */ |
| 129 | } /* namespace android */ |
| 130 | |
| 131 | #endif // ANDROID_HWUI_GLOP_H |