Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkLightingImageFilter.h
1 /*
2  * Copyright 2012 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkLightingImageFilter_DEFINED
9 #define SkLightingImageFilter_DEFINED
10 
11 #include "SkImageFilter.h"
12 #include "SkColor.h"
13 
14 
15 class SkImageFilterLight;
16 struct SkPoint3;
17 
18 class SK_API SkLightingImageFilter : public SkImageFilter {
19 public:
20  static sk_sp<SkImageFilter> MakeDistantLitDiffuse(const SkPoint3& direction,
21  SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
22  sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
23  static sk_sp<SkImageFilter> MakePointLitDiffuse(const SkPoint3& location,
24  SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
25  sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
26  static sk_sp<SkImageFilter> MakeSpotLitDiffuse(const SkPoint3& location,
27  const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
28  SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
29  sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
30  static sk_sp<SkImageFilter> MakeDistantLitSpecular(const SkPoint3& direction,
31  SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
32  SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
33  static sk_sp<SkImageFilter> MakePointLitSpecular(const SkPoint3& location,
34  SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
35  SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
36  static sk_sp<SkImageFilter> MakeSpotLitSpecular(const SkPoint3& location,
37  const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
38  SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
39  SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
40  ~SkLightingImageFilter() override;
41 
42  SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
43 
44 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
45  static SkImageFilter* CreateDistantLitDiffuse(const SkPoint3& direction,
46  SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
47  SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
48  return MakeDistantLitDiffuse(direction, lightColor, surfaceScale, kd,
49  sk_ref_sp<SkImageFilter>(input), cropRect).release();
50  }
51  static SkImageFilter* CreatePointLitDiffuse(const SkPoint3& location,
52  SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
53  SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
54  return MakePointLitDiffuse(location, lightColor, surfaceScale, kd,
55  sk_ref_sp<SkImageFilter>(input), cropRect).release();
56  }
57  static SkImageFilter* CreateSpotLitDiffuse(const SkPoint3& location,
58  const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
59  SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
60  SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
61  return MakeSpotLitDiffuse(location, target, specularExponent, cutoffAngle,
62  lightColor, surfaceScale, kd,
63  sk_ref_sp<SkImageFilter>(input), cropRect).release();
64  }
65  static SkImageFilter* CreateDistantLitSpecular(const SkPoint3& direction,
66  SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
67  SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
68  return MakeDistantLitSpecular(direction, lightColor, surfaceScale, ks, shininess,
69  sk_ref_sp<SkImageFilter>(input), cropRect).release();
70  }
71  static SkImageFilter* CreatePointLitSpecular(const SkPoint3& location,
72  SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
73  SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
74  return MakePointLitSpecular(location, lightColor, surfaceScale, ks, shininess,
75  sk_ref_sp<SkImageFilter>(input), cropRect).release();
76  }
77  static SkImageFilter* CreateSpotLitSpecular(const SkPoint3& location,
78  const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
79  SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
80  SkScalar shininess, SkImageFilter* input = NULL, const CropRect* cropRect = NULL) {
81  return MakeSpotLitSpecular(location, target, specularExponent, cutoffAngle,
82  lightColor, surfaceScale, ks, shininess,
83  sk_ref_sp<SkImageFilter>(input), cropRect).release();
84  }
85 #endif
86 
87 protected:
89  SkScalar surfaceScale,
91  const CropRect* cropRect);
92  void flatten(SkWriteBuffer&) const override;
93  const SkImageFilterLight* light() const { return fLight.get(); }
94  SkScalar surfaceScale() const { return fSurfaceScale; }
95  bool affectsTransparentBlack() const override { return true; }
96 
97 private:
99  SkScalar fSurfaceScale;
100 
101  typedef SkImageFilter INHERITED;
102 };
103 
104 #endif
T *SK_WARN_UNUSED_RESULT release()
Return the bare pointer, and set the internal object pointer to nullptr.
Definition: SkRefCnt.h:363
Definition: SkLightingImageFilter.h:18
Definition: SkImageFilter.h:55
Definition: SkPoint3.h:13
void flatten(SkWriteBuffer &) const override
Override this if your subclass needs to record data that it will need to recreate itself from its Cre...
Definition: SkRefCnt.h:135
Base class for image filters.
Definition: SkImageFilter.h:35
uint32_t SkColor
32 bit ARGB color value, not premultiplied.
Definition: SkColor.h:28
Definition: SkWriteBuffer.h:26
Types and macros for colors.