1f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy/* 2f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Copyright (C) 2010 The Android Open Source Project 3f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * 4f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * you may not use this file except in compliance with the License. 6f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * You may obtain a copy of the License at 7f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * 8f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * http://www.apache.org/licenses/LICENSE-2.0 9f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * 10f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Unless required by applicable law or agreed to in writing, software 11f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * See the License for the specific language governing permissions and 14f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * limitations under the License. 15f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 16f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_VERTEX_H 185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_VERTEX_H 19f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 206d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik#include "Vector.h" 216d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 22253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy#include "FloatColor.h" 230519c810a56bded1284fcb2ae40f438878c6585fChris Craik#include "utils/Macros.h" 24a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 25f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guynamespace android { 26f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guynamespace uirenderer { 27f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 28f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy/** 29f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy * Simple structure to describe a vertex with a position and a texture. 30f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy */ 315b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haasestruct Vertex { 3232f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik /** 3332f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik * Fudge-factor used to disambiguate geometry pixel positioning. 3432f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik * 3532f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik * Used to offset lines and points to avoid ambiguous intersection with pixel centers (see 3632f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik * Program::set()), and used to make geometry damage rect calculation conservative (see 3732f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik * Rect::snapGeometryToPixelBoundaries()) 3832f05e343c5ffb17f3235942bcda651bd3b9f1d6Chris Craik */ 39564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik static float GeometryFudgeFactor() { return 0.0656f; } 40564acf7c9bff822f608cda0d5df0a64a9f9aaefdChris Craik 413380cfdc77100e87aa8390386ccf390834dea171Romain Guy float x, y; 425b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 435b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase static inline void set(Vertex* vertex, float x, float y) { 4451d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik vertex->x = x; 4551d6a3db97bdd5315f1a17a4b447d10a92217b98Chris Craik vertex->y = y; 465b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase } 476d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 481bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck static inline void set(Vertex* vertex, Vector2 val) { set(vertex, val.x, val.y); } 496d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 506d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) { 513380cfdc77100e87aa8390386ccf390834dea171Romain Guy set(vertex, src.x + x, src.y + y); 526d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik } 536d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 541bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck}; // struct Vertex 555b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 56a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(Vertex); 57a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 585b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase/** 59ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy * Simple structure to describe a vertex with a position and texture UV. 605b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase */ 61f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guystruct TextureVertex { 623380cfdc77100e87aa8390386ccf390834dea171Romain Guy float x, y; 633380cfdc77100e87aa8390386ccf390834dea171Romain Guy float u, v; 64f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 65f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy static inline void set(TextureVertex* vertex, float x, float y, float u, float v) { 661bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck *vertex = {x, y, u, v}; 67f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy } 6882ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 6982ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy static inline void setUV(TextureVertex* vertex, float u, float v) { 703380cfdc77100e87aa8390386ccf390834dea171Romain Guy vertex[0].u = u; 713380cfdc77100e87aa8390386ccf390834dea171Romain Guy vertex[0].v = v; 7282ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy } 731bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck}; // struct TextureVertex 74f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 75a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(TextureVertex); 76a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 775b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase/** 78253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy * Simple structure to describe a vertex with a position, texture UV and an 79253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy * sRGB color with alpha. The color is stored pre-multiplied in linear space. 80ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy */ 81a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsukstruct ColorTextureVertex { 82a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk float x, y; 83a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk float u, v; 841bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck float r, g, b, a; // pre-multiplied linear 85ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy 861bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck static inline void set(ColorTextureVertex* vertex, float x, float y, float u, float v, 871bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck uint32_t color) { 88253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy FloatColor c; 89253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy c.set(color); 901bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck *vertex = {x, y, u, v, c.r, c.g, c.b, c.a}; 91ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy } 921bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck}; // struct ColorTextureVertex 93ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy 94a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(ColorTextureVertex); 95a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 96ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy/** 975b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase * Simple structure to describe a vertex with a position and an alpha value. 985b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase */ 99a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsukstruct AlphaVertex { 100a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk float x, y; 1015b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase float alpha; 1025b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 1035b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase static inline void set(AlphaVertex* vertex, float x, float y, float alpha) { 1041bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck *vertex = {x, y, alpha}; 1055b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase } 1065b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 1071bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src, float x, 1081bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck float y) { 109a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk AlphaVertex::set(vertex, src.x + x, src.y + y, src.alpha); 1106d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik } 1116d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 1121bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck static inline void setColor(AlphaVertex* vertex, float alpha) { vertex[0].alpha = alpha; } 1131bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck}; // struct AlphaVertex 1145b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 115a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(AlphaVertex); 116a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 1171bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck}; // namespace uirenderer 1181bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck}; // namespace android 119f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 1201bcacfdcab0eaa0cee92bd7f5a1b5e271dd68e52John Reck#endif // ANDROID_HWUI_VERTEX_H 121