blob: 23fdca9d7fa90916477181af6c54b77e137a966c [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);
ztenghui50ecf842014-03-11 16:52:30 -070038 static int calculateOccludedUmbra(const Vector2* umbra, int umbraLength,
39 const Vector3* poly, int polyLength, Vector2* occludedUmbra);
ztenghuic50a03d2014-08-21 13:47:54 -070040
ztenghui512e6432014-09-10 13:08:20 -070041 static int setupAngleList(VertexAngleData* angleDataList,
42 int polyLength, const Vector2* polygon, const Vector2& centroid,
43 bool isPenumbra, const char* name);
44
45 static int convertPolysToVerticesPerRay(
46 bool hasOccludedUmbraArea, const Vector2* poly2d, int polyLength,
47 const Vector2* umbra, int umbraLength, const Vector2* penumbra,
48 int penumbraLength, const Vector2& centroid,
49 Vector2* umbraVerticesPerRay, Vector2* penumbraVerticesPerRay,
50 Vector2* occludedUmbraVerticesPerRay);
51
52 static bool checkClockwise(int maxIndex, int listLength,
53 VertexAngleData* angleList, const char* name);
54
55 static void calculateDistanceCounter(bool needsOffsetToUmbra, int angleLength,
56 const VertexAngleData* allVerticesAngleData, int* distances);
57
58 static void mergeAngleList(int maxUmbraAngleIndex, int maxPenumbraAngleIndex,
59 const VertexAngleData* umbraAngleList, int umbraLength,
60 const VertexAngleData* penumbraAngleList, int penumbraLength,
61 VertexAngleData* allVerticesAngleData);
62
63 static int setupPolyAngleList(float* polyAngleList, int polyAngleLength,
64 const Vector2* poly2d, const Vector2& centroid);
65
66 static bool checkPolyClockwise(int polyAngleLength, int maxPolyAngleIndex,
67 const float* polyAngleList);
68
69 static int getEdgeStartIndex(const int* offsets, int rayIndex, int totalRayNumber,
70 const VertexAngleData* allVerticesAngleData);
71
72 static int getPolyEdgeStartIndex(int maxPolyAngleIndex, int polyLength,
73 const float* polyAngleList, float rayAngle);
ztenghui7b4516e2014-01-07 10:42:55 -080074
75 static void computeLightPolygon(int points, const Vector3& lightCenter,
76 float size, Vector3* ret);
77
ztenghui7b4516e2014-01-07 10:42:55 -080078 static void smoothPolygon(int level, int rays, float* rayDist);
ztenghui7b4516e2014-01-07 10:42:55 -080079 static float rayIntersectPoly(const Vector2* poly, int polyLength,
80 const Vector2& point, float dx, float dy);
81
ztenghui7b4516e2014-01-07 10:42:55 -080082 static void xsort(Vector2* points, int pointsLength);
83 static int hull(Vector2* points, int pointsLength, Vector2* retPoly);
ztenghuif5ca8b42014-01-27 15:53:28 -080084 static bool ccw(double ax, double ay, double bx, double by, double cx, double cy);
ztenghui50ecf842014-03-11 16:52:30 -070085 static int intersection(const Vector2* poly1, int poly1length, Vector2* poly2, int poly2length);
ztenghui7b4516e2014-01-07 10:42:55 -080086 static void sort(Vector2* poly, int polyLength, const Vector2& center);
87
ztenghui7b4516e2014-01-07 10:42:55 -080088 static void swap(Vector2* points, int i, int j);
89 static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center);
90 static void quicksortX(Vector2* points, int low, int high);
91
92 static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len);
93 static void makeClockwise(Vector2* polygon, int len);
ztenghui7b4516e2014-01-07 10:42:55 -080094 static void reverse(Vector2* polygon, int len);
95 static inline bool lineIntersection(double x1, double y1, double x2, double y2,
96 double x3, double y3, double x4, double y4, Vector2& ret);
97
ztenghuic50a03d2014-08-21 13:47:54 -070098 static void generateTriangleStrip(bool isCasterOpaque, float shadowStrengthScale,
ztenghui512e6432014-09-10 13:08:20 -070099 Vector2* penumbra, int penumbraLength, Vector2* umbra, int umbraLength,
100 const Vector3* poly, int polyLength, VertexBuffer& retstrips, const Vector2& centroid);
ztenghui7b4516e2014-01-07 10:42:55 -0800101
ztenghuif5ca8b42014-01-27 15:53:28 -0800102#if DEBUG_SHADOW
ztenghuif5ca8b42014-01-27 15:53:28 -0800103 static bool testConvex(const Vector2* polygon, int polygonLength,
104 const char* name);
105 static void testIntersection(const Vector2* poly1, int poly1Length,
106 const Vector2* poly2, int poly2Length,
107 const Vector2* intersection, int intersectionLength);
108 static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound );
ztenghuic50a03d2014-08-21 13:47:54 -0700109 static void dumpPolygon(const Vector2* poly, int polyLength, const char* polyName);
110 static void dumpPolygon(const Vector3* poly, int polyLength, const char* polyName);
ztenghuif5ca8b42014-01-27 15:53:28 -0800111#endif
112
ztenghui7b4516e2014-01-07 10:42:55 -0800113}; // SpotShadow
114
115}; // namespace uirenderer
116}; // namespace android
117
118#endif // ANDROID_HWUI_SPOT_SHADOW_H