blob: e2d94f7ebc5cb97b30eb06f9797deddba3a4cbb6 [file] [log] [blame]
ztenghui7b4516e2014-01-07 10:42:55 -08001/*
2 * Copyright (C) 2014 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
17#ifndef ANDROID_HWUI_SPOT_SHADOW_H
18#define ANDROID_HWUI_SPOT_SHADOW_H
19
20#include "Debug.h"
21#include "Vector.h"
22#include "VertexBuffer.h"
23
24namespace android {
25namespace uirenderer {
26
27class SpotShadow {
28public:
ztenghuic50a03d2014-08-21 13:47:54 -070029 static void createSpotShadow(bool isCasterOpaque, const Vector3& lightCenter,
30 float lightSize, const Vector3* poly, int polyLength,
31 const Vector3& polyCentroid, VertexBuffer& retstrips);
ztenghui7b4516e2014-01-07 10:42:55 -080032
33private:
ztenghui512e6432014-09-10 13:08:20 -070034 struct VertexAngleData;
35
ztenghuic50a03d2014-08-21 13:47:54 -070036 static float projectCasterToOutline(Vector2& outline,
37 const Vector3& lightCenter, const Vector3& polyVertex);
ztenghuic50a03d2014-08-21 13:47:54 -070038
ztenghui7b4516e2014-01-07 10:42:55 -080039 static void computeLightPolygon(int points, const Vector3& lightCenter,
40 float size, Vector3* ret);
41
ztenghui7b4516e2014-01-07 10:42:55 -080042 static void smoothPolygon(int level, int rays, float* rayDist);
ztenghui7b4516e2014-01-07 10:42:55 -080043 static float rayIntersectPoly(const Vector2* poly, int polyLength,
44 const Vector2& point, float dx, float dy);
45
ztenghui7b4516e2014-01-07 10:42:55 -080046 static void xsort(Vector2* points, int pointsLength);
47 static int hull(Vector2* points, int pointsLength, Vector2* retPoly);
ztenghui9122b1b2014-10-03 11:21:11 -070048 static bool ccw(float ax, float ay, float bx, float by, float cx, float cy);
ztenghui7b4516e2014-01-07 10:42:55 -080049 static void sort(Vector2* poly, int polyLength, const Vector2& center);
50
ztenghui7b4516e2014-01-07 10:42:55 -080051 static void swap(Vector2* points, int i, int j);
52 static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center);
53 static void quicksortX(Vector2* points, int low, int high);
54
55 static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len);
56 static void makeClockwise(Vector2* polygon, int len);
ztenghui7b4516e2014-01-07 10:42:55 -080057 static void reverse(Vector2* polygon, int len);
ztenghui7b4516e2014-01-07 10:42:55 -080058
ztenghuic50a03d2014-08-21 13:47:54 -070059 static void generateTriangleStrip(bool isCasterOpaque, float shadowStrengthScale,
ztenghui512e6432014-09-10 13:08:20 -070060 Vector2* penumbra, int penumbraLength, Vector2* umbra, int umbraLength,
61 const Vector3* poly, int polyLength, VertexBuffer& retstrips, const Vector2& centroid);
ztenghui7b4516e2014-01-07 10:42:55 -080062
ztenghuif5ca8b42014-01-27 15:53:28 -080063#if DEBUG_SHADOW
ztenghuif5ca8b42014-01-27 15:53:28 -080064 static bool testConvex(const Vector2* polygon, int polygonLength,
65 const char* name);
66 static void testIntersection(const Vector2* poly1, int poly1Length,
67 const Vector2* poly2, int poly2Length,
68 const Vector2* intersection, int intersectionLength);
69 static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound );
ztenghuic50a03d2014-08-21 13:47:54 -070070 static void dumpPolygon(const Vector2* poly, int polyLength, const char* polyName);
71 static void dumpPolygon(const Vector3* poly, int polyLength, const char* polyName);
ztenghuif5ca8b42014-01-27 15:53:28 -080072#endif
73
ztenghui7b4516e2014-01-07 10:42:55 -080074}; // SpotShadow
75
76}; // namespace uirenderer
77}; // namespace android
78
79#endif // ANDROID_HWUI_SPOT_SHADOW_H