Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Image.toByteData and Picture.toImage implementations (#2) #20326

Closed
wants to merge 78 commits into from
Closed

Image.toByteData and Picture.toImage implementations (#2) #20326

wants to merge 78 commits into from

Conversation

deakjahn
Copy link
Contributor

@deakjahn deakjahn commented Aug 7, 2020

Description

  • Image.toByteData() was not implemented in either DomCanvas or CanvasKit. This PR covers both.
  • Picture.toImage() was not implemented in either DomCanvas or CanvasKit. This PR covers CanvasKit (I also have a solution for DomCanvas but that would need some discussion, it might clash with functionality somewhere else; details in a comment below).

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

external bool isEmpty();
external bool isOpaque();
external SkRect bounds();
external int width();
Copy link
Contributor

Choose a reason for hiding this comment

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

These should be getters I imagine. However, getters don't need the (), for example external bool get isEmpty; (notice no () at the end).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know any more. The doc I finally found explicitely says they are functions, using ().

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Interesting. According to the @JS bindings it's a plain object (in JS you'd write { width: x, height: y, aphaType: z, colorSpace: a, colorType: b }). Perhaps there's a difference between SkImageInfo constructed by JS and one returned by CanvasKit?

Why don't you do what works now, and we can clean this up later?

/cc @kjlubick

Copy link
Contributor

Choose a reason for hiding this comment

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

According to CanvasKit bindings it should be a POJO: https://github.com/google/skia/blob/1d4b92d87806e0d3ed8b4155da98d7d0ac757bd6/modules/canvaskit/canvaskit_bindings.cpp#L1873

That is, there shouldn't be any methods/functions on SkImageInfo, only properties.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is correct, the SkImageInfo is just a POJO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I do, I do.

.build()
.webOnlyRootElement);

await matchGoldenFile('canvas_to_picture.png', region: region, write: true);
Copy link
Contributor

Choose a reason for hiding this comment

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

For this to pass on CI you'll need to remove write: true. However, you will also need to add the new screenshot file to https://github.com/flutter/goldens (example PR: flutter/goldens#103).

If that's too much ceremony, feel free to comment out this line in this PR, and I can do the dance with the screenshots in a follow up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I simply can't get the screenshot. The test doesn't run on either Windows or Linux for me locally (on Windows by design, on Linux it should work but it doesn't, Chrome starts and then nothing ever happens).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Commenting out renders the test inactive. If it's OK like this, let's do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

Filed flutter/flutter#63711 to follow up later.

@deakjahn
Copy link
Contributor Author

Same error with Linux Web Engine. I can't find any reference to color spaces in that log.

@yjbanov
Copy link
Contributor

yjbanov commented Aug 19, 2020

@deakjahn Sorry, I renamed the compositor directory to canvaskit today, so this PR needs to be rebased again 😅

It looks like this PR is almost good to go. The only remaining issue is an unused import.

@deakjahn
Copy link
Contributor Author

deakjahn commented Aug 19, 2020

An import? Did I add it? Which one? I don't remember needing to add any import at all but that doesn't mean a thing. :-)

Never mind, I could have read before I speak...

@deakjahn
Copy link
Contributor Author

You made me comment out the image comparison test at the end but this means that the test itself times out, doesn't it?

@yjbanov
Copy link
Contributor

yjbanov commented Aug 22, 2020

I'm not sure. Would you be able to squash this PR into a single commit so I could try it on my computer? I tried rebasing this PR on top of latest master branch but my git skills turned out insufficient :)

@deakjahn
Copy link
Contributor Author

deakjahn commented Aug 23, 2020

That's the problem over here, too, I never did anything similar in git. Time to start to read up, I guess.

@deakjahn
Copy link
Contributor Author

I can't even squash two, let alone 70-plus... :-(

@deakjahn
Copy link
Contributor Author

deakjahn commented Aug 23, 2020

I have a suggestion that might help us. It's only six files, after all. So, if

  • I close this PR, too,
  • Delete my fork,
  • Fork the engine again,
  • Copy the six modified files and commit them in one go,
  • Create a third PR

that might fly, I guess.

@yjbanov
Copy link
Contributor

yjbanov commented Aug 25, 2020

That plan SGTM. I'm wondering if Github allows downloading a PR as a patch file that could be applied locally as a single commit 🤔

@deakjahn
Copy link
Contributor Author

It would if I squashed it into one. But then there would be no need...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes platform-web Code specifically for the web engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants