Skip to content

Commit

Permalink
send buffer transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhbooth committed May 30, 2024
1 parent 4953878 commit 57d216b
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 50 deletions.
8 changes: 6 additions & 2 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use smithay_client_toolkit::primary_selection::selection::PrimarySelectionSource
use smithay_client_toolkit::primary_selection::PrimarySelectionManagerState;
use smithay_client_toolkit::reexports::client::backend::ObjectId as SctkObjectId;
use smithay_client_toolkit::reexports::client::globals::GlobalList;
use smithay_client_toolkit::reexports::client::protocol::wl_output::Transform;
use smithay_client_toolkit::reexports::client::protocol::wl_subcompositor::WlSubcompositor;
use smithay_client_toolkit::reexports::client::protocol::wl_surface::WlSurface;
use smithay_client_toolkit::reexports::client::Connection;
Expand Down Expand Up @@ -519,8 +520,11 @@ impl RemoteSurface {
Ok(())
}

pub fn set_transformation(&mut self, scale: i32) {
self.wl_surface().set_buffer_scale(scale)
pub fn set_transformation(&mut self, scale: i32, transform: Option<Transform>) {
self.wl_surface().set_buffer_scale(scale);
if let Some(transform) = transform {
self.wl_surface().set_buffer_transform(transform);
}
}

pub fn set_input_region(
Expand Down
5 changes: 4 additions & 1 deletion src/client/server_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ impl WprsClientState {
)
.location(loc!())?;

remote_surface.set_transformation(surface_state.buffer_scale);
remote_surface.set_transformation(
surface_state.buffer_scale,
surface_state.buffer_transform.map(Into::into),
);

remote_surface
.set_input_region(surface_state.input_region.take(), &self.compositor_state)
Expand Down
146 changes: 99 additions & 47 deletions src/serialization/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use smithay::backend::input::AxisSource as SmithayAxisSource;
use smithay::backend::input::KeyState as SmithayKeyState;
use smithay::output::Subpixel as SmithaySubpixel;
use smithay::reexports::wayland_server::backend;
use smithay::reexports::wayland_server::protocol::wl_output::Transform as SmithayWlTransform;
use smithay::reexports::wayland_server::protocol::wl_shm::Format as SmithayBufferFormat;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::reexports::wayland_server::Resource;
Expand Down Expand Up @@ -583,6 +584,102 @@ impl Default for Region {
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Archive, Deserialize, Serialize)]
#[archive_attr(derive(bytecheck::CheckBytes, Debug))]
pub enum Transform {
Normal,
_90,
_180,
_270,
Flipped,
Flipped90,
Flipped180,
Flipped270,
}

impl From<SctkTransform> for Transform {
fn from(transform: SctkTransform) -> Self {
match transform {
SctkTransform::Normal => Self::Normal,
SctkTransform::_90 => Self::_90,
SctkTransform::_180 => Self::_180,
SctkTransform::_270 => Self::_270,
SctkTransform::Flipped => Self::Flipped,
SctkTransform::Flipped90 => Self::Flipped90,
SctkTransform::Flipped180 => Self::Flipped180,
SctkTransform::Flipped270 => Self::Flipped270,
_ => {
warn!("Unknown transformation {transform:?}, using Normal instead.");
Self::Normal
},
}
}
}

impl From<Transform> for SctkTransform {
fn from(transform: Transform) -> Self {
match transform {
Transform::Normal => Self::Normal,
Transform::_90 => Self::_90,
Transform::_180 => Self::_180,
Transform::_270 => Self::_270,
Transform::Flipped => Self::Flipped,
Transform::Flipped90 => Self::Flipped90,
Transform::Flipped180 => Self::Flipped180,
Transform::Flipped270 => Self::Flipped270,
}
}
}

impl From<SmithayTransform> for Transform {
fn from(transform: SmithayTransform) -> Self {
match transform {
SmithayTransform::Normal => Self::Normal,
SmithayTransform::_90 => Self::_90,
SmithayTransform::_180 => Self::_180,
SmithayTransform::_270 => Self::_270,
SmithayTransform::Flipped => Self::Flipped,
SmithayTransform::Flipped90 => Self::Flipped90,
SmithayTransform::Flipped180 => Self::Flipped180,
SmithayTransform::Flipped270 => Self::Flipped270,
}
}
}

impl From<SmithayWlTransform> for Transform {
fn from(transform: SmithayWlTransform) -> Self {
match transform {
SmithayWlTransform::Normal => Self::Normal,
SmithayWlTransform::_90 => Self::_90,
SmithayWlTransform::_180 => Self::_180,
SmithayWlTransform::_270 => Self::_270,
SmithayWlTransform::Flipped => Self::Flipped,
SmithayWlTransform::Flipped90 => Self::Flipped90,
SmithayWlTransform::Flipped180 => Self::Flipped180,
SmithayWlTransform::Flipped270 => Self::Flipped270,
_ => {
warn!("Unknown transformation {transform:?}, using Normal instead.");
Self::Normal
},
}
}
}

impl From<Transform> for SmithayTransform {
fn from(transform: Transform) -> Self {
match transform {
Transform::Normal => Self::Normal,
Transform::_90 => Self::_90,
Transform::_180 => Self::_180,
Transform::_270 => Self::_270,
Transform::Flipped => Self::Flipped,
Transform::Flipped90 => Self::Flipped90,
Transform::Flipped180 => Self::Flipped180,
Transform::Flipped270 => Self::Flipped270,
}
}
}

/// An entry for a vector of child surfaces. The (x, y) position is stored
/// explicitly, the z position (stacking order) is stored implicitly based on
/// the index of the item in the vector.
Expand All @@ -602,6 +699,7 @@ pub struct SurfaceState {
pub role: Option<Role>,
// TODO: include buffer_delta, transform from SurfaceAttributes
pub buffer_scale: i32,
pub buffer_transform: Option<Transform>,
pub opaque_region: Option<Region>,
pub input_region: Option<Region>,
pub z_ordered_children: Vec<SubsurfacePosition>,
Expand All @@ -620,6 +718,7 @@ impl SurfaceState {
buffer,
role: None,
buffer_scale: 1,
buffer_transform: None,
opaque_region: None,
input_region: None,

Expand Down Expand Up @@ -716,53 +815,6 @@ impl From<Subpixel> for SmithaySubpixel {
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Archive, Deserialize, Serialize)]
#[archive_attr(derive(bytecheck::CheckBytes, Debug))]
pub enum Transform {
Normal,
_90,
_180,
_270,
Flipped,
Flipped90,
Flipped180,
Flipped270,
}

impl From<SctkTransform> for Transform {
fn from(transform: SctkTransform) -> Self {
match transform {
SctkTransform::Normal => Self::Normal,
SctkTransform::_90 => Self::_90,
SctkTransform::_180 => Self::_180,
SctkTransform::_270 => Self::_270,
SctkTransform::Flipped => Self::Flipped,
SctkTransform::Flipped90 => Self::Flipped90,
SctkTransform::Flipped180 => Self::Flipped180,
SctkTransform::Flipped270 => Self::Flipped270,
_ => {
warn!("Unknown transformation {transform:?}, using Normal instead.");
Self::Normal
},
}
}
}

impl From<Transform> for SmithayTransform {
fn from(transform: Transform) -> Self {
match transform {
Transform::Normal => Self::Normal,
Transform::_90 => Self::_90,
Transform::_180 => Self::_180,
Transform::_270 => Self::_270,
Transform::Flipped => Self::Flipped,
Transform::Flipped90 => Self::Flipped90,
Transform::Flipped180 => Self::Flipped180,
Transform::Flipped270 => Self::Flipped270,
}
}
}

#[derive(Debug, Copy, Clone, Eq, PartialEq, Archive, Deserialize, Serialize)]
#[archive_attr(derive(bytecheck::CheckBytes, Debug))]
pub struct Mode {
Expand Down
1 change: 1 addition & 0 deletions src/server/smithay_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ pub fn set_transformation(
surface_state: &mut SurfaceState,
) {
surface_state.buffer_scale = surface_attributes.buffer_scale;
surface_state.buffer_transform = Some(surface_attributes.buffer_transform.into());
}

#[instrument(skip_all, level = "debug")]
Expand Down

0 comments on commit 57d216b

Please sign in to comment.