forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

picture.rs67 lines, 2.1 KiBHistoryRawDownload
1//! Contexts, typed parameter buffers and the decode/encode picture protocol.
2//!
3//! The protocol is cros-libva's typestate `Picture`: `new -> begin -> render
4//! -> end -> sync`, each step consuming the previous state. [`submit`] runs the
5//! first four steps for the common case.
6
7use std::borrow::Borrow;
8use std::rc::Rc;
9
10use cros_libva::{BufferType, SurfaceMemoryDescriptor};
11
12use crate::config::Config;
13use crate::display::Display;
14use crate::error::{Result, va_ok};
15
16pub use cros_libva::{
17 Buffer, Context, EncCodedBuffer, MappedCodedBuffer, MappedCodedSegment, Picture, PictureBegin,
18 PictureEnd, PictureNew, PictureRender, PictureSync,
19};
20
21/// `vaCreateContext` for `config` at `coded_width` x `coded_height`, with the
22/// given surfaces as its render targets. `progressive` selects a progressive
23/// (non-interlaced) context.
24pub fn create_context<D: SurfaceMemoryDescriptor>(
25 display: &Rc<Display>,
26 config: &Config,
27 coded_width: u32,
28 coded_height: u32,
29 render_targets: Option<&Vec<cros_libva::Surface<D>>>,
30 progressive: bool,
31) -> Result<Rc<Context>> {
32 va_ok(
33 "vaCreateContext",
34 display.create_context(
35 config.raw(),
36 coded_width,
37 coded_height,
38 render_targets,
39 progressive,
40 ),
41 )
42}
43
44/// Create one parameter, slice or data buffer on `context` (`vaCreateBuffer`).
45pub fn buffer(context: &Rc<Context>, ty: BufferType) -> Result<Buffer> {
46 va_ok("vaCreateBuffer", context.create_buffer(ty))
47}
48
49/// Submit one picture: `begin`, one `render` carrying every buffer in
50/// `buffers`, then `end`. The result is still to be synced by the caller.
51pub fn submit<D, T>(
52 context: &Rc<Context>,
53 target: T,
54 buffers: Vec<Buffer>,
55) -> Result<Picture<PictureEnd, T>>
56where
57 D: SurfaceMemoryDescriptor,
58 T: Borrow<cros_libva::Surface<D>>,
59{
60 let mut picture = Picture::new(0, Rc::clone(context), target);
61 for b in buffers {
62 picture.add_buffer(b);
63 }
64 let begun = va_ok("vaBeginPicture", picture.begin())?;
65 let rendered = va_ok("vaRenderPicture", begun.render())?;
66 va_ok("vaEndPicture", rendered.end())
67}