| 1 | /* |
| 2 | * Copyright (C) 2010 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_VERTEX_H |
| 18 | #define ANDROID_HWUI_VERTEX_H |
| 19 | |
| 20 | #include "Vector.h" |
| 21 | |
| 22 | #include "utils/Macros.h" |
| 23 | |
| 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | |
| 27 | /** |
| 28 | * Simple structure to describe a vertex with a position and a texture. |
| 29 | */ |
| 30 | struct Vertex { |
| 31 | /** |
| 32 | * Fudge-factor used to disambiguate geometry pixel positioning. |
| 33 | * |
| 34 | * Used to offset lines and points to avoid ambiguous intersection with pixel centers (see |
| 35 | * Program::set()), and used to make geometry damage rect calculation conservative (see |
| 36 | * Rect::snapGeometryToPixelBoundaries()) |
| 37 | */ |
| 38 | static float GeometryFudgeFactor() { return 0.0656f; } |
| 39 | |
| 40 | float x, y; |
| 41 | |
| 42 | static inline void set(Vertex* vertex, float x, float y) { |
| 43 | vertex->x = x; |
| 44 | vertex->y = y; |
| 45 | } |
| 46 | |
| 47 | static inline void set(Vertex* vertex, Vector2 val) { set(vertex, val.x, val.y); } |
| 48 | |
| 49 | static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) { |
| 50 | set(vertex, src.x + x, src.y + y); |
| 51 | } |
| 52 | |
| 53 | }; // struct Vertex |
| 54 | |
| 55 | REQUIRE_COMPATIBLE_LAYOUT(Vertex); |
| 56 | |
| 57 | /** |
| 58 | * Simple structure to describe a vertex with a position and texture UV. |
| 59 | */ |
| 60 | struct TextureVertex { |
| 61 | float x, y; |
| 62 | float u, v; |
| 63 | |
| 64 | static inline void set(TextureVertex* vertex, float x, float y, float u, float v) { |
| 65 | *vertex = {x, y, u, v}; |
| 66 | } |
| 67 | |
| 68 | static inline void setUV(TextureVertex* vertex, float u, float v) { |
| 69 | vertex[0].u = u; |
| 70 | vertex[0].v = v; |
| 71 | } |
| 72 | }; // struct TextureVertex |
| 73 | |
| 74 | REQUIRE_COMPATIBLE_LAYOUT(TextureVertex); |
| 75 | |
| 76 | } // namespace uirenderer |
| 77 | } // namespace android |
| 78 | |
| 79 | #endif // ANDROID_HWUI_VERTEX_H |