I know that Flutter's Canvas.drawShadow
translates to Skia's SkShadowUtils::DrawUtils
, where the elevation
on the Flutter side affects the zPlaneParams
on the Skia side (see the flutter::PhysicalShapeLayer::DrawShadow
engine implementation, which is called with dpr
from Canvas::drawShadow
which is directly called from Dart), however, I cannot at all figure out how elevation
behaves when drawing a shadow in native (forget Flutter web because that is completely different again):
void drawShadow(Path path, Color color, double elevation, bool transparentOccluder) { // ...
_drawShadow(path, color.value, elevation, transparentOccluder);
}
void _drawShadow(Path path, int color, double elevation, bool transparentOccluder)
native 'Canvas_drawShadow';
void Canvas::drawShadow(const CanvasPath* path, SkColor color, double elevation, bool transparentOccluder)
{ // ..
SkScalar dpr = UIDartState::Current()->window()->viewport_metrics().device_pixel_ratio;
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path->path(), color,
elevation, transparentOccluder, dpr);
}
void flutter::PhysicalShapeLayer::DrawShadow(...) {
// ...
SkShadowUtils::DrawShadow(canvas, path, SkPoint3::Make(0, 0, dpr * elevation),
SkPoint3::Make(shadow_x, shadow_y, dpr * kLightHeight),
dpr * kLightRadius, ambientColor, spotColor, flags);
}
And so on - see the Skia source code link if you wish to dive deeper.
Precisely, I do not understand what range of numbers elevation
accepts, i.e. what numbers I can put it - I would have assumed 0
to 600
looking at kLightHeight
, but that does not map completely to what I experienced. Even then, I still do not know what values for elevation
mean.
Additionally, I would love to understand how the size of the path and the canvas scale generally affects the shadow and potentially where the light source is located.
I need this information to ensure consistent behavior across different screen sizes.
So if anyone knows or can figure it out from the links I provided, I would gladly accept any input.