blob: db982ad0c8f49d05303fa488ec93d8c092618df2 [file] [log] [blame]
Romain Guyf7f93552010-07-08 19:17:03 -07001/*
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 Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_VERTEX_H
18#define ANDROID_HWUI_VERTEX_H
Romain Guyf7f93552010-07-08 19:17:03 -070019
Chris Craik6d29c8d2013-05-08 18:35:44 -070020#include "Vector.h"
21
Romain Guy253f2c22016-09-28 17:34:42 -070022#include "FloatColor.h"
Chris Craik0519c812015-02-11 13:17:06 -080023#include "utils/Macros.h"
Rob Tsuka9fc9b22015-01-22 12:46:31 -080024
Romain Guyf7f93552010-07-08 19:17:03 -070025namespace android {
26namespace uirenderer {
27
28/**
Romain Guyf7f93552010-07-08 19:17:03 -070029 * Simple structure to describe a vertex with a position and a texture.
30 */
Chet Haase5b0200b2011-04-13 17:58:08 -070031struct Vertex {
Chris Craik32f05e32013-09-17 16:20:29 -070032 /**
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 Craik564acf72014-01-02 16:46:18 -080039 static float GeometryFudgeFactor() { return 0.0656f; }
40
Romain Guy3380cfd2013-08-15 16:57:57 -070041 float x, y;
Chet Haase5b0200b2011-04-13 17:58:08 -070042
43 static inline void set(Vertex* vertex, float x, float y) {
Chris Craik51d6a3d2014-12-22 17:16:56 -080044 vertex->x = x;
45 vertex->y = y;
Chet Haase5b0200b2011-04-13 17:58:08 -070046 }
Chris Craik6d29c8d2013-05-08 18:35:44 -070047
John Reck1aa5d2d2014-07-24 13:38:28 -070048 static inline void set(Vertex* vertex, Vector2 val) {
Chris Craik6d29c8d2013-05-08 18:35:44 -070049 set(vertex, val.x, val.y);
50 }
51
52 static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) {
Romain Guy3380cfd2013-08-15 16:57:57 -070053 set(vertex, src.x + x, src.y + y);
Chris Craik6d29c8d2013-05-08 18:35:44 -070054 }
55
Chet Haase5b0200b2011-04-13 17:58:08 -070056}; // struct Vertex
57
Rob Tsuka9fc9b22015-01-22 12:46:31 -080058REQUIRE_COMPATIBLE_LAYOUT(Vertex);
59
Chet Haase5b0200b2011-04-13 17:58:08 -070060/**
Romain Guyff316ec2013-02-13 18:39:43 -080061 * Simple structure to describe a vertex with a position and texture UV.
Chet Haase5b0200b2011-04-13 17:58:08 -070062 */
Romain Guyf7f93552010-07-08 19:17:03 -070063struct TextureVertex {
Romain Guy3380cfd2013-08-15 16:57:57 -070064 float x, y;
65 float u, v;
Romain Guyf7f93552010-07-08 19:17:03 -070066
67 static inline void set(TextureVertex* vertex, float x, float y, float u, float v) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -080068 *vertex = { x, y, u, v };
Romain Guyf7f93552010-07-08 19:17:03 -070069 }
Romain Guy82ba8142010-07-09 13:25:56 -070070
71 static inline void setUV(TextureVertex* vertex, float u, float v) {
Romain Guy3380cfd2013-08-15 16:57:57 -070072 vertex[0].u = u;
73 vertex[0].v = v;
Romain Guy82ba8142010-07-09 13:25:56 -070074 }
Romain Guyf7f93552010-07-08 19:17:03 -070075}; // struct TextureVertex
76
Rob Tsuka9fc9b22015-01-22 12:46:31 -080077REQUIRE_COMPATIBLE_LAYOUT(TextureVertex);
78
Chet Haase5b0200b2011-04-13 17:58:08 -070079/**
Romain Guy253f2c22016-09-28 17:34:42 -070080 * Simple structure to describe a vertex with a position, texture UV and an
81 * sRGB color with alpha. The color is stored pre-multiplied in linear space.
Romain Guyff316ec2013-02-13 18:39:43 -080082 */
Rob Tsuka9fc9b22015-01-22 12:46:31 -080083struct ColorTextureVertex {
84 float x, y;
85 float u, v;
Romain Guy253f2c22016-09-28 17:34:42 -070086 float r, g, b, a; // pre-multiplied linear
Romain Guyff316ec2013-02-13 18:39:43 -080087
88 static inline void set(ColorTextureVertex* vertex, float x, float y,
Romain Guy253f2c22016-09-28 17:34:42 -070089 float u, float v, uint32_t color) {
90 FloatColor c;
91 c.set(color);
92 *vertex = { x, y, u, v, c.r, c.g, c.b, c.a };
Romain Guyff316ec2013-02-13 18:39:43 -080093 }
94}; // struct ColorTextureVertex
95
Rob Tsuka9fc9b22015-01-22 12:46:31 -080096REQUIRE_COMPATIBLE_LAYOUT(ColorTextureVertex);
97
Romain Guyff316ec2013-02-13 18:39:43 -080098/**
Chet Haase5b0200b2011-04-13 17:58:08 -070099 * Simple structure to describe a vertex with a position and an alpha value.
100 */
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800101struct AlphaVertex {
102 float x, y;
Chet Haase5b0200b2011-04-13 17:58:08 -0700103 float alpha;
104
105 static inline void set(AlphaVertex* vertex, float x, float y, float alpha) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800106 *vertex = { x, y, alpha };
Chet Haase5b0200b2011-04-13 17:58:08 -0700107 }
108
Chris Craik6d29c8d2013-05-08 18:35:44 -0700109 static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src,
110 float x, float y) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800111 AlphaVertex::set(vertex, src.x + x, src.y + y, src.alpha);
Chris Craik6d29c8d2013-05-08 18:35:44 -0700112 }
113
Chet Haase5b0200b2011-04-13 17:58:08 -0700114 static inline void setColor(AlphaVertex* vertex, float alpha) {
115 vertex[0].alpha = alpha;
116 }
117}; // struct AlphaVertex
118
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800119REQUIRE_COMPATIBLE_LAYOUT(AlphaVertex);
120
Romain Guyf7f93552010-07-08 19:17:03 -0700121}; // namespace uirenderer
122}; // namespace android
123
Romain Guy5b3b3522010-10-27 18:57:51 -0700124#endif // ANDROID_HWUI_VERTEX_H