blob: c1bf980658b2d8fa26bf8838f6e556eddc33291b [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
Chris Craik0519c812015-02-11 13:17:06 -080022#include "utils/Macros.h"
Rob Tsuka9fc9b22015-01-22 12:46:31 -080023
Romain Guyf7f93552010-07-08 19:17:03 -070024namespace android {
25namespace uirenderer {
26
27/**
Romain Guyf7f93552010-07-08 19:17:03 -070028 * Simple structure to describe a vertex with a position and a texture.
29 */
Chet Haase5b0200b2011-04-13 17:58:08 -070030struct Vertex {
Chris Craik32f05e32013-09-17 16:20:29 -070031 /**
32 * Fudge-factor used to disambiguate geometry pixel positioning.
33 *
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())
37 */
Chris Craik564acf72014-01-02 16:46:18 -080038 static float GeometryFudgeFactor() { return 0.0656f; }
39
Romain Guy3380cfd2013-08-15 16:57:57 -070040 float x, y;
Chet Haase5b0200b2011-04-13 17:58:08 -070041
42 static inline void set(Vertex* vertex, float x, float y) {
Chris Craik51d6a3d2014-12-22 17:16:56 -080043 vertex->x = x;
44 vertex->y = y;
Chet Haase5b0200b2011-04-13 17:58:08 -070045 }
Chris Craik6d29c8d2013-05-08 18:35:44 -070046
John Reck1aa5d2d2014-07-24 13:38:28 -070047 static inline void set(Vertex* vertex, Vector2 val) {
Chris Craik6d29c8d2013-05-08 18:35:44 -070048 set(vertex, val.x, val.y);
49 }
50
51 static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) {
Romain Guy3380cfd2013-08-15 16:57:57 -070052 set(vertex, src.x + x, src.y + y);
Chris Craik6d29c8d2013-05-08 18:35:44 -070053 }
54
Chet Haase5b0200b2011-04-13 17:58:08 -070055}; // struct Vertex
56
Rob Tsuka9fc9b22015-01-22 12:46:31 -080057REQUIRE_COMPATIBLE_LAYOUT(Vertex);
58
Chet Haase5b0200b2011-04-13 17:58:08 -070059/**
Romain Guyff316ec2013-02-13 18:39:43 -080060 * Simple structure to describe a vertex with a position and texture UV.
Chet Haase5b0200b2011-04-13 17:58:08 -070061 */
Romain Guyf7f93552010-07-08 19:17:03 -070062struct TextureVertex {
Romain Guy3380cfd2013-08-15 16:57:57 -070063 float x, y;
64 float u, v;
Romain Guyf7f93552010-07-08 19:17:03 -070065
66 static inline void set(TextureVertex* vertex, float x, float y, float u, float v) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -080067 *vertex = { x, y, u, v };
Romain Guyf7f93552010-07-08 19:17:03 -070068 }
Romain Guy82ba8142010-07-09 13:25:56 -070069
70 static inline void setUV(TextureVertex* vertex, float u, float v) {
Romain Guy3380cfd2013-08-15 16:57:57 -070071 vertex[0].u = u;
72 vertex[0].v = v;
Romain Guy82ba8142010-07-09 13:25:56 -070073 }
Romain Guyf7f93552010-07-08 19:17:03 -070074}; // struct TextureVertex
75
Rob Tsuka9fc9b22015-01-22 12:46:31 -080076REQUIRE_COMPATIBLE_LAYOUT(TextureVertex);
77
Chet Haase5b0200b2011-04-13 17:58:08 -070078/**
Romain Guyff316ec2013-02-13 18:39:43 -080079 * Simple structure to describe a vertex with a position, texture UV and ARGB color.
80 */
Rob Tsuka9fc9b22015-01-22 12:46:31 -080081struct ColorTextureVertex {
82 float x, y;
83 float u, v;
Romain Guy3380cfd2013-08-15 16:57:57 -070084 float r, g, b, a;
Romain Guyff316ec2013-02-13 18:39:43 -080085
86 static inline void set(ColorTextureVertex* vertex, float x, float y,
87 float u, float v, int color) {
Romain Guyff316ec2013-02-13 18:39:43 -080088
Rob Tsuka9fc9b22015-01-22 12:46:31 -080089 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 };
Romain Guyff316ec2013-02-13 18:39:43 -080094 }
95}; // struct ColorTextureVertex
96
Rob Tsuka9fc9b22015-01-22 12:46:31 -080097REQUIRE_COMPATIBLE_LAYOUT(ColorTextureVertex);
98
Romain Guyff316ec2013-02-13 18:39:43 -080099/**
Chet Haase5b0200b2011-04-13 17:58:08 -0700100 * Simple structure to describe a vertex with a position and an alpha value.
101 */
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800102struct AlphaVertex {
103 float x, y;
Chet Haase5b0200b2011-04-13 17:58:08 -0700104 float alpha;
105
106 static inline void set(AlphaVertex* vertex, float x, float y, float alpha) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800107 *vertex = { x, y, alpha };
Chet Haase5b0200b2011-04-13 17:58:08 -0700108 }
109
Chris Craik6d29c8d2013-05-08 18:35:44 -0700110 static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src,
111 float x, float y) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800112 AlphaVertex::set(vertex, src.x + x, src.y + y, src.alpha);
Chris Craik6d29c8d2013-05-08 18:35:44 -0700113 }
114
Chet Haase5b0200b2011-04-13 17:58:08 -0700115 static inline void setColor(AlphaVertex* vertex, float alpha) {
116 vertex[0].alpha = alpha;
117 }
118}; // struct AlphaVertex
119
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800120REQUIRE_COMPATIBLE_LAYOUT(AlphaVertex);
121
Romain Guyf7f93552010-07-08 19:17:03 -0700122}; // namespace uirenderer
123}; // namespace android
124
Romain Guy5b3b3522010-10-27 18:57:51 -0700125#endif // ANDROID_HWUI_VERTEX_H