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.
11 use crate::buffer::Buffer;
12 use crate::buffer::BufferType;
13 use crate::display::Display;
14 use crate::status::Status;
18 /// A VA context for a particular [`Display`].
21 id: bindings::VAContextID,
25 /// Creates a Context by wrapping around a `vaCreateContext` call. This is just a helper for
26 /// [`Display::create_context`].
32 surfaces: Option<&Vec<Surface>>,
34 ) -> Result<Rc<Self>> {
35 let mut context_id = 0;
36 let flags = if progressive {
37 bindings::constants::VA_PROGRESSIVE as i32
42 let mut render_targets = match surfaces {
43 Some(surfaces) => Surface::as_id_vec(surfaces),
44 None => Default::default(),
47 // Safe because `self` represents a valid VADisplay and render_targets
48 // and ntargets are properly initialized. Note that render_targets==NULL
49 // is valid so long as ntargets==0.
51 bindings::vaCreateContext(
57 render_targets.as_mut_ptr(),
58 render_targets.len() as i32,
70 /// Returns a shared reference to the [`Display`] used by this context.
71 pub fn display(&self) -> &Rc<Display> {
75 /// Returns the ID of this context.
76 pub(crate) fn id(&self) -> bindings::VAContextID {
80 /// Create a new buffer of type `type_`.
81 pub fn create_buffer(self: &Rc<Self>, type_: BufferType) -> Result<Buffer> {
82 Buffer::new(Rc::clone(self), type_)
86 impl Drop for Context {
88 // Safe because `self` represents a valid VAContext.
90 Status(unsafe { bindings::vaDestroyContext(self.display.handle(), self.id) }).check();
92 error!("vaDestroyContext failed: {}", status.unwrap_err());