blob: fd3845da5efb7eb9fd8ba466a69caa642e27ec75 [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
Chris Craik0519c812015-02-11 13:17:06 -080024#include <type_traits>
Rob Tsuka9fc9b22015-01-22 12:46:31 -080025
Romain Guyf7f93552010-07-08 19:17:03 -070026namespace android {
27namespace uirenderer {
28
29/**
Romain Guyf7f93552010-07-08 19:17:03 -070030 * Simple structure to describe a vertex with a position and a texture.
31 */
Chet Haase5b0200b2011-04-13 17:58:08 -070032struct Vertex {
Chris Craik32f05e32013-09-17 16:20:29 -070033 /**
34 * Fudge-factor used to disambiguate geometry pixel positioning.
35 *
36 * Used to offset lines and points to avoid ambiguous intersection with pixel centers (see
37 * Program::set()), and used to make geometry damage rect calculation conservative (see
38 * Rect::snapGeometryToPixelBoundaries())
39 */
Chris Craik564acf72014-01-02 16:46:18 -080040 static float GeometryFudgeFactor() { return 0.0656f; }
41
Chris Craik32f05e32013-09-17 16:20:29 -070042
Romain Guy3380cfd2013-08-15 16:57:57 -070043 float x, y;
Chet Haase5b0200b2011-04-13 17:58:08 -070044
45 static inline void set(Vertex* vertex, float x, float y) {
Chris Craik51d6a3d2014-12-22 17:16:56 -080046 vertex->x = x;
47 vertex->y = y;
Chet Haase5b0200b2011-04-13 17:58:08 -070048 }
Chris Craik6d29c8d2013-05-08 18:35:44 -070049
John Reck1aa5d2d2014-07-24 13:38:28 -070050 static inline void set(Vertex* vertex, Vector2 val) {
Chris Craik6d29c8d2013-05-08 18:35:44 -070051 set(vertex, val.x, val.y);
52 }
53
54 static inline void copyWithOffset(Vertex* vertex, const Vertex& src, float x, float y) {
Romain Guy3380cfd2013-08-15 16:57:57 -070055 set(vertex, src.x + x, src.y + y);
Chris Craik6d29c8d2013-05-08 18:35:44 -070056 }
57
Chet Haase5b0200b2011-04-13 17:58:08 -070058}; // struct Vertex
59
Rob Tsuka9fc9b22015-01-22 12:46:31 -080060REQUIRE_COMPATIBLE_LAYOUT(Vertex);
61
Chet Haase5b0200b2011-04-13 17:58:08 -070062/**
Romain Guyff316ec2013-02-13 18:39:43 -080063 * Simple structure to describe a vertex with a position and texture UV.
Chet Haase5b0200b2011-04-13 17:58:08 -070064 */
Romain Guyf7f93552010-07-08 19:17:03 -070065struct TextureVertex {
Romain Guy3380cfd2013-08-15 16:57:57 -070066 float x, y;
67 float u, v;
Romain Guyf7f93552010-07-08 19:17:03 -070068
69 static inline void set(TextureVertex* vertex, float x, float y, float u, float v) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -080070 *vertex = { x, y, u, v };
Romain Guyf7f93552010-07-08 19:17:03 -070071 }
Romain Guy82ba8142010-07-09 13:25:56 -070072
73 static inline void setUV(TextureVertex* vertex, float u, float v) {
Romain Guy3380cfd2013-08-15 16:57:57 -070074 vertex[0].u = u;
75 vertex[0].v = v;
Romain Guy82ba8142010-07-09 13:25:56 -070076 }
Romain Guyf7f93552010-07-08 19:17:03 -070077}; // struct TextureVertex
78
Rob Tsuka9fc9b22015-01-22 12:46:31 -080079REQUIRE_COMPATIBLE_LAYOUT(TextureVertex);
80
Chet Haase5b0200b2011-04-13 17:58:08 -070081/**
Romain Guyff316ec2013-02-13 18:39:43 -080082 * Simple structure to describe a vertex with a position, texture UV and ARGB color.
83 */
Rob Tsuka9fc9b22015-01-22 12:46:31 -080084struct ColorTextureVertex {
85 float x, y;
86 float u, v;
Romain Guy3380cfd2013-08-15 16:57:57 -070087 float r, g, b, a;
Romain Guyff316ec2013-02-13 18:39:43 -080088
89 static inline void set(ColorTextureVertex* vertex, float x, float y,
90 float u, float v, int color) {
Romain Guyff316ec2013-02-13 18:39:43 -080091
Rob Tsuka9fc9b22015-01-22 12:46:31 -080092 float a = ((color >> 24) & 0xff) / 255.0f;
93 float r = a * ((color >> 16) & 0xff) / 255.0f;
94 float g = a * ((color >> 8) & 0xff) / 255.0f;
95 float b = a * ((color) & 0xff) / 255.0f;
96 *vertex = { x, y, u, v, r, g, b, a };
Romain Guyff316ec2013-02-13 18:39:43 -080097 }
98}; // struct ColorTextureVertex
99
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800100REQUIRE_COMPATIBLE_LAYOUT(ColorTextureVertex);
101
Romain Guyff316ec2013-02-13 18:39:43 -0800102/**
Chet Haase5b0200b2011-04-13 17:58:08 -0700103 * Simple structure to describe a vertex with a position and an alpha value.
104 */
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800105struct AlphaVertex {
106 float x, y;
Chet Haase5b0200b2011-04-13 17:58:08 -0700107 float alpha;
108
109 static inline void set(AlphaVertex* vertex, float x, float y, float alpha) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800110 *vertex = { x, y, alpha };
Chet Haase5b0200b2011-04-13 17:58:08 -0700111 }
112
Chris Craik6d29c8d2013-05-08 18:35:44 -0700113 static inline void copyWithOffset(AlphaVertex* vertex, const AlphaVertex& src,
114 float x, float y) {
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800115 AlphaVertex::set(vertex, src.x + x, src.y + y, src.alpha);
Chris Craik6d29c8d2013-05-08 18:35:44 -0700116 }
117
Chet Haase5b0200b2011-04-13 17:58:08 -0700118 static inline void setColor(AlphaVertex* vertex, float alpha) {
119 vertex[0].alpha = alpha;
120 }
121}; // struct AlphaVertex
122
Rob Tsuka9fc9b22015-01-22 12:46:31 -0800123REQUIRE_COMPATIBLE_LAYOUT(AlphaVertex);
124
Romain Guyf7f93552010-07-08 19:17:03 -0700125}; // namespace uirenderer
126}; // namespace android
127
Romain Guy5b3b3522010-10-27 18:57:51 -0700128#endif // ANDROID_HWUI_VERTEX_H