Skip to content
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

Automatically change hardware scaling based on browser zoom level #12737

Merged
merged 1 commit into from
Jul 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions packages/dev/core/src/Engines/thinEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,12 @@ export class ThinEngine {

private _activeRequests = new Array<IFileRequest>();

/**
* If set to true zooming in and out in the browser will rescale the hardware-scaling correctly.
*/
public adaptToDeviceRatio: boolean = false;
/** @hidden */
private _adaptToDeviceRatio: boolean = false;
private _lastDevicePixelRatio: number = 1.0;

/** @hidden */
public _transformTextureUrl: Nullable<(url: string) => string> = null;
Expand Down Expand Up @@ -751,7 +755,7 @@ export class ThinEngine {
this._creationOptions = options;

// Save this off for use in resize().
this._adaptToDeviceRatio = adaptToDeviceRatio ?? false;
this.adaptToDeviceRatio = adaptToDeviceRatio ?? false;

this._stencilStateComposer.stencilGlobal = this._stencilState;

Expand Down Expand Up @@ -962,6 +966,7 @@ export class ThinEngine {

const limitDeviceRatio = options.limitDeviceRatio || devicePixelRatio;
this._hardwareScalingLevel = adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, devicePixelRatio) : 1.0;
this._lastDevicePixelRatio = devicePixelRatio;
this.resize();

this._isStencilEnable = options.stencil ? true : false;
Expand Down Expand Up @@ -1729,10 +1734,11 @@ export class ThinEngine {
let height: number;

// Requery hardware scaling level to handle zoomed-in resizing.
if (this._adaptToDeviceRatio) {
if (this.adaptToDeviceRatio) {
const devicePixelRatio = IsWindowObjectExist() ? window.devicePixelRatio || 1.0 : 1.0;
const limitDeviceRatio = this._creationOptions.limitDeviceRatio || devicePixelRatio;
this._hardwareScalingLevel = this._adaptToDeviceRatio ? 1.0 / Math.min(limitDeviceRatio, devicePixelRatio) : 1.0;
const changeRatio = this._lastDevicePixelRatio / devicePixelRatio;
this._lastDevicePixelRatio = devicePixelRatio;
this._hardwareScalingLevel *= changeRatio;
}

if (IsWindowObjectExist()) {
Expand Down