ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | namespace android { |
| 25 | namespace uirenderer { |
| 26 | |
| 27 | class SpotShadow { |
| 28 | public: |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 29 | static void createSpotShadow(bool isCasterOpaque, const Vector3& lightCenter, |
| 30 | float lightSize, const Vector3* poly, int polyLength, |
| 31 | const Vector3& polyCentroid, VertexBuffer& retstrips); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 32 | |
| 33 | private: |
ztenghui | 512e643 | 2014-09-10 13:08:20 -0700 | [diff] [blame] | 34 | struct VertexAngleData; |
| 35 | |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 36 | static float projectCasterToOutline(Vector2& outline, |
| 37 | const Vector3& lightCenter, const Vector3& polyVertex); |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 38 | |
ztenghui | 512e643 | 2014-09-10 13:08:20 -0700 | [diff] [blame] | 39 | static int setupAngleList(VertexAngleData* angleDataList, |
| 40 | int polyLength, const Vector2* polygon, const Vector2& centroid, |
| 41 | bool isPenumbra, const char* name); |
| 42 | |
| 43 | static int convertPolysToVerticesPerRay( |
| 44 | bool hasOccludedUmbraArea, const Vector2* poly2d, int polyLength, |
| 45 | const Vector2* umbra, int umbraLength, const Vector2* penumbra, |
| 46 | int penumbraLength, const Vector2& centroid, |
| 47 | Vector2* umbraVerticesPerRay, Vector2* penumbraVerticesPerRay, |
| 48 | Vector2* occludedUmbraVerticesPerRay); |
| 49 | |
| 50 | static bool checkClockwise(int maxIndex, int listLength, |
| 51 | VertexAngleData* angleList, const char* name); |
| 52 | |
| 53 | static void calculateDistanceCounter(bool needsOffsetToUmbra, int angleLength, |
| 54 | const VertexAngleData* allVerticesAngleData, int* distances); |
| 55 | |
| 56 | static void mergeAngleList(int maxUmbraAngleIndex, int maxPenumbraAngleIndex, |
| 57 | const VertexAngleData* umbraAngleList, int umbraLength, |
| 58 | const VertexAngleData* penumbraAngleList, int penumbraLength, |
| 59 | VertexAngleData* allVerticesAngleData); |
| 60 | |
| 61 | static int setupPolyAngleList(float* polyAngleList, int polyAngleLength, |
| 62 | const Vector2* poly2d, const Vector2& centroid); |
| 63 | |
| 64 | static bool checkPolyClockwise(int polyAngleLength, int maxPolyAngleIndex, |
| 65 | const float* polyAngleList); |
| 66 | |
| 67 | static int getEdgeStartIndex(const int* offsets, int rayIndex, int totalRayNumber, |
| 68 | const VertexAngleData* allVerticesAngleData); |
| 69 | |
| 70 | static int getPolyEdgeStartIndex(int maxPolyAngleIndex, int polyLength, |
| 71 | const float* polyAngleList, float rayAngle); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 72 | |
| 73 | static void computeLightPolygon(int points, const Vector3& lightCenter, |
| 74 | float size, Vector3* ret); |
| 75 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 76 | static void smoothPolygon(int level, int rays, float* rayDist); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 77 | static float rayIntersectPoly(const Vector2* poly, int polyLength, |
| 78 | const Vector2& point, float dx, float dy); |
| 79 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 80 | static void xsort(Vector2* points, int pointsLength); |
| 81 | static int hull(Vector2* points, int pointsLength, Vector2* retPoly); |
ztenghui | 9122b1b | 2014-10-03 11:21:11 -0700 | [diff] [blame] | 82 | static bool ccw(float ax, float ay, float bx, float by, float cx, float cy); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 83 | static void sort(Vector2* poly, int polyLength, const Vector2& center); |
| 84 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 85 | static void swap(Vector2* points, int i, int j); |
| 86 | static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center); |
| 87 | static void quicksortX(Vector2* points, int low, int high); |
| 88 | |
| 89 | static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len); |
| 90 | static void makeClockwise(Vector2* polygon, int len); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 91 | static void reverse(Vector2* polygon, int len); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 92 | |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 93 | static void generateTriangleStrip(bool isCasterOpaque, float shadowStrengthScale, |
ztenghui | 512e643 | 2014-09-10 13:08:20 -0700 | [diff] [blame] | 94 | Vector2* penumbra, int penumbraLength, Vector2* umbra, int umbraLength, |
| 95 | const Vector3* poly, int polyLength, VertexBuffer& retstrips, const Vector2& centroid); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 96 | |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 97 | #if DEBUG_SHADOW |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 98 | static bool testConvex(const Vector2* polygon, int polygonLength, |
| 99 | const char* name); |
| 100 | static void testIntersection(const Vector2* poly1, int poly1Length, |
| 101 | const Vector2* poly2, int poly2Length, |
| 102 | const Vector2* intersection, int intersectionLength); |
| 103 | static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound ); |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 104 | static void dumpPolygon(const Vector2* poly, int polyLength, const char* polyName); |
| 105 | static void dumpPolygon(const Vector3* poly, int polyLength, const char* polyName); |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 106 | #endif |
| 107 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 108 | }; // SpotShadow |
| 109 | |
| 110 | }; // namespace uirenderer |
| 111 | }; // namespace android |
| 112 | |
| 113 | #endif // ANDROID_HWUI_SPOT_SHADOW_H |