subsurface: Add option to apply buffer transform
This commit is contained in:
parent
e034001468
commit
288919958e
1 changed files with 29 additions and 3 deletions
|
|
@ -29,6 +29,7 @@ use cctk::sctk::{
|
|||
protocol::{
|
||||
wl_buffer::{self, WlBuffer},
|
||||
wl_compositor::WlCompositor,
|
||||
wl_output,
|
||||
wl_shm::{self, WlShm},
|
||||
wl_shm_pool::{self, WlShmPool},
|
||||
wl_subcompositor::WlSubcompositor,
|
||||
|
|
@ -375,6 +376,7 @@ impl SubsurfaceState {
|
|||
wp_alpha_modifier_surface,
|
||||
wl_buffer: None,
|
||||
bounds: None,
|
||||
transform: wl_output::Transform::Normal,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -474,6 +476,7 @@ pub(crate) struct SubsurfaceInstance {
|
|||
wp_alpha_modifier_surface: Option<WpAlphaModifierSurfaceV1>,
|
||||
wl_buffer: Option<WlBuffer>,
|
||||
bounds: Option<Rectangle<f32>>,
|
||||
transform: wl_output::Transform,
|
||||
}
|
||||
|
||||
impl SubsurfaceInstance {
|
||||
|
|
@ -527,11 +530,15 @@ impl SubsurfaceInstance {
|
|||
info.bounds.height as i32,
|
||||
);
|
||||
}
|
||||
let transform_changed = self.transform != info.transform;
|
||||
if transform_changed {
|
||||
self.wl_surface.set_buffer_transform(info.transform);
|
||||
}
|
||||
if buffer_changed {
|
||||
self.wl_surface.attach(Some(&buffer), 0, 0);
|
||||
self.wl_surface.damage(0, 0, i32::MAX, i32::MAX);
|
||||
}
|
||||
if buffer_changed || bounds_changed {
|
||||
if buffer_changed || bounds_changed || transform_changed {
|
||||
_ = self.wl_surface.frame(&state.qh, self.wl_surface.clone());
|
||||
self.wl_surface.commit();
|
||||
}
|
||||
|
|
@ -544,6 +551,7 @@ impl SubsurfaceInstance {
|
|||
|
||||
self.wl_buffer = Some(buffer);
|
||||
self.bounds = Some(info.bounds);
|
||||
self.transform = info.transform;
|
||||
}
|
||||
|
||||
pub fn unmap(&self) {
|
||||
|
|
@ -567,6 +575,7 @@ pub(crate) struct SubsurfaceInfo {
|
|||
pub buffer: SubsurfaceBuffer,
|
||||
pub bounds: Rectangle<f32>,
|
||||
pub alpha: f32,
|
||||
pub transform: wl_output::Transform,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
|
|
@ -584,6 +593,7 @@ pub struct Subsurface {
|
|||
height: Length,
|
||||
content_fit: ContentFit,
|
||||
alpha: f32,
|
||||
transform: wl_output::Transform,
|
||||
}
|
||||
|
||||
impl<Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Subsurface
|
||||
|
|
@ -601,9 +611,18 @@ where
|
|||
_renderer: &Renderer,
|
||||
limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
let buffer_size =
|
||||
Size::new(self.buffer.width() as f32, self.buffer.height() as f32);
|
||||
let (width, height) = match self.transform {
|
||||
wl_output::Transform::_90
|
||||
| wl_output::Transform::_270
|
||||
| wl_output::Transform::Flipped90
|
||||
| wl_output::Transform::Flipped270 => {
|
||||
(self.buffer.height(), self.buffer.width())
|
||||
}
|
||||
_ => (self.buffer.width(), self.buffer.height()),
|
||||
};
|
||||
let buffer_size = Size::new(width as f32, height as f32);
|
||||
|
||||
// TODO apply transform
|
||||
let raw_size = limits.resolve(self.width, self.height, buffer_size);
|
||||
|
||||
let full_size = self.content_fit.fit(buffer_size, raw_size);
|
||||
|
|
@ -639,6 +658,7 @@ where
|
|||
buffer: self.buffer.clone(),
|
||||
bounds: layout.bounds(),
|
||||
alpha: self.alpha,
|
||||
transform: self.transform,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
@ -653,6 +673,7 @@ impl Subsurface {
|
|||
height: Length::Shrink,
|
||||
content_fit: ContentFit::Contain,
|
||||
alpha: 1.,
|
||||
transform: wl_output::Transform::Normal,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -675,6 +696,11 @@ impl Subsurface {
|
|||
self.alpha = alpha;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn transform(mut self, transform: wl_output::Transform) -> Self {
|
||||
self.transform = transform;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<Message, Theme, Renderer> From<Subsurface>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue