- Notifications
You must be signed in to change notification settings - Fork163
feat: Support custom ImageAsset#1079
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
4bf0a59 todd4d549Compare| pub type ImageSizeFit = skresources_ImageAsset_SizeFit; | ||
| pub type ImageFrameData = skresources_ImageAsset_FrameData; | ||
| pub fn create_image_frame_data( |
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 thought it would be possible to create the FrameData struct as a rust struct but it uses skia shared pointer and it looks like there is no way to get the shared pointer from theRCHandle without getting into the skia world. Correct me if I wrong
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.
Yes, we could provide a generic function for that, but this would in turn mean that we directly handle sp typed smartpointers in Rust, which we don't. There might be a way to create a compatible struct in Rust and placing a RCHandle at the same field position, but this feels scary. Speaking of that, FrameData should be wrapped and made opaque to the Rust world (with functions wrapping access to the fields), otherwise clients could mess around with the smartpointer.
dd4d549 to3be9709Compare
pragmatrix left a comment
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 a lot for that. I like the addition.
Here are the things I like to be changed:
- Put the image_asset.rs into a new subdirectory named modules/resources and refer it from resources.rs (because it is not a module).
- The
skresources_ImageAsset_SizeFitenum variants are prefixed with ak. Add avariant_name!check, and addSizeFittoskia_bindgen.rsENUM_REWRITES, this should fix it. - Wrap the
FrameDatain aHandle<>, and offer access to the members through functions (the simple members don't need C wrappers). This is to prevent clients from messing with the sp and also fixes a bug with the current implementation, where the reference count is not reduced when dropped. - Add a test case based on a reasonable use case if possible.
| pub type ImageSizeFit = skresources_ImageAsset_SizeFit; | ||
| pub type ImageFrameData = skresources_ImageAsset_FrameData; | ||
| pub fn create_image_frame_data( |
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.
Yes, we could provide a generic function for that, but this would in turn mean that we directly handle sp typed smartpointers in Rust, which we don't. There might be a way to create a compatible struct in Rust and placing a RCHandle at the same field position, but this feels scary. Speaking of that, FrameData should be wrapped and made opaque to the Rust world (with functions wrapping access to the fields), otherwise clients could mess around with the smartpointer.
dmtrKovalenko commentedDec 29, 2024
Thank you for review I have a question though about this
the problem is that it should not be a handle it is stack allocated struct that is used by skia so it needs to be the owned struct when we return it to the skia world. That's why there is no need to drop it or even have access to the fields. If Correct me if I'm wrong |
dmtrKovalenko commentedDec 31, 2024
hey@pragmatrix gentle pin on my previous question when you'll had a chance |
pragmatrix commentedDec 31, 2024
The If it is only passed from Rust to C/C++ (Skia world) it works, but after calling |
3be9709 to66201f1Compare
Uh oh!
There was an error while loading.Please reload this page.
Here is an implementation that allows to return your custom implementation of ImageAsset wrapping the rust trait to the skia world using ResourceProvider. ImageAssets are overridable so I added an ability to override it using rust trait object just like you already do for ResourceProvider.
My use case: I have already available decoded images in the memory so I just manually creating the frame_data from the pointer. This is a code I use:
Please let me know if you like the implementation and if you do I'll add the tests covering this API.