fix: (flutter/web) use window.devicePixelRatio for viewport

This commit is contained in:
Nick Fisher
2024-08-27 21:51:09 +08:00
parent 7ac7ae43ab
commit 704b7f6734
2 changed files with 12 additions and 11 deletions

View File

@@ -43,8 +43,10 @@ class _ThermionWidgetState extends State<ThermionWidget> {
}
});
var dpr = MediaQuery.of(context).devicePixelRatio;
var size = ((context.findRenderObject()) as RenderBox).size;
_texture = await ThermionFlutterPlugin.createTexture(size.width, size.height, 0, 0, dpr);
_texture = await ThermionFlutterPlugin.createTexture(
size.width, size.height, 0, 0, dpr);
if (mounted) {
setState(() {});
@@ -140,4 +142,3 @@ class TransparencyPainter extends CustomPainter {
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}

View File

@@ -16,17 +16,14 @@ class ThermionFlutterWebPlugin extends ThermionFlutterPlatform {
Future<ThermionFlutterTexture?> createTexture(double width, double height,
double offsetLeft, double offsetRight, double pixelRatio) async {
await _viewer!.destroySwapChain();
var physicalWidth = (width * pixelRatio).ceil();
var physicalHeight = (width * pixelRatio).ceil();
await _viewer!.createSwapChain(physicalWidth, physicalHeight);
await _viewer!.createSwapChain(width.ceil(), height.ceil());
final canvas = document.getElementById("canvas") as HTMLCanvasElement;
canvas.width = physicalWidth;
canvas.height = physicalHeight;
canvas.width = (width * pixelRatio).ceil();
canvas.height = (height * pixelRatio).ceil();
print("canvas dimensions ${width}x${height}");
_viewer!.updateViewportAndCameraProjection(physicalWidth, physicalHeight, 1.0);
_viewer!
.updateViewportAndCameraProjection(width.ceil(), height.ceil(), 1.0);
return ThermionFlutterTexture(null, null, 0, 0, null);
}
@@ -52,7 +49,10 @@ class ThermionFlutterWebPlugin extends ThermionFlutterPlatform {
canvas.id = "canvas";
document.body!.appendChild(canvas);
canvas.style.display = 'none';
await _viewer!.initialize(1, 1, uberArchivePath: uberArchivePath);
final pixelRatio = window.devicePixelRatio;
await _viewer!
.initialize(1, 1, pixelRatio, uberArchivePath: uberArchivePath);
return _viewer!;
}
}