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

ImageSurface: Support memory pressure #1115

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

badcel
Copy link
Member

@badcel badcel commented Aug 18, 2024

  • I agree that my contribution may be licensed either under MIT or any version of LGPL license.

@badcel badcel mentioned this pull request Aug 18, 2024
3 tasks
@badcel badcel force-pushed the image-surface-supprt-memory-pressure branch from a15425c to 4ca5f91 Compare August 18, 2024 16:52
@badcel
Copy link
Member Author

badcel commented Aug 18, 2024

@cameronwhite Can you take a look here? I'm pretty sure that the code to add memory pressure in Surface is incorrect / to low. Can we add some kind of logic to calculate the size in bytes of all supported surfaces?

@badcel badcel requested a review from cameronwhite August 18, 2024 16:54
@cameronwhite
Copy link
Contributor

Yeah I think the width * height is incorrect since that's the width in pixels, but that doesn't take into account the pixel format (number of bytes per pixel)
I don't think there is actually an API to get a memory usage estimate other than for ImageSurface (which does directly correspond to a memory buffer with a specific pixel format). E.g. some backends like SVG probably don't have a reasonable way to produce this

A general function could check the surface's type (https://www.cairographics.org/manual/cairo-cairo-surface-t.html#cairo-surface-get-type) and then only add memory pressure for ImageSurface? (That's also the only surface type we create in Pinta)
Using width * height could also be a fallback estimate, but I don't know if over-estimating the memory pressure is a bad thing for the GC

@badcel badcel force-pushed the image-surface-supprt-memory-pressure branch from 4ca5f91 to 6e10363 Compare August 28, 2024 19:03
@badcel badcel marked this pull request as ready for review August 28, 2024 19:05
@badcel
Copy link
Member Author

badcel commented Aug 28, 2024

@cameronwhite I updated the code to only apply memory pressure if we know the size of the image surface and skip the memory pressure in other cases. I think it is better to start as conservative as possible and we can add additional use cases if the need comes up.

Do you think the code is good to go?

Copy link
Contributor

@cameronwhite cameronwhite left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@badcel badcel force-pushed the image-surface-supprt-memory-pressure branch from 6e10363 to e76484c Compare August 29, 2024 15:01
@badcel badcel merged commit 4311034 into main Aug 29, 2024
3 checks passed
@badcel badcel deleted the image-surface-supprt-memory-pressure branch August 29, 2024 15:14
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.

2 participants