-
Notifications
You must be signed in to change notification settings - Fork 15k
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
refactor: use typeutils for nativeImage serialization #23693
Conversation
9d44647
to
b53f7f0
Compare
lib/common/type-utils.ts
Outdated
const { size, scaleFactor, dataURL } = rep; | ||
|
||
// Use Buffer when there's only one representation for better perf. | ||
// This avoids compressing to/from PNG where it's not necessary to |
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.
Interesting in knowing more about this, why can't multiple representations use the bitmap buffer?
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.
If one uses a buffer to construct an image with multiple representation from multiple dataURLs
, the dataURLs themselves are not preserved. If you test:
const image = nativeImage.createEmpty();
const dataURL1 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=';
image.addRepresentation({ scaleFactor: 1.0, dataURL: dataURL1 });
const dataURL2 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAFklEQVQYlWP8//8/AwMDEwMDAwMDAwAkBgMBBMzldwAAAABJRU5ErkJggg==';
image.addRepresentation({ scaleFactor: 2.0, dataURL: dataURL2 });
const serializedImage = serialize(image);
const nonEmpty = deserialize(serializedImage);
expect(nonEmpty.toDataURL({ scaleFactor: 1.0 })).to.equal(dataURL1);
expect(nonEmpty.toDataURL({ scaleFactor: 2.0 })).to.equal(dataURL2);
expect(nonEmpty.toDataURL({ scaleFactor: 2.0 })).to.equal(dataURL2);
will fail, as the only dataURL
associated with the image will be dataURL1
. However, there's a perf boost with buffer serialization (see: #23549) so we want to allow it where possible.
45cb617
to
14121d1
Compare
14121d1
to
defa10d
Compare
No Release Notes |
@codebytere has manually backported this PR to "10-x-y", please check out #23794 |
@codebytere has manually backported this PR to "9-x-y", please check out #23796 |
@codebytere has manually backported this PR to "8-x-y", please check out #23797 |
* refactor: use typeutils for nativeImage serialization (#23693) * fix: ensure nativeImage serialization main->renderer
Description of Change
Follow-up to #23666, as stated in PR body. Uses existing
typeUtils
to serializenativeImages
and improves perf by using a buffer to construct thenativeImage
if there is only one representation.cc @miniak @MarshallOfSound
Checklist
npm test
passesRelease Notes
Notes: none