Skip to content

Commit

Permalink
device/queue: move implementations for generic buffers to the generic…
Browse files Browse the repository at this point in the history
… module
  • Loading branch information
Gnurou committed Oct 7, 2024
1 parent 7919f42 commit 0132541
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
23 changes: 0 additions & 23 deletions lib/src/device/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{Format, PixelFormat, QueueType};
use buffer::*;
use direction::*;
use dqbuf::*;
use generic::{GenericBufferHandles, GenericQBuffer, GenericSupportedMemoryType};
use log::debug;
use qbuf::*;

Expand Down Expand Up @@ -563,28 +562,6 @@ mod private {
}
}

impl<'a, D: Direction> QueueableProvider<'a> for Queue<D, BuffersAllocated<GenericBufferHandles>> {
type Queueable = GenericQBuffer<D, &'a Self>;
}

impl<'a, D: Direction> GetBufferByIndex<'a> for Queue<D, BuffersAllocated<GenericBufferHandles>> {
fn try_get_buffer(&'a self, index: usize) -> Result<Self::Queueable, TryGetBufferError> {
let buffer_info = self.try_obtain_buffer(index)?;

Ok(match self.state.memory_type {
GenericSupportedMemoryType::Mmap => {
GenericQBuffer::Mmap(QBuffer::new(self, buffer_info))
}
GenericSupportedMemoryType::UserPtr => {
GenericQBuffer::User(QBuffer::new(self, buffer_info))
}
GenericSupportedMemoryType::DmaBuf => {
GenericQBuffer::DmaBuf(QBuffer::new(self, buffer_info))
}
})
}
}

impl<'a, D, P, Q> QueueableProvider<'a> for Q
where
D: Direction,
Expand Down
29 changes: 28 additions & 1 deletion lib/src/device/queue/generic.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{
device::queue::{
direction::{Capture, Direction, Output},
private,
qbuf::{QBuffer, QueueResult},
BuffersAllocated, CaptureQueueable, OutputQueueable, Queue,
BuffersAllocated, CaptureQueueable, OutputQueueable, Queue, TryGetBufferError,
},
memory::DmaBufHandle,
};
Expand Down Expand Up @@ -122,6 +123,32 @@ where
}
}

impl<'a, D: Direction> private::QueueableProvider<'a>
for Queue<D, BuffersAllocated<GenericBufferHandles>>
{
type Queueable = GenericQBuffer<D, &'a Self>;
}

impl<'a, D: Direction> private::GetBufferByIndex<'a>
for Queue<D, BuffersAllocated<GenericBufferHandles>>
{
fn try_get_buffer(&'a self, index: usize) -> Result<Self::Queueable, TryGetBufferError> {
let buffer_info = self.try_obtain_buffer(index)?;

Ok(match self.state.memory_type {
GenericSupportedMemoryType::Mmap => {
GenericQBuffer::Mmap(QBuffer::new(self, buffer_info))
}
GenericSupportedMemoryType::UserPtr => {
GenericQBuffer::User(QBuffer::new(self, buffer_info))
}
GenericSupportedMemoryType::DmaBuf => {
GenericQBuffer::DmaBuf(QBuffer::new(self, buffer_info))
}
})
}
}

/// Any CAPTURE GenericQBuffer implements CaptureQueueable.
impl<Q> CaptureQueueable<GenericBufferHandles> for GenericQBuffer<Capture, Q>
where
Expand Down

0 comments on commit 0132541

Please sign in to comment.