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
15class SkImageFilterLight;
16struct SkPoint3;
17
18class SK_API SkLightingImageFilter : public SkImageFilter {
19public:
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
44protected:
45    SkLightingImageFilter(sk_sp<SkImageFilterLight> light,
46                          SkScalar surfaceScale,
47                          sk_sp<SkImageFilter> input,
48                          const CropRect* cropRect);
49    void flatten(SkWriteBuffer&) const override;
50    const SkImageFilterLight* light() const { return fLight.get(); }
51    SkScalar surfaceScale() const { return fSurfaceScale; }
52    bool affectsTransparentBlack() const override { return true; }
53
54private:
55    sk_sp<SkImageFilterLight> fLight;
56    SkScalar fSurfaceScale;
57
58    typedef SkImageFilter INHERITED;
59};
60
61#endif
62