Skip to content

Commit

Permalink
Automatically change hardware scaling based on browser zoom level (#1…
Browse files Browse the repository at this point in the history
…2737)

Fixes #12711
This does 2 things:
1) If adapt to device ratio is turned on we are using the delta between the last recorded device pixel ratio and the current one to change the hardware scaling rate.
2) adaptToDeviceRatio is not public and can be changed not only in the constructor.
  • Loading branch information
RaananW authored Jul 12, 2022
1 parent df4c808 commit 63a3059
Showing 1 changed file with 11 additions and 5 deletions.
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

0 comments on commit 63a3059

Please sign in to comment.