Options
These globals are now defined:
double duration; // The requested duration of the animation. double frame; // A value in [0, 1] of where we are in the animation.
This global is now defined:
GrBackendRenderTarget backEndRenderTarget;
GrBackendTexture backEndTextureRenderTarget;
Optional source image
These globals are now defined:
SkBitmap source; sk_sp<SkImage> image; GrBackendTexture backEndTexture; // GPU Only.
Note:
Adding comments with SK_FOLD_START and SK_FOLD_END creates foldable code
blocks.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
These blocks will be folded by default and are useful for highlighting specific lines of code.
You can also use the keyboard shortcuts Ctrl+S and Ctrl+E in the code editor to set them.
xxxxxxxxxx
33
const SkScalar kLightHeight = 600;
const SkScalar kLightRadius = 800;
void DrawShadow(SkCanvas* canvas,
const SkPath& path,
SkColor color,
float elevation,
bool transparentOccluder,
SkScalar dpr) {
const SkScalar kAmbientAlpha = 0.039f;
const SkScalar kSpotAlpha = 0.25f;
uint32_t flags = transparentOccluder
? SkShadowFlags::kTransparentOccluder_ShadowFlag
: SkShadowFlags::kNone_ShadowFlag;
flags |= SkShadowFlags::kDirectionalLight_ShadowFlag;
SkColor inAmbient = SkColorSetA(color, kAmbientAlpha * SkColorGetA(color));
SkColor inSpot = SkColorSetA(color, kSpotAlpha * SkColorGetA(color));
SkColor ambientColor, spotColor;
SkShadowUtils::ComputeTonalColors(inAmbient, inSpot, &ambientColor,
&spotColor);
SkShadowUtils::DrawShadow(canvas, path, SkPoint3::Make(0, 0, dpr * elevation),
SkPoint3::Make(0, -1, 1),
kLightRadius / kLightHeight, ambientColor,
spotColor, flags);
}
void draw(SkCanvas* canvas) {
SkPath path;
path.addRoundRect({50, 50, 150, 150}, 10, 10);
canvas->drawColor(SK_ColorYELLOW);
DrawShadow(canvas, path, SK_ColorDKGRAY, 10, true, 1.0);
}