Remove deprecated drawShadow interfaces
Bug: skia:7263 Change-Id: I90fcc35e8d070b324287139ebecc3d15dbec0137 Reviewed-on: https://skia-review.googlesource.com/109164 Reviewed-by: Robert Phillips <robertphillips@google.com> Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
parent
0fc07f95bb
commit
a556684b10
@ -11,12 +11,16 @@
|
||||
#include "SkResourceCache.h"
|
||||
#include "SkShadowUtils.h"
|
||||
|
||||
void draw_shadow(SkCanvas* canvas, const SkPath& path, int height, SkColor color, SkPoint3 lightPos,
|
||||
SkScalar lightR, bool isAmbient, uint32_t flags) {
|
||||
void draw_shadow(SkCanvas* canvas, const SkPath& path, SkScalar height, SkColor color,
|
||||
SkPoint3 lightPos, SkScalar lightR, bool isAmbient, uint32_t flags) {
|
||||
SkScalar ambientAlpha = isAmbient ? .5f : 0.f;
|
||||
SkScalar spotAlpha = isAmbient ? 0.f : .5f;
|
||||
SkShadowUtils::DrawShadow(canvas, path, height, lightPos, lightR, ambientAlpha, spotAlpha,
|
||||
color, flags);
|
||||
SkColor ambientColor = SkColorSetARGB(ambientAlpha*SkColorGetA(color), SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
SkColor spotColor = SkColorSetARGB(spotAlpha*SkColorGetA(color), SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
SkShadowUtils::DrawShadow(canvas, path, SkPoint3{ 0, 0, height}, lightPos, lightR,
|
||||
ambientColor, spotColor, flags);
|
||||
}
|
||||
|
||||
static constexpr int kW = 800;
|
||||
@ -75,14 +79,15 @@ void draw_paths(SkCanvas* canvas, ShadowMode mode) {
|
||||
canvas->concat(m);
|
||||
|
||||
if (kDebugColorNoOccluders == mode || kDebugColorOccluders == mode) {
|
||||
flags |= SkShadowFlags::kDisableTonalColor_ShadowFlag;
|
||||
draw_shadow(canvas, path, kHeight, SK_ColorRED, lightPos, kLightR,
|
||||
true, flags);
|
||||
draw_shadow(canvas, path, kHeight, SK_ColorBLUE, lightPos, kLightR,
|
||||
false, flags);
|
||||
} else if (kGrayscale == mode) {
|
||||
SkShadowUtils::DrawShadow(canvas, path, kHeight, lightPos, kLightR,
|
||||
0.1f, 0.25f, SK_ColorBLACK, flags);
|
||||
SkColor ambientColor = SkColorSetARGB(0.1f * 255, 0, 0, 0);
|
||||
SkColor spotColor = SkColorSetARGB(0.25f * 255, 0, 0, 0);
|
||||
SkShadowUtils::DrawShadow(canvas, path, SkPoint3{0, 0, kHeight}, lightPos,
|
||||
kLightR, ambientColor, spotColor, flags);
|
||||
}
|
||||
|
||||
SkPaint paint;
|
||||
|
@ -54,13 +54,22 @@ void draw_content(SkCanvas* canvas, BackgroundMode mode) {
|
||||
lightPos.fX = 75;
|
||||
SkScalar xPos = 75;
|
||||
for (int col = 0; col < 10; ++col) {
|
||||
paint.setColor(kColors[10 * row + col]);
|
||||
SkColor color = kColors[10 * row + col];
|
||||
paint.setColor(color);
|
||||
|
||||
canvas->save();
|
||||
canvas->translate(xPos, yPos);
|
||||
|
||||
SkColor baseAmbient = SkColorSetARGB(kAmbientAlpha*SkColorGetA(color),
|
||||
SkColorGetR(color), SkColorGetG(color),
|
||||
SkColorGetB(color));
|
||||
SkColor baseSpot = SkColorSetARGB(kSpotAlpha*SkColorGetA(color),
|
||||
SkColorGetR(color), SkColorGetG(color),
|
||||
SkColorGetB(color));
|
||||
SkColor tonalAmbient, tonalSpot;
|
||||
SkShadowUtils::ComputeTonalColors(baseAmbient, baseSpot, &tonalAmbient, &tonalSpot);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, kLightWidth,
|
||||
kAmbientAlpha, kSpotAlpha, paint.getColor(), 0);
|
||||
lightPos, kLightWidth, tonalAmbient, tonalSpot);
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
|
||||
|
@ -16,10 +16,8 @@ enum SkShadowFlags {
|
||||
kTransparentOccluder_ShadowFlag = 0x01,
|
||||
/** Don't try to use analytic shadows. */
|
||||
kGeometricOnly_ShadowFlag = 0x02,
|
||||
/** Disable use of tonal values when applying color (deprecated) */
|
||||
kDisableTonalColor_ShadowFlag = 0x04,
|
||||
/** mask for all shadow flags */
|
||||
kAll_ShadowFlag = 0x07
|
||||
kAll_ShadowFlag = 0x03
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -42,81 +42,13 @@ public:
|
||||
uint32_t flags = SkShadowFlags::kNone_ShadowFlag);
|
||||
|
||||
/**
|
||||
* Deprecated version that uses one color and two alphas, and supports tonal color.
|
||||
* Helper routine to compute color values for one-pass tonal alpha.
|
||||
*
|
||||
* 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).
|
||||
* @param lightPos The 3D position of the light relative to the canvas plane. This is
|
||||
* independent of the canvas's current matrix.
|
||||
* @param lightRadius The radius of the disc light.
|
||||
* @param ambientAlpha The maximum alpha of the ambient shadow.
|
||||
* @param spotAlpha The maxium alpha of the spot shadow.
|
||||
* @param color The shadow color.
|
||||
* @param flags Options controlling opaque occluder optimizations and shadow appearance. See
|
||||
* SkShadowFlags.
|
||||
* @param inAmbientColor Original ambient color
|
||||
* @param inSpotColor Original spot color
|
||||
* @param outAmbientColor Modified ambient color
|
||||
* @param outSpotColor Modified spot color
|
||||
*/
|
||||
static void DrawShadow(SkCanvas* canvas, const SkPath& path, const SkPoint3& zPlane,
|
||||
const SkPoint3& lightPos, SkScalar lightRadius, SkScalar ambientAlpha,
|
||||
SkScalar spotAlpha, SkColor color,
|
||||
uint32_t flags = SkShadowFlags::kNone_ShadowFlag) {
|
||||
SkColor ambientColor;
|
||||
SkColor spotColor;
|
||||
if (flags & SkShadowFlags::kDisableTonalColor_ShadowFlag) {
|
||||
ambientColor = SkColorSetARGB(ambientAlpha*SkColorGetA(color), SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
spotColor = SkColorSetARGB(spotAlpha*SkColorGetA(color), SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
} else {
|
||||
SkColor inAmbient = SkColorSetA(color, ambientAlpha*SkColorGetA(color));
|
||||
SkColor inSpot = SkColorSetA(color, spotAlpha*SkColorGetA(color));
|
||||
ComputeTonalColors(inAmbient, inSpot, &ambientColor, &spotColor);
|
||||
}
|
||||
|
||||
DrawShadow(canvas, path, zPlane, lightPos, lightRadius, ambientColor, spotColor, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated version with height value (to be removed when Flutter is updated).
|
||||
*
|
||||
* Draw an offset spot shadow and outlining ambient shadow for the given path using a disc
|
||||
* light.
|
||||
*
|
||||
* @param canvas The canvas on which to draw the shadows.
|
||||
* @param path The occluder used to generate the shadows.
|
||||
* @param occluderHeight The vertical offset of the occluder from the canvas. This is
|
||||
* independent of the canvas's current matrix.
|
||||
* @param lightPos The 3D position of the light relative to the canvas plane. This is
|
||||
* independent of the canvas's current matrix.
|
||||
* @param lightRadius The radius of the disc light.
|
||||
* @param ambientAlpha The maximum alpha of the ambient shadow.
|
||||
* @param spotAlpha The maxium alpha of the spot shadow.
|
||||
* @param color The shadow color.
|
||||
* @param flags Options controlling opaque occluder optimizations and shadow appearance. See
|
||||
* SkShadowFlags.
|
||||
*/
|
||||
static void DrawShadow(SkCanvas* canvas, const SkPath& path, SkScalar occluderHeight,
|
||||
const SkPoint3& lightPos, SkScalar lightRadius, SkScalar ambientAlpha,
|
||||
SkScalar spotAlpha, SkColor color,
|
||||
uint32_t flags = SkShadowFlags::kNone_ShadowFlag) {
|
||||
SkPoint3 zPlane = SkPoint3::Make(0, 0, occluderHeight);
|
||||
DrawShadow(canvas, path, zPlane, lightPos, lightRadius, ambientAlpha, spotAlpha,
|
||||
color, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper routine to compute color values for one-pass tonal alpha.
|
||||
*
|
||||
* @param inAmbientColor Original ambient color
|
||||
* @param inSpotColor Original spot color
|
||||
* @param outAmbientColor Modified ambient color
|
||||
* @param outSpotColor Modified spot color
|
||||
*/
|
||||
static void ComputeTonalColors(SkColor inAmbientColor, SkColor inSpotColor,
|
||||
SkColor* outAmbientColor, SkColor* outSpotColor);
|
||||
};
|
||||
|
@ -155,9 +155,10 @@ protected:
|
||||
flags |= SkShadowFlags::kGeometricOnly_ShadowFlag;
|
||||
}
|
||||
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
ambientAlpha, spotAlpha, SK_ColorBLACK, flags);
|
||||
SkColor ambientColor = SkColorSetARGB(ambientAlpha * 255, 0, 0, 0);
|
||||
SkColor spotColor = SkColorSetARGB(spotAlpha * 255, 0, 0, 0);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams, lightPos, lightWidth,
|
||||
ambientColor, spotColor, flags);
|
||||
|
||||
if (fShowObject) {
|
||||
canvas->drawPath(path, paint);
|
||||
|
@ -111,10 +111,10 @@ protected:
|
||||
}
|
||||
|
||||
if (fTwoPassColor) {
|
||||
flags |= SkShadowFlags::kDisableTonalColor_ShadowFlag;
|
||||
SkColor ambientColor = SkColorSetARGB(ambientAlpha*255, 0, 0, 0);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
ambientAlpha, 0, SK_ColorBLACK, flags);
|
||||
ambientColor, SK_ColorTRANSPARENT, flags);
|
||||
|
||||
if (paint.getColor() != SK_ColorBLACK) {
|
||||
SkColor color = paint.getColor();
|
||||
@ -126,19 +126,31 @@ protected:
|
||||
SkScalar luminance = 0.5f*(max + min) / 255.f;
|
||||
SkScalar alpha = (.6 - .4*luminance)*luminance*luminance + 0.3f;
|
||||
spotAlpha -= (alpha - 0.3f)*.5f;
|
||||
SkColor spotColor = SkColorSetARGB(alpha*SkColorGetA(color), SkColorGetR(color),
|
||||
SkColorGetG(color), SkColorGetB(color));
|
||||
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
0, alpha, paint.getColor(), flags);
|
||||
SK_ColorTRANSPARENT, spotColor, flags);
|
||||
}
|
||||
|
||||
SkColor spotGreyscale = SkColorSetARGB(spotAlpha * 255, 0, 0, 0);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
0, spotAlpha, SK_ColorBLACK, flags);
|
||||
SK_ColorTRANSPARENT, spotGreyscale, flags);
|
||||
} else {
|
||||
SkColor color = paint.getColor();
|
||||
SkColor baseAmbient = SkColorSetARGB(ambientAlpha*SkColorGetA(color),
|
||||
SkColorGetR(color), SkColorGetG(color),
|
||||
SkColorGetB(color));
|
||||
SkColor baseSpot = SkColorSetARGB(spotAlpha*SkColorGetA(color),
|
||||
SkColorGetR(color), SkColorGetG(color),
|
||||
SkColorGetB(color));
|
||||
SkColor tonalAmbient, tonalSpot;
|
||||
SkShadowUtils::ComputeTonalColors(baseAmbient, baseSpot, &tonalAmbient, &tonalSpot);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
ambientAlpha, spotAlpha, paint.getColor(), flags);
|
||||
tonalAmbient, tonalSpot, flags);
|
||||
}
|
||||
if (fShowObject) {
|
||||
canvas->drawPath(path, paint);
|
||||
|
@ -94,9 +94,12 @@ protected:
|
||||
if (fUseAlt) {
|
||||
flags |= SkShadowFlags::kGeometricOnly_ShadowFlag;
|
||||
}
|
||||
|
||||
SkColor ambientColor = SkColorSetARGB(ambientAlpha * 255, 0, 0, 0);
|
||||
SkColor spotColor = SkColorSetARGB(spotAlpha * 255, 0, 0, 0);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
ambientAlpha, spotAlpha, SK_ColorBLACK, flags);
|
||||
ambientColor, spotColor, flags);
|
||||
|
||||
if (fShowObject) {
|
||||
canvas->drawPath(path, paint);
|
||||
|
@ -121,16 +121,15 @@ protected:
|
||||
if (!fShowSpot) {
|
||||
spotAlpha = 0;
|
||||
}
|
||||
flags |= SkShadowFlags::kDisableTonalColor_ShadowFlag;
|
||||
if (fUseAlt) {
|
||||
flags |= SkShadowFlags::kGeometricOnly_ShadowFlag;
|
||||
}
|
||||
|
||||
SkColor ambientColor = SkColorSetARGB(ambientAlpha * 255, 255, 0, 0);
|
||||
SkColor spotColor = SkColorSetARGB(spotAlpha * 255, 0, 0, 255);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
ambientAlpha, 0, SK_ColorRED, flags);
|
||||
SkShadowUtils::DrawShadow(canvas, path, zPlaneParams,
|
||||
lightPos, lightWidth,
|
||||
0, spotAlpha, SK_ColorBLUE, flags);
|
||||
ambientColor, spotColor, flags);
|
||||
|
||||
if (fShowObject) {
|
||||
canvas->drawPath(path, paint);
|
||||
|
Loading…
Reference in New Issue
Block a user