wayland-egl-0.32.0/.cargo_vcs_info.json0000644000000001510000000000100133170ustar { "git": { "sha1": "c05c6c3433d2188b027764cae17bff6673953e37" }, "path_in_vcs": "wayland-egl" }wayland-egl-0.32.0/CHANGELOG.md000064400000000000000000000011551046102023000137250ustar 00000000000000# CHANGELOG: wayland-egl ## Unreleased ## 0.32.0 -- 2023-09-02 #### Breaking changes - Update wayland-backend to 0.3 & wayland-client 0.31 ## 0.31.0 -- 2023-07-13 #### Breaking changes - Update wayland-sys to 0.31 ## 0.30.0 -- 2022-12-27 ## 0.30.0-alpha9 #### Breaking changes - `WlEglSurface` creation API now correcly handles all error conditions, as a result `wayland-egl` now has its own error type. ## 0.30.0-alpha6 #### Breaking changes - `WlEglSurface` is now `!Sync`, as it should have been from the start ## 0.30.0-alpha1 Rework of the crate as a consequence of the rework of `wayland-client`. wayland-egl-0.32.0/Cargo.toml0000644000000021370000000000100113230ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" rust-version = "1.65" name = "wayland-egl" version = "0.32.0" authors = ["Elinor Berger "] description = "Bindings to libwayland-egl." documentation = "https://docs.rs/wayland-egl/" readme = "README.md" keywords = [ "wayland", "client", ] categories = [ "gui", "api-bindings", ] license = "MIT" repository = "https://github.com/smithay/wayland-rs" [package.metadata.docs.rs] all-features = true rustdoc-args = [ "--cfg", "docsrs", ] [dependencies.wayland-backend] version = "0.3.0" features = ["client_system"] [dependencies.wayland-sys] version = "0.31.0" features = ["egl"] wayland-egl-0.32.0/Cargo.toml.orig000064400000000000000000000012351046102023000150020ustar 00000000000000[package] name = "wayland-egl" version = "0.32.0" documentation = "https://docs.rs/wayland-egl/" repository = "https://github.com/smithay/wayland-rs" authors = ["Elinor Berger "] license = "MIT" edition = "2018" rust-version = "1.65" categories = ["gui", "api-bindings"] keywords = ["wayland", "client"] description = "Bindings to libwayland-egl." readme = "README.md" [dependencies] wayland-backend = { version = "0.3.0", path = "../wayland-backend", features = ["client_system"] } wayland-sys = { version = "0.31.0", path="../wayland-sys", features = ["egl"] } [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] wayland-egl-0.32.0/LICENSE.txt000064400000000000000000000020401046102023000137310ustar 00000000000000Copyright (c) 2015 Victor Berger Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.wayland-egl-0.32.0/README.md000064400000000000000000000013731046102023000133750ustar 00000000000000[![crates.io](https://img.shields.io/crates/v/wayland-egl.svg)](https://crates.io/crates/wayland-egl) [![docs.rs](https://docs.rs/wayland-egl/badge.svg)](https://docs.rs/wayland-egl) [![Continuous Integration](https://github.com/Smithay/wayland-rs/workflows/Continuous%20Integration/badge.svg)](https://github.com/Smithay/wayland-rs/actions?query=workflow%3A%22Continuous+Integration%22) [![codecov](https://codecov.io/gh/Smithay/wayland-rs/branch/master/graph/badge.svg)](https://codecov.io/gh/Smithay/wayland-rs) # wayland-egl This crate provides bindings for OpenGL/Vulkan support for Wayland client apps. It allows to create an `EGLSurface` from any `WlSurface`, which can then play the role of the base surface for initializing an OpenGL or Vulkan context.wayland-egl-0.32.0/src/lib.rs000064400000000000000000000115601046102023000140200ustar 00000000000000#![warn(missing_docs, missing_debug_implementations)] #![forbid(improper_ctypes, unsafe_op_in_unsafe_fn)] //! EGL utilities //! //! This module contains bindings to the `libwayland-egl.so` library. //! //! This library is used to interface with the OpenGL stack, and creating //! EGL surfaces from a wayland surface. //! //! See [`WlEglSurface`] documentation for details. use std::{fmt, os::raw::c_void}; use wayland_backend::client::ObjectId; use wayland_sys::{client::wl_proxy, egl::*, ffi_dispatch}; /// Checks if the wayland-egl lib is available and can be used /// /// Trying to create an [`WlEglSurface`] while this function returns /// `false` will result in a panic. pub fn is_available() -> bool { is_lib_available() } /// EGL surface /// /// This object is a simple wrapper around a `wl_surface` to add the EGL /// capabilities. Just use the [`ptr()`](WlEglSurface::ptr) method once this object /// is created to get the window pointer your OpenGL library is needing to initialize /// the EGL context (you'll most likely need the display ptr as well, that you can /// get via the [`ObjectId::as_ptr()`] method on of the `wl_display` ID). #[derive(Debug)] pub struct WlEglSurface { ptr: *mut wl_egl_window, } impl WlEglSurface { /// Create an EGL surface from a wayland surface /// /// This method will check that the provided `ObjectId` is still alive and from the /// correct interface (`wl_surface`). /// /// You must always destroy the [`WlEglSurface`] *before* the underling `wl_surface` /// protocol object. pub fn new(surface: ObjectId, width: i32, height: i32) -> Result { if surface.interface().name != "wl_surface" { return Err(Error::InvalidId); } let ptr = surface.as_ptr(); if ptr.is_null() { // ObjectId::as_ptr() returns NULL if the surface is no longer alive Err(Error::InvalidId) } else { // SAFETY: We are sure the pointer is valid and the interface is correct. unsafe { Self::new_from_raw(ptr, width, height) } } } /// Create an EGL surface from a raw pointer to a wayland surface. /// /// # Safety /// /// The provided pointer must be a valid `wl_surface` pointer from `libwayland-client`. pub unsafe fn new_from_raw( surface: *mut wl_proxy, width: i32, height: i32, ) -> Result { if width <= 0 || height <= 0 { return Err(Error::InvalidSize); } let ptr = ffi_dispatch!(wayland_egl_handle(), wl_egl_window_create, surface, width, height); if ptr.is_null() { panic!("egl window allocation failed"); } Ok(Self { ptr }) } /// Fetch current size of the EGL surface pub fn get_size(&self) -> (i32, i32) { let mut w = 0i32; let mut h = 0i32; unsafe { ffi_dispatch!( wayland_egl_handle(), wl_egl_window_get_attached_size, self.ptr, &mut w as *mut i32, &mut h as *mut i32 ); } (w, h) } /// Resize the EGL surface /// /// The two first arguments `(width, height)` are the new size of /// the surface, the two others `(dx, dy)` represent the displacement /// of the top-left corner of the surface. It allows you to control the /// direction of the resizing if necessary. pub fn resize(&self, width: i32, height: i32, dx: i32, dy: i32) { unsafe { ffi_dispatch!( wayland_egl_handle(), wl_egl_window_resize, self.ptr, width, height, dx, dy ) } } /// Raw pointer to the EGL surface /// /// You'll need this pointer to initialize the EGL context in your /// favourite OpenGL lib. pub fn ptr(&self) -> *const c_void { self.ptr as *const c_void } } // SAFETY: We own the pointer to the wl_egl_window and can therefore be transferred to another thread. unsafe impl Send for WlEglSurface {} // Note that WlEglSurface is !Sync. This is because the pointer performs no internal synchronization. impl Drop for WlEglSurface { fn drop(&mut self) { unsafe { ffi_dispatch!(wayland_egl_handle(), wl_egl_window_destroy, self.ptr); } } } /// EGL surface creation error. #[derive(Debug)] pub enum Error { /// Surface width or height are <= 0. InvalidSize, /// Passed surface object is not a surface. InvalidId, } impl std::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { Error::InvalidSize => write!(f, "surface width or height is <= 0"), Error::InvalidId => write!(f, "object id is not a surface"), } } }