OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkLightingImageFilter_DEFINED | 8 #ifndef SkLightingImageFilter_DEFINED |
9 #define SkLightingImageFilter_DEFINED | 9 #define SkLightingImageFilter_DEFINED |
10 | 10 |
11 #include "SkImageFilter.h" | 11 #include "SkImageFilter.h" |
12 #include "SkColor.h" | 12 #include "SkColor.h" |
13 | 13 |
14 class SK_API SkPoint3 { | |
15 public: | |
16 SkPoint3() {} | |
17 SkPoint3(SkScalar x, SkScalar y, SkScalar z) | |
18 : fX(x), fY(y), fZ(z) {} | |
19 SkScalar dot(const SkPoint3& other) const { | |
20 return fX * other.fX + fY * other.fY + fZ * other.fZ; | |
21 } | |
22 SkScalar maxComponent() const { | |
23 return fX > fY ? (fX > fZ ? fX : fZ) : (fY > fZ ? fY : fZ); | |
24 } | |
25 void normalize() { | |
26 // Small epsilon is added to prevent division by 0. | |
27 SkScalar scale = SkScalarInvert(SkScalarSqrt(dot(*this)) + SK_ScalarNear
lyZero); | |
28 fX = fX * scale; | |
29 fY = fY * scale; | |
30 fZ = fZ * scale; | |
31 } | |
32 SkPoint3 operator*(SkScalar scalar) const { | |
33 return SkPoint3(fX * scalar, fY * scalar, fZ * scalar); | |
34 } | |
35 SkPoint3 operator-(const SkPoint3& other) const { | |
36 return SkPoint3(fX - other.fX, fY - other.fY, fZ - other.fZ); | |
37 } | |
38 bool operator==(const SkPoint3& other) const { | |
39 return fX == other.fX && fY == other.fY && fZ == other.fZ; | |
40 } | |
41 SkScalar fX, fY, fZ; | |
42 }; | |
43 | |
44 class SkLight; | 14 class SkLight; |
| 15 struct SkPoint3; |
45 | 16 |
46 class SK_API SkLightingImageFilter : public SkImageFilter { | 17 class SK_API SkLightingImageFilter : public SkImageFilter { |
47 public: | 18 public: |
48 static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction, | 19 static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction, |
49 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, | 20 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, |
50 SkImageFilter* input = NULL, const CropRect* cropRect = NULL); | 21 SkImageFilter* input = NULL, const CropRect* cropRect = NULL); |
51 static SkImageFilter* CreatePointLitDiffuse(const SkPoint3& location, | 22 static SkImageFilter* CreatePointLitDiffuse(const SkPoint3& location, |
52 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, | 23 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, |
53 SkImageFilter* input = NULL, const CropRect* cropRect = NULL); | 24 SkImageFilter* input = NULL, const CropRect* cropRect = NULL); |
54 static SkImageFilter* CreateSpotLitDiffuse(const SkPoint3& location, | 25 static SkImageFilter* CreateSpotLitDiffuse(const SkPoint3& location, |
(...skipping 23 matching lines...) Expand all Loading... |
78 const SkLight* light() const { return fLight.get(); } | 49 const SkLight* light() const { return fLight.get(); } |
79 SkScalar surfaceScale() const { return fSurfaceScale; } | 50 SkScalar surfaceScale() const { return fSurfaceScale; } |
80 | 51 |
81 private: | 52 private: |
82 typedef SkImageFilter INHERITED; | 53 typedef SkImageFilter INHERITED; |
83 SkAutoTUnref<SkLight> fLight; | 54 SkAutoTUnref<SkLight> fLight; |
84 SkScalar fSurfaceScale; | 55 SkScalar fSurfaceScale; |
85 }; | 56 }; |
86 | 57 |
87 #endif | 58 #endif |
OLD | NEW |