Skip to content

Commit a2c37fd

Browse files
committed
Add Buffer::width and Buffer::height
1 parent c72c4a8 commit a2c37fd

File tree

12 files changed

+117
-0
lines changed

12 files changed

+117
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Update to `objc2` 0.6.0.
44
- Bump MSRV to Rust 1.71.
5+
- Added `Buffer::width` and `Buffer::height`.
56

67
# 0.4.6
78

src/backend_dispatch.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,26 @@ macro_rules! make_dispatch {
124124
}
125125

126126
impl<'a, D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferDispatch<'a, D, W> {
127+
#[inline]
128+
fn width(&self) -> usize {
129+
match self {
130+
$(
131+
$(#[$attr])*
132+
Self::$name(inner) => inner.width(),
133+
)*
134+
}
135+
}
136+
137+
#[inline]
138+
fn height(&self) -> usize {
139+
match self {
140+
$(
141+
$(#[$attr])*
142+
Self::$name(inner) => inner.height(),
143+
)*
144+
}
145+
}
146+
127147
#[inline]
128148
fn pixels(&self) -> &[u32] {
129149
match self {

src/backend_interface.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub(crate) trait SurfaceInterface<D: HasDisplayHandle + ?Sized, W: HasWindowHand
3535
}
3636

3737
pub(crate) trait BufferInterface {
38+
fn width(&self) -> usize;
39+
fn height(&self) -> usize;
3840
fn pixels(&self) -> &[u32];
3941
fn pixels_mut(&mut self) -> &mut [u32];
4042
fn age(&self) -> u8;

src/backends/android.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@ pub struct BufferImpl<'a, D: ?Sized, W> {
123123
unsafe impl<'a, D, W> Send for BufferImpl<'a, D, W> {}
124124

125125
impl<'a, D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'a, D, W> {
126+
fn width(&self) -> usize {
127+
self.native_window_buffer.width()
128+
}
129+
130+
fn height(&self) -> usize {
131+
self.native_window_buffer.height()
132+
}
133+
126134
#[inline]
127135
fn pixels(&self) -> &[u32] {
128136
&self.buffer

src/backends/cg.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,14 @@ pub struct BufferImpl<'a, D, W> {
269269
}
270270

271271
impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
272+
fn width(&self) -> usize {
273+
self.imp.width
274+
}
275+
276+
fn height(&self) -> usize {
277+
self.imp.height
278+
}
279+
272280
#[inline]
273281
fn pixels(&self) -> &[u32] {
274282
&self.buffer

src/backends/kms.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ impl<D: ?Sized, W: ?Sized> Drop for KmsImpl<D, W> {
293293
}
294294

295295
impl<D: ?Sized, W: ?Sized> BufferInterface for BufferImpl<'_, D, W> {
296+
fn width(&self) -> usize {
297+
self.size.0.get() as usize
298+
}
299+
300+
fn height(&self) -> usize {
301+
self.size.1.get() as usize
302+
}
303+
296304
#[inline]
297305
fn pixels(&self) -> &[u32] {
298306
bytemuck::cast_slice(self.mapping.as_ref())

src/backends/orbital.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ pub struct BufferImpl<'a, D, W> {
191191
}
192192

193193
impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
194+
fn width(&self) -> usize {
195+
self.imp.width as usize
196+
}
197+
198+
fn height(&self) -> usize {
199+
self.imp.height as usize
200+
}
201+
194202
#[inline]
195203
fn pixels(&self) -> &[u32] {
196204
match &self.pixels {

src/backends/wayland/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,14 @@ pub struct BufferImpl<'a, D: ?Sized, W> {
263263
}
264264

265265
impl<D: HasDisplayHandle + ?Sized, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
266+
fn width(&self) -> usize {
267+
self.stack.member().width
268+
}
269+
270+
fn height(&self) -> usize {
271+
self.stack.member().height
272+
}
273+
266274
#[inline]
267275
fn pixels(&self) -> &[u32] {
268276
self.stack.member()

src/backends/web.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,22 @@ pub struct BufferImpl<'a, D, W> {
377377
}
378378

379379
impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
380+
fn width(&self) -> usize {
381+
self.imp
382+
.size
383+
.expect("must set size of surface before calling `width()` on the buffer")
384+
.0
385+
.get() as usize
386+
}
387+
388+
fn height(&self) -> usize {
389+
self.imp
390+
.size
391+
.expect("must set size of surface before calling `height()` on the buffer")
392+
.1
393+
.get() as usize
394+
}
395+
380396
fn pixels(&self) -> &[u32] {
381397
&self.imp.buffer
382398
}

src/backends/win32.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ impl<D: HasDisplayHandle, W: HasWindowHandle> SurfaceInterface<D, W> for Win32Im
284284
pub struct BufferImpl<'a, D, W>(&'a mut Win32Impl<D, W>);
285285

286286
impl<D: HasDisplayHandle, W: HasWindowHandle> BufferInterface for BufferImpl<'_, D, W> {
287+
fn width(&self) -> usize {
288+
self.0.buffer.as_ref().unwrap().width.get() as usize
289+
}
290+
291+
fn height(&self) -> usize {
292+
self.0.buffer.as_ref().unwrap().height.get() as usize
293+
}
294+
287295
#[inline]
288296
fn pixels(&self) -> &[u32] {
289297
self.0.buffer.as_ref().unwrap().pixels()

0 commit comments

Comments
 (0)