2017-01-13 19:37:37 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#ifndef SkShadowUtils_DEFINED
|
|
|
|
#define SkShadowUtils_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkPoint3.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/private/SkShadowFlags.h"
|
2017-01-13 19:37:37 +00:00
|
|
|
|
|
|
|
class SkCanvas;
|
2021-01-11 16:01:09 +00:00
|
|
|
class SkMatrix;
|
2017-01-13 19:37:37 +00:00
|
|
|
class SkPath;
|
2017-02-23 14:34:03 +00:00
|
|
|
class SkResourceCache;
|
2022-03-09 14:50:30 +00:00
|
|
|
struct SkRect;
|
2017-01-13 19:37:37 +00:00
|
|
|
|
2017-09-20 19:51:08 +00:00
|
|
|
class SK_API SkShadowUtils {
|
2017-01-13 19:37:37 +00:00
|
|
|
public:
|
2017-02-23 14:34:03 +00:00
|
|
|
/**
|
2018-01-18 20:19:13 +00:00
|
|
|
* Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
|
|
|
|
* light. The shadow may be cached, depending on the path type and canvas matrix. If the
|
|
|
|
* matrix is perspective or the path is volatile, it will not be cached.
|
|
|
|
*
|
|
|
|
* @param canvas The canvas on which to draw the shadows.
|
|
|
|
* @param path The occluder used to generate the shadows.
|
|
|
|
* @param zPlaneParams Values for the plane function which returns the Z offset of the
|
|
|
|
* occluder from the canvas based on local x and y values (the current matrix is not applied).
|
2020-12-16 16:56:11 +00:00
|
|
|
* @param lightPos Generally, the 3D position of the light relative to the canvas plane.
|
|
|
|
* If kDirectionalLight_ShadowFlag is set, this specifies a vector pointing
|
|
|
|
* towards the light.
|
|
|
|
* @param lightRadius Generally, the radius of the disc light.
|
|
|
|
* If DirectionalLight_ShadowFlag is set, this specifies the amount of
|
|
|
|
* blur when the occluder is at Z offset == 1. The blur will grow linearly
|
|
|
|
* as the Z value increases.
|
2018-01-18 20:19:13 +00:00
|
|
|
* @param ambientColor The color of the ambient shadow.
|
|
|
|
* @param spotColor The color of the spot shadow.
|
2020-12-16 16:56:11 +00:00
|
|
|
* @param flags Options controlling opaque occluder optimizations, shadow appearance,
|
|
|
|
* and light position. See SkShadowFlags.
|
2018-01-18 20:19:13 +00:00
|
|
|
*/
|
|
|
|
static void DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams,
|
|
|
|
const SkPoint3& lightPos, SkScalar lightRadius,
|
|
|
|
SkColor ambientColor, SkColor spotColor,
|
|
|
|
uint32_t flags = SkShadowFlags::kNone_ShadowFlag);
|
|
|
|
|
2021-01-11 16:01:09 +00:00
|
|
|
/**
|
|
|
|
* Generate bounding box for shadows relative to path. Includes both the ambient and spot
|
|
|
|
* shadow bounds.
|
|
|
|
*
|
|
|
|
* @param ctm Current transformation matrix to device space.
|
|
|
|
* @param path The occluder used to generate the shadows.
|
|
|
|
* @param zPlaneParams Values for the plane function which returns the Z offset of the
|
|
|
|
* occluder from the canvas based on local x and y values (the current matrix is not applied).
|
|
|
|
* @param lightPos Generally, the 3D position of the light relative to the canvas plane.
|
|
|
|
* If kDirectionalLight_ShadowFlag is set, this specifies a vector pointing
|
|
|
|
* towards the light.
|
|
|
|
* @param lightRadius Generally, the radius of the disc light.
|
|
|
|
* If DirectionalLight_ShadowFlag is set, this specifies the amount of
|
|
|
|
* blur when the occluder is at Z offset == 1. The blur will grow linearly
|
|
|
|
* as the Z value increases.
|
|
|
|
* @param flags Options controlling opaque occluder optimizations, shadow appearance,
|
|
|
|
* and light position. See SkShadowFlags.
|
|
|
|
* @param bounds Return value for shadow bounding box.
|
|
|
|
* @return Returns true if successful, false otherwise.
|
|
|
|
*/
|
|
|
|
static bool GetLocalBounds(const SkMatrix& ctm, const SkPath& path,
|
|
|
|
const SkPoint3& zPlaneParams, const SkPoint3& lightPos,
|
|
|
|
SkScalar lightRadius, uint32_t flags, SkRect* bounds);
|
|
|
|
|
2018-01-18 20:19:13 +00:00
|
|
|
/**
|
2018-02-22 15:58:34 +00:00
|
|
|
* Helper routine to compute color values for one-pass tonal alpha.
|
2018-01-18 20:19:13 +00:00
|
|
|
*
|
2018-02-22 15:58:34 +00:00
|
|
|
* @param inAmbientColor Original ambient color
|
|
|
|
* @param inSpotColor Original spot color
|
|
|
|
* @param outAmbientColor Modified ambient color
|
|
|
|
* @param outSpotColor Modified spot color
|
2017-02-23 14:34:03 +00:00
|
|
|
*/
|
2018-01-18 20:19:13 +00:00
|
|
|
static void ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
|
|
|
|
SkColor* outAmbientColor, SkColor* outSpotColor);
|
2017-01-13 19:37:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|