-
-
Notifications
You must be signed in to change notification settings - Fork 971
fix: Calculate zoom ratio before rendering svg #3616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few small comments
While trying to test different width/height scale, a bug in 0be4940 was discovered. Looking at the original code for Image _getImage(Size size) {
final image = _imageCache.getValue(size);
if (image == null) {
final recorder = PictureRecorder();
final canvas = Canvas(recorder);
canvas.scale(pixelRatio);
_render(canvas, size);
final picture = recorder.endRecording();
final image = picture.toImageSync(
(size.width * pixelRatio).ceil(),
(size.height * pixelRatio).ceil(),
);
picture.dispose();
_imageCache.setValue(size, image);
return image;
}
return image;
} We can see that the unscaled size is passed into Here's a comparison of a scaling of scaleX=3, scaleY=1.5 with and without this pr now:
Should the test be updated to have different X and Y scaling, or should an additional test be added? |
Some comments about the tests: Golden files were mistakenly updated in 5a5a302 due to the Upon further inspection, the |
In the ...
import 'package:flutter/widgets.dart' hide Image; // Remember to hide the other Image type
/// A [Svg] to be rendered on a Flame [Game].
class Svg {
/// Creates an [Svg] with the received [pictureInfo].
/// Default [pixelRatio] is the device pixel ratio.
Svg(this.pictureInfo, {double? pixelRatio})
: pixelRatio = pixelRatio ??
WidgetsBinding
.instance.platformDispatcher.views.first.devicePixelRatio; |
Seems to work 👍, with the new testing method however, I'm not sure how to set the device pixel ratio. Currently a teardown step is added to the 'render sharply' test that sets the device pixel ratio to 1. Using |
Just set the device pixel ratio inside of the test, or in the setup function. The tear down is called after each test has run. |
Ah, I'm not sure how should this be done under either My assumption is that the reason it's set to 3 with the new test is because of |
@vunyunt ah right, I forgot that you can't access the tester from within |
Alright, the test has been restored to just before 85e885b |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
Description
SvgComponent currently renders in lower-than-native resolution when
game.camera.viewfinder.zoom
is larger than 1. This is addressed by taking a ratio ofcanvas.getDestinationClipBounds().size
andcanvas.getLocalClipBounds().size
, and applying it to the existing canvas scaling.I'm still not quite sure how well this would work with
pixelRatio
, but I've verified that when running the "render sharply" test which has the device pixel ratio set to 3, the canvas size ratio mentioned above is 1, and not rendering in excessive resolution.The test uses a
Transform.scale
to simulate viewfinder zoom. I've also verified that when running without the patch, this test generates a blurry image:Checklist
docs
and added dartdoc comments with///
.examples
ordocs
.Breaking Change?
Related Issues
Fixes #3615