2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_HWUI_VERTEX_H
18 #define ANDROID_HWUI_VERTEX_H
22 #include "utils/Macros.h"
25 namespace uirenderer {
28 * Simple structure to describe a vertex with a position and a texture.
32 * Fudge-factor used to disambiguate geometry pixel positioning.
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())
38 static float GeometryFudgeFactor() { return 0.0656f; }
42 static inline void set(Vertex* vertex, float x, float y) {
47 static inline void set(Vertex* vertex, Vector2 val) {
48 set(vertex, val.x, val.y);
51 static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) {
52 set(vertex, src.x + x, src.y + y);
57 REQUIRE_COMPATIBLE_LAYOUT(Vertex);
60 * Simple structure to describe a vertex with a position and texture UV.
62 struct TextureVertex {
66 static inline void set(TextureVertex* vertex, float x, float y, float u, float v) {
67 *vertex = { x, y, u, v };
70 static inline void setUV(TextureVertex* vertex, float u, float v) {
74 }; // struct TextureVertex
76 REQUIRE_COMPATIBLE_LAYOUT(TextureVertex);
79 * Simple structure to describe a vertex with a position, texture UV and ARGB color.
81 struct ColorTextureVertex {
86 static inline void set(ColorTextureVertex* vertex, float x, float y,
87 float u, float v, int color) {
89 float a = ((color >> 24) & 0xff) / 255.0f;
90 float r = a * ((color >> 16) & 0xff) / 255.0f;
91 float g = a * ((color >> 8) & 0xff) / 255.0f;
92 float b = a * ((color) & 0xff) / 255.0f;
93 *vertex = { x, y, u, v, r, g, b, a };
95 }; // struct ColorTextureVertex
97 REQUIRE_COMPATIBLE_LAYOUT(ColorTextureVertex);
100 * Simple structure to describe a vertex with a position and an alpha value.
106 static inline void set(AlphaVertex* vertex, float x, float y, float alpha) {
107 *vertex = { x, y, alpha };
110 static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src,
112 AlphaVertex::set(vertex, src.x + x, src.y + y, src.alpha);
115 static inline void setColor(AlphaVertex* vertex, float alpha) {
116 vertex[0].alpha = alpha;
118 }; // struct AlphaVertex
120 REQUIRE_COMPATIBLE_LAYOUT(AlphaVertex);
122 }; // namespace uirenderer
123 }; // namespace android
125 #endif // ANDROID_HWUI_VERTEX_H