blob: 79f46f9e9a06e1a47aaf343803da06bfcdb28411 [file] [log] [blame]
ztenghui55bfb4e2013-12-03 10:38:55 -08001
2/*
3 * Copyright (C) 2013 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef ANDROID_HWUI_SHADOW_TESSELLATOR_H
19#define ANDROID_HWUI_SHADOW_TESSELLATOR_H
20
Tom Hudson2dc236b2014-10-15 15:46:42 -040021#include <SkPath.h>
22
ztenghui55bfb4e2013-12-03 10:38:55 -080023#include "Debug.h"
24#include "Matrix.h"
25
26namespace android {
27namespace uirenderer {
28
Tom Hudson2dc236b2014-10-15 15:46:42 -040029class VertexBuffer;
30
ztenghui63d41ab2014-02-14 13:13:41 -080031// All SHADOW_* are used to define all the geometry property of shadows.
32// Use a simplified example to illustrate the geometry setup here.
33// Assuming we use 6 rays and only 1 layer, Then we will have 2 hexagons, which
34// are 0 to 5 and 6 to 11. The area between them will be the penumbra area, and
35// the area inside the 2nd hexagon is the umbra.
ztenghui50ecf842014-03-11 16:52:30 -070036// Ambient shadow is using only 1 layer for opaque caster, otherwise, spot
37// shadow and ambient shadow are using 2 layers.
ztenghui63d41ab2014-02-14 13:13:41 -080038// Triange strip indices for penumbra area: (0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 0, 6)
ztenghui63d41ab2014-02-14 13:13:41 -080039// 0
40//
41// 5 6 1
42// 11 7
ztenghui50ecf842014-03-11 16:52:30 -070043//
ztenghui63d41ab2014-02-14 13:13:41 -080044// 10 8
45// 4 9 2
46//
47// 3
48
49// The total number of rays starting from the centroid of shadow area, in order
50// to generate the shadow geometry.
Chris Craik726118b2014-03-07 18:27:49 -080051#define SHADOW_RAY_COUNT 128
ztenghui63d41ab2014-02-14 13:13:41 -080052
53// The total number of all the vertices representing the shadow.
ztenghui50ecf842014-03-11 16:52:30 -070054// For the case we only have 1 layer, then we will just fill only 2/3 of it.
55#define SHADOW_VERTEX_COUNT (3 * SHADOW_RAY_COUNT)
ztenghui63d41ab2014-02-14 13:13:41 -080056
57// The total number of indices used for drawing the shadow geometry as triangle strips.
ztenghui50ecf842014-03-11 16:52:30 -070058// Depending on the mode we are drawing, we can have 1 layer or 2 layers.
59// Therefore, we only build the longer index buffer.
60#define TWO_POLY_RING_SHADOW_INDEX_COUNT (4 * (SHADOW_RAY_COUNT + 1))
61#define ONE_POLY_RING_SHADOW_INDEX_COUNT (2 * (SHADOW_RAY_COUNT + 1))
62
63#define MAX_SHADOW_INDEX_COUNT TWO_POLY_RING_SHADOW_INDEX_COUNT
ztenghui63d41ab2014-02-14 13:13:41 -080064
Chris Craikb98f2112014-03-11 17:42:29 -070065#define SHADOW_MIN_CASTER_Z 0.001f
66
ztenghui7940dc52014-04-22 11:21:49 -070067#define MINIMAL_DELTA_THETA (M_PI / 180 / 1000)
68
ztenghui55bfb4e2013-12-03 10:38:55 -080069class ShadowTessellator {
70public:
John Reck1bcacfd2017-11-03 10:12:19 -070071 static void tessellateAmbientShadow(bool isCasterOpaque, const Vector3* casterPolygon,
72 int casterVertexCount, const Vector3& centroid3d,
73 const Rect& casterBounds, const Rect& localClip, float maxZ,
74 VertexBuffer& shadowVertexBuffer);
ztenghui7b4516e2014-01-07 10:42:55 -080075
John Reck1bcacfd2017-11-03 10:12:19 -070076 static void tessellateSpotShadow(bool isCasterOpaque, const Vector3* casterPolygon,
77 int casterVertexCount, const Vector3& casterCentroid,
78 const mat4& receiverTransform, const Vector3& lightCenter,
79 int lightRadius, const Rect& casterBounds,
80 const Rect& localClip, VertexBuffer& shadowVertexBuffer);
ztenghui63d41ab2014-02-14 13:13:41 -080081
ztenghui63d41ab2014-02-14 13:13:41 -080082 static Vector2 centroid2d(const Vector2* poly, int polyLength);
ztenghui2e023f32014-04-28 16:43:13 -070083
ztenghuic50a03d2014-08-21 13:47:54 -070084 static Vector2 calculateNormal(const Vector2& p1, const Vector2& p2);
ztenghui2e023f32014-04-28 16:43:13 -070085
John Reck1bcacfd2017-11-03 10:12:19 -070086 static int getExtraVertexNumber(const Vector2& vector1, const Vector2& vector2, float divisor);
ztenghui512e6432014-09-10 13:08:20 -070087
88 static void checkOverflow(int used, int total, const char* bufferName);
John Reck1bcacfd2017-11-03 10:12:19 -070089}; // ShadowTessellator
ztenghui55bfb4e2013-12-03 10:38:55 -080090
John Reck1bcacfd2017-11-03 10:12:19 -070091}; // namespace uirenderer
92}; // namespace android
ztenghui55bfb4e2013-12-03 10:38:55 -080093
John Reck1bcacfd2017-11-03 10:12:19 -070094#endif // ANDROID_HWUI_SHADOW_TESSELLATOR_H