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_old(bool isCasterOpaque, const Vector3* poly, |
ztenghui | 50ecf84 | 2014-03-11 16:52:30 -0700 | [diff] [blame] | 30 | int polyLength, const Vector3& lightCenter, float lightSize, |
| 31 | int lightVertexCount, VertexBuffer& retStrips); |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame^] | 32 | static void createSpotShadow(bool isCasterOpaque, const Vector3& lightCenter, |
| 33 | float lightSize, const Vector3* poly, int polyLength, |
| 34 | const Vector3& polyCentroid, VertexBuffer& retstrips); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 35 | |
| 36 | private: |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame^] | 37 | static float projectCasterToOutline(Vector2& outline, |
| 38 | const Vector3& lightCenter, const Vector3& polyVertex); |
ztenghui | 50ecf84 | 2014-03-11 16:52:30 -0700 | [diff] [blame] | 39 | static int calculateOccludedUmbra(const Vector2* umbra, int umbraLength, |
| 40 | const Vector3* poly, int polyLength, Vector2* occludedUmbra); |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame^] | 41 | |
| 42 | static void computeSpotShadow_old(bool isCasterOpaque, const Vector3* lightPoly, |
ztenghui | 50ecf84 | 2014-03-11 16:52:30 -0700 | [diff] [blame] | 43 | int lightPolyLength, const Vector3& lightCenter, const Vector3* poly, |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame^] | 44 | int polyLength, VertexBuffer& shadowTriangleStrip); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 45 | |
| 46 | static void computeLightPolygon(int points, const Vector3& lightCenter, |
| 47 | float size, Vector3* ret); |
| 48 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 49 | static void smoothPolygon(int level, int rays, float* rayDist); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 50 | static float rayIntersectPoly(const Vector2* poly, int polyLength, |
| 51 | const Vector2& point, float dx, float dy); |
| 52 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 53 | static void xsort(Vector2* points, int pointsLength); |
| 54 | static int hull(Vector2* points, int pointsLength, Vector2* retPoly); |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 55 | static bool ccw(double ax, double ay, double bx, double by, double cx, double cy); |
ztenghui | 50ecf84 | 2014-03-11 16:52:30 -0700 | [diff] [blame] | 56 | static int intersection(const Vector2* poly1, int poly1length, Vector2* poly2, int poly2length); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 57 | static void sort(Vector2* poly, int polyLength, const Vector2& center); |
| 58 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 59 | static void swap(Vector2* points, int i, int j); |
| 60 | static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center); |
| 61 | static void quicksortX(Vector2* points, int low, int high); |
| 62 | |
| 63 | static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len); |
| 64 | static void makeClockwise(Vector2* polygon, int len); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 65 | static void reverse(Vector2* polygon, int len); |
| 66 | static inline bool lineIntersection(double x1, double y1, double x2, double y2, |
| 67 | double x3, double y3, double x4, double y4, Vector2& ret); |
| 68 | |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame^] | 69 | static void generateTriangleStrip(bool isCasterOpaque, float shadowStrengthScale, |
| 70 | const Vector2* penumbra, int penumbraLength, const Vector2* umbra, int umbraLength, |
ztenghui | 50ecf84 | 2014-03-11 16:52:30 -0700 | [diff] [blame] | 71 | const Vector3* poly, int polyLength, VertexBuffer& retstrips); |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 72 | |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 73 | #if DEBUG_SHADOW |
| 74 | // Verification utility function. |
| 75 | static bool testConvex(const Vector2* polygon, int polygonLength, |
| 76 | const char* name); |
| 77 | static void testIntersection(const Vector2* poly1, int poly1Length, |
| 78 | const Vector2* poly2, int poly2Length, |
| 79 | const Vector2* intersection, int intersectionLength); |
| 80 | static void updateBound(const Vector2 inVector, Vector2& lowerBound, Vector2& upperBound ); |
ztenghui | c50a03d | 2014-08-21 13:47:54 -0700 | [diff] [blame^] | 81 | static void dumpPolygon(const Vector2* poly, int polyLength, const char* polyName); |
| 82 | static void dumpPolygon(const Vector3* poly, int polyLength, const char* polyName); |
ztenghui | f5ca8b4 | 2014-01-27 15:53:28 -0800 | [diff] [blame] | 83 | #endif |
| 84 | |
ztenghui | 7b4516e | 2014-01-07 10:42:55 -0800 | [diff] [blame] | 85 | }; // SpotShadow |
| 86 | |
| 87 | }; // namespace uirenderer |
| 88 | }; // namespace android |
| 89 | |
| 90 | #endif // ANDROID_HWUI_SPOT_SHADOW_H |