SkLightingImageFilter.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef SkLightingImageFilter_DEFINED
  8. #define SkLightingImageFilter_DEFINED
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkImageFilter.h"
  11. class SkImageFilterLight;
  12. struct SkPoint3;
  13. class SK_API SkLightingImageFilter : public SkImageFilter {
  14. public:
  15. static sk_sp<SkImageFilter> MakeDistantLitDiffuse(const SkPoint3& direction,
  16. SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
  17. sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
  18. static sk_sp<SkImageFilter> MakePointLitDiffuse(const SkPoint3& location,
  19. SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
  20. sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
  21. static sk_sp<SkImageFilter> MakeSpotLitDiffuse(const SkPoint3& location,
  22. const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
  23. SkColor lightColor, SkScalar surfaceScale, SkScalar kd,
  24. sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
  25. static sk_sp<SkImageFilter> MakeDistantLitSpecular(const SkPoint3& direction,
  26. SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
  27. SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
  28. static sk_sp<SkImageFilter> MakePointLitSpecular(const SkPoint3& location,
  29. SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
  30. SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
  31. static sk_sp<SkImageFilter> MakeSpotLitSpecular(const SkPoint3& location,
  32. const SkPoint3& target, SkScalar specularExponent, SkScalar cutoffAngle,
  33. SkColor lightColor, SkScalar surfaceScale, SkScalar ks,
  34. SkScalar shininess, sk_sp<SkImageFilter> input, const CropRect* cropRect = nullptr);
  35. ~SkLightingImageFilter() override;
  36. static void RegisterFlattenables();
  37. protected:
  38. SkLightingImageFilter(sk_sp<SkImageFilterLight> light,
  39. SkScalar surfaceScale,
  40. sk_sp<SkImageFilter> input,
  41. const CropRect* cropRect);
  42. void flatten(SkWriteBuffer&) const override;
  43. const SkImageFilterLight* light() const { return fLight.get(); }
  44. inline sk_sp<const SkImageFilterLight> refLight() const;
  45. SkScalar surfaceScale() const { return fSurfaceScale; }
  46. bool affectsTransparentBlack() const override { return true; }
  47. private:
  48. sk_sp<SkImageFilterLight> fLight;
  49. SkScalar fSurfaceScale;
  50. typedef SkImageFilter INHERITED;
  51. };
  52. #endif