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 481aa5d2d7068147ff781cfe911a93f01593a68c79John Reck static inline void set(Vertex* vertex, Vector2 val) { 496d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik set(vertex, val.x, val.y); 506d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik } 516d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 526d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) { 533380cfdc77100e87aa8390386ccf390834dea171Romain Guy set(vertex, src.x + x, src.y + y); 546d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik } 556d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 565b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase}; // struct Vertex 575b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 58a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(Vertex); 59a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 605b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase/** 61ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy * Simple structure to describe a vertex with a position and texture UV. 625b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase */ 63f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guystruct TextureVertex { 643380cfdc77100e87aa8390386ccf390834dea171Romain Guy float x, y; 653380cfdc77100e87aa8390386ccf390834dea171Romain Guy float u, v; 66f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 67f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy static inline void set(TextureVertex* vertex, float x, float y, float u, float v) { 68a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk *vertex = { x, y, u, v }; 69f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy } 7082ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy 7182ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy static inline void setUV(TextureVertex* vertex, float u, float v) { 723380cfdc77100e87aa8390386ccf390834dea171Romain Guy vertex[0].u = u; 733380cfdc77100e87aa8390386ccf390834dea171Romain Guy vertex[0].v = v; 7482ba814ca0dea659be2cc6523bc0137679d961ceRomain Guy } 75f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy}; // struct TextureVertex 76f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 77a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(TextureVertex); 78a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 795b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase/** 80253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy * Simple structure to describe a vertex with a position, texture UV and an 81253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy * sRGB color with alpha. The color is stored pre-multiplied in linear space. 82ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy */ 83a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsukstruct ColorTextureVertex { 84a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk float x, y; 85a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk float u, v; 86253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy float r, g, b, a; // pre-multiplied linear 87ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy 88ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy static inline void set(ColorTextureVertex* vertex, float x, float y, 89253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy float u, float v, uint32_t color) { 90253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy FloatColor c; 91253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy c.set(color); 92253f2c213f6ecda63b6872aee77bd30d5ec07c82Romain Guy *vertex = { x, y, u, v, c.r, c.g, c.b, c.a }; 93ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy } 94ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy}; // struct ColorTextureVertex 95ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy 96a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(ColorTextureVertex); 97a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 98ff316ec7a76e52572a2e89b691e6b3bba0cafba3Romain Guy/** 995b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase * Simple structure to describe a vertex with a position and an alpha value. 1005b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase */ 101a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsukstruct AlphaVertex { 102a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk float x, y; 1035b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase float alpha; 1045b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 1055b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase static inline void set(AlphaVertex* vertex, float x, float y, float alpha) { 106a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk *vertex = { x, y, alpha }; 1075b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase } 1085b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 1096d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src, 1106d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik float x, float y) { 111a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk AlphaVertex::set(vertex, src.x + x, src.y + y, src.alpha); 1126d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik } 1136d29c8d5218cac0fb35f3b7c253f2bdebd44f15aChris Craik 1145b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase static inline void setColor(AlphaVertex* vertex, float alpha) { 1155b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase vertex[0].alpha = alpha; 1165b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase } 1175b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase}; // struct AlphaVertex 1185b0200bd47e8a9a4dc8d2e6c3a110d522b30bf82Chet Haase 119a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob TsukREQUIRE_COMPATIBLE_LAYOUT(AlphaVertex); 120a9fc9b20da43b0e5d01b10097d6f2e6fafcd6626Rob Tsuk 121f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy}; // namespace uirenderer 122f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy}; // namespace android 123f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy 1245b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_VERTEX_H 125