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.
10 use crate::buffer::Buffer;
11 use crate::buffer::BufferType;
12 use crate::display::Display;
13 use crate::status::Status;
17 /// A VA context for a particular [`Display`].
20 id: bindings::VAContextID,
24 /// Creates a Context by wrapping around a `vaCreateContext` call. This is just a helper for
25 /// [`Display::create_context`].
31 surfaces: Option<&Vec<Surface>>,
33 ) -> Result<Rc<Self>> {
34 let mut context_id = 0;
35 let flags = if progressive {
36 bindings::constants::VA_PROGRESSIVE as i32
41 let mut render_targets = match surfaces {
42 Some(surfaces) => Surface::as_id_vec(surfaces),
43 None => Default::default(),
46 // Safe because `self` represents a valid VADisplay and render_targets
47 // and ntargets are properly initialized. Note that render_targets==NULL
48 // is valid so long as ntargets==0.
50 bindings::vaCreateContext(
56 render_targets.as_mut_ptr(),
57 render_targets.len() as i32,
69 /// Returns a shared reference to the [`Display`] used by this context.
70 pub fn display(&self) -> &Rc<Display> {
74 /// Returns the ID of this context.
75 pub(crate) fn id(&self) -> bindings::VAContextID {
79 /// Create a new buffer of type `type_`.
80 pub fn create_buffer(self: &Rc<Self>, type_: BufferType) -> Result<Buffer> {
81 Buffer::new(Rc::clone(self), type_)
85 impl Drop for Context {
87 // Safe because `self` represents a valid VAContext.
89 Status(unsafe { bindings::vaDestroyContext(self.display.handle(), self.id) }).check();
91 println!("vaDestroyContext failed: {}", status.unwrap_err());