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

prevent render canvas with quality less than 100% #7537

Merged
merged 2 commits into from Jan 9, 2022

Conversation

vitonsky
Copy link
Contributor

@vitonsky vitonsky commented Dec 5, 2021

Fix issue #7502

@@ -232,7 +232,7 @@
* @private
*/
_isRetinaScaling: function() {
return (fabric.devicePixelRatio !== 1 && this.enableRetinaScaling);
return (fabric.devicePixelRatio > 1 && this.enableRetinaScaling);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you also need to change getRetinaScaling to return a number that is at minimum 1 i think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make sense to switch places of these parts for performance? Checking a boolean variable should be faster than comparing two values. Like this: this.enableRetinaScaling && fabric.devicePixelRatio > 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dok11 i don't sure. JS engine probably is don't know whats variable contain, so will not check variable as boolean directly. But symbol > may suggest that it's just math operation which is instant

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vitonsky I even tested it, and it seems like it doesn't care :D
https://jsbench.me/zkkxq3rjv0/1

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i m sure performance is not an issue here, but in the JS bench seems like Math.random and toFixed are actually the 2 things that will matter for performance. no?

@stale
Copy link

stale bot commented Dec 28, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added stale Issue marked as stale by the stale bot and removed stale Issue marked as stale by the stale bot labels Dec 28, 2021
@ShaMan123
Copy link
Contributor

ShaMan123 commented Jan 6, 2022

@vitonsky could you push a commit that calculates retina scaling from within _onResize as suggested in #7502 (comment)

@asturur asturur merged commit da355a9 into fabricjs:master Jan 9, 2022
@asturur
Copy link
Member

asturur commented Jan 9, 2022

we broke so many tests. not sure why it wasn't visible in the pr

},

/**
* @private
* @return {Number} retinaScaling if applied, otherwise 1;
*/
getRetinaScaling: function() {
return this._isRetinaScaling() ? fabric.devicePixelRatio : 1;
return Math.max(1, fabric.devicePixelRatio);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok this was the error.
We lessen the importance of the boolean here.
If retina scaling is set as false, whatever is the devicePixelRatio, we return 1.
My bad for not noticing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we can fix it like this?

this._isRetinaScaling() ? Math.max(1, fabric.devicePixelRatio) : 1

@vitonsky
Copy link
Contributor Author

@ShaMan123

@vitonsky could you push a commit that calculates retina scaling from within _onResize as suggested in #7502 (comment)

I'm not sure that we can do it on the library level. If you wish, make own pull request with this change if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants