SkShadowUtils.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2017 Google Inc.
  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 SkShadowUtils_DEFINED
  8. #define SkShadowUtils_DEFINED
  9. #include "include/core/SkColor.h"
  10. #include "include/core/SkPoint3.h"
  11. #include "include/core/SkScalar.h"
  12. #include "include/private/SkShadowFlags.h"
  13. class SkCanvas;
  14. class SkPath;
  15. class SkResourceCache;
  16. class SK_API SkShadowUtils {
  17. public:
  18. /**
  19. * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
  20. * light. The shadow may be cached, depending on the path type and canvas matrix. If the
  21. * matrix is perspective or the path is volatile, it will not be cached.
  22. *
  23. * @param canvas The canvas on which to draw the shadows.
  24. * @param path The occluder used to generate the shadows.
  25. * @param zPlaneParams Values for the plane function which returns the Z offset of the
  26. * occluder from the canvas based on local x and y values (the current matrix is not applied).
  27. * @param lightPos The 3D position of the light relative to the canvas plane. This is
  28. * independent of the canvas's current matrix.
  29. * @param lightRadius The radius of the disc light.
  30. * @param ambientColor The color of the ambient shadow.
  31. * @param spotColor The color of the spot shadow.
  32. * @param flags Options controlling opaque occluder optimizations and shadow appearance. See
  33. * SkShadowFlags.
  34. */
  35. static void DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams,
  36. const SkPoint3& lightPos, SkScalar lightRadius,
  37. SkColor ambientColor, SkColor spotColor,
  38. uint32_t flags = SkShadowFlags::kNone_ShadowFlag);
  39. /**
  40. * Helper routine to compute color values for one-pass tonal alpha.
  41. *
  42. * @param inAmbientColor Original ambient color
  43. * @param inSpotColor Original spot color
  44. * @param outAmbientColor Modified ambient color
  45. * @param outSpotColor Modified spot color
  46. */
  47. static void ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
  48. SkColor* outAmbientColor, SkColor* outSpotColor);
  49. };
  50. #endif