blob: 7839dc3ebb8cf1fa774877c9e684dbba678cb96c [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:
29 static void createSpotShadow(const Vector3* poly, int polyLength,
30 const Vector3& lightCenter, float lightSize, int lightVertexCount,
ztenghui63d41ab2014-02-14 13:13:41 -080031 VertexBuffer& retStrips);
ztenghui7b4516e2014-01-07 10:42:55 -080032
33private:
34 static void computeSpotShadow(const Vector3* lightPoly, int lightPolyLength,
35 const Vector3& lightCenter, const Vector3* poly, int polyLength,
ztenghui63d41ab2014-02-14 13:13:41 -080036 VertexBuffer& retstrips);
ztenghui7b4516e2014-01-07 10:42:55 -080037
38 static void computeLightPolygon(int points, const Vector3& lightCenter,
39 float size, Vector3* ret);
40
Chris Craik726118b2014-03-07 18:27:49 -080041 static int getStripSize(int rays);
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);
ztenghuif5ca8b42014-01-27 15:53:28 -080048 static bool ccw(double ax, double ay, double bx, double by, double cx, double cy);
ztenghui7b4516e2014-01-07 10:42:55 -080049 static int intersection(Vector2* poly1, int poly1length, Vector2* poly2, int poly2length);
50 static void sort(Vector2* poly, int polyLength, const Vector2& center);
51
ztenghui7b4516e2014-01-07 10:42:55 -080052 static void swap(Vector2* points, int i, int j);
53 static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center);
54 static void quicksortX(Vector2* points, int low, int high);
55
56 static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len);
57 static void makeClockwise(Vector2* polygon, int len);
58 static bool isClockwise(Vector2* polygon, int len);
59 static void reverse(Vector2* polygon, int len);
60 static inline bool lineIntersection(double x1, double y1, double x2, double y2,
61 double x3, double y3, double x4, double y4, Vector2& ret);
62
63 static void generateTriangleStrip(const Vector2* penumbra, int penumbraLength,
ztenghui63d41ab2014-02-14 13:13:41 -080064 const Vector2* umbra, int umbraLength, VertexBuffer& retstrips);
ztenghui7b4516e2014-01-07 10:42:55 -080065
ztenghuif5ca8b42014-01-27 15:53:28 -080066#if DEBUG_SHADOW
67 // Verification utility function.
68 static bool testConvex(const Vector2* polygon, int polygonLength,
69 const char* name);
70 static void testIntersection(const Vector2* poly1, int poly1Length,
71 const Vector2* poly2, int poly2Length,
72 const Vector2* intersection, int intersectionLength);
73 static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound );
74#endif
75
ztenghui7b4516e2014-01-07 10:42:55 -080076}; // SpotShadow
77
78}; // namespace uirenderer
79}; // namespace android
80
81#endif // ANDROID_HWUI_SPOT_SHADOW_H