From 852b4147246fdce268d50aad2bee11e21e562930 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Thu, 18 Jan 2024 04:25:57 +0200 Subject: [PATCH 1/2] chore(examples): showcase usage of softbuffer in transparent example --- Cargo.toml | 1 + examples/transparent.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index c6d6a339a..705443376 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,7 @@ url = "2" [dev-dependencies] image = "0.24" env_logger = "0.10" +softbuffer = "0.4.1" [target."cfg(any(target_os = \"android\", target_os = \"windows\"))".dependencies] once_cell = "1" diff --git a/examples/transparent.rs b/examples/transparent.rs index 1d83800a2..6439748a4 100644 --- a/examples/transparent.rs +++ b/examples/transparent.rs @@ -2,6 +2,8 @@ // Copyright 2021-2023 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 +use std::{num::NonZeroU32, rc::Rc}; + use tao::{ event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, @@ -19,6 +21,14 @@ fn main() { .build(&event_loop) .unwrap(); + #[cfg(windows)] + let (window, _context, mut surface) = { + let window = Rc::new(window); + let context = softbuffer::Context::new(window.clone()).unwrap(); + let surface = softbuffer::Surface::new(&context, window.clone()).unwrap(); + (window, context, surface) + }; + window.set_title("A fantastic window!"); event_loop.run(move |event, _, control_flow| { @@ -30,6 +40,25 @@ fn main() { event: WindowEvent::CloseRequested, .. } => *control_flow = ControlFlow::Exit, + + #[cfg(windows)] + Event::RedrawRequested(_) => { + let (width, height) = { + let size = window.inner_size(); + (size.width, size.height) + }; + surface + .resize( + NonZeroU32::new(width).unwrap(), + NonZeroU32::new(height).unwrap(), + ) + .unwrap(); + + let mut buffer = surface.buffer_mut().unwrap(); + buffer.fill(0); + buffer.present().unwrap(); + } + _ => (), } }); From 0e490cfcc8bc705e9d77ccff4ecc181144e8abfa Mon Sep 17 00:00:00 2001 From: amrbashir Date: Thu, 18 Jan 2024 04:30:51 +0200 Subject: [PATCH 2/2] only on windows --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 705443376..b4e4609a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,6 +51,8 @@ url = "2" [dev-dependencies] image = "0.24" env_logger = "0.10" + +[target."cfg(target_os = \"windows\")".dev-dependencies] softbuffer = "0.4.1" [target."cfg(any(target_os = \"android\", target_os = \"windows\"))".dependencies]