blob: 599d37ecd1748bd4d60e754558d574ee547f8ce2 [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:
ztenghui50ecf842014-03-11 16:52:30 -070029 static VertexBufferMode createSpotShadow(bool isCasterOpaque, const Vector3* poly,
30 int polyLength, const Vector3& lightCenter, float lightSize,
31 int lightVertexCount, VertexBuffer& retStrips);
ztenghui7b4516e2014-01-07 10:42:55 -080032
33private:
ztenghui50ecf842014-03-11 16:52:30 -070034 static int calculateOccludedUmbra(const Vector2* umbra, int umbraLength,
35 const Vector3* poly, int polyLength, Vector2* occludedUmbra);
36 static void computeSpotShadow(bool isCasterOpaque, const Vector3* lightPoly,
37 int lightPolyLength, const Vector3& lightCenter, const Vector3* poly,
38 int polyLength, VertexBuffer& retstrips);
ztenghui7b4516e2014-01-07 10:42:55 -080039
40 static void computeLightPolygon(int points, const Vector3& lightCenter,
41 float size, Vector3* ret);
42
ztenghui7b4516e2014-01-07 10:42:55 -080043 static void smoothPolygon(int level, int rays, float* rayDist);
ztenghui7b4516e2014-01-07 10:42:55 -080044 static float rayIntersectPoly(const Vector2* poly, int polyLength,
45 const Vector2& point, float dx, float dy);
46
ztenghui7b4516e2014-01-07 10:42:55 -080047 static void xsort(Vector2* points, int pointsLength);
48 static int hull(Vector2* points, int pointsLength, Vector2* retPoly);
ztenghuif5ca8b42014-01-27 15:53:28 -080049 static bool ccw(double ax, double ay, double bx, double by, double cx, double cy);
ztenghui50ecf842014-03-11 16:52:30 -070050 static int intersection(const Vector2* poly1, int poly1length, Vector2* poly2, int poly2length);
ztenghui7b4516e2014-01-07 10:42:55 -080051 static void sort(Vector2* poly, int polyLength, const Vector2& center);
52
ztenghui7b4516e2014-01-07 10:42:55 -080053 static void swap(Vector2* points, int i, int j);
54 static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center);
55 static void quicksortX(Vector2* points, int low, int high);
56
57 static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len);
58 static void makeClockwise(Vector2* polygon, int len);
ztenghui50ecf842014-03-11 16:52:30 -070059 static bool isClockwise(const Vector2* polygon, int len);
ztenghui7b4516e2014-01-07 10:42:55 -080060 static void reverse(Vector2* polygon, int len);
61 static inline bool lineIntersection(double x1, double y1, double x2, double y2,
62 double x3, double y3, double x4, double y4, Vector2& ret);
63
ztenghui50ecf842014-03-11 16:52:30 -070064 static void generateTriangleStrip(bool isCasterOpaque, const Vector2* penumbra,
65 int penumbraLength, const Vector2* umbra, int umbraLength,
66 const Vector3* poly, int polyLength, VertexBuffer& retstrips);
ztenghui7b4516e2014-01-07 10:42:55 -080067
ztenghuif5ca8b42014-01-27 15:53:28 -080068#if DEBUG_SHADOW
69 // Verification utility function.
70 static bool testConvex(const Vector2* polygon, int polygonLength,
71 const char* name);
72 static void testIntersection(const Vector2* poly1, int poly1Length,
73 const Vector2* poly2, int poly2Length,
74 const Vector2* intersection, int intersectionLength);
75 static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound );
76#endif
77
ztenghui7b4516e2014-01-07 10:42:55 -080078}; // SpotShadow
79
80}; // namespace uirenderer
81}; // namespace android
82
83#endif // ANDROID_HWUI_SPOT_SHADOW_H