blob: 7beee855e1f2c688455ea9fe39f49132fb26f364 [file] [log] [blame]
Jim Van Verth43475ad2017-01-13 14:37:37 -05001
2/*
3 * Copyright 2017 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8#ifndef SkShadowUtils_DEFINED
9#define SkShadowUtils_DEFINED
10
11#include "SkColor.h"
Mike Reed54518ac2017-07-22 08:29:48 -040012#include "SkPoint3.h"
Jim Van Verth43475ad2017-01-13 14:37:37 -050013#include "SkScalar.h"
Jim Van Verth2103cf02017-01-16 13:03:37 -050014#include "../private/SkShadowFlags.h"
Jim Van Verth43475ad2017-01-13 14:37:37 -050015
16class SkCanvas;
17class SkPath;
Brian Salomon804e0912017-02-23 09:34:03 -050018class SkResourceCache;
Jim Van Verth43475ad2017-01-13 14:37:37 -050019
Derek Sollenberger2fbf1bc2017-09-20 15:51:08 -040020class SK_API SkShadowUtils {
Jim Van Verth43475ad2017-01-13 14:37:37 -050021public:
Brian Salomon804e0912017-02-23 09:34:03 -050022 /**
23 * Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
Jim Van Verth37c5a962017-05-10 14:13:24 -040024 * light. The shadow may be cached, depending on the path type and canvas matrix. If the
25 * matrix is perspective or the path is volatile, it will not be cached.
Brian Salomon804e0912017-02-23 09:34:03 -050026 *
27 * @param canvas The canvas on which to draw the shadows.
28 * @param path The occluder used to generate the shadows.
Jim Van Verth37c5a962017-05-10 14:13:24 -040029 * @param zPlaneParams Values for the plane function which returns the Z offset of the
30 * occluder from the canvas based on local x and y values (the current matrix is not applied).
Brian Salomon804e0912017-02-23 09:34:03 -050031 * @param lightPos The 3D position of the light relative to the canvas plane. This is
32 * independent of the canvas's current matrix.
33 * @param lightRadius The radius of the disc light.
Jim Van Verthb1b80f72018-01-18 15:19:13 -050034 * @param ambientColor The color of the ambient shadow.
35 * @param spotColor The color of the spot shadow.
36 * @param flags Options controlling opaque occluder optimizations and shadow appearance. See
37 * SkShadowFlags.
38 */
39 static void DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlaneParams,
40 const SkPoint3& lightPos, SkScalar lightRadius,
41 SkColor ambientColor, SkColor spotColor,
42 uint32_t flags = SkShadowFlags::kNone_ShadowFlag);
43
44 /**
Jim Van Vertha5566842018-02-22 10:58:34 -050045 * Helper routine to compute color values for one-pass tonal alpha.
Jim Van Verthb1b80f72018-01-18 15:19:13 -050046 *
Jim Van Vertha5566842018-02-22 10:58:34 -050047 * @param inAmbientColor Original ambient color
48 * @param inSpotColor Original spot color
49 * @param outAmbientColor Modified ambient color
50 * @param outSpotColor Modified spot color
Brian Salomon804e0912017-02-23 09:34:03 -050051 */
Jim Van Verthb1b80f72018-01-18 15:19:13 -050052 static void ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
53 SkColor* outAmbientColor, SkColor* outSpotColor);
Jim Van Verth43475ad2017-01-13 14:37:37 -050054};
55
56#endif