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

druid::PaintCtx::capture_image_area fails in macOS #2245

Open
longmathemagician opened this issue Aug 17, 2022 · 0 comments · May be fixed by #2246
Open

druid::PaintCtx::capture_image_area fails in macOS #2245

longmathemagician opened this issue Aug 17, 2022 · 0 comments · May be fixed by #2246
Labels
bug does not behave the way it is supposed to piet requires fixes or changes in Piet

Comments

@longmathemagician
Copy link
Contributor

TLDR: The surface type of the graphics context you end up with inside druid is different from what's used in piet's test cases, so functions that work fine in standalone piet do not work in druid when you're using the provided PaintCtx. This is the case for capture_image_area under piet-coregraphics.

There is a very similar issue with Windows under piet-direct2d (#2216), but the fix is simple enough (linebender/piet#526). With macOS it's considerably trickier: In piet-coregraphics, capture_image_area passes the active CGContextRef pointer to CGBitmapContextCreateImage. This works fine in the test case where the graphics context is a CGBitmapContext, but it does not work when CGContextRef points to a screen-type context. As far as I can tell there is no universal or appropriate alternate method to cache a region of a context -- the closest you get is this one for bitmap contexts. Even attempting to identify context types and respond accordingly is tricky, you can call CGContextGetTypeID on it to get a type id but unless I'm missing something major there's not a supported approach to mapping the returned id to any particular type of CGContext.

Unless there's a simple fix I'm completely missing (some sort of NS* magic, perhaps), the way forward could be a macOS-specific ext trait or env flag to give the option of caching all drawing in a CGBitmapContext rather than drawing directly to the CGContextRef we get from NSGraphicsContext::currentContext. Barring a better fix I'll submit a PR with this approach once I get the bugs worked out, but it'd be nice to have a cleaner solution than having to take a performance hit just to get this one function working.

@xStrom xStrom added bug does not behave the way it is supposed to piet requires fixes or changes in Piet labels Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug does not behave the way it is supposed to piet requires fixes or changes in Piet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants