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" |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 22 | |
| 23 | namespace android { |
| 24 | namespace uirenderer { |
| 25 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 26 | class VertexBuffer; |
| 27 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 28 | class SpotShadow { |
| 29 | public: |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 30 | static void createSpotShadow(bool isCasterOpaque, const Vector3& lightCenter, float lightSize, |
| 31 | const Vector3* poly, int polyLength, const Vector3& polyCentroid, |
| 32 | VertexBuffer& retstrips); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 33 | |
| 34 | private: |
ztenghui | 512e643 | 2014-09-10 13:08:20 -0700 | [diff] [blame] | 35 | struct VertexAngleData; |
| 36 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 37 | static float projectCasterToOutline(Vector2& outline, const Vector3& lightCenter, |
| 38 | const Vector3& polyVertex); |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 39 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 40 | static void computeLightPolygon(int points, const Vector3& lightCenter, float size, |
| 41 | Vector3* ret); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 42 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 43 | static void smoothPolygon(int level, int rays, float* rayDist); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 44 | static float rayIntersectPoly(const Vector2* poly, int polyLength, const Vector2& point, |
| 45 | float dx, float dy); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 46 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 47 | static void xsort(Vector2* points, int pointsLength); |
| 48 | static int hull(Vector2* points, int pointsLength, Vector2* retPoly); |
ztenghui | 9122b1b | 2014-10-03 11:21:11 -0700 | [diff] [blame] | 49 | 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] | 50 | static void sort(Vector2* poly, int polyLength, const Vector2& center); |
| 51 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 52 | 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); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 57 | static void reverse(Vector2* polygon, int len); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 58 | |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 59 | static void generateTriangleStrip(bool isCasterOpaque, float shadowStrengthScale, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 60 | Vector2* penumbra, int penumbraLength, Vector2* umbra, |
| 61 | int umbraLength, const Vector3* poly, int polyLength, |
| 62 | VertexBuffer& retstrips, const Vector2& centroid); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 63 | |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 64 | #if DEBUG_SHADOW |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 65 | static bool testConvex(const Vector2* polygon, int polygonLength, const char* name); |
| 66 | static void testIntersection(const Vector2* poly1, int poly1Length, const Vector2* poly2, |
| 67 | int poly2Length, const Vector2* intersection, |
| 68 | int intersectionLength); |
| 69 | static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound); |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame] | 70 | static void dumpPolygon(const Vector2* poly, int polyLength, const char* polyName); |
| 71 | static void dumpPolygon(const Vector3* poly, int polyLength, const char* polyName); |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 72 | #endif |
| 73 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 74 | }; // SpotShadow |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 75 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 76 | }; // namespace uirenderer |
| 77 | }; // namespace android |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 78 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 79 | #endif // ANDROID_HWUI_SPOT_SHADOW_H |