1 // Copyright 2022 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 use crate::buffer::Buffer;
9 use crate::buffer::BufferType;
10 use crate::display::Display;
15 /// A VA context for a particular [`Display`].
18 id: bindings::VAContextID,
22 /// Creates a Context by wrapping around a `vaCreateContext` call. This is just a helper for
23 /// [`Display::create_context`].
29 surfaces: Option<&Vec<Surface>>,
31 ) -> VAResult<Rc<Self>> {
32 let mut context_id = 0;
33 let flags = if progressive {
34 bindings::constants::VA_PROGRESSIVE as i32
39 let mut render_targets = match surfaces {
40 Some(surfaces) => Surface::as_id_vec(surfaces),
41 None => Default::default(),
44 // Safe because `self` represents a valid VADisplay and render_targets
45 // and ntargets are properly initialized. Note that render_targets==NULL
46 // is valid so long as ntargets==0.
48 bindings::vaCreateContext(
54 render_targets.as_mut_ptr(),
55 render_targets.len() as i32,
67 /// Returns a shared reference to the [`Display`] used by this context.
68 pub fn display(&self) -> &Rc<Display> {
72 /// Returns the ID of this context.
73 pub(crate) fn id(&self) -> bindings::VAContextID {
77 /// Create a new buffer of type `type_`.
78 pub fn create_buffer(self: &Rc<Self>, type_: BufferType) -> VAResult<Buffer> {
79 Buffer::new(Rc::clone(self), type_)
83 impl Drop for Context {
85 // Safe because `self` represents a valid VAContext.
87 (unsafe { bindings::vaDestroyContext(self.display.handle(), self.id) }).check();
89 println!("vaDestroyContext failed: {}", status.unwrap_err());