Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite boilerplate code in buffer.rs #11

Open
Gnurou opened this issue Mar 13, 2024 · 0 comments
Open

Rewrite boilerplate code in buffer.rs #11

Gnurou opened this issue Mar 13, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Gnurou
Copy link
Contributor

Gnurou commented Mar 13, 2024

Per @bgrzesik on #10:

We could use a private trait in favor of BufferType enum. Something like:

trait BufferElement: Into<Self::RawType> {
    const TYPE: bindings::VABufferType::Type;
    type RawType;

    fn raw_element_size() -> usize {
        std::mem::size_of::<Self::RawType>()
    }
}

Replace tuple structs with strongly typed and documented copy of raw struct. It would have to be converted to raw when added to the picture (or prior vaRenderPicture), but during this step we could clone Rc<>s to dependencies (like surfaces and EncCodedBuffer) to Picture<> so those wouldn't get dropped before sync. It would clean up some cros-codecs code.

Also Picture::add_buffer could accept a trait that would wrap our use cases. Like so:

trait BufferContents {
    const TYPE: bindings::VABufferType::Type;

    fn element_size(&self) -> usize;

    fn num_elements(&self) -> usize;

    unsafe fn data_ptr(&mut self) -> *mut std::ffi::c_void;
}

// Or just use slice somehow
pub struct BufferArray<T>
where
    T: BufferElement,
{
    array: Vec<T::RawType>,
    // ... deps
}

impl<T> BufferContents for BufferArray<T>
where
    T: BufferElement,
{
 // ...
}

impl<T> BufferContents for Box<T> // Or just T
where
    T: BufferElement,
{
 // ...
}

impl BufferContents for SliceData
{
 // ...
}

In this way we could handle buffer arrays and single element buffers transparently.
On top of that we maybe could look into doing some validations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant