-
Notifications
You must be signed in to change notification settings - Fork 95
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
Greatly improve capture_image_area
on D2D, CG, and Cairo
#513
Greatly improve capture_image_area
on D2D, CG, and Cairo
#513
Conversation
27388f4
to
417ef3a
Compare
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.
Once the snapshot testing is properly updated in this PR, the proper target images will also need to be added to the submodule. You can read more about it in our CONTRIBUTING.md.
I'm not super familiar with that system, so @cmyr will probably need to step in here.
I did try this new test image out on Windows and the result does not look like the macOS result. So probably the Windows implementation is broken as well. Not sure about Linux. Well getting the sample count incremented should show us the situation a bit better, so let's start with that.
Thanks for the feedback and the pointer to the snapshots. Out of curiosity, could you post the Windows image? I don't currently have access to a windows machine :) |
I just read through the |
417ef3a
to
1fb793c
Compare
Okay, so I took some time to also implement I also have access to a Windows machine again, so I'll test the d2d behaviour as well soon-ish 😅 I also slightly changed the reference picture, so that it's a bit easier to spot if the cropping is slightly off, by using more prominent background colors. For reference, this is what I get at the moment: |
I don't know the reason for sure, however I doubt it has to do with difficulity of changing them. My guess is that it is a way to prevent the main repository size from ballooning. Every iteration of the images would still be present in the git history. While a submodule can link to to a different repository with pruned history. |
Makes sense. In general I'm not in a hurry about getting this merged. However, I'm currently still kind of engaged in this topic, and usually my attention tends to drift after some point 😅 Is there anyone other than @cmyr who we could ping to help out here, or should we just wait until an answer comes along? |
There's Raph but I'll just message @cmyr directly to see if he can spare a moment, as he's definitely the top expert on this submodule snapshot business. |
@xStrom is right, the rationale for keeping these in a submodule is just so that there aren't a bunch of binary blobs in this repository, which would need to be downloaded on each checkout. @x3ro I've invited you as a collaborator to that repo; let me know if you have any questions about how it all works :) |
Added local copies of druid and piet in order to add capture_image_area implementation for Cairo from linebender/piet#513 It works, except when painting from cache the image might get painted twice. I think this is because the size of the image returned by capture_image_area is not the same as the rect passed to it.
356be12
to
f24f897
Compare
Thanks, I'll try to get around to adding the snapshots in the coming days. In the meantime, maybe someone can help me out by looking at f24f897 – I tried to fix the test case for d2d, and also somehow got it to work, but something in that implementation is a bit fishy. |
The fact that it is Unfortunately I ran out of time right now. However I plan on returning to this issue soon, perhaps tomorrow. |
This functionality was added in linebender/piet#387 but it never worked correctly. This will hopefully be fixed by linebender/piet#513.
f9aa987
to
f77432a
Compare
Okay, so with the updated snapshots all tests pass now. As a next step I'm going to look into the d2d weirdness again 😅 |
c89127b
to
ec58a6f
Compare
Cool, so this version seems to make sense overall, and passes the snapshots that I've created 🎉 The snapshots don't really test the transformation matrix behaviour beyond the dpi scaling (and, for d2d, not at all). Do we need to come up with test cases for that to get this merged? |
I keep finding bugs elsewhere in Piet when trying to test this PR. 😅 I've now submitted #520 to fix an issue that caused the macOS test picture generator to crash at any scale other than There's also another issue related to pixel components that I'm still investigating, but will likely open a PR for, tomorrow. Hopefully then I can finally get a better grasp on what this PR here is doing, and provide some feedback. |
I ran the test image with 1x scale instead of the default 2x scale and got weird results. CoreGraphics 1x scaleLooks the most correct, although I haven't measured anything. Cairo 1x scaleThe corner boxes seem to be missing their red lines. Direct2D 1x scaleThere are even more red lines missing, and the whole thing is shifted to the top left corner. I haven't had time yet to actually try to figure out what is causing these issues, but I thought it's worth reporting the findings. Instead I've been trying to improve the whole test picture system. #519, #520, #521 are now merged. #522 isn't merged yet, but once it is it will provide an easier way to generate these test images at different scale factors. Otherwise if you rebase on |
Thanks for your work on the test picture system and for sharing your findings. I'll look into why this breaks w/ d2d and cairo :) |
Mmh, I've looked at Cairo, and there it could just be a rounding problem. The boxes are let outer_rect_red = Rect::new(20., 20., 180., 180.);
let inner_rect_blue = Rect::new(21., 21., 179., 179.); With 2x scale, this results in a 1px thin line, and thus with 1x scale it should be a 0.5px thin line, which ends up not being visible 🤔 At least that is my guess. Making the line 2px thick in 2x scale makes it visible in 1x scale as well. |
9e8af80
to
34003c3
Compare
You're doing |
|
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.
I finally had some time to dig deeper into the Direct2D issues. I think I solved them and have written about the changes needed in this review comment batch.
I'll still need to review CoreGraphics and Cairo later too, but hopefully we're getting close to done here.
Nice, thanks so much for your thorough review. I'll see when I get around to this, but I won't have access to a Windows machine until at least next week, so I guess it'll happen then 😅 |
You could make those changes on a non-Windows machine. I'm pretty confident it will work and can do the testing myself, plus CI. |
The `capture_image_area` method of the CoreGraphicsContext was not taking into account that a transformation matrix is applied to the context. As a result, it only worked correctly if one applied this scaling manually to the `src_rect` prior to passing it to the method. With this addition, we now respect the CG transformation matrix and apply it to the `src_rect` prior to cropping the captured `CGImage`.
The `capture_image_area` method of the CoreGraphicsContext was not taking into account that a transformation matrix is applied to the context. As a result, it only worked correctly if one applied this scaling manually to the `src_rect` prior to passing it to the method. With this addition, we now respect the CG transformation matrix and apply it to the `src_rect` prior to cropping the captured `CGImage`.
38ae58b
to
f4aa0b2
Compare
It does indeed look correct now, thanks for the fix! I think I'll get around to updating the snapshots tomorrow 🚀 |
bf6023f
to
3bdd281
Compare
3bdd281
to
09711a3
Compare
Looks like this is working as intended now. So now I would merge the snapshots, and then we'd merge this PR? 🤔 |
order doesn't really matter but normally I'd get the PR in first, then merge the snapshots. The snapshots will continue to work as long as the referenced commit exists, it doesn't need to be in the main branch. 🤷 |
Yeah, I'll have time tomorrow to do the final review here and then merge. After this is merged, we can merge snapshots. |
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.
Thank you for your continued effort to get this done! I have tested it on all three platforms and it seems to be correct.
The Affine
transformations aren't tested, but that is a fine line to split the work and if someone runs into issues with it, it can be resolved in a different PR.
capture_image_area
not respecting CG transformation matrixcapture_image_area
on D2D, CG, and Cairo
The
capture_image_area
method of the CoreGraphicsContext was nottaking into account that a transformation matrix is applied to the
context. As a result, it only worked correctly if one applied this
scaling manually to the
src_rect
prior to passing it to the method.With this addition, we now respect the CG transformation matrix and
apply it to the
src_rect
prior to cropping the capturedCGImage
.