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 { | 14 #ifdef SK_LEGACY_SKPOINT3_CTORS |
15 public: | 15 // TODO: remove this. Chromium relies on having this included here |
16 SkPoint3() {} | 16 #include "SkPoint3.h" |
17 SkPoint3(SkScalar x, SkScalar y, SkScalar z) | 17 #else |
18 : fX(x), fY(y), fZ(z) {} | 18 struct SkPoint3; |
19 SkScalar dot(const SkPoint3& other) const { | 19 #endif |
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 | 20 |
44 class SkLight; | 21 class SkLight; |
45 | 22 |
46 class SK_API SkLightingImageFilter : public SkImageFilter { | 23 class SK_API SkLightingImageFilter : public SkImageFilter { |
47 public: | 24 public: |
48 static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction, | 25 static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction, |
49 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, | 26 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, |
50 SkImageFilter* input = NULL, const CropRect* cropRect = NULL); | 27 SkImageFilter* input = NULL, const CropRect* cropRect = NULL); |
51 static SkImageFilter* CreatePointLitDiffuse(const SkPoint3& location, | 28 static SkImageFilter* CreatePointLitDiffuse(const SkPoint3& location, |
52 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, | 29 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, |
(...skipping 25 matching lines...) Expand all Loading... |
78 const SkLight* light() const { return fLight.get(); } | 55 const SkLight* light() const { return fLight.get(); } |
79 SkScalar surfaceScale() const { return fSurfaceScale; } | 56 SkScalar surfaceScale() const { return fSurfaceScale; } |
80 | 57 |
81 private: | 58 private: |
82 typedef SkImageFilter INHERITED; | 59 typedef SkImageFilter INHERITED; |
83 SkAutoTUnref<SkLight> fLight; | 60 SkAutoTUnref<SkLight> fLight; |
84 SkScalar fSurfaceScale; | 61 SkScalar fSurfaceScale; |
85 }; | 62 }; |
86 | 63 |
87 #endif | 64 #endif |
OLD | NEW |