blob: 51c1c2d2d32c73d7883956f99582d968d5fd40b0 [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"
ztenghui7b4516e2014-01-07 10:42:55 -080022
23namespace android {
24namespace uirenderer {
25
Tom Hudson2dc236b2014-10-15 15:46:42 -040026class VertexBuffer;
27
ztenghui7b4516e2014-01-07 10:42:55 -080028class SpotShadow {
29public:
ztenghuic50a03d2014-08-21 13:47:54 -070030 static void createSpotShadow(bool isCasterOpaque, const Vector3& lightCenter,
31 float lightSize, const Vector3* poly, int polyLength,
32 const Vector3& polyCentroid, VertexBuffer& retstrips);
ztenghui7b4516e2014-01-07 10:42:55 -080033
34private:
ztenghui512e6432014-09-10 13:08:20 -070035 struct VertexAngleData;
36
ztenghuic50a03d2014-08-21 13:47:54 -070037 static float projectCasterToOutline(Vector2& outline,
38 const Vector3& lightCenter, const Vector3& polyVertex);
ztenghuic50a03d2014-08-21 13:47:54 -070039
ztenghui512e6432014-09-10 13:08:20 -070040 static int setupAngleList(VertexAngleData* angleDataList,
41 int polyLength, const Vector2* polygon, const Vector2& centroid,
42 bool isPenumbra, const char* name);
43
44 static int convertPolysToVerticesPerRay(
45 bool hasOccludedUmbraArea, const Vector2* poly2d, int polyLength,
46 const Vector2* umbra, int umbraLength, const Vector2* penumbra,
47 int penumbraLength, const Vector2& centroid,
48 Vector2* umbraVerticesPerRay, Vector2* penumbraVerticesPerRay,
49 Vector2* occludedUmbraVerticesPerRay);
50
51 static bool checkClockwise(int maxIndex, int listLength,
52 VertexAngleData* angleList, const char* name);
53
54 static void calculateDistanceCounter(bool needsOffsetToUmbra, int angleLength,
55 const VertexAngleData* allVerticesAngleData, int* distances);
56
57 static void mergeAngleList(int maxUmbraAngleIndex, int maxPenumbraAngleIndex,
58 const VertexAngleData* umbraAngleList, int umbraLength,
59 const VertexAngleData* penumbraAngleList, int penumbraLength,
60 VertexAngleData* allVerticesAngleData);
61
62 static int setupPolyAngleList(float* polyAngleList, int polyAngleLength,
63 const Vector2* poly2d, const Vector2& centroid);
64
65 static bool checkPolyClockwise(int polyAngleLength, int maxPolyAngleIndex,
66 const float* polyAngleList);
67
68 static int getEdgeStartIndex(const int* offsets, int rayIndex, int totalRayNumber,
69 const VertexAngleData* allVerticesAngleData);
70
71 static int getPolyEdgeStartIndex(int maxPolyAngleIndex, int polyLength,
72 const float* polyAngleList, float rayAngle);
ztenghui7b4516e2014-01-07 10:42:55 -080073
74 static void computeLightPolygon(int points, const Vector3& lightCenter,
75 float size, Vector3* ret);
76
ztenghui7b4516e2014-01-07 10:42:55 -080077 static void smoothPolygon(int level, int rays, float* rayDist);
ztenghui7b4516e2014-01-07 10:42:55 -080078 static float rayIntersectPoly(const Vector2* poly, int polyLength,
79 const Vector2& point, float dx, float dy);
80
ztenghui7b4516e2014-01-07 10:42:55 -080081 static void xsort(Vector2* points, int pointsLength);
82 static int hull(Vector2* points, int pointsLength, Vector2* retPoly);
ztenghui9122b1b2014-10-03 11:21:11 -070083 static bool ccw(float ax, float ay, float bx, float by, float cx, float cy);
ztenghui7b4516e2014-01-07 10:42:55 -080084 static void sort(Vector2* poly, int polyLength, const Vector2& center);
85
ztenghui7b4516e2014-01-07 10:42:55 -080086 static void swap(Vector2* points, int i, int j);
87 static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center);
88 static void quicksortX(Vector2* points, int low, int high);
89
90 static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len);
91 static void makeClockwise(Vector2* polygon, int len);
ztenghui7b4516e2014-01-07 10:42:55 -080092 static void reverse(Vector2* polygon, int len);
ztenghui7b4516e2014-01-07 10:42:55 -080093
ztenghuic50a03d2014-08-21 13:47:54 -070094 static void generateTriangleStrip(bool isCasterOpaque, float shadowStrengthScale,
ztenghui512e6432014-09-10 13:08:20 -070095 Vector2* penumbra, int penumbraLength, Vector2* umbra, int umbraLength,
96 const Vector3* poly, int polyLength, VertexBuffer& retstrips, const Vector2& centroid);
ztenghui7b4516e2014-01-07 10:42:55 -080097
ztenghuif5ca8b42014-01-27 15:53:28 -080098#if DEBUG_SHADOW
ztenghuif5ca8b42014-01-27 15:53:28 -080099 static bool testConvex(const Vector2* polygon, int polygonLength,
100 const char* name);
101 static void testIntersection(const Vector2* poly1, int poly1Length,
102 const Vector2* poly2, int poly2Length,
103 const Vector2* intersection, int intersectionLength);
104 static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound );
ztenghuic50a03d2014-08-21 13:47:54 -0700105 static void dumpPolygon(const Vector2* poly, int polyLength, const char* polyName);
106 static void dumpPolygon(const Vector3* poly, int polyLength, const char* polyName);
ztenghuif5ca8b42014-01-27 15:53:28 -0800107#endif
108
ztenghui7b4516e2014-01-07 10:42:55 -0800109}; // SpotShadow
110
111}; // namespace uirenderer
112}; // namespace android
113
114#endif // ANDROID_HWUI_SPOT_SHADOW_H