-
Notifications
You must be signed in to change notification settings - Fork 452
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
base: main
Are you sure you want to change the base?
feat: add MakeTextureFromImage #2637
Conversation
} | ||
|
||
JSI_HOST_FUNCTION(textureSize) { | ||
return static_cast<double>(getObject()->textureSize()); |
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.
What does this do?
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.
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.
oups I forgot, we need to update the documentation at
https://shopify.github.io/react-native-skia/docs/animations/textures/#under-the-hood
and the `useTexture` hook.
…On Tue, Sep 17, 2024 at 11:03 AM Terry Sahaidak ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In packages/skia/cpp/api/JsiSkImage.h
<#2637 (comment)>
:
> @@ -186,6 +186,14 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject<SkImage> {
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
}
+ JSI_HOST_FUNCTION(isTextureBacked) {
+ return static_cast<bool>(getObject()->isTextureBacked());
+ }
+
+ JSI_HOST_FUNCTION(textureSize) {
+ return static_cast<double>(getObject()->textureSize());
Usefull to have an idea how much memory your textures use
<https://api.skia.org/classSkImage.html#acd7bda080bbe286f56fb0fe7b8af30c7>.
In the future, we could allow users to configure skia memory cache size
<https://api.skia.org/classGrDirectContext.html#af972a5f50215ee314c48e5749d6259b9>
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.
—
Reply to this email directly, view it on GitHub
<#2637 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACKXVVWLTZS2KSAEHI5ZMTZW7V5JAVCNFSM6AAAAABOJPQNJSVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDGMBYHA3TGMZRGQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
…rysahaidak/react-native-skia into terrysahaidak/upload-texture
@terrysahaidak any chance you could look at the failing tests? I will try to look at the failing tests as well |
@terrysahaidak head up, I merged main in this branch which is now using m130 from Skia |
1 similar comment
@terrysahaidak head up, I merged main in this branch which is now using m130 from Skia |
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()
andtextureSize()
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.