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: |
| 29 | static void createSpotShadow(const Vector3* poly, int polyLength, |
| 30 | const Vector3& lightCenter, float lightSize, int lightVertexCount, |
| 31 | int rays, int layers, float strength, VertexBuffer& retStrips); |
| 32 | |
| 33 | private: |
| 34 | static void computeSpotShadow(const Vector3* lightPoly, int lightPolyLength, |
| 35 | const Vector3& lightCenter, const Vector3* poly, int polyLength, |
| 36 | int rays, int layers, float strength, VertexBuffer& retstrips); |
| 37 | |
| 38 | static void computeLightPolygon(int points, const Vector3& lightCenter, |
| 39 | float size, Vector3* ret); |
| 40 | |
| 41 | static int getStripSize(int rays, int layers); |
| 42 | static void smoothPolygon(int level, int rays, float* rayDist); |
| 43 | static float calculateOpacity(float jf, float deltaDist); |
| 44 | static float rayIntersectPoly(const Vector2* poly, int polyLength, |
| 45 | const Vector2& point, float dx, float dy); |
| 46 | |
| 47 | static Vector2 centroid2d(const Vector2* poly, int polyLength); |
| 48 | |
| 49 | static void xsort(Vector2* points, int pointsLength); |
| 50 | static int hull(Vector2* points, int pointsLength, Vector2* retPoly); |
| 51 | static bool rightTurn(double ax, double ay, double bx, double by, double cx, double cy); |
| 52 | static int intersection(Vector2* poly1, int poly1length, Vector2* poly2, int poly2length); |
| 53 | static void sort(Vector2* poly, int polyLength, const Vector2& center); |
| 54 | |
| 55 | static float angle(const Vector2& point, const Vector2& center); |
| 56 | static void swap(Vector2* points, int i, int j); |
| 57 | static void quicksortCirc(Vector2* points, int low, int high, const Vector2& center); |
| 58 | static void quicksortX(Vector2* points, int low, int high); |
| 59 | |
| 60 | static bool testPointInsidePolygon(const Vector2 testPoint, const Vector2* poly, int len); |
| 61 | static void makeClockwise(Vector2* polygon, int len); |
| 62 | static bool isClockwise(Vector2* polygon, int len); |
| 63 | static void reverse(Vector2* polygon, int len); |
| 64 | static inline bool lineIntersection(double x1, double y1, double x2, double y2, |
| 65 | double x3, double y3, double x4, double y4, Vector2& ret); |
| 66 | |
| 67 | static void generateTriangleStrip(const Vector2* penumbra, int penumbraLength, |
| 68 | const Vector2* umbra, int umbraLength, int rays, int layers, |
| 69 | float strength, VertexBuffer& retstrips); |
| 70 | |
| 71 | static const double EPSILON = 1e-7; |
| 72 | }; // SpotShadow |
| 73 | |
| 74 | }; // namespace uirenderer |
| 75 | }; // namespace android |
| 76 | |
| 77 | #endif // ANDROID_HWUI_SPOT_SHADOW_H |