Skip to content

Commit

Permalink
screencapture: implement ext_image_copy_capture_manager_v1
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Oct 9, 2024
1 parent ba9e597 commit 50845b4
Show file tree
Hide file tree
Showing 28 changed files with 1,194 additions and 25 deletions.
2 changes: 2 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ Jay supports the following wayland protocols:
| ext_foreign_toplevel_image_capture_source_manager_v1 | 1 | |
| ext_foreign_toplevel_list_v1 | 1 | Yes |
| ext_idle_notifier_v1 | 1 | Yes |
| ext_image_copy_capture_manager_v1 | 1[^composited] | Yes |
| ext_output_image_capture_source_manager_v1 | 1 | |
| ext_session_lock_manager_v1 | 1 | Yes |
| ext_transient_seat_manager_v1 | 1[^ts_rejected] | Yes |
Expand Down Expand Up @@ -187,3 +188,4 @@ Jay supports the following wayland protocols:

[^lsaccess]: Sandboxes can restrict access to this protocol.
[^ts_rejected]: Seat creation is always rejected.
[^composited]: Cursors are always composited.
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Vulkan is now the default renderer.
- Emulate vblank events on the nvidia driver.
- Implement ext-image-capture-source-v1.
- Implement ext-image-copy-capture-v1.

# 1.6.0 (2024-09-25)

