Improve safety notes on the slint::Image texture import functions

Elaborate how to call this function safely, and copy the same description to the C++ docs.
This commit is contained in:
Simon Hausmann 2023-06-22 11:44:25 +02:00 committed by Simon Hausmann
parent 279c143d31
commit aa41277df1
2 changed files with 18 additions and 2 deletions

View file

@ -126,6 +126,16 @@ public:
/// ///
/// The texture must be bindable against the `GL_TEXTURE_2D` target, have `GL_RGBA` as format /// The texture must be bindable against the `GL_TEXTURE_2D` target, have `GL_RGBA` as format
/// for the pixel data. /// for the pixel data.
///
/// Safety:
///
/// This function is unsafe because invalid texture ids may lead to undefind behavior in OpenGL
/// drivers. A valid texture id is one that was created by the same OpenGL context that is
/// current during any of the invocations of the callback set on
/// [`Window::set_rendering_notifier()`]. OpenGL contexts between instances of [`slint::Window`]
/// are not sharing resources. Consequently
/// [`slint::Image`] objects created from borrowed OpenGL textures cannot be shared between
/// different windows.
[[nodiscard]] static Image create_from_borrowed_gl_2d_rgba_texture(uint32_t texture_id, [[nodiscard]] static Image create_from_borrowed_gl_2d_rgba_texture(uint32_t texture_id,
Size<unsigned int> size) Size<unsigned int> size)
{ {

View file

@ -619,8 +619,14 @@ impl Image {
/// The texture must be bindable against the `GL_TEXTURE_2D` target, have `GL_RGBA` as format /// The texture must be bindable against the `GL_TEXTURE_2D` target, have `GL_RGBA` as format
/// for the pixel data. /// for the pixel data.
/// ///
/// Safety: This method is marked as unsafe as passing invalid texture ids may result in /// # Safety
/// undefined behavior in OpenGL drivers. ///
/// This function is unsafe because invalid texture ids may lead to undefind behavior in OpenGL
/// drivers. A valid texture id is one that was created by the same OpenGL context that is
/// current during any of the invocations of the callback set on [`Window::set_rendering_notifier()`](crate::api::Window::set_rendering_notifier).
/// OpenGL contexts between instances of [`slint::Window`](crate::api::Window) are not sharing resources. Consequently
/// [`slint::Image`](Self) objects created from borrowed OpenGL textures cannot be shared between
/// different windows.
#[allow(unsafe_code)] #[allow(unsafe_code)]
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
pub unsafe fn from_borrowed_gl_2d_rgba_texture( pub unsafe fn from_borrowed_gl_2d_rgba_texture(