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 | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 22 | namespace android { |
| 23 | namespace uirenderer { |
| 24 | |
| 25 | /** |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 26 | * Simple structure to describe a vertex with a position and a texture. |
| 27 | */ |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 28 | struct Vertex { |
Chris Craik | 32f05e3 | 2013-09-17 16:20:29 -0700 | [diff] [blame^] | 29 | /** |
| 30 | * Fudge-factor used to disambiguate geometry pixel positioning. |
| 31 | * |
| 32 | * Used to offset lines and points to avoid ambiguous intersection with pixel centers (see |
| 33 | * Program::set()), and used to make geometry damage rect calculation conservative (see |
| 34 | * Rect::snapGeometryToPixelBoundaries()) |
| 35 | */ |
| 36 | static const float gGeometryFudgeFactor = 0.0656f; |
| 37 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 38 | float position[2]; |
| 39 | |
| 40 | static inline void set(Vertex* vertex, float x, float y) { |
| 41 | vertex[0].position[0] = x; |
| 42 | vertex[0].position[1] = y; |
| 43 | } |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 44 | |
| 45 | static inline void set(Vertex* vertex, vec2 val) { |
| 46 | set(vertex, val.x, val.y); |
| 47 | } |
| 48 | |
| 49 | static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) { |
| 50 | set(vertex, src.position[0] + x, src.position[1] + y); |
| 51 | } |
| 52 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 53 | }; // struct Vertex |
| 54 | |
| 55 | /** |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 56 | * Simple structure to describe a vertex with a position and texture UV. |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 57 | */ |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 58 | struct TextureVertex { |
| 59 | float position[2]; |
| 60 | float texture[2]; |
| 61 | |
| 62 | static inline void set(TextureVertex* vertex, float x, float y, float u, float v) { |
| 63 | vertex[0].position[0] = x; |
| 64 | vertex[0].position[1] = y; |
| 65 | vertex[0].texture[0] = u; |
| 66 | vertex[0].texture[1] = v; |
| 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) { |
| 70 | vertex[0].texture[0] = u; |
| 71 | vertex[0].texture[1] = v; |
| 72 | } |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 73 | }; // struct TextureVertex |
| 74 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 75 | /** |
Romain Guy | ff316ec | 2013-02-13 18:39:43 -0800 | [diff] [blame] | 76 | * Simple structure to describe a vertex with a position, texture UV and ARGB color. |
| 77 | */ |
| 78 | struct ColorTextureVertex : TextureVertex { |
| 79 | float color[4]; |
| 80 | |
| 81 | static inline void set(ColorTextureVertex* vertex, float x, float y, |
| 82 | float u, float v, int color) { |
| 83 | TextureVertex::set(vertex, x, y, u, v); |
| 84 | |
| 85 | const float a = ((color >> 24) & 0xff) / 255.0f; |
| 86 | vertex[0].color[0] = a * ((color >> 16) & 0xff) / 255.0f; |
| 87 | vertex[0].color[1] = a * ((color >> 8) & 0xff) / 255.0f; |
| 88 | vertex[0].color[2] = a * ((color ) & 0xff) / 255.0f; |
| 89 | vertex[0].color[3] = a; |
| 90 | } |
| 91 | }; // struct ColorTextureVertex |
| 92 | |
| 93 | /** |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 94 | * Simple structure to describe a vertex with a position and an alpha value. |
| 95 | */ |
| 96 | struct AlphaVertex : Vertex { |
| 97 | float alpha; |
| 98 | |
| 99 | static inline void set(AlphaVertex* vertex, float x, float y, float alpha) { |
| 100 | Vertex::set(vertex, x, y); |
| 101 | vertex[0].alpha = alpha; |
| 102 | } |
| 103 | |
Chris Craik | 6d29c8d | 2013-05-08 18:35:44 -0700 | [diff] [blame] | 104 | static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src, |
| 105 | float x, float y) { |
| 106 | Vertex::set(vertex, src.position[0] + x, src.position[1] + y); |
| 107 | vertex[0].alpha = src.alpha; |
| 108 | } |
| 109 | |
Chet Haase | 5b0200b | 2011-04-13 17:58:08 -0700 | [diff] [blame] | 110 | static inline void setColor(AlphaVertex* vertex, float alpha) { |
| 111 | vertex[0].alpha = alpha; |
| 112 | } |
| 113 | }; // struct AlphaVertex |
| 114 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 115 | }; // namespace uirenderer |
| 116 | }; // namespace android |
| 117 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 118 | #endif // ANDROID_HWUI_VERTEX_H |