Expand Down
12 changes: 9 additions & 3 deletions src/client/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use {
ifs::{
ext_foreign_toplevel_handle_v1::ExtForeignToplevelHandleV1,
ext_image_capture_source_v1::ExtImageCaptureSourceV1,
ext_image_copy::ext_image_copy_capture_session_v1::ExtImageCopyCaptureSessionV1,
ipc::{
wl_data_source::WlDataSource, zwlr_data_control_source_v1::ZwlrDataControlSourceV1,
zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1,
Expand Down Expand Up @@ -33,9 +34,10 @@ use {
copyhashmap::{CopyHashMap, Locked},
},
wire::{
ExtForeignToplevelHandleV1Id, ExtImageCaptureSourceV1Id, JayOutputId, JayScreencastId,
JayToplevelId, JayWorkspaceId, WlBufferId, WlDataSourceId, WlOutputId, WlPointerId,
WlRegionId, WlRegistryId, WlSeatId, WlSurfaceId, WpDrmLeaseConnectorV1Id,
ExtForeignToplevelHandleV1Id, ExtImageCaptureSourceV1Id,
ExtImageCopyCaptureSessionV1Id, JayOutputId, JayScreencastId, JayToplevelId,
JayWorkspaceId, WlBufferId, WlDataSourceId, WlOutputId, WlPointerId, WlRegionId,
WlRegistryId, WlSeatId, WlSurfaceId, WpDrmLeaseConnectorV1Id,
WpLinuxDrmSyncobjTimelineV1Id, XdgPopupId, XdgPositionerId, XdgSurfaceId,
XdgToplevelId, XdgWmBaseId, ZwlrDataControlSourceV1Id, ZwpPrimarySelectionSourceV1Id,
ZwpTabletToolV2Id,
Expand Down Expand Up @@ -73,6 +75,8 @@ pub struct Objects {
pub image_capture_sources: CopyHashMap<ExtImageCaptureSourceV1Id, Rc<ExtImageCaptureSourceV1>>,
pub foreign_toplevel_handles:
CopyHashMap<ExtForeignToplevelHandleV1Id, Rc<ExtForeignToplevelHandleV1>>,
pub ext_copy_sessions:
CopyHashMap<ExtImageCopyCaptureSessionV1Id, Rc<ExtImageCopyCaptureSessionV1>>,
ids: RefCell<Vec<usize>>,
}

Expand Down Expand Up @@ -108,6 +112,7 @@ impl Objects {
xdg_popups: Default::default(),
image_capture_sources: Default::default(),
foreign_toplevel_handles: Default::default(),
ext_copy_sessions: Default::default(),
ids: RefCell::new(vec![]),
}
}
Expand Down Expand Up @@ -147,6 +152,7 @@ impl Objects {
self.xdg_popups.clear();
self.image_capture_sources.clear();
self.foreign_toplevel_handles.clear();
self.ext_copy_sessions.clear();
}

pub fn id<T>(&self, client_data: &Client) -> Result<T, ClientError>
Expand Down
1 change: 1 addition & 0 deletions src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ fn create_dummy_output(state: &Rc<State>) {
latch_event: Default::default(),
presentation_event: Default::default(),
flip_margin_ns: Default::default(),
ext_copy_sessions: Default::default(),
});
let dummy_workspace = Rc::new(WorkspaceNode {
id: state.node_ids.next(),
Expand Down
1 change: 1 addition & 0 deletions src/gfx_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ pub trait GfxFramebuffer: Debug {

pub trait GfxInternalFramebuffer: GfxFramebuffer {
fn into_fb(self: Rc<Self>) -> Rc<dyn GfxFramebuffer>;
fn stride(&self) -> i32;

fn staging_size(&self) -> usize;

Expand Down
4 changes: 4 additions & 0 deletions src/gfx_apis/gl/gl/render_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct GlRenderBuffer {
pub ctx: Rc<EglContext>,
pub width: i32,
pub height: i32,
pub stride: i32,
pub format: &'static Format,
rbo: GLuint,
}
Expand All @@ -30,6 +31,7 @@ impl GlRenderBuffer {
ctx: &Rc<EglContext>,
width: i32,
height: i32,
stride: i32,
format: &'static Format,
) -> Result<Rc<GlRenderBuffer>, RenderError> {
let Some(shm_info) = &format.shm_info else {
Expand All @@ -46,6 +48,7 @@ impl GlRenderBuffer {
ctx: ctx.clone(),
width,
height,
stride,
format,
rbo,
}))
Expand All @@ -71,6 +74,7 @@ impl GlRenderBuffer {
ctx: ctx.clone(),
width: img.dmabuf.width,
height: img.dmabuf.height,
stride: 0,
format: img.dmabuf.format,
rbo,
}))
Expand Down
4 changes: 2 additions & 2 deletions src/gfx_apis/gl/renderer/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ impl GfxContext for GlRenderContext {
_cpu_worker: &Rc<CpuWorker>,
width: i32,
height: i32,
_stride: i32,
stride: i32,
format: &'static Format,
) -> Result<Rc<dyn GfxInternalFramebuffer>, GfxError> {
let fb = self.ctx.with_current(|| unsafe {
GlRenderBuffer::new(&self.ctx, width, height, format)?.create_framebuffer()
GlRenderBuffer::new(&self.ctx, width, height, stride, format)?.create_framebuffer()
})?;
Ok(Rc::new(Framebuffer { ctx: self, gl: fb }))
}
Expand Down
4 changes: 4 additions & 0 deletions src/gfx_apis/gl/renderer/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ impl GfxInternalFramebuffer for Framebuffer {
self
}

fn stride(&self) -> i32 {
self.gl.rb.stride
}

fn staging_size(&self) -> usize {
0
}
Expand Down
7 changes: 7 additions & 0 deletions src/gfx_apis/vulkan/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ impl GfxInternalFramebuffer for VulkanImage {
self
}

fn stride(&self) -> i32 {
let VulkanImageMemory::Internal(shm) = &self.ty else {
unreachable!();
};
shm.stride as _
}

fn staging_size(&self) -> usize {
let VulkanImageMemory::Internal(shm) = &self.ty else {
unreachable!();
Expand Down
2 changes: 2 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use {
ext_foreign_toplevel_image_capture_source_manager_v1::ExtForeignToplevelImageCaptureSourceManagerV1Global,
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1Global,
ext_idle_notifier_v1::ExtIdleNotifierV1Global,
ext_image_copy::ext_image_copy_capture_manager_v1::ExtImageCopyCaptureManagerV1Global,
ext_output_image_capture_source_manager_v1::ExtOutputImageCaptureSourceManagerV1Global,
ext_session_lock_manager_v1::ExtSessionLockManagerV1Global,
ipc::{
Expand Down Expand Up @@ -201,6 +202,7 @@ impl Globals {
add_singleton!(JayDamageTrackingGlobal);
add_singleton!(ExtOutputImageCaptureSourceManagerV1Global);
add_singleton!(ExtForeignToplevelImageCaptureSourceManagerV1Global);
add_singleton!(ExtImageCopyCaptureManagerV1Global);
}

pub fn add_backend_singletons(&self, backend: &Rc<dyn Backend>) {
Expand Down
1 change: 1 addition & 0 deletions src/ifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub mod ext_foreign_toplevel_list_v1;
pub mod ext_idle_notification_v1;
pub mod ext_idle_notifier_v1;
pub mod ext_image_capture_source_v1;
pub mod ext_image_copy;
pub mod ext_output_image_capture_source_manager_v1;
pub mod ext_session_lock_manager_v1;
pub mod ext_session_lock_v1;
Expand Down
2 changes: 0 additions & 2 deletions src/ifs/ext_image_capture_source_v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use {
thiserror::Error,
};

#[expect(dead_code)]
#[derive(Clone)]
pub enum ImageCaptureSource {
Output(Rc<OutputGlobalOpt>),
Expand All @@ -22,7 +21,6 @@ pub struct ExtImageCaptureSourceV1 {
pub id: ExtImageCaptureSourceV1Id,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
#[expect(dead_code)]
pub ty: ImageCaptureSource,
}

Expand Down
4 changes: 4 additions & 0 deletions src/ifs/ext_image_copy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod ext_image_copy_capture_cursor_session_v1;
pub mod ext_image_copy_capture_frame_v1;
pub mod ext_image_copy_capture_manager_v1;
pub mod ext_image_copy_capture_session_v1;
75 changes: 75 additions & 0 deletions src/ifs/ext_image_copy/ext_image_copy_capture_cursor_session_v1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use {
crate::{
client::{Client, ClientError},
ifs::{
ext_image_capture_source_v1::ImageCaptureSource,
ext_image_copy::ext_image_copy_capture_session_v1::ExtImageCopyCaptureSessionV1,
},
leaks::Tracker,
object::{Object, Version},
wire::{ext_image_copy_capture_cursor_session_v1::*, ExtImageCopyCaptureCursorSessionV1Id},
},
std::{cell::Cell, rc::Rc},
thiserror::Error,
};

pub struct ExtImageCopyCaptureCursorSessionV1 {
pub(super) id: ExtImageCopyCaptureCursorSessionV1Id,
pub(super) client: Rc<Client>,
pub(super) tracker: Tracker<Self>,
pub(super) version: Version,
pub(super) have_session: Cell<bool>,
pub(super) source: ImageCaptureSource,
}

impl ExtImageCopyCaptureCursorSessionV1RequestHandler for ExtImageCopyCaptureCursorSessionV1 {
type Error = ExtImageCopyCaptureCursorSessionV1Error;

fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self)?;
Ok(())
}

fn get_capture_session(
&self,
req: GetCaptureSession,
_slf: &Rc<Self>,
) -> Result<(), Self::Error> {
if self.have_session.replace(true) {
return Err(ExtImageCopyCaptureCursorSessionV1Error::HaveSession);
}
let obj = Rc::new_cyclic(|slf| {
ExtImageCopyCaptureSessionV1::new(
req.session,
&self.client,
self.version,
&self.source,
slf,
)
});
track!(self.client, obj);
self.client.add_client_obj(&obj)?;
obj.send_shm_formats();
obj.send_buffer_size(1, 1);
obj.send_done();
Ok(())
}
}

object_base! {
self = ExtImageCopyCaptureCursorSessionV1;
version = self.version;
}

impl Object for ExtImageCopyCaptureCursorSessionV1 {}

simple_add_obj!(ExtImageCopyCaptureCursorSessionV1);

#[derive(Debug, Error)]
pub enum ExtImageCopyCaptureCursorSessionV1Error {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("The session has already been created")]
HaveSession,
}
efrom!(ExtImageCopyCaptureCursorSessionV1Error, ClientError);
Loading

0 comments on commit 50845b4

Please sign in to comment.