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

feat: add MakeTextureFromImage #2637

Open
wants to merge 22 commits into
base: main
Choose a base branch
from

Conversation

terrysahaidak
Copy link
Contributor

@terrysahaidak terrysahaidak commented Sep 16, 2024

This PR allows us to upload SkImage to GPU to cache as a texture.

Skia doesn't cache images as textures automatically, so on each drawImage call it will upload it to GPU to draw. It's fine when you render a few images, but if you need to render 20-30 images it becomes a problem, especially on Android. On iOS it's mostly fine. I assume copying images from cpu to gpu is much faster on iOS.

I added MakeTextureFromImage for ImageFactory (Skia.Image).

Also I added isTextureBacked() and textureSize() to SkImage which are helpful when you work with textures.

It was tested on both iOS and Android.

As part of this PR, I exposed getDirectContext on Platform Context for both iOS and Android. It is used for the TextureFromImage call, but probably will be used for other APIs in the future.

}

JSI_HOST_FUNCTION(textureSize) {
return static_cast<double>(getObject()->textureSize());
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usefull to have an idea how much memory your textures use. In the future, we could allow users to configure skia memory cache size so you can then calculate also for each texture the pressure and also call purge when you need.

For now added it so we can collect info on how much GPU memory we used by our textures.

@wcandillon wcandillon self-requested a review September 17, 2024 11:15
@wcandillon
Copy link
Contributor

wcandillon commented Sep 17, 2024 via email

@wcandillon wcandillon self-requested a review September 18, 2024 22:02
@wcandillon
Copy link
Contributor

wcandillon commented Sep 27, 2024

@terrysahaidak any chance you could look at the failing tests? I will try to look at the failing tests as well

@wcandillon
Copy link
Contributor

@terrysahaidak head up, I merged main in this branch which is now using m130 from Skia

1 similar comment
@wcandillon
Copy link
Contributor

@terrysahaidak head up, I merged main in this branch which is now using m130 from Skia

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