Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_VERTEX_H |
| 18 | #define ANDROID_HWUI_VERTEX_H |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 19 | |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 20 | #include "Vector.h" |
| 21 | |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 22 | #include "FloatColor.h" |
Chris Craik | 0519c81 | 2015-02-11 13:17:06 -0800 | [diff] [blame] | 23 | #include "utils/Macros.h" |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 24 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
| 28 | /** |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 29 | * Simple structure to describe a vertex with a position and a texture. |
| 30 | */ |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 31 | struct Vertex { |
Chris Craik | 32f05e3 | 2013-09-17 16:20:29 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Fudge-factor used to disambiguate geometry pixel positioning. |
| 34 | * |
| 35 | * Used to offset lines and points to avoid ambiguous intersection with pixel centers (see |
| 36 | * Program::set()), and used to make geometry damage rect calculation conservative (see |
| 37 | * Rect::snapGeometryToPixelBoundaries()) |
| 38 | */ |
Chris Craik | 564acf7 | 2014-01-02 16:46:18 -0800 | [diff] [blame] | 39 | static float GeometryFudgeFactor() { return 0.0656f; } |
| 40 | |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame] | 41 | float x, y; |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 42 | |
| 43 | static inline void set(Vertex* vertex, float x, float y) { |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 44 | vertex->x = x; |
| 45 | vertex->y = y; |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 46 | } |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 47 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 48 | static inline void set(Vertex* vertex, Vector2 val) { set(vertex, val.x, val.y); } |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 49 | |
| 50 | static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame] | 51 | set(vertex, src.x + x, src.y + y); |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 52 | } |
| 53 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 54 | }; // struct Vertex |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 55 | |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 56 | REQUIRE_COMPATIBLE_LAYOUT(Vertex); |
| 57 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 58 | /** |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 59 | * Simple structure to describe a vertex with a position and texture UV. |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 60 | */ |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 61 | struct TextureVertex { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame] | 62 | float x, y; |
| 63 | float u, v; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 64 | |
| 65 | static inline void set(TextureVertex* vertex, float x, float y, float u, float v) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 66 | *vertex = {x, y, u, v}; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 67 | } |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 68 | |
| 69 | static inline void setUV(TextureVertex* vertex, float u, float v) { |
Romain Guy | 3380cfd | 2013-08-15 16:57:57 -0700 | [diff] [blame] | 70 | vertex[0].u = u; |
| 71 | vertex[0].v = v; |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 72 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 73 | }; // struct TextureVertex |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 74 | |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 75 | REQUIRE_COMPATIBLE_LAYOUT(TextureVertex); |
| 76 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 77 | /** |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 78 | * Simple structure to describe a vertex with a position, texture UV and an |
| 79 | * sRGB color with alpha. The color is stored pre-multiplied in linear space. |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 80 | */ |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 81 | struct ColorTextureVertex { |
| 82 | float x, y; |
| 83 | float u, v; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 84 | float r, g, b, a; // pre-multiplied linear |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 85 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 86 | static inline void set(ColorTextureVertex* vertex, float x, float y, float u, float v, |
| 87 | uint32_t color) { |
Romain Guy | 253f2c2 | 2016-09-28 17:34:42 -0700 | [diff] [blame] | 88 | FloatColor c; |
| 89 | c.set(color); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 90 | *vertex = {x, y, u, v, c.r, c.g, c.b, c.a}; |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 91 | } |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 92 | }; // struct ColorTextureVertex |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 93 | |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 94 | REQUIRE_COMPATIBLE_LAYOUT(ColorTextureVertex); |
| 95 | |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 96 | /** |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 97 | * Simple structure to describe a vertex with a position and an alpha value. |
| 98 | */ |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 99 | struct AlphaVertex { |
| 100 | float x, y; |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 101 | float alpha; |
| 102 | |
| 103 | static inline void set(AlphaVertex* vertex, float x, float y, float alpha) { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 104 | *vertex = {x, y, alpha}; |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 105 | } |
| 106 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 107 | static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src, float x, |
| 108 | float y) { |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 109 | AlphaVertex::set(vertex, src.x + x, src.y + y, src.alpha); |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 110 | } |
| 111 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 112 | static inline void setColor(AlphaVertex* vertex, float alpha) { vertex[0].alpha = alpha; } |
| 113 | }; // struct AlphaVertex |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 114 | |
Rob Tsuk | a9fc9b2 | 2015-01-22 12:46:31 -0800 | [diff] [blame] | 115 | REQUIRE_COMPATIBLE_LAYOUT(AlphaVertex); |
| 116 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 117 | }; // namespace uirenderer |
| 118 | }; // namespace android |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 119 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 120 | #endif // ANDROID_HWUI_VERTEX_H |