use crate::base::{self, BaseError, BaseEvent, GeEvent, Raw, Reply, WiredIn, WiredOut, Xid};
use crate::ext;
use crate::ffi::base::*;
use crate::ffi::ext::*;
use crate::lat1_str::{Lat1Str, Lat1String, Lat1StrF};
use crate::xproto;
use crate::shm;
use crate::xproto::PropEl;
use bitflags::bitflags;
use libc::{self, iovec};
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::os::unix::io::RawFd;
pub const XNAME: &str = "XVideo";
pub const MAJOR_VERSION: u32 = 2;
pub const MINOR_VERSION: u32 = 2;
pub const VERSION_STRING: &str = "2.2";
pub(crate) static mut FFI_EXT: xcb_extension_t = xcb_extension_t {
name: "XVideo\0".as_ptr() as *const _,
global_id: 0,
};
pub fn prefetch_extension_data(conn: &base::Connection) {
unsafe {
xcb_prefetch_extension_data(conn.get_raw_conn(), &mut FFI_EXT as *mut _);
}
}
pub fn get_extension_data(conn: &base::Connection) -> std::option::Option<ext::ExtensionData> {
unsafe {
let reply = xcb_get_extension_data(conn.get_raw_conn(), &mut FFI_EXT as *mut _);
assert!(!reply.is_null(), "Could not fetch Xv extension data");
let reply = xproto::QueryExtensionReply::from_raw(reply);
if !reply.present() {
std::mem::forget(reply);
return None;
}
let res = ext::ExtensionData{
ext: ext::Extension::Xv,
major_opcode: reply.major_opcode(),
first_event: reply.first_event(),
first_error: reply.first_error(),
};
std::mem::forget(reply);
Some(res)
}
}
pub struct BadPortError {
raw: *mut xcb_generic_error_t,
}
impl base::Raw<xcb_generic_error_t> for BadPortError {
unsafe fn from_raw(raw: *mut xcb_generic_error_t) -> Self { BadPortError { raw } }
fn as_raw(&self) -> *mut xcb_generic_error_t {
self.raw
}
}
impl base::BaseError for BadPortError {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Xv);
const NUMBER: u32 = 0;
}
impl BadPortError {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
fn wire_len(&self) -> usize { 32 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn error_code(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for BadPortError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BadPortError")
.field("response_type", &self.response_type())
.field("error_code", &self.error_code())
.field("sequence", &self.sequence())
.finish()
}
}
impl Drop for BadPortError {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for BadPortError {}
unsafe impl Sync for BadPortError {}
pub struct BadEncodingError {
raw: *mut xcb_generic_error_t,
}
impl base::Raw<xcb_generic_error_t> for BadEncodingError {
unsafe fn from_raw(raw: *mut xcb_generic_error_t) -> Self { BadEncodingError { raw } }
fn as_raw(&self) -> *mut xcb_generic_error_t {
self.raw
}
}
impl base::BaseError for BadEncodingError {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Xv);
const NUMBER: u32 = 1;
}
impl BadEncodingError {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
fn wire_len(&self) -> usize { 32 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn error_code(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for BadEncodingError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BadEncodingError")
.field("response_type", &self.response_type())
.field("error_code", &self.error_code())
.field("sequence", &self.sequence())
.finish()
}
}
impl Drop for BadEncodingError {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for BadEncodingError {}
unsafe impl Sync for BadEncodingError {}
pub struct BadControlError {
raw: *mut xcb_generic_error_t,
}
impl base::Raw<xcb_generic_error_t> for BadControlError {
unsafe fn from_raw(raw: *mut xcb_generic_error_t) -> Self { BadControlError { raw } }
fn as_raw(&self) -> *mut xcb_generic_error_t {
self.raw
}
}
impl base::BaseError for BadControlError {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Xv);
const NUMBER: u32 = 2;
}
impl BadControlError {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
fn wire_len(&self) -> usize { 32 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn error_code(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for BadControlError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("BadControlError")
.field("response_type", &self.response_type())
.field("error_code", &self.error_code())
.field("sequence", &self.sequence())
.finish()
}
}
impl Drop for BadControlError {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for BadControlError {}
unsafe impl Sync for BadControlError {}
#[derive(Debug)]
pub enum Error {
BadPort(BadPortError),
BadEncoding(BadEncodingError),
BadControl(BadControlError),
}
impl base::ResolveWireError for Error {
unsafe fn resolve_wire_error(first_error: u8, raw: *mut xcb_generic_error_t) -> Self {
debug_assert!(!raw.is_null());
let error_code = (*raw).error_code;
match error_code - first_error {
0 => Error::BadPort(BadPortError::from_raw(raw)),
1 => Error::BadEncoding(BadEncodingError::from_raw(raw)),
2 => Error::BadControl(BadControlError::from_raw(raw)),
_ => unreachable!(
"Could not resolve xv Error with error_code {} and first_error {}",
error_code, first_error
),
}
}
}
pub struct VideoNotifyEvent {
raw: *mut xcb_generic_event_t,
}
impl base::Raw<xcb_generic_event_t> for VideoNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_generic_event_t) -> Self { VideoNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_generic_event_t {
self.raw
}
}
impl base::BaseEvent for VideoNotifyEvent {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Xv);
const NUMBER: u32 = 0;
}
impl VideoNotifyEvent {
pub fn new(event_base: u8,
reason: VideoNotifyReason,
time: xproto::Timestamp,
drawable: xproto::Drawable,
port: Port,
) -> VideoNotifyEvent {
unsafe {
let ptr = libc::malloc(32) as *mut u8;
let wire_buf = std::slice::from_raw_parts_mut(ptr, 32);
let mut wire_off = 0usize;
let response_type = event_base;
let sequence = 0u16;
wire_off += response_type.serialize(&mut wire_buf[wire_off ..]);
wire_off += (std::mem::transmute::<_, u32>(reason) as u8).serialize(&mut wire_buf[wire_off ..]);
wire_off += sequence.serialize(&mut wire_buf[wire_off ..]);
wire_off += time.serialize(&mut wire_buf[wire_off ..]);
wire_off += drawable.serialize(&mut wire_buf[wire_off ..]);
port.serialize(&mut wire_buf[wire_off ..]);
VideoNotifyEvent::from_raw(ptr as *mut xcb_generic_event_t)
}
}
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn reason(&self) -> VideoNotifyReason {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, VideoNotifyReason>(val)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn time(&self) -> xproto::Timestamp {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Timestamp;
base::value_from_ptr(ptr)
}
}
fn drawable(&self) -> xproto::Drawable {
unsafe {
let offset = 8usize;
let res_id = *(self.wire_ptr().add(offset) as *const u32);
xproto::Drawable::Unknown(res_id)
}
}
pub fn port(&self) -> Port {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const Port;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for VideoNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("VideoNotifyEvent")
.field("response_type", &self.response_type())
.field("reason", &self.reason())
.field("sequence", &self.sequence())
.field("time", &self.time())
.field("drawable", &self.drawable())
.field("port", &self.port())
.finish()
}
}
impl base::WiredOut for VideoNotifyEvent {
fn wire_len(&self) -> usize {
32usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for VideoNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize {
32
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_generic_event_t;
std::ptr::copy(ptr as *const xcb_generic_event_t, raw, sz);
VideoNotifyEvent { raw }
}
}
impl Drop for VideoNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for VideoNotifyEvent {}
unsafe impl Sync for VideoNotifyEvent {}
pub struct PortNotifyEvent {
raw: *mut xcb_generic_event_t,
}
impl base::Raw<xcb_generic_event_t> for PortNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_generic_event_t) -> Self { PortNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_generic_event_t {
self.raw
}
}
impl base::BaseEvent for PortNotifyEvent {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Xv);
const NUMBER: u32 = 1;
}
impl PortNotifyEvent {
pub fn new(event_base: u8,
time: xproto::Timestamp,
port: Port,
attribute: xproto::Atom,
value: i32,
) -> PortNotifyEvent {
unsafe {
let ptr = libc::malloc(32) as *mut u8;
let wire_buf = std::slice::from_raw_parts_mut(ptr, 32);
let mut wire_off = 0usize;
let response_type = 1u8 + event_base;
let sequence = 0u16;
wire_off += response_type.serialize(&mut wire_buf[wire_off ..]);
wire_off += 1usize;
wire_off += sequence.serialize(&mut wire_buf[wire_off ..]);
wire_off += time.serialize(&mut wire_buf[wire_off ..]);
wire_off += port.serialize(&mut wire_buf[wire_off ..]);
wire_off += attribute.serialize(&mut wire_buf[wire_off ..]);
value.serialize(&mut wire_buf[wire_off ..]);
PortNotifyEvent::from_raw(ptr as *mut xcb_generic_event_t)
}
}
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn time(&self) -> xproto::Timestamp {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Timestamp;
base::value_from_ptr(ptr)
}
}
pub fn port(&self) -> Port {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const Port;
base::value_from_ptr(ptr)
}
}
pub fn attribute(&self) -> xproto::Atom {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Atom;
base::value_from_ptr(ptr)
}
}
pub fn value(&self) -> i32 {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const i32;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for PortNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("PortNotifyEvent")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("time", &self.time())
.field("port", &self.port())
.field("attribute", &self.attribute())
.field("value", &self.value())
.finish()
}
}
impl base::WiredOut for PortNotifyEvent {
fn wire_len(&self) -> usize {
32usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for PortNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize {
32
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_generic_event_t;
std::ptr::copy(ptr as *const xcb_generic_event_t, raw, sz);
PortNotifyEvent { raw }
}
}
impl Drop for PortNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for PortNotifyEvent {}
unsafe impl Sync for PortNotifyEvent {}
#[derive(Debug)]
pub enum Event {
VideoNotify(VideoNotifyEvent),
PortNotify(PortNotifyEvent),
}
impl Event {
pub fn as_raw(&self) -> *mut xcb_generic_event_t {
match self {
Self::VideoNotify(e) => e.as_raw(),
Self::PortNotify(e) => e.as_raw(),
}
}
}
impl base::ResolveWireEvent for Event {
unsafe fn resolve_wire_event(first_event: u8, raw: *mut xcb_generic_event_t) -> std::option::Option<Self> {
debug_assert!(!raw.is_null());
let response_type = (*raw).response_type & 0x7F;
debug_assert!(response_type != 0, "This is not an event but an error!");
debug_assert!(response_type != XCB_GE_GENERIC, "This is a GE_GENERIC event!");
match response_type - first_event {
0 => Some(Event::VideoNotify(VideoNotifyEvent::from_raw(raw))),
1 => Some(Event::PortNotify(PortNotifyEvent::from_raw(raw))),
_ => None,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct Port {
res_id: u32,
}
impl base::Xid for Port {
fn none() -> Self { Port { res_id: 0 } }
fn resource_id(&self) -> u32 { self.res_id }
}
impl base::XidNew for Port {
unsafe fn new(res_id: u32) -> Self { Port { res_id } }
}
#[test]
fn test_sizeof_port() {
assert_eq!(std::mem::size_of::<Port>(), 4);
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct Encoding {
res_id: u32,
}
impl base::Xid for Encoding {
fn none() -> Self { Encoding { res_id: 0 } }
fn resource_id(&self) -> u32 { self.res_id }
}
impl base::XidNew for Encoding {
unsafe fn new(res_id: u32) -> Self { Encoding { res_id } }
}
#[test]
fn test_sizeof_encoding() {
assert_eq!(std::mem::size_of::<Encoding>(), 4);
}
bitflags! {
pub struct Type: u32 {
const INPUT_MASK = 0x00000001;
const OUTPUT_MASK = 0x00000002;
const VIDEO_MASK = 0x00000004;
const STILL_MASK = 0x00000008;
const IMAGE_MASK = 0x00000010;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum ImageFormatInfoType {
Rgb = 0,
Yuv = 1,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum ImageFormatInfoFormat {
Packed = 0,
Planar = 1,
}
bitflags! {
pub struct AttributeFlag: u32 {
const GETTABLE = 0x00000001;
const SETTABLE = 0x00000002;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum VideoNotifyReason {
Started = 0,
Stopped = 1,
Busy = 2,
Preempted = 3,
HardError = 4,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum ScanlineOrder {
TopToBottom = 0,
BottomToTop = 1,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum GrabPortStatus {
Success = 0,
BadExtension = 1,
AlreadyGrabbed = 2,
InvalidTime = 3,
BadReply = 4,
BadAlloc = 5,
}
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct Rational {
pub numerator: i32,
pub denominator: i32,
}
#[test]
fn test_sizeof_rational() {
assert_eq!(std::mem::size_of::<Rational>(), 8);
}
impl base::WiredOut for Rational {
fn wire_len(&self) -> usize { 8 }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
let me = unsafe {
std::slice::from_raw_parts(self as *const Rational as _, 8)
};
(&mut wire_buf[..me.len()]).copy_from_slice(me);
8
}
}
impl base::WiredIn for Rational {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize { 8 }
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
*offset += 8;
*(ptr as *const Rational)
}
}
#[derive(Copy, Clone)]
pub struct Format {
data: [u8; 8],
}
#[allow(unused_parens)]
impl Format {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &Format {
debug_assert_eq!(data.as_ref().len(), 8);
&*(data.as_ref() as *const [u8] as *const Format)
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
visual: xproto::Visualid,
depth: u8,
) -> Format {
unsafe {
let mut wire_buf = [0u8; 8];
let mut wire_off = 0usize;
wire_off += visual.serialize(&mut wire_buf[wire_off .. ]);
wire_off += depth.serialize(&mut wire_buf[wire_off .. ]);
wire_off += 3; Format { data: wire_buf }
}
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
fn wire_len(&self) -> usize { self.data.len() }
pub fn visual(&self) -> xproto::Visualid {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Visualid;
base::value_from_ptr(ptr)
}
}
pub fn depth(&self) -> u8 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
}
#[test]
fn test_sizeof_format() {
assert_eq!(std::mem::size_of::<Format>(), 8);
}
impl base::WiredOut for Format {
fn wire_len(&self) -> usize { 8 }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for Format {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize { 8 }
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
*offset += 8;
*(ptr as *const Format)
}
}
impl std::fmt::Debug for Format {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Format")
.field("visual", &self.visual())
.field("depth", &self.depth())
.field("pad", &3)
.finish()
}
}
pub struct AdaptorInfo {
data: [u8],
}
#[allow(unused_parens)]
impl AdaptorInfo {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &AdaptorInfo {
debug_assert_eq!(data.as_ref().len(), <&AdaptorInfo as base::WiredIn>::compute_wire_len(data.as_ref().as_ptr(), ()));
&*(data.as_ref() as *const [u8] as *const AdaptorInfo)
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
pub fn base_id(&self) -> Port {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const Port;
base::value_from_ptr(ptr)
}
}
fn name_size(&self) -> u16 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn num_ports(&self) -> u16 {
unsafe {
let offset = 6usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
fn num_formats(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn r#type(&self) -> Type {
unsafe {
let offset = 10usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, Type>(val)
}
}
pub fn name(&self) -> &Lat1Str {
unsafe {
let offset = 12usize;
let len = (self.name_size() as usize) as _;
let ptr = self.wire_ptr().add(offset);
let bytes = std::slice::from_raw_parts(ptr, len);
Lat1Str::from_bytes(bytes)
}
}
pub fn formats(&self) -> &[Format] {
unsafe {
let offset = ((12usize + (self.name_size() as usize)) + base::align_pad((12usize + (self.name_size() as usize)), 4));
let len = (self.num_formats() as usize) as _;
let ptr = self.wire_ptr().add(offset) as *const Format;
std::slice::from_raw_parts(ptr, len)
}
}
}
impl base::WiredOut for AdaptorInfo {
fn wire_len(&self) -> usize { self.data.len() }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for &AdaptorInfo {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 4usize;
let name_size = *(ptr.add(sz) as *const u16);
sz += 2usize;
sz += 2usize;
let num_formats = *(ptr.add(sz) as *const u16);
sz += 2usize;
sz += 1usize;
sz += 1usize;
sz += (name_size as usize);
sz += base::align_pad(sz, 4);
sz += ((num_formats as usize) * 8usize);
sz
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
AdaptorInfo::from_data(data)
}
}
#[derive(Clone)]
pub struct AdaptorInfoBuf {
data: Vec<u8>,
}
impl AdaptorInfoBuf {
pub(crate) unsafe fn from_data(data: Vec<u8>) -> AdaptorInfoBuf {
debug_assert_eq!(<&AdaptorInfo>::compute_wire_len(data.as_ptr(), ()), data.len());
AdaptorInfoBuf { data }
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
base_id: Port,
num_ports: u16,
r#type: Type,
name: &[u8],
formats: &[Format],
) -> AdaptorInfoBuf {
unsafe {
let mut wire_sz = 0usize;
wire_sz += 4; wire_sz += 2; wire_sz += 2; wire_sz += 2; wire_sz += 1; wire_sz += 1; wire_sz += name.len();
wire_sz += base::align_pad(wire_sz, 4);
wire_sz += formats.iter().map(|el| el.wire_len()).sum::<usize>();
let mut wire_buf = vec![0u8; wire_sz];
let mut wire_off = 0usize;
wire_off += base_id.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (name.len() as u16).serialize(&mut wire_buf[wire_off .. ]);
wire_off += num_ports.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (formats.len() as u16).serialize(&mut wire_buf[wire_off .. ]);
wire_off += (r#type.bits() as u8).serialize(&mut wire_buf[wire_off .. ]);
wire_off += 1; wire_buf[wire_off .. wire_off + name.len()].copy_from_slice(name);
wire_off += name.len();
wire_off += base::align_pad(wire_off, 4);
for el in formats {
wire_off += el.serialize(&mut wire_buf[wire_off ..]);
}
AdaptorInfoBuf { data: wire_buf }
}
}
}
impl base::WiredIn for AdaptorInfoBuf {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, params: ()) -> usize {
<&AdaptorInfo>::compute_wire_len(ptr, params)
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
AdaptorInfoBuf::from_data(data.to_vec())
}
}
impl std::ops::Deref for AdaptorInfoBuf {
type Target = AdaptorInfo;
fn deref(&self) -> &Self::Target {
unsafe { AdaptorInfo::from_data(&self.data) }
}
}
impl std::borrow::Borrow<AdaptorInfo> for AdaptorInfoBuf {
fn borrow(&self) -> &AdaptorInfo {
unsafe { AdaptorInfo::from_data(&self.data) }
}
}
impl std::borrow::ToOwned for AdaptorInfo {
type Owned = AdaptorInfoBuf;
fn to_owned(&self) -> Self::Owned {
AdaptorInfoBuf {
data: self.data.to_vec()
}
}
}
impl std::fmt::Debug for AdaptorInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AdaptorInfo")
.field("base_id", &self.base_id())
.field("name_size", &self.name_size())
.field("num_ports", &self.num_ports())
.field("num_formats", &self.num_formats())
.field("r#type", &self.r#type())
.field("pad", &1)
.field("name", &self.name())
.field("align_pad", &4)
.field("formats", &self.formats())
.finish()
}
}
impl std::fmt::Debug for AdaptorInfoBuf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AdaptorInfoBuf")
.field("base_id", &self.base_id())
.field("name_size", &self.name_size())
.field("num_ports", &self.num_ports())
.field("num_formats", &self.num_formats())
.field("r#type", &self.r#type())
.field("pad", &1)
.field("name", &self.name())
.field("align_pad", &4)
.field("formats", &self.formats())
.finish()
}
}
#[derive(Clone)]
pub struct AdaptorInfoIterator<'a> {
pub(crate) params: (),
pub(crate) rem: usize,
pub(crate) ptr: *const u8,
pub(crate) phantom: std::marker::PhantomData<&'a AdaptorInfo>,
}
impl<'a> Iterator for AdaptorInfoIterator<'a> {
type Item = &'a AdaptorInfo;
fn next(&mut self) -> std::option::Option<Self::Item> {
if self.rem == 0 {
None
} else { unsafe {
self.rem -= 1;
let mut offset = 0;
let res = <&AdaptorInfo>::unserialize(self.ptr, self.params, &mut offset);
self.ptr = self.ptr.add(offset);
Some(res)
}}
}
}
impl<'a> std::fmt::Debug for AdaptorInfoIterator<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
pub struct EncodingInfo {
data: [u8],
}
#[allow(unused_parens)]
impl EncodingInfo {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &EncodingInfo {
debug_assert_eq!(data.as_ref().len(), <&EncodingInfo as base::WiredIn>::compute_wire_len(data.as_ref().as_ptr(), ()));
&*(data.as_ref() as *const [u8] as *const EncodingInfo)
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
pub fn encoding(&self) -> Encoding {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const Encoding;
base::value_from_ptr(ptr)
}
}
fn name_size(&self) -> u16 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn width(&self) -> u16 {
unsafe {
let offset = 6usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn height(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn rate(&self) -> Rational {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const Rational;
base::value_from_ptr(ptr)
}
}
pub fn name(&self) -> &Lat1Str {
unsafe {
let offset = 20usize;
let len = (self.name_size() as usize) as _;
let ptr = self.wire_ptr().add(offset);
let bytes = std::slice::from_raw_parts(ptr, len);
Lat1Str::from_bytes(bytes)
}
}
}
impl base::WiredOut for EncodingInfo {
fn wire_len(&self) -> usize { self.data.len() }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for &EncodingInfo {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 4usize;
let name_size = *(ptr.add(sz) as *const u16);
sz += 2usize;
sz += 2usize;
sz += 2usize;
sz += 2usize;
sz += 8usize;
sz += (name_size as usize);
sz += base::align_pad(sz, 4);
sz
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
EncodingInfo::from_data(data)
}
}
#[derive(Clone)]
pub struct EncodingInfoBuf {
data: Vec<u8>,
}
impl EncodingInfoBuf {
pub(crate) unsafe fn from_data(data: Vec<u8>) -> EncodingInfoBuf {
debug_assert_eq!(<&EncodingInfo>::compute_wire_len(data.as_ptr(), ()), data.len());
EncodingInfoBuf { data }
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
encoding: Encoding,
width: u16,
height: u16,
rate: Rational,
name: &[u8],
) -> EncodingInfoBuf {
unsafe {
let mut wire_sz = 0usize;
wire_sz += 4; wire_sz += 2; wire_sz += 2; wire_sz += 2; wire_sz += 2; wire_sz += 8; wire_sz += name.len();
wire_sz += base::align_pad(wire_sz, 4);
let mut wire_buf = vec![0u8; wire_sz];
let mut wire_off = 0usize;
wire_off += encoding.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (name.len() as u16).serialize(&mut wire_buf[wire_off .. ]);
wire_off += width.serialize(&mut wire_buf[wire_off .. ]);
wire_off += height.serialize(&mut wire_buf[wire_off .. ]);
wire_off += 2; wire_off += rate.serialize(&mut wire_buf[wire_off .. ]);
wire_buf[wire_off .. wire_off + name.len()].copy_from_slice(name);
wire_off += name.len();
wire_off += base::align_pad(wire_off, 4);
EncodingInfoBuf { data: wire_buf }
}
}
}
impl base::WiredIn for EncodingInfoBuf {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, params: ()) -> usize {
<&EncodingInfo>::compute_wire_len(ptr, params)
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
EncodingInfoBuf::from_data(data.to_vec())
}
}
impl std::ops::Deref for EncodingInfoBuf {
type Target = EncodingInfo;
fn deref(&self) -> &Self::Target {
unsafe { EncodingInfo::from_data(&self.data) }
}
}
impl std::borrow::Borrow<EncodingInfo> for EncodingInfoBuf {
fn borrow(&self) -> &EncodingInfo {
unsafe { EncodingInfo::from_data(&self.data) }
}
}
impl std::borrow::ToOwned for EncodingInfo {
type Owned = EncodingInfoBuf;
fn to_owned(&self) -> Self::Owned {
EncodingInfoBuf {
data: self.data.to_vec()
}
}
}
impl std::fmt::Debug for EncodingInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EncodingInfo")
.field("encoding", &self.encoding())
.field("name_size", &self.name_size())
.field("width", &self.width())
.field("height", &self.height())
.field("pad", &2)
.field("rate", &self.rate())
.field("name", &self.name())
.field("align_pad", &4)
.finish()
}
}
impl std::fmt::Debug for EncodingInfoBuf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("EncodingInfoBuf")
.field("encoding", &self.encoding())
.field("name_size", &self.name_size())
.field("width", &self.width())
.field("height", &self.height())
.field("pad", &2)
.field("rate", &self.rate())
.field("name", &self.name())
.field("align_pad", &4)
.finish()
}
}
#[derive(Clone)]
pub struct EncodingInfoIterator<'a> {
pub(crate) params: (),
pub(crate) rem: usize,
pub(crate) ptr: *const u8,
pub(crate) phantom: std::marker::PhantomData<&'a EncodingInfo>,
}
impl<'a> Iterator for EncodingInfoIterator<'a> {
type Item = &'a EncodingInfo;
fn next(&mut self) -> std::option::Option<Self::Item> {
if self.rem == 0 {
None
} else { unsafe {
self.rem -= 1;
let mut offset = 0;
let res = <&EncodingInfo>::unserialize(self.ptr, self.params, &mut offset);
self.ptr = self.ptr.add(offset);
Some(res)
}}
}
}
impl<'a> std::fmt::Debug for EncodingInfoIterator<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
pub struct Image {
data: [u8],
}
#[allow(unused_parens)]
impl Image {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &Image {
debug_assert_eq!(data.as_ref().len(), <&Image as base::WiredIn>::compute_wire_len(data.as_ref().as_ptr(), ()));
&*(data.as_ref() as *const [u8] as *const Image)
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
pub fn id(&self) -> u32 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn width(&self) -> u16 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn height(&self) -> u16 {
unsafe {
let offset = 6usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
fn data_size(&self) -> u32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
fn num_planes(&self) -> u32 {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn pitches(&self) -> &[u32] {
unsafe {
let offset = 16usize;
let len = (self.num_planes() as usize);
let ptr = self.wire_ptr().add(offset) as *const u32;
std::slice::from_raw_parts(ptr, len)
}
}
pub fn offsets(&self) -> &[u32] {
unsafe {
let offset = (16usize + ((self.num_planes() as usize) * 4usize));
let len = (self.num_planes() as usize);
let ptr = self.wire_ptr().add(offset) as *const u32;
std::slice::from_raw_parts(ptr, len)
}
}
pub fn data(&self) -> &[u8] {
unsafe {
let offset = ((16usize + ((self.num_planes() as usize) * 4usize)) + ((self.num_planes() as usize) * 4usize));
let len = (self.data_size() as usize);
let ptr = self.wire_ptr().add(offset) as *const u8;
std::slice::from_raw_parts(ptr, len)
}
}
}
impl base::WiredOut for Image {
fn wire_len(&self) -> usize { self.data.len() }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for &Image {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 4usize;
sz += 2usize;
sz += 2usize;
let data_size = *(ptr.add(sz) as *const u32);
sz += 4usize;
let num_planes = *(ptr.add(sz) as *const u32);
sz += 4usize;
sz += ((num_planes as usize) * 4usize);
sz += ((num_planes as usize) * 4usize);
sz += (data_size as usize);
sz
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
Image::from_data(data)
}
}
#[derive(Clone)]
pub struct ImageBuf {
data: Vec<u8>,
}
impl ImageBuf {
pub(crate) unsafe fn from_data(data: Vec<u8>) -> ImageBuf {
debug_assert_eq!(<&Image>::compute_wire_len(data.as_ptr(), ()), data.len());
ImageBuf { data }
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
id: u32,
width: u16,
height: u16,
pitches: &[u32],
offsets: &[u32],
data: &[u8],
) -> ImageBuf {
unsafe {
let mut wire_sz = 0usize;
wire_sz += 4; wire_sz += 2; wire_sz += 2; wire_sz += 4; wire_sz += 4; wire_sz += pitches.iter().map(|el| el.wire_len()).sum::<usize>();
wire_sz += offsets.iter().map(|el| el.wire_len()).sum::<usize>();
wire_sz += data.iter().map(|el| el.wire_len()).sum::<usize>();
let mut wire_buf = vec![0u8; wire_sz];
let mut wire_off = 0usize;
wire_off += id.serialize(&mut wire_buf[wire_off .. ]);
wire_off += width.serialize(&mut wire_buf[wire_off .. ]);
wire_off += height.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (data.len() as u32).serialize(&mut wire_buf[wire_off .. ]);
wire_off += (pitches.len() as u32).serialize(&mut wire_buf[wire_off .. ]);
for el in pitches {
wire_off += el.serialize(&mut wire_buf[wire_off ..]);
}
for el in offsets {
wire_off += el.serialize(&mut wire_buf[wire_off ..]);
}
for el in data {
wire_off += el.serialize(&mut wire_buf[wire_off ..]);
}
ImageBuf { data: wire_buf }
}
}
}
impl base::WiredIn for ImageBuf {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, params: ()) -> usize {
<&Image>::compute_wire_len(ptr, params)
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
ImageBuf::from_data(data.to_vec())
}
}
impl std::ops::Deref for ImageBuf {
type Target = Image;
fn deref(&self) -> &Self::Target {
unsafe { Image::from_data(&self.data) }
}
}
impl std::borrow::Borrow<Image> for ImageBuf {
fn borrow(&self) -> &Image {
unsafe { Image::from_data(&self.data) }
}
}
impl std::borrow::ToOwned for Image {
type Owned = ImageBuf;
fn to_owned(&self) -> Self::Owned {
ImageBuf {
data: self.data.to_vec()
}
}
}
impl std::fmt::Debug for Image {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Image")
.field("id", &self.id())
.field("width", &self.width())
.field("height", &self.height())
.field("data_size", &self.data_size())
.field("num_planes", &self.num_planes())
.field("pitches", &self.pitches())
.field("offsets", &self.offsets())
.field("data", &self.data())
.finish()
}
}
impl std::fmt::Debug for ImageBuf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ImageBuf")
.field("id", &self.id())
.field("width", &self.width())
.field("height", &self.height())
.field("data_size", &self.data_size())
.field("num_planes", &self.num_planes())
.field("pitches", &self.pitches())
.field("offsets", &self.offsets())
.field("data", &self.data())
.finish()
}
}
#[derive(Clone)]
pub struct ImageIterator<'a> {
pub(crate) params: (),
pub(crate) rem: usize,
pub(crate) ptr: *const u8,
pub(crate) phantom: std::marker::PhantomData<&'a Image>,
}
impl<'a> Iterator for ImageIterator<'a> {
type Item = &'a Image;
fn next(&mut self) -> std::option::Option<Self::Item> {
if self.rem == 0 {
None
} else { unsafe {
self.rem -= 1;
let mut offset = 0;
let res = <&Image>::unserialize(self.ptr, self.params, &mut offset);
self.ptr = self.ptr.add(offset);
Some(res)
}}
}
}
impl<'a> std::fmt::Debug for ImageIterator<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
pub struct AttributeInfo {
data: [u8],
}
#[allow(unused_parens)]
impl AttributeInfo {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &AttributeInfo {
debug_assert_eq!(data.as_ref().len(), <&AttributeInfo as base::WiredIn>::compute_wire_len(data.as_ref().as_ptr(), ()));
&*(data.as_ref() as *const [u8] as *const AttributeInfo)
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
pub fn flags(&self) -> AttributeFlag {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, AttributeFlag>(val)
}
}
pub fn min(&self) -> i32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const i32;
base::value_from_ptr(ptr)
}
}
pub fn max(&self) -> i32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const i32;
base::value_from_ptr(ptr)
}
}
fn size(&self) -> u32 {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn name(&self) -> &Lat1Str {
unsafe {
let offset = 16usize;
let len = (self.size() as usize) as _;
let ptr = self.wire_ptr().add(offset);
let bytes = std::slice::from_raw_parts(ptr, len);
Lat1Str::from_bytes(bytes)
}
}
}
impl base::WiredOut for AttributeInfo {
fn wire_len(&self) -> usize { self.data.len() }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for &AttributeInfo {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 4usize;
sz += 4usize;
sz += 4usize;
let size = *(ptr.add(sz) as *const u32);
sz += 4usize;
sz += (size as usize);
sz += base::align_pad(sz, 4);
sz
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
AttributeInfo::from_data(data)
}
}
#[derive(Clone)]
pub struct AttributeInfoBuf {
data: Vec<u8>,
}
impl AttributeInfoBuf {
pub(crate) unsafe fn from_data(data: Vec<u8>) -> AttributeInfoBuf {
debug_assert_eq!(<&AttributeInfo>::compute_wire_len(data.as_ptr(), ()), data.len());
AttributeInfoBuf { data }
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
flags: AttributeFlag,
min: i32,
max: i32,
name: &[u8],
) -> AttributeInfoBuf {
unsafe {
let mut wire_sz = 0usize;
wire_sz += 4; wire_sz += 4; wire_sz += 4; wire_sz += 4; wire_sz += name.len();
wire_sz += base::align_pad(wire_sz, 4);
let mut wire_buf = vec![0u8; wire_sz];
let mut wire_off = 0usize;
wire_off += flags.bits().serialize(&mut wire_buf[wire_off .. ]);
wire_off += min.serialize(&mut wire_buf[wire_off .. ]);
wire_off += max.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (name.len() as u32).serialize(&mut wire_buf[wire_off .. ]);
wire_buf[wire_off .. wire_off + name.len()].copy_from_slice(name);
wire_off += name.len();
wire_off += base::align_pad(wire_off, 4);
AttributeInfoBuf { data: wire_buf }
}
}
}
impl base::WiredIn for AttributeInfoBuf {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, params: ()) -> usize {
<&AttributeInfo>::compute_wire_len(ptr, params)
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
AttributeInfoBuf::from_data(data.to_vec())
}
}
impl std::ops::Deref for AttributeInfoBuf {
type Target = AttributeInfo;
fn deref(&self) -> &Self::Target {
unsafe { AttributeInfo::from_data(&self.data) }
}
}
impl std::borrow::Borrow<AttributeInfo> for AttributeInfoBuf {
fn borrow(&self) -> &AttributeInfo {
unsafe { AttributeInfo::from_data(&self.data) }
}
}
impl std::borrow::ToOwned for AttributeInfo {
type Owned = AttributeInfoBuf;
fn to_owned(&self) -> Self::Owned {
AttributeInfoBuf {
data: self.data.to_vec()
}
}
}
impl std::fmt::Debug for AttributeInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AttributeInfo")
.field("flags", &self.flags())
.field("min", &self.min())
.field("max", &self.max())
.field("size", &self.size())
.field("name", &self.name())
.field("align_pad", &4)
.finish()
}
}
impl std::fmt::Debug for AttributeInfoBuf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AttributeInfoBuf")
.field("flags", &self.flags())
.field("min", &self.min())
.field("max", &self.max())
.field("size", &self.size())
.field("name", &self.name())
.field("align_pad", &4)
.finish()
}
}
#[derive(Clone)]
pub struct AttributeInfoIterator<'a> {
pub(crate) params: (),
pub(crate) rem: usize,
pub(crate) ptr: *const u8,
pub(crate) phantom: std::marker::PhantomData<&'a AttributeInfo>,
}
impl<'a> Iterator for AttributeInfoIterator<'a> {
type Item = &'a AttributeInfo;
fn next(&mut self) -> std::option::Option<Self::Item> {
if self.rem == 0 {
None
} else { unsafe {
self.rem -= 1;
let mut offset = 0;
let res = <&AttributeInfo>::unserialize(self.ptr, self.params, &mut offset);
self.ptr = self.ptr.add(offset);
Some(res)
}}
}
}
impl<'a> std::fmt::Debug for AttributeInfoIterator<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
#[derive(Copy, Clone)]
pub struct ImageFormatInfo {
data: [u8; 128],
}
#[allow(unused_parens)]
impl ImageFormatInfo {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &ImageFormatInfo {
debug_assert_eq!(data.as_ref().len(), 128);
&*(data.as_ref() as *const [u8] as *const ImageFormatInfo)
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
id: u32,
r#type: ImageFormatInfoType,
byte_order: xproto::ImageOrder,
guid: &[u8; 16],
bpp: u8,
num_planes: u8,
depth: u8,
red_mask: u32,
green_mask: u32,
blue_mask: u32,
format: ImageFormatInfoFormat,
y_sample_bits: u32,
u_sample_bits: u32,
v_sample_bits: u32,
vhorz_y_period: u32,
vhorz_u_period: u32,
vhorz_v_period: u32,
vvert_y_period: u32,
vvert_u_period: u32,
vvert_v_period: u32,
vcomp_order: &[u8; 32],
vscanline_order: ScanlineOrder,
) -> ImageFormatInfo {
unsafe {
let mut wire_buf = [0u8; 128];
let mut wire_off = 0usize;
wire_off += id.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (std::mem::transmute::<_, u32>(r#type) as u8).serialize(&mut wire_buf[wire_off .. ]);
wire_off += (std::mem::transmute::<_, u32>(byte_order) as u8).serialize(&mut wire_buf[wire_off .. ]);
wire_off += 2; for el in guid {
wire_off += el.serialize(&mut wire_buf[wire_off ..]);
}
wire_off += bpp.serialize(&mut wire_buf[wire_off .. ]);
wire_off += num_planes.serialize(&mut wire_buf[wire_off .. ]);
wire_off += 2; wire_off += depth.serialize(&mut wire_buf[wire_off .. ]);
wire_off += 3; wire_off += red_mask.serialize(&mut wire_buf[wire_off .. ]);
wire_off += green_mask.serialize(&mut wire_buf[wire_off .. ]);
wire_off += blue_mask.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (std::mem::transmute::<_, u32>(format) as u8).serialize(&mut wire_buf[wire_off .. ]);
wire_off += 3; wire_off += y_sample_bits.serialize(&mut wire_buf[wire_off .. ]);
wire_off += u_sample_bits.serialize(&mut wire_buf[wire_off .. ]);
wire_off += v_sample_bits.serialize(&mut wire_buf[wire_off .. ]);
wire_off += vhorz_y_period.serialize(&mut wire_buf[wire_off .. ]);
wire_off += vhorz_u_period.serialize(&mut wire_buf[wire_off .. ]);
wire_off += vhorz_v_period.serialize(&mut wire_buf[wire_off .. ]);
wire_off += vvert_y_period.serialize(&mut wire_buf[wire_off .. ]);
wire_off += vvert_u_period.serialize(&mut wire_buf[wire_off .. ]);
wire_off += vvert_v_period.serialize(&mut wire_buf[wire_off .. ]);
for el in vcomp_order {
wire_off += el.serialize(&mut wire_buf[wire_off ..]);
}
wire_off += (std::mem::transmute::<_, u32>(vscanline_order) as u8).serialize(&mut wire_buf[wire_off .. ]);
wire_off += 11; ImageFormatInfo { data: wire_buf }
}
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
fn wire_len(&self) -> usize { self.data.len() }
pub fn id(&self) -> u32 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn r#type(&self) -> ImageFormatInfoType {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, ImageFormatInfoType>(val)
}
}
pub fn byte_order(&self) -> xproto::ImageOrder {
unsafe {
let offset = 5usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, xproto::ImageOrder>(val)
}
}
pub fn guid(&self) -> &[u8; 16] {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const [u8; 16];
&*ptr
}
}
pub fn bpp(&self) -> u8 {
unsafe {
let offset = 24usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn num_planes(&self) -> u8 {
unsafe {
let offset = 25usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn depth(&self) -> u8 {
unsafe {
let offset = 28usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn red_mask(&self) -> u32 {
unsafe {
let offset = 32usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn green_mask(&self) -> u32 {
unsafe {
let offset = 36usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn blue_mask(&self) -> u32 {
unsafe {
let offset = 40usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn format(&self) -> ImageFormatInfoFormat {
unsafe {
let offset = 44usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, ImageFormatInfoFormat>(val)
}
}
pub fn y_sample_bits(&self) -> u32 {
unsafe {
let offset = 48usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn u_sample_bits(&self) -> u32 {
unsafe {
let offset = 52usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn v_sample_bits(&self) -> u32 {
unsafe {
let offset = 56usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn vhorz_y_period(&self) -> u32 {
unsafe {
let offset = 60usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn vhorz_u_period(&self) -> u32 {
unsafe {
let offset = 64usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn vhorz_v_period(&self) -> u32 {
unsafe {
let offset = 68usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn vvert_y_period(&self) -> u32 {
unsafe {
let offset = 72usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn vvert_u_period(&self) -> u32 {
unsafe {
let offset = 76usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn vvert_v_period(&self) -> u32 {
unsafe {
let offset = 80usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn vcomp_order(&self) -> &[u8; 32] {
unsafe {
let offset = 84usize;
let ptr = self.wire_ptr().add(offset) as *const [u8; 32];
&*ptr
}
}
pub fn vscanline_order(&self) -> ScanlineOrder {
unsafe {
let offset = 116usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, ScanlineOrder>(val)
}
}
}
#[test]
fn test_sizeof_image_format_info() {
assert_eq!(std::mem::size_of::<ImageFormatInfo>(), 128);
}
impl base::WiredOut for ImageFormatInfo {
fn wire_len(&self) -> usize { 128 }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for ImageFormatInfo {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize { 128 }
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
*offset += 128;
*(ptr as *const ImageFormatInfo)
}
}
impl std::fmt::Debug for ImageFormatInfo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ImageFormatInfo")
.field("id", &self.id())
.field("r#type", &self.r#type())
.field("byte_order", &self.byte_order())
.field("pad", &2)
.field("guid", &self.guid())
.field("bpp", &self.bpp())
.field("num_planes", &self.num_planes())
.field("pad", &2)
.field("depth", &self.depth())
.field("pad", &3)
.field("red_mask", &self.red_mask())
.field("green_mask", &self.green_mask())
.field("blue_mask", &self.blue_mask())
.field("format", &self.format())
.field("pad", &3)
.field("y_sample_bits", &self.y_sample_bits())
.field("u_sample_bits", &self.u_sample_bits())
.field("v_sample_bits", &self.v_sample_bits())
.field("vhorz_y_period", &self.vhorz_y_period())
.field("vhorz_u_period", &self.vhorz_u_period())
.field("vhorz_v_period", &self.vhorz_v_period())
.field("vvert_y_period", &self.vvert_y_period())
.field("vvert_u_period", &self.vvert_u_period())
.field("vvert_v_period", &self.vvert_v_period())
.field("vcomp_order", &self.vcomp_order())
.field("vscanline_order", &self.vscanline_order())
.field("pad", &11)
.finish()
}
}
pub(crate) fn request_name(opcode: u16) -> std::option::Option<&'static str> {
match opcode {
0 => Some("xv::QueryExtension"),
1 => Some("xv::QueryAdaptors"),
2 => Some("xv::QueryEncodings"),
3 => Some("xv::GrabPort"),
4 => Some("xv::UngrabPort"),
5 => Some("xv::PutVideo"),
6 => Some("xv::PutStill"),
7 => Some("xv::GetVideo"),
8 => Some("xv::GetStill"),
9 => Some("xv::StopVideo"),
10 => Some("xv::SelectVideoNotify"),
11 => Some("xv::SelectPortNotify"),
12 => Some("xv::QueryBestSize"),
13 => Some("xv::SetPortAttribute"),
14 => Some("xv::GetPortAttribute"),
15 => Some("xv::QueryPortAttributes"),
16 => Some("xv::ListImageFormats"),
17 => Some("xv::QueryImageAttributes"),
18 => Some("xv::PutImage"),
19 => Some("xv::ShmPutImage"),
_ => None,
}
}
pub struct QueryExtensionReply {
raw: *const u8,
}
impl QueryExtensionReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn major(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn minor(&self) -> u16 {
unsafe {
let offset = 10usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for QueryExtensionReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryExtensionReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryExtensionReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("major", &self.major())
.field("minor", &self.minor())
.finish()
}
}
impl Drop for QueryExtensionReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryExtensionReply {}
unsafe impl std::marker::Sync for QueryExtensionReply {}
#[derive(Debug)]
pub struct QueryExtensionCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryExtensionCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryExtensionCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryExtensionCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryExtensionCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryExtensionCookie {
type Reply = QueryExtensionReply;
}
impl base::Cookie for QueryExtensionCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryExtensionCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryExtensionCookieUnchecked {
type Reply = QueryExtensionReply;
}
#[derive(Clone, Debug)]
pub struct QueryExtension {
}
unsafe impl base::RawRequest for QueryExtension {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 0,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 4];
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 4;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryExtension {
type Cookie = QueryExtensionCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryExtension {
type Reply = QueryExtensionReply;
type Cookie = QueryExtensionCookie;
type CookieUnchecked = QueryExtensionCookieUnchecked;
}
pub struct QueryAdaptorsReply {
raw: *const u8,
}
impl QueryAdaptorsReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
unsafe fn compute_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 1usize;
sz += 1usize;
sz += 2usize;
sz += 4usize;
let num_adaptors = *(ptr.add(sz) as *const u16);
sz += 2usize;
sz += 22usize;
for _ in 0 .. (num_adaptors as usize) {
sz += <&AdaptorInfo>::compute_wire_len(ptr.add(sz), ());
}
sz
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
fn num_adaptors(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn info(&self) -> AdaptorInfoIterator {
unsafe {
let offset = 32usize;
AdaptorInfoIterator {
params: (),
rem: (self.num_adaptors() as usize),
ptr: self.wire_ptr().add(offset),
phantom: std::marker::PhantomData,
}
}
}
}
impl base::Reply for QueryAdaptorsReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryAdaptorsReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryAdaptorsReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("num_adaptors", &self.num_adaptors())
.field("pad", &22)
.field("info", &self.info())
.finish()
}
}
impl Drop for QueryAdaptorsReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryAdaptorsReply {}
unsafe impl std::marker::Sync for QueryAdaptorsReply {}
#[derive(Debug)]
pub struct QueryAdaptorsCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryAdaptorsCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryAdaptorsCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryAdaptorsCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryAdaptorsCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryAdaptorsCookie {
type Reply = QueryAdaptorsReply;
}
impl base::Cookie for QueryAdaptorsCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryAdaptorsCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryAdaptorsCookieUnchecked {
type Reply = QueryAdaptorsReply;
}
#[derive(Clone, Debug)]
pub struct QueryAdaptors {
pub window: xproto::Window,
}
unsafe impl base::RawRequest for QueryAdaptors {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 1,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.window.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryAdaptors {
type Cookie = QueryAdaptorsCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryAdaptors {
type Reply = QueryAdaptorsReply;
type Cookie = QueryAdaptorsCookie;
type CookieUnchecked = QueryAdaptorsCookieUnchecked;
}
pub struct QueryEncodingsReply {
raw: *const u8,
}
impl QueryEncodingsReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
unsafe fn compute_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 1usize;
sz += 1usize;
sz += 2usize;
sz += 4usize;
let num_encodings = *(ptr.add(sz) as *const u16);
sz += 2usize;
sz += 22usize;
for _ in 0 .. (num_encodings as usize) {
sz += <&EncodingInfo>::compute_wire_len(ptr.add(sz), ());
}
sz
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
fn num_encodings(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn info(&self) -> EncodingInfoIterator {
unsafe {
let offset = 32usize;
EncodingInfoIterator {
params: (),
rem: (self.num_encodings() as usize),
ptr: self.wire_ptr().add(offset),
phantom: std::marker::PhantomData,
}
}
}
}
impl base::Reply for QueryEncodingsReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryEncodingsReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryEncodingsReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("num_encodings", &self.num_encodings())
.field("pad", &22)
.field("info", &self.info())
.finish()
}
}
impl Drop for QueryEncodingsReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryEncodingsReply {}
unsafe impl std::marker::Sync for QueryEncodingsReply {}
#[derive(Debug)]
pub struct QueryEncodingsCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryEncodingsCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryEncodingsCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryEncodingsCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryEncodingsCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryEncodingsCookie {
type Reply = QueryEncodingsReply;
}
impl base::Cookie for QueryEncodingsCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryEncodingsCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryEncodingsCookieUnchecked {
type Reply = QueryEncodingsReply;
}
#[derive(Clone, Debug)]
pub struct QueryEncodings {
pub port: Port,
}
unsafe impl base::RawRequest for QueryEncodings {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 2,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.port.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryEncodings {
type Cookie = QueryEncodingsCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryEncodings {
type Reply = QueryEncodingsReply;
type Cookie = QueryEncodingsCookie;
type CookieUnchecked = QueryEncodingsCookieUnchecked;
}
pub struct GrabPortReply {
raw: *const u8,
}
impl GrabPortReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn result(&self) -> GrabPortStatus {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, GrabPortStatus>(val)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for GrabPortReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for GrabPortReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GrabPortReply")
.field("response_type", &self.response_type())
.field("result", &self.result())
.field("sequence", &self.sequence())
.field("length", &self.length())
.finish()
}
}
impl Drop for GrabPortReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for GrabPortReply {}
unsafe impl std::marker::Sync for GrabPortReply {}
#[derive(Debug)]
pub struct GrabPortCookie {
seq: u64,
}
#[derive(Debug)]
pub struct GrabPortCookieUnchecked {
seq: u64,
}
impl base::Cookie for GrabPortCookie {
unsafe fn from_sequence(seq: u64) -> Self {
GrabPortCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for GrabPortCookie {
}
unsafe impl base::CookieWithReplyChecked for GrabPortCookie {
type Reply = GrabPortReply;
}
impl base::Cookie for GrabPortCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
GrabPortCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for GrabPortCookieUnchecked {
type Reply = GrabPortReply;
}
#[derive(Clone, Debug)]
pub struct GrabPort {
pub port: Port,
pub time: xproto::Timestamp,
}
unsafe impl base::RawRequest for GrabPort {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 3,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.port.serialize(&mut buf0[4 .. ]);
self.time.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for GrabPort {
type Cookie = GrabPortCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for GrabPort {
type Reply = GrabPortReply;
type Cookie = GrabPortCookie;
type CookieUnchecked = GrabPortCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct UngrabPort {
pub port: Port,
pub time: xproto::Timestamp,
}
unsafe impl base::RawRequest for UngrabPort {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 4,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.port.serialize(&mut buf0[4 .. ]);
self.time.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for UngrabPort {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for UngrabPort {
}
#[derive(Clone, Debug)]
pub struct PutVideo {
pub port: Port,
pub drawable: xproto::Drawable,
pub gc: xproto::Gcontext,
pub vid_x: i16,
pub vid_y: i16,
pub vid_w: u16,
pub vid_h: u16,
pub drw_x: i16,
pub drw_y: i16,
pub drw_w: u16,
pub drw_h: u16,
}
unsafe impl base::RawRequest for PutVideo {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 5,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 32];
self.port.serialize(&mut buf0[4 .. ]);
self.drawable.serialize(&mut buf0[8 .. ]);
self.gc.serialize(&mut buf0[12 .. ]);
self.vid_x.serialize(&mut buf0[16 .. ]);
self.vid_y.serialize(&mut buf0[18 .. ]);
self.vid_w.serialize(&mut buf0[20 .. ]);
self.vid_h.serialize(&mut buf0[22 .. ]);
self.drw_x.serialize(&mut buf0[24 .. ]);
self.drw_y.serialize(&mut buf0[26 .. ]);
self.drw_w.serialize(&mut buf0[28 .. ]);
self.drw_h.serialize(&mut buf0[30 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 32;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for PutVideo {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for PutVideo {
}
#[derive(Clone, Debug)]
pub struct PutStill {
pub port: Port,
pub drawable: xproto::Drawable,
pub gc: xproto::Gcontext,
pub vid_x: i16,
pub vid_y: i16,
pub vid_w: u16,
pub vid_h: u16,
pub drw_x: i16,
pub drw_y: i16,
pub drw_w: u16,
pub drw_h: u16,
}
unsafe impl base::RawRequest for PutStill {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 6,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 32];
self.port.serialize(&mut buf0[4 .. ]);
self.drawable.serialize(&mut buf0[8 .. ]);
self.gc.serialize(&mut buf0[12 .. ]);
self.vid_x.serialize(&mut buf0[16 .. ]);
self.vid_y.serialize(&mut buf0[18 .. ]);
self.vid_w.serialize(&mut buf0[20 .. ]);
self.vid_h.serialize(&mut buf0[22 .. ]);
self.drw_x.serialize(&mut buf0[24 .. ]);
self.drw_y.serialize(&mut buf0[26 .. ]);
self.drw_w.serialize(&mut buf0[28 .. ]);
self.drw_h.serialize(&mut buf0[30 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 32;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for PutStill {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for PutStill {
}
#[derive(Clone, Debug)]
pub struct GetVideo {
pub port: Port,
pub drawable: xproto::Drawable,
pub gc: xproto::Gcontext,
pub vid_x: i16,
pub vid_y: i16,
pub vid_w: u16,
pub vid_h: u16,
pub drw_x: i16,
pub drw_y: i16,
pub drw_w: u16,
pub drw_h: u16,
}
unsafe impl base::RawRequest for GetVideo {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 7,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 32];
self.port.serialize(&mut buf0[4 .. ]);
self.drawable.serialize(&mut buf0[8 .. ]);
self.gc.serialize(&mut buf0[12 .. ]);
self.vid_x.serialize(&mut buf0[16 .. ]);
self.vid_y.serialize(&mut buf0[18 .. ]);
self.vid_w.serialize(&mut buf0[20 .. ]);
self.vid_h.serialize(&mut buf0[22 .. ]);
self.drw_x.serialize(&mut buf0[24 .. ]);
self.drw_y.serialize(&mut buf0[26 .. ]);
self.drw_w.serialize(&mut buf0[28 .. ]);
self.drw_h.serialize(&mut buf0[30 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 32;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for GetVideo {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for GetVideo {
}
#[derive(Clone, Debug)]
pub struct GetStill {
pub port: Port,
pub drawable: xproto::Drawable,
pub gc: xproto::Gcontext,
pub vid_x: i16,
pub vid_y: i16,
pub vid_w: u16,
pub vid_h: u16,
pub drw_x: i16,
pub drw_y: i16,
pub drw_w: u16,
pub drw_h: u16,
}
unsafe impl base::RawRequest for GetStill {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 8,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 32];
self.port.serialize(&mut buf0[4 .. ]);
self.drawable.serialize(&mut buf0[8 .. ]);
self.gc.serialize(&mut buf0[12 .. ]);
self.vid_x.serialize(&mut buf0[16 .. ]);
self.vid_y.serialize(&mut buf0[18 .. ]);
self.vid_w.serialize(&mut buf0[20 .. ]);
self.vid_h.serialize(&mut buf0[22 .. ]);
self.drw_x.serialize(&mut buf0[24 .. ]);
self.drw_y.serialize(&mut buf0[26 .. ]);
self.drw_w.serialize(&mut buf0[28 .. ]);
self.drw_h.serialize(&mut buf0[30 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 32;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for GetStill {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for GetStill {
}
#[derive(Clone, Debug)]
pub struct StopVideo {
pub port: Port,
pub drawable: xproto::Drawable,
}
unsafe impl base::RawRequest for StopVideo {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 9,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.port.serialize(&mut buf0[4 .. ]);
self.drawable.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for StopVideo {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for StopVideo {
}
#[derive(Clone, Debug)]
pub struct SelectVideoNotify {
pub drawable: xproto::Drawable,
pub onoff: bool,
}
unsafe impl base::RawRequest for SelectVideoNotify {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 10,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.drawable.serialize(&mut buf0[4 .. ]);
(if self.onoff { 1u8 } else { 0u8 }).serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for SelectVideoNotify {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for SelectVideoNotify {
}
#[derive(Clone, Debug)]
pub struct SelectPortNotify {
pub port: Port,
pub onoff: bool,
}
unsafe impl base::RawRequest for SelectPortNotify {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 11,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.port.serialize(&mut buf0[4 .. ]);
(if self.onoff { 1u8 } else { 0u8 }).serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for SelectPortNotify {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for SelectPortNotify {
}
pub struct QueryBestSizeReply {
raw: *const u8,
}
impl QueryBestSizeReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn actual_width(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn actual_height(&self) -> u16 {
unsafe {
let offset = 10usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for QueryBestSizeReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryBestSizeReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryBestSizeReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("actual_width", &self.actual_width())
.field("actual_height", &self.actual_height())
.finish()
}
}
impl Drop for QueryBestSizeReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryBestSizeReply {}
unsafe impl std::marker::Sync for QueryBestSizeReply {}
#[derive(Debug)]
pub struct QueryBestSizeCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryBestSizeCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryBestSizeCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryBestSizeCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryBestSizeCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryBestSizeCookie {
type Reply = QueryBestSizeReply;
}
impl base::Cookie for QueryBestSizeCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryBestSizeCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryBestSizeCookieUnchecked {
type Reply = QueryBestSizeReply;
}
#[derive(Clone, Debug)]
pub struct QueryBestSize {
pub port: Port,
pub vid_w: u16,
pub vid_h: u16,
pub drw_w: u16,
pub drw_h: u16,
pub motion: bool,
}
unsafe impl base::RawRequest for QueryBestSize {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 12,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 20];
self.port.serialize(&mut buf0[4 .. ]);
self.vid_w.serialize(&mut buf0[8 .. ]);
self.vid_h.serialize(&mut buf0[10 .. ]);
self.drw_w.serialize(&mut buf0[12 .. ]);
self.drw_h.serialize(&mut buf0[14 .. ]);
(if self.motion { 1u8 } else { 0u8 }).serialize(&mut buf0[16 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 20;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryBestSize {
type Cookie = QueryBestSizeCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryBestSize {
type Reply = QueryBestSizeReply;
type Cookie = QueryBestSizeCookie;
type CookieUnchecked = QueryBestSizeCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct SetPortAttribute {
pub port: Port,
pub attribute: xproto::Atom,
pub value: i32,
}
unsafe impl base::RawRequest for SetPortAttribute {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 13,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 16];
self.port.serialize(&mut buf0[4 .. ]);
self.attribute.serialize(&mut buf0[8 .. ]);
self.value.serialize(&mut buf0[12 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 16;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for SetPortAttribute {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for SetPortAttribute {
}
pub struct GetPortAttributeReply {
raw: *const u8,
}
impl GetPortAttributeReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn value(&self) -> i32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const i32;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for GetPortAttributeReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for GetPortAttributeReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GetPortAttributeReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("value", &self.value())
.finish()
}
}
impl Drop for GetPortAttributeReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for GetPortAttributeReply {}
unsafe impl std::marker::Sync for GetPortAttributeReply {}
#[derive(Debug)]
pub struct GetPortAttributeCookie {
seq: u64,
}
#[derive(Debug)]
pub struct GetPortAttributeCookieUnchecked {
seq: u64,
}
impl base::Cookie for GetPortAttributeCookie {
unsafe fn from_sequence(seq: u64) -> Self {
GetPortAttributeCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for GetPortAttributeCookie {
}
unsafe impl base::CookieWithReplyChecked for GetPortAttributeCookie {
type Reply = GetPortAttributeReply;
}
impl base::Cookie for GetPortAttributeCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
GetPortAttributeCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for GetPortAttributeCookieUnchecked {
type Reply = GetPortAttributeReply;
}
#[derive(Clone, Debug)]
pub struct GetPortAttribute {
pub port: Port,
pub attribute: xproto::Atom,
}
unsafe impl base::RawRequest for GetPortAttribute {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 14,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.port.serialize(&mut buf0[4 .. ]);
self.attribute.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for GetPortAttribute {
type Cookie = GetPortAttributeCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for GetPortAttribute {
type Reply = GetPortAttributeReply;
type Cookie = GetPortAttributeCookie;
type CookieUnchecked = GetPortAttributeCookieUnchecked;
}
pub struct QueryPortAttributesReply {
raw: *const u8,
}
impl QueryPortAttributesReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
unsafe fn compute_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 1usize;
sz += 1usize;
sz += 2usize;
sz += 4usize;
let num_attributes = *(ptr.add(sz) as *const u32);
sz += 4usize;
sz += 4usize;
sz += 16usize;
for _ in 0 .. (num_attributes as usize) {
sz += <&AttributeInfo>::compute_wire_len(ptr.add(sz), ());
}
sz
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
fn num_attributes(&self) -> u32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn text_size(&self) -> u32 {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn attributes(&self) -> AttributeInfoIterator {
unsafe {
let offset = 32usize;
AttributeInfoIterator {
params: (),
rem: (self.num_attributes() as usize),
ptr: self.wire_ptr().add(offset),
phantom: std::marker::PhantomData,
}
}
}
}
impl base::Reply for QueryPortAttributesReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryPortAttributesReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryPortAttributesReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("num_attributes", &self.num_attributes())
.field("text_size", &self.text_size())
.field("pad", &16)
.field("attributes", &self.attributes())
.finish()
}
}
impl Drop for QueryPortAttributesReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryPortAttributesReply {}
unsafe impl std::marker::Sync for QueryPortAttributesReply {}
#[derive(Debug)]
pub struct QueryPortAttributesCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryPortAttributesCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryPortAttributesCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryPortAttributesCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryPortAttributesCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryPortAttributesCookie {
type Reply = QueryPortAttributesReply;
}
impl base::Cookie for QueryPortAttributesCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryPortAttributesCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryPortAttributesCookieUnchecked {
type Reply = QueryPortAttributesReply;
}
#[derive(Clone, Debug)]
pub struct QueryPortAttributes {
pub port: Port,
}
unsafe impl base::RawRequest for QueryPortAttributes {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 15,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.port.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryPortAttributes {
type Cookie = QueryPortAttributesCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryPortAttributes {
type Reply = QueryPortAttributesReply;
type Cookie = QueryPortAttributesCookie;
type CookieUnchecked = QueryPortAttributesCookieUnchecked;
}
pub struct ListImageFormatsReply {
raw: *const u8,
}
impl ListImageFormatsReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
unsafe fn compute_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 1usize;
sz += 1usize;
sz += 2usize;
sz += 4usize;
let num_formats = *(ptr.add(sz) as *const u32);
sz += 4usize;
sz += 20usize;
sz += ((num_formats as usize) * 128usize);
sz
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
fn num_formats(&self) -> u32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn format(&self) -> &[ImageFormatInfo] {
unsafe {
let offset = 32usize;
let len = (self.num_formats() as usize) as _;
let ptr = self.wire_ptr().add(offset) as *const ImageFormatInfo;
std::slice::from_raw_parts(ptr, len)
}
}
}
impl base::Reply for ListImageFormatsReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for ListImageFormatsReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ListImageFormatsReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("num_formats", &self.num_formats())
.field("pad", &20)
.field("format", &self.format())
.finish()
}
}
impl Drop for ListImageFormatsReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for ListImageFormatsReply {}
unsafe impl std::marker::Sync for ListImageFormatsReply {}
#[derive(Debug)]
pub struct ListImageFormatsCookie {
seq: u64,
}
#[derive(Debug)]
pub struct ListImageFormatsCookieUnchecked {
seq: u64,
}
impl base::Cookie for ListImageFormatsCookie {
unsafe fn from_sequence(seq: u64) -> Self {
ListImageFormatsCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for ListImageFormatsCookie {
}
unsafe impl base::CookieWithReplyChecked for ListImageFormatsCookie {
type Reply = ListImageFormatsReply;
}
impl base::Cookie for ListImageFormatsCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
ListImageFormatsCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for ListImageFormatsCookieUnchecked {
type Reply = ListImageFormatsReply;
}
#[derive(Clone, Debug)]
pub struct ListImageFormats {
pub port: Port,
}
unsafe impl base::RawRequest for ListImageFormats {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 16,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.port.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for ListImageFormats {
type Cookie = ListImageFormatsCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for ListImageFormats {
type Reply = ListImageFormatsReply;
type Cookie = ListImageFormatsCookie;
type CookieUnchecked = ListImageFormatsCookieUnchecked;
}
pub struct QueryImageAttributesReply {
raw: *const u8,
}
impl QueryImageAttributesReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
unsafe fn compute_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 1usize;
sz += 1usize;
sz += 2usize;
sz += 4usize;
let num_planes = *(ptr.add(sz) as *const u32);
sz += 4usize;
sz += 4usize;
sz += 2usize;
sz += 2usize;
sz += 12usize;
sz += ((num_planes as usize) * 4usize);
sz += ((num_planes as usize) * 4usize);
sz
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
fn num_planes(&self) -> u32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn data_size(&self) -> u32 {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn width(&self) -> u16 {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn height(&self) -> u16 {
unsafe {
let offset = 18usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn pitches(&self) -> &[u32] {
unsafe {
let offset = 32usize;
let len = (self.num_planes() as usize);
let ptr = self.wire_ptr().add(offset) as *const u32;
std::slice::from_raw_parts(ptr, len)
}
}
pub fn offsets(&self) -> &[u32] {
unsafe {
let offset = (32usize + ((self.num_planes() as usize) * 4usize));
let len = (self.num_planes() as usize);
let ptr = self.wire_ptr().add(offset) as *const u32;
std::slice::from_raw_parts(ptr, len)
}
}
}
impl base::Reply for QueryImageAttributesReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryImageAttributesReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryImageAttributesReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("num_planes", &self.num_planes())
.field("data_size", &self.data_size())
.field("width", &self.width())
.field("height", &self.height())
.field("pad", &12)
.field("pitches", &self.pitches())
.field("offsets", &self.offsets())
.finish()
}
}
impl Drop for QueryImageAttributesReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryImageAttributesReply {}
unsafe impl std::marker::Sync for QueryImageAttributesReply {}
#[derive(Debug)]
pub struct QueryImageAttributesCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryImageAttributesCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryImageAttributesCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryImageAttributesCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryImageAttributesCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryImageAttributesCookie {
type Reply = QueryImageAttributesReply;
}
impl base::Cookie for QueryImageAttributesCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryImageAttributesCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryImageAttributesCookieUnchecked {
type Reply = QueryImageAttributesReply;
}
#[derive(Clone, Debug)]
pub struct QueryImageAttributes {
pub port: Port,
pub id: u32,
pub width: u16,
pub height: u16,
}
unsafe impl base::RawRequest for QueryImageAttributes {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 17,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 16];
self.port.serialize(&mut buf0[4 .. ]);
self.id.serialize(&mut buf0[8 .. ]);
self.width.serialize(&mut buf0[12 .. ]);
self.height.serialize(&mut buf0[14 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 16;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryImageAttributes {
type Cookie = QueryImageAttributesCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryImageAttributes {
type Reply = QueryImageAttributesReply;
type Cookie = QueryImageAttributesCookie;
type CookieUnchecked = QueryImageAttributesCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct PutImage<'a> {
pub port: Port,
pub drawable: xproto::Drawable,
pub gc: xproto::Gcontext,
pub id: u32,
pub src_x: i16,
pub src_y: i16,
pub src_w: u16,
pub src_h: u16,
pub drw_x: i16,
pub drw_y: i16,
pub drw_w: u16,
pub drw_h: u16,
pub width: u16,
pub height: u16,
pub data: &'a [u8],
}
unsafe impl<'a> base::RawRequest for PutImage<'a> {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 4,
ext: (&mut FFI_EXT) as *mut _,
opcode: 18,
isvoid: 1,
};
let mut sections: [iovec; 6] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 6];
let buf0: &mut [u8] = &mut [0; 40];
self.port.serialize(&mut buf0[4 .. ]);
self.drawable.serialize(&mut buf0[8 .. ]);
self.gc.serialize(&mut buf0[12 .. ]);
self.id.serialize(&mut buf0[16 .. ]);
self.src_x.serialize(&mut buf0[20 .. ]);
self.src_y.serialize(&mut buf0[22 .. ]);
self.src_w.serialize(&mut buf0[24 .. ]);
self.src_h.serialize(&mut buf0[26 .. ]);
self.drw_x.serialize(&mut buf0[28 .. ]);
self.drw_y.serialize(&mut buf0[30 .. ]);
self.drw_w.serialize(&mut buf0[32 .. ]);
self.drw_h.serialize(&mut buf0[34 .. ]);
self.width.serialize(&mut buf0[36 .. ]);
self.height.serialize(&mut buf0[38 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 40;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
sections[4].iov_base = self.data.as_ptr() as *mut _;
sections[4].iov_len = self.data.len() * std::mem::size_of::<u8>();
sections[5].iov_len = base::align_pad(sections[4].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl<'a> base::Request for PutImage<'a> {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl<'a> base::RequestWithoutReply for PutImage<'a> {
}
#[derive(Clone, Debug)]
pub struct ShmPutImage {
pub port: Port,
pub drawable: xproto::Drawable,
pub gc: xproto::Gcontext,
pub shmseg: shm::Seg,
pub id: u32,
pub offset: u32,
pub src_x: i16,
pub src_y: i16,
pub src_w: u16,
pub src_h: u16,
pub drw_x: i16,
pub drw_y: i16,
pub drw_w: u16,
pub drw_h: u16,
pub width: u16,
pub height: u16,
pub send_event: u8,
}
unsafe impl base::RawRequest for ShmPutImage {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 19,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 52];
self.port.serialize(&mut buf0[4 .. ]);
self.drawable.serialize(&mut buf0[8 .. ]);
self.gc.serialize(&mut buf0[12 .. ]);
self.shmseg.serialize(&mut buf0[16 .. ]);
self.id.serialize(&mut buf0[20 .. ]);
self.offset.serialize(&mut buf0[24 .. ]);
self.src_x.serialize(&mut buf0[28 .. ]);
self.src_y.serialize(&mut buf0[30 .. ]);
self.src_w.serialize(&mut buf0[32 .. ]);
self.src_h.serialize(&mut buf0[34 .. ]);
self.drw_x.serialize(&mut buf0[36 .. ]);
self.drw_y.serialize(&mut buf0[38 .. ]);
self.drw_w.serialize(&mut buf0[40 .. ]);
self.drw_h.serialize(&mut buf0[42 .. ]);
self.width.serialize(&mut buf0[44 .. ]);
self.height.serialize(&mut buf0[46 .. ]);
self.send_event.serialize(&mut buf0[48 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 52;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for ShmPutImage {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for ShmPutImage {
}