mirror of
https://github.com/wayvr-org/wayvr.git
synced 2026-11-29 21:32:45 -08:00
client-side decorations
This commit is contained in:
1 parent
28842d6d69
commit
3f43003a0b
9 files changed
+283
-66
No files matched your search
@@ -8,6 +8,7 @@ const SHADERS: &[(&str, ShaderKind)] = &[
|
||||
("grid.frag", ShaderKind::Fragment),
|
||||
("screen.frag", ShaderKind::Fragment),
|
||||
("simple.frag", ShaderKind::Fragment),
|
||||
("wayland.frag", ShaderKind::Fragment),
|
||||
("srgb.frag", ShaderKind::Fragment),
|
||||
("sky.frag", ShaderKind::Fragment),
|
||||
];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use anyhow::Context;
|
||||
use smithay::backend::allocator::Buffer;
|
||||
use smithay::backend::allocator::dmabuf::Dmabuf;
|
||||
use smithay::backend::renderer::{BufferType, buffer_type};
|
||||
use smithay::desktop::{
|
||||
@@ -42,7 +43,7 @@ use smithay::wayland::shell::xdg::decoration::{XdgDecorationHandler, XdgDecorati
|
||||
use smithay::wayland::shell::xdg::{
|
||||
PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,
|
||||
};
|
||||
use smithay::wayland::shm::{ShmHandler, ShmState, with_buffer_contents};
|
||||
use smithay::wayland::shm::{ShmHandler, ShmState, shm_format_to_fourcc, with_buffer_contents};
|
||||
use smithay::wayland::single_pixel_buffer::get_single_pixel_buffer;
|
||||
use smithay::wayland::viewporter::ViewporterState;
|
||||
use smithay::{
|
||||
@@ -59,6 +60,7 @@ use std::sync::{Arc, Mutex};
|
||||
use wayland_server::Client;
|
||||
use wayland_server::backend::{ClientData, ClientId, DisconnectReason};
|
||||
use wayland_server::protocol::wl_surface::WlSurface;
|
||||
use wlx_capture::DrmFourcc;
|
||||
|
||||
use crate::backend::wayvr::image_importer::ImageImporter;
|
||||
use crate::backend::wayvr::{SurfaceBufWithImage, WAYVR_SCREEN_RES, time};
|
||||
@@ -90,6 +92,7 @@ pub struct Application {
|
||||
pub viewporter: ViewporterState,
|
||||
pub display_handle: DisplayHandle,
|
||||
pub redraw_requests: HashSet<ObjectId>,
|
||||
pub(super) no_server_decorations: HashSet<ObjectId>,
|
||||
pub pending_frame_callbacks: HashMap<ObjectId, Vec<wl_callback::WlCallback>>,
|
||||
pub cursor_image: CursorImageStatus,
|
||||
/// pointer that last drove the wvr_server mouse. used for DND
|
||||
@@ -179,6 +182,23 @@ impl Application {
|
||||
self.redraw_requests.remove(surface_id)
|
||||
}
|
||||
|
||||
pub fn has_server_side_decorations(&self, surface: &WlSurface) -> bool {
|
||||
!self.no_server_decorations.contains(&surface.id())
|
||||
}
|
||||
|
||||
fn set_server_side_decorations(&mut self, surface: &WlSurface, enabled: bool) {
|
||||
let id = surface.id();
|
||||
let changed = if enabled {
|
||||
self.no_server_decorations.remove(&id)
|
||||
} else {
|
||||
self.no_server_decorations.insert(id.clone())
|
||||
};
|
||||
|
||||
if changed {
|
||||
self.redraw_requests.insert(id);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn output_logical_size(&self) -> Size<i32, Logical> {
|
||||
self.output.current_mode().map_or_else(
|
||||
|| Size::new(WAYVR_SCREEN_RES[0], WAYVR_SCREEN_RES[1]),
|
||||
@@ -220,6 +240,13 @@ impl Application {
|
||||
}
|
||||
}
|
||||
|
||||
fn drm_format_has_alpha(format: DrmFourcc) -> bool {
|
||||
matches!(
|
||||
format,
|
||||
DrmFourcc::Abgr8888 | DrmFourcc::Argb8888 | DrmFourcc::Abgr2101010
|
||||
)
|
||||
}
|
||||
|
||||
impl compositor::CompositorHandler for Application {
|
||||
fn compositor_state(&mut self) -> &mut compositor::CompositorState {
|
||||
&mut self.compositor
|
||||
@@ -260,6 +287,7 @@ impl compositor::CompositorHandler for Application {
|
||||
),
|
||||
scale: attrs.buffer_scale,
|
||||
dmabuf: true,
|
||||
has_alpha: drm_format_has_alpha(dmabuf.format().code),
|
||||
};
|
||||
|
||||
if let Some(old_buffer) =
|
||||
@@ -287,6 +315,8 @@ impl compositor::CompositorHandler for Application {
|
||||
),
|
||||
scale: attrs.buffer_scale,
|
||||
dmabuf: false,
|
||||
has_alpha: shm_format_to_fourcc(buf.format)
|
||||
.is_some_and(drm_format_has_alpha),
|
||||
};
|
||||
sbwi.apply_to_surface(states, None);
|
||||
}
|
||||
@@ -308,6 +338,7 @@ impl compositor::CompositorHandler for Application {
|
||||
),
|
||||
scale: attrs.buffer_scale,
|
||||
dmabuf: false,
|
||||
has_alpha: true,
|
||||
};
|
||||
sbwi.apply_to_surface(states, None);
|
||||
}
|
||||
@@ -459,6 +490,8 @@ impl XdgShellHandler for Application {
|
||||
|
||||
fn toplevel_destroyed(&mut self, surface: ToplevelSurface) {
|
||||
self.output.leave(surface.wl_surface());
|
||||
self.no_server_decorations
|
||||
.remove(&surface.wl_surface().id());
|
||||
|
||||
if let Some(client) = surface.wl_surface().client() {
|
||||
self.wayvr_tasks
|
||||
@@ -672,24 +705,26 @@ impl selection_ext::DataControlHandler for Application {
|
||||
}
|
||||
impl XdgDecorationHandler for Application {
|
||||
fn new_decoration(&mut self, toplevel: ToplevelSurface) {
|
||||
self.set_server_side_decorations(toplevel.wl_surface(), true);
|
||||
toplevel.with_pending_state(|state| {
|
||||
state.decoration_mode = Some(zxdg_toplevel_decoration_v1::Mode::ServerSide);
|
||||
});
|
||||
toplevel.send_configure();
|
||||
}
|
||||
|
||||
fn request_mode(
|
||||
&mut self,
|
||||
toplevel: ToplevelSurface,
|
||||
_mode: zxdg_toplevel_decoration_v1::Mode,
|
||||
) {
|
||||
fn request_mode(&mut self, toplevel: ToplevelSurface, mode: zxdg_toplevel_decoration_v1::Mode) {
|
||||
self.set_server_side_decorations(
|
||||
toplevel.wl_surface(),
|
||||
matches!(mode, zxdg_toplevel_decoration_v1::Mode::ServerSide),
|
||||
);
|
||||
toplevel.with_pending_state(|state| {
|
||||
state.decoration_mode = Some(zxdg_toplevel_decoration_v1::Mode::ServerSide);
|
||||
state.decoration_mode = Some(mode);
|
||||
});
|
||||
toplevel.send_configure();
|
||||
}
|
||||
|
||||
fn unset_mode(&mut self, toplevel: ToplevelSurface) {
|
||||
self.set_server_side_decorations(toplevel.wl_surface(), true);
|
||||
toplevel.with_pending_state(|state| {
|
||||
state.decoration_mode = Some(zxdg_toplevel_decoration_v1::Mode::ServerSide);
|
||||
});
|
||||
@@ -704,11 +739,19 @@ impl KdeDecorationHandler for Application {
|
||||
|
||||
fn request_mode(
|
||||
&mut self,
|
||||
_surface: &WlSurface,
|
||||
surface: &WlSurface,
|
||||
decoration: &org_kde_kwin_server_decoration::OrgKdeKwinServerDecoration,
|
||||
_mode: wayland_server::WEnum<org_kde_kwin_server_decoration::Mode>,
|
||||
mode: wayland_server::WEnum<org_kde_kwin_server_decoration::Mode>,
|
||||
) {
|
||||
decoration.mode(org_kde_kwin_server_decoration::Mode::Server);
|
||||
let wayland_server::WEnum::Value(mode) = mode else {
|
||||
return;
|
||||
};
|
||||
|
||||
self.set_server_side_decorations(
|
||||
surface,
|
||||
matches!(mode, org_kde_kwin_server_decoration::Mode::Server),
|
||||
);
|
||||
decoration.mode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ pub struct RenderedSurface {
|
||||
pub image: Arc<ImageView>,
|
||||
pub pos: Vec2,
|
||||
pub size: Vec2,
|
||||
pub has_alpha: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -215,6 +216,7 @@ pub fn collect_rendered_surface_tree_at(
|
||||
image: surf.image,
|
||||
pos: Vec2::new(pos.x as f32, pos.y as f32),
|
||||
size: Vec2::new(extent[0] / scale, extent[1] / scale),
|
||||
has_alpha: surf.has_alpha,
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -326,11 +328,19 @@ pub fn rendered_surfaces_dirty(old: &[RenderedSurface], new: &[RenderedSurface])
|
||||
a.surface_id != b.surface_id
|
||||
|| a.pos != b.pos
|
||||
|| a.size != b.size
|
||||
|| a.has_alpha != b.has_alpha
|
||||
|| !Arc::ptr_eq(a.image.image(), b.image.image())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compute_transforms(inner_extent: [u32; 2]) -> (Affine2, RangeInclusive<f32>) {
|
||||
pub fn compute_transforms(
|
||||
inner_extent: [u32; 2],
|
||||
server_side_decorations: bool,
|
||||
) -> (Affine2, RangeInclusive<f32>) {
|
||||
if !server_side_decorations {
|
||||
return (Affine2::IDENTITY, 0.0..=1.0);
|
||||
}
|
||||
|
||||
let ix = inner_extent[0].max(1) as f32;
|
||||
let iy = inner_extent[1].max(1) as f32;
|
||||
|
||||
@@ -357,9 +367,14 @@ pub fn build_hit_context(
|
||||
toplevel: &WlSurface,
|
||||
_popup_manager: &PopupManager,
|
||||
inner_extent: [u32; 2],
|
||||
server_side_decorations: bool,
|
||||
) -> WvrHitContext {
|
||||
let (mouse_transform, uv_range) = compute_transforms(inner_extent);
|
||||
let panel_height = BORDER_SIZE * 2 + BAR_SIZE;
|
||||
let (mouse_transform, uv_range) = compute_transforms(inner_extent, server_side_decorations);
|
||||
let panel_height = if server_side_decorations {
|
||||
BORDER_SIZE * 2 + BAR_SIZE
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let surfaces = collect_rendered_surface_tree(toplevel);
|
||||
|
||||
|
||||
@@ -297,6 +297,7 @@ impl WvrServerState {
|
||||
popup_manager: PopupManager::default(),
|
||||
viewporter,
|
||||
redraw_requests: HashSet::new(),
|
||||
no_server_decorations: HashSet::new(),
|
||||
pending_frame_callbacks: HashMap::new(),
|
||||
cursor_image: CursorImageStatus::default_named(),
|
||||
vr_pointer: 0,
|
||||
@@ -1040,6 +1041,7 @@ impl WvrServerState {
|
||||
&toplevel,
|
||||
&self.manager.state.popup_manager,
|
||||
inner_extent,
|
||||
self.manager.state.has_server_side_decorations(&toplevel),
|
||||
);
|
||||
|
||||
let new_x = (hover.pos.x + mouse_delta.x).clamp(0., inner_extent[0] as f64);
|
||||
@@ -1436,6 +1438,7 @@ pub struct SurfaceBufWithImage {
|
||||
pub transform: Transform,
|
||||
pub scale: i32,
|
||||
pub dmabuf: bool,
|
||||
pub has_alpha: bool,
|
||||
}
|
||||
|
||||
impl SurfaceBufWithImage {
|
||||
|
||||
@@ -10,7 +10,7 @@ use wgui::gfx::{
|
||||
use wlx_capture::DrmFormat;
|
||||
|
||||
use crate::shaders::{
|
||||
frag_color, frag_grid, frag_screen, frag_simple, frag_sky, frag_srgb, vert_quad,
|
||||
frag_color, frag_grid, frag_screen, frag_simple, frag_sky, frag_srgb, frag_wayland, vert_quad,
|
||||
};
|
||||
|
||||
use dmabuf::get_drm_formats;
|
||||
@@ -32,6 +32,7 @@ impl WGfxExtras {
|
||||
shaders.insert("frag_grid", frag_grid::load(gfx)?);
|
||||
shaders.insert("frag_screen", frag_screen::load(gfx)?);
|
||||
shaders.insert("frag_simple", frag_simple::load(gfx)?);
|
||||
shaders.insert("frag_wayland", frag_wayland::load(gfx)?);
|
||||
|
||||
let drm_formats = get_drm_formats(gfx).into();
|
||||
let vertices = [
|
||||
|
||||
@@ -56,12 +56,45 @@ impl ScreenPipeline {
|
||||
stereo: StereoMode,
|
||||
offsetf: [f32; 2],
|
||||
transform: wlx_frame::Transform,
|
||||
) -> anyhow::Result<Self> {
|
||||
Self::new_with_shader(meta, app, stereo, offsetf, transform, "frag_screen")
|
||||
}
|
||||
|
||||
pub fn new_wayland(
|
||||
meta: &FrameMeta,
|
||||
app: &mut AppState,
|
||||
stereo: StereoMode,
|
||||
offsetf: [f32; 2],
|
||||
transform: wlx_frame::Transform,
|
||||
has_alpha: bool,
|
||||
) -> anyhow::Result<Self> {
|
||||
Self::new_with_shader(
|
||||
meta,
|
||||
app,
|
||||
stereo,
|
||||
offsetf,
|
||||
transform,
|
||||
if has_alpha {
|
||||
"frag_wayland"
|
||||
} else {
|
||||
"frag_screen"
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn new_with_shader(
|
||||
meta: &FrameMeta,
|
||||
app: &mut AppState,
|
||||
stereo: StereoMode,
|
||||
offsetf: [f32; 2],
|
||||
transform: wlx_frame::Transform,
|
||||
fragment_shader: &str,
|
||||
) -> anyhow::Result<Self> {
|
||||
let extentf = [meta.extent[0] as f32, meta.extent[1] as f32];
|
||||
|
||||
let pipeline = app.gfx.create_pipeline(
|
||||
app.gfx_extras.shaders.get("vert_quad").unwrap(), // want panic
|
||||
app.gfx_extras.shaders.get("frag_screen").unwrap(), // want panic
|
||||
app.gfx_extras.shaders.get(fragment_shader).unwrap(), // want panic
|
||||
WPipelineCreateInfo::new(app.gfx.surface_format()).use_updatable_descriptors([0]),
|
||||
)?;
|
||||
|
||||
|
||||
+125
-51
@@ -18,7 +18,7 @@ use wgui::{
|
||||
components::button::ComponentButton,
|
||||
event::{CallbackDataCommon, EventCallback},
|
||||
gfx::{
|
||||
BLEND_ALPHA, BufferUsage, ImageView, Scissor, Vert2Uv,
|
||||
AttachmentBlend, BlendFactor, BlendOp, BufferUsage, ImageView, Scissor, Vert2Uv,
|
||||
cmd::WGfxClearMode,
|
||||
pipeline::{WGfxPipeline, WPipelineCreateInfo},
|
||||
upload_quad_vertices,
|
||||
@@ -77,6 +77,15 @@ pub enum WvrCommand {
|
||||
const BORDER_SIZE: u32 = 5;
|
||||
const BAR_SIZE: u32 = 48;
|
||||
|
||||
const BLEND_WAYLAND_ALPHA: AttachmentBlend = AttachmentBlend {
|
||||
src_color_blend_factor: BlendFactor::One,
|
||||
dst_color_blend_factor: BlendFactor::OneMinusSrcAlpha,
|
||||
color_blend_op: BlendOp::Add,
|
||||
src_alpha_blend_factor: BlendFactor::One,
|
||||
dst_alpha_blend_factor: BlendFactor::OneMinusSrcAlpha,
|
||||
alpha_blend_op: BlendOp::Add,
|
||||
};
|
||||
|
||||
pub fn create_wl_window_overlay(
|
||||
name: Arc<str>,
|
||||
app: &mut AppState,
|
||||
@@ -136,7 +145,8 @@ pub struct WvrWindowBackend {
|
||||
name: Arc<str>,
|
||||
icon: Arc<str>,
|
||||
pipeline: Option<ScreenPipeline>,
|
||||
subsurface_pipeline: Arc<WGfxPipeline<Vert2Uv>>,
|
||||
subsurface_pipeline_opaque: Arc<WGfxPipeline<Vert2Uv>>,
|
||||
subsurface_pipeline_alpha: Arc<WGfxPipeline<Vert2Uv>>,
|
||||
popup_outside_button: Option<wayvr::MouseIndex>,
|
||||
interaction_transform: Option<Affine2>,
|
||||
window: WindowHandle,
|
||||
@@ -160,6 +170,8 @@ pub struct WvrWindowBackend {
|
||||
scale: (f32, f32),
|
||||
resizable: bool,
|
||||
had_focus: bool,
|
||||
server_side_decorations: bool,
|
||||
source_has_alpha: bool,
|
||||
}
|
||||
|
||||
impl WvrWindowBackend {
|
||||
@@ -171,10 +183,15 @@ impl WvrWindowBackend {
|
||||
scale: (f32, f32),
|
||||
resizable: bool,
|
||||
) -> anyhow::Result<Self> {
|
||||
let subsurface_pipeline = app.gfx.create_pipeline(
|
||||
let subsurface_pipeline_opaque = app.gfx.create_pipeline(
|
||||
app.gfx_extras.shaders.get("vert_quad").unwrap(), // want panic
|
||||
app.gfx_extras.shaders.get("frag_simple").unwrap(), // want panic
|
||||
WPipelineCreateInfo::new(app.gfx.surface_format()).use_blend(BLEND_ALPHA),
|
||||
app.gfx_extras.shaders.get("frag_screen").unwrap(), // want panic
|
||||
WPipelineCreateInfo::new(app.gfx.surface_format()).use_blend(BLEND_WAYLAND_ALPHA),
|
||||
)?;
|
||||
let subsurface_pipeline_alpha = app.gfx.create_pipeline(
|
||||
app.gfx_extras.shaders.get("vert_quad").unwrap(), // want panic
|
||||
app.gfx_extras.shaders.get("frag_wayland").unwrap(), // want panic
|
||||
WPipelineCreateInfo::new(app.gfx.surface_format()).use_blend(BLEND_WAYLAND_ALPHA),
|
||||
)?;
|
||||
|
||||
let on_custom_attrib: OnCustomAttribFunc =
|
||||
@@ -241,7 +258,8 @@ impl WvrWindowBackend {
|
||||
popups: Default::default(),
|
||||
surfaces: Default::default(),
|
||||
hit_context: None,
|
||||
subsurface_pipeline,
|
||||
subsurface_pipeline_opaque,
|
||||
subsurface_pipeline_alpha,
|
||||
popup_outside_button: None,
|
||||
interaction_transform: None,
|
||||
just_resumed: false,
|
||||
@@ -265,9 +283,27 @@ impl WvrWindowBackend {
|
||||
scale,
|
||||
resizable,
|
||||
had_focus: false,
|
||||
server_side_decorations: true,
|
||||
source_has_alpha: false,
|
||||
})
|
||||
}
|
||||
|
||||
const fn content_offset(&self) -> [f32; 2] {
|
||||
if self.server_side_decorations {
|
||||
[BORDER_SIZE as f32, (BAR_SIZE + BORDER_SIZE) as f32]
|
||||
} else {
|
||||
[0.0, 0.0]
|
||||
}
|
||||
}
|
||||
|
||||
const fn panel_height(&self) -> u32 {
|
||||
if self.server_side_decorations {
|
||||
BORDER_SIZE * 2 + BAR_SIZE
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_extent(&mut self, app: &mut AppState, meta: &FrameMeta) -> anyhow::Result<()> {
|
||||
let (old_scale, old_curve_scale) = self.scale;
|
||||
let (new_scale, curve_scale) = overlay_scale_from_extent(meta.extent);
|
||||
@@ -308,15 +344,20 @@ impl WvrWindowBackend {
|
||||
|
||||
self.interaction_transform = Some(ui_transform(meta.extent));
|
||||
|
||||
let mut scale = vec2(
|
||||
((meta.extent[0] + BORDER_SIZE * 2) as f32) / meta.extent[0] as f32,
|
||||
((meta.extent[1] + BORDER_SIZE * 2 + BAR_SIZE) as f32) / meta.extent[1] as f32,
|
||||
);
|
||||
|
||||
let mut translation = vec2(
|
||||
-(BORDER_SIZE as f32) / meta.extent[0] as f32,
|
||||
-((BORDER_SIZE + BAR_SIZE) as f32) / meta.extent[1] as f32,
|
||||
);
|
||||
let (mut scale, mut translation) = if self.server_side_decorations {
|
||||
(
|
||||
vec2(
|
||||
((meta.extent[0] + BORDER_SIZE * 2) as f32) / meta.extent[0] as f32,
|
||||
((meta.extent[1] + BORDER_SIZE * 2 + BAR_SIZE) as f32) / meta.extent[1] as f32,
|
||||
),
|
||||
vec2(
|
||||
-(BORDER_SIZE as f32) / meta.extent[0] as f32,
|
||||
-((BORDER_SIZE + BAR_SIZE) as f32) / meta.extent[1] as f32,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
(vec2(1.0, 1.0), vec2(0.0, 0.0))
|
||||
};
|
||||
|
||||
if self.stereo_adjust_mouse
|
||||
&& let Some(stereo) = self.stereo
|
||||
@@ -337,11 +378,13 @@ impl WvrWindowBackend {
|
||||
self.mouse_transform = Affine2::from_scale_angle_translation(scale, 0.0, translation);
|
||||
self.uv_range = translation[0]..=(1.0 - translation[0]);
|
||||
|
||||
self.panel.max_size = vec2(
|
||||
(meta.extent[0]/* + BORDER_SIZE * 2 (disabled for now) */) as _,
|
||||
BAR_SIZE as _,
|
||||
);
|
||||
self.panel.update_layout(app)?;
|
||||
if self.server_side_decorations {
|
||||
self.panel.max_size = vec2(
|
||||
(meta.extent[0]/* + BORDER_SIZE * 2 (disabled for now) */) as _,
|
||||
BAR_SIZE as _,
|
||||
);
|
||||
self.panel.update_layout(app)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -433,20 +476,23 @@ impl WvrWindowBackend {
|
||||
&buf_vert, extentf[0], extentf[1], s.pos.x, s.pos.y, s.size.x, s.size.y,
|
||||
)?;
|
||||
|
||||
let set0 = self.subsurface_pipeline.uniform_sampler(
|
||||
0,
|
||||
s.image.clone(),
|
||||
app.gfx.texture_filter(),
|
||||
)?;
|
||||
let pipeline = if s.has_alpha {
|
||||
&self.subsurface_pipeline_alpha
|
||||
} else {
|
||||
&self.subsurface_pipeline_opaque
|
||||
};
|
||||
|
||||
let pass = self.subsurface_pipeline.create_pass(
|
||||
let set0 = pipeline.uniform_sampler(0, s.image.clone(), app.gfx.texture_filter())?;
|
||||
|
||||
let offset = self.content_offset();
|
||||
let pass = pipeline.create_pass(
|
||||
extentf,
|
||||
[BORDER_SIZE as _, (BAR_SIZE + BORDER_SIZE) as _],
|
||||
offset,
|
||||
buf_vert,
|
||||
0..4,
|
||||
0..1,
|
||||
vec![set0],
|
||||
Scissor::from_viewport(extentf, [BORDER_SIZE as _, (BAR_SIZE + BORDER_SIZE) as _]),
|
||||
Scissor::from_viewport(extentf, offset),
|
||||
)?;
|
||||
|
||||
for buf in &mut rdr.cmd_bufs {
|
||||
@@ -514,6 +560,14 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
return Ok(ShouldRender::Unable);
|
||||
};
|
||||
|
||||
let server_side_decorations = app.wvr_server.as_ref().is_none_or(|wvr| {
|
||||
wvr.manager
|
||||
.state
|
||||
.has_server_side_decorations(toplevel.wl_surface())
|
||||
});
|
||||
let decoration_changed = self.server_side_decorations != server_side_decorations;
|
||||
self.server_side_decorations = server_side_decorations;
|
||||
|
||||
let surface_id = toplevel.wl_surface().id();
|
||||
let surfaces = collect_rendered_surface_tree(toplevel.wl_surface());
|
||||
|
||||
@@ -552,7 +606,9 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
let mut tree_dirty = false;
|
||||
|
||||
if let Some(wvr_server) = app.wvr_server.as_mut() {
|
||||
self.update_decor(wvr_server);
|
||||
if self.server_side_decorations {
|
||||
self.update_decor(wvr_server);
|
||||
}
|
||||
|
||||
let state = &mut wvr_server.manager.state;
|
||||
tree_dirty |= state.take_redraw_request(&surface_id);
|
||||
@@ -567,8 +623,12 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
}
|
||||
}
|
||||
|
||||
let should_render_panel = self.panel.should_render(app)?;
|
||||
let force_render = tree_dirty || mem::take(&mut self.just_resumed);
|
||||
let should_render_panel = if self.server_side_decorations {
|
||||
self.panel.should_render(app)?
|
||||
} else {
|
||||
ShouldRender::Can
|
||||
};
|
||||
let just_resumed = mem::take(&mut self.just_resumed);
|
||||
|
||||
let hit_surfaces = surfaces.clone();
|
||||
self.surfaces = surfaces;
|
||||
@@ -579,6 +639,13 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
return Ok(ShouldRender::Unable);
|
||||
};
|
||||
|
||||
let source_alpha_changed = self.source_has_alpha != surf.has_alpha;
|
||||
self.source_has_alpha = surf.has_alpha;
|
||||
if source_alpha_changed && self.pipeline.is_some() {
|
||||
self.pipeline = None;
|
||||
}
|
||||
let force_render = tree_dirty || decoration_changed || source_alpha_changed || just_resumed;
|
||||
|
||||
let mut meta = FrameMeta {
|
||||
extent: surf.image.extent_2d(),
|
||||
format: surf.image.format(),
|
||||
@@ -605,42 +672,47 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
let inner_extent = meta.extent;
|
||||
self.sync_committed_toplevel_size(app, inner_extent);
|
||||
|
||||
let hit_context = WvrHitContext {
|
||||
surfaces: hit_surfaces,
|
||||
popup_roots: popup_roots.into(),
|
||||
mouse_transform: self.mouse_transform,
|
||||
uv_range: self.uv_range.clone(),
|
||||
inner_extent,
|
||||
panel_height: BORDER_SIZE * 2 + BAR_SIZE,
|
||||
};
|
||||
self.hit_context = Some(hit_context);
|
||||
if self.server_side_decorations {
|
||||
meta.extent[0] += BORDER_SIZE * 2;
|
||||
meta.extent[1] += BORDER_SIZE * 2 + BAR_SIZE;
|
||||
}
|
||||
|
||||
meta.extent[0] += BORDER_SIZE * 2;
|
||||
meta.extent[1] += BORDER_SIZE * 2 + BAR_SIZE;
|
||||
let content_offset = self.content_offset();
|
||||
|
||||
if let Some(pipeline) = self.pipeline.as_mut() {
|
||||
if self.inner_extent != inner_extent {
|
||||
if self.inner_extent != inner_extent || decoration_changed {
|
||||
pipeline.set_layout(
|
||||
app,
|
||||
[inner_extent[0] as _, inner_extent[1] as _],
|
||||
[BORDER_SIZE as _, (BAR_SIZE + BORDER_SIZE) as _],
|
||||
content_offset,
|
||||
Transform::Normal,
|
||||
)?;
|
||||
self.apply_extent(app, &meta)?;
|
||||
self.inner_extent = inner_extent;
|
||||
}
|
||||
} else {
|
||||
let pipeline = ScreenPipeline::new(
|
||||
let pipeline = ScreenPipeline::new_wayland(
|
||||
&meta,
|
||||
app,
|
||||
self.stereo.unwrap_or(StereoMode::None),
|
||||
[BORDER_SIZE as _, (BAR_SIZE + BORDER_SIZE) as _],
|
||||
content_offset,
|
||||
Transform::Normal,
|
||||
self.source_has_alpha,
|
||||
)?;
|
||||
self.apply_extent(app, &meta)?;
|
||||
self.pipeline = Some(pipeline);
|
||||
}
|
||||
|
||||
let hit_context = WvrHitContext {
|
||||
surfaces: hit_surfaces,
|
||||
popup_roots: popup_roots.into(),
|
||||
mouse_transform: self.mouse_transform,
|
||||
uv_range: self.uv_range.clone(),
|
||||
inner_extent,
|
||||
panel_height: self.panel_height(),
|
||||
};
|
||||
self.hit_context = Some(hit_context);
|
||||
|
||||
let mouse = app
|
||||
.wvr_server
|
||||
.as_ref()
|
||||
@@ -690,12 +762,14 @@ impl OverlayBackend for WvrWindowBackend {
|
||||
app: &mut state::AppState,
|
||||
rdr: &mut RenderResources,
|
||||
) -> anyhow::Result<()> {
|
||||
self.panel.render(app, rdr)?;
|
||||
// `GuiPanel` is not stereo-aware, so just render the same pass twice
|
||||
if rdr.cmd_bufs.len() > 1 {
|
||||
rdr.cmd_bufs.reverse();
|
||||
if self.server_side_decorations {
|
||||
self.panel.render(app, rdr)?;
|
||||
rdr.cmd_bufs.reverse();
|
||||
// `GuiPanel` is not stereo-aware, so just render the same pass twice
|
||||
if rdr.cmd_bufs.len() > 1 {
|
||||
rdr.cmd_bufs.reverse();
|
||||
self.panel.render(app, rdr)?;
|
||||
rdr.cmd_bufs.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
let image = self.cur_image.as_ref().unwrap().clone();
|
||||
|
||||
@@ -91,6 +91,24 @@ pub mod frag_simple {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod frag_wayland {
|
||||
use super::{Arc, DescriptorBinding, DescriptorType, ShaderModule, ShaderStage, WGfx};
|
||||
|
||||
pub fn load(gfx: &WGfx) -> anyhow::Result<Arc<ShaderModule>> {
|
||||
super::load(
|
||||
gfx,
|
||||
include_bytes!(concat!(env!("OUT_DIR"), "/wayland.frag.spv")),
|
||||
ShaderStage::Fragment,
|
||||
&[DescriptorBinding::new(
|
||||
0,
|
||||
0,
|
||||
DescriptorType::CombinedImageSampler,
|
||||
ShaderStage::Fragment,
|
||||
)],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub mod frag_srgb {
|
||||
use super::{Arc, DescriptorBinding, DescriptorType, ShaderModule, ShaderStage, WGfx};
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#version 310 es
|
||||
precision highp float;
|
||||
|
||||
layout (location = 0) in vec2 in_uv;
|
||||
layout (location = 0) out vec4 out_color;
|
||||
|
||||
layout (set = 0, binding = 0) uniform sampler2D in_texture;
|
||||
|
||||
vec3 srgb_to_linear(vec3 color)
|
||||
{
|
||||
bvec3 cutoff = lessThan(color, vec3(0.04045));
|
||||
vec3 higher = pow((color + vec3(0.055)) / vec3(1.055), vec3(2.4));
|
||||
vec3 lower = color / vec3(12.92);
|
||||
return mix(higher, lower, cutoff);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(in_texture, in_uv);
|
||||
|
||||
// wl_surface buffer contents use premultiplied alpha
|
||||
if (color.a > 0.0) {
|
||||
color.rgb = srgb_to_linear(clamp(color.rgb / color.a, 0.0, 1.0)) * color.a;
|
||||
} else {
|
||||
color.rgb = vec3(0.0);
|
||||
}
|
||||
|
||||
out_color = color;
|
||||
}
|
||||
Reference in new issue
Block a user