summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Radomski <dextero@google.com>2024-03-13 16:03:42 +0000
committerMarcin Radomski <dextero@google.com>2024-03-13 18:04:21 +0000
commit45d1e16e5b94a2867281ec40a33a2a5c271ed920 (patch)
treeb86b60172a4402713932852a07cd94f3f88de2fc
parent517a652a90b8c8dea12267c9769604bbe99e9ae6 (diff)
downloaddrm-fourcc-45d1e16e5b94a2867281ec40a33a2a5c271ed920.tar.gz
Import 'drm-fourcc' crateupstream
Request Document: go/android-rust-importing-crates For CL Reviewers: go/android3p#cl-review For Build Team: go/ab-third-party-imports Bug: http://b/328180685 Test: m libdrm_fourcc Test: atest drm-fourcc_test_src_lib Note: the latest version on crates.io does *not* contain the LICENSE file, even though it's marked as MIT-licensed in Cargo.toml. The main branch on github [1] has the LICENSE file (which I included here). Please let me know if that's OK. [1] https://github.com/dzfranklin/drm-fourcc-rs Change-Id: I680512cebe07a1314aadd359646e489b9524e58b
-rw-r--r--.cargo_vcs_info.json5
-rw-r--r--.gitignore2
-rw-r--r--.idea/.gitignore8
-rw-r--r--.idea/drm-fourcc.iml17
-rw-r--r--.idea/misc.xml4
-rw-r--r--.idea/modules.xml8
-rw-r--r--.idea/vcs.xml6
-rw-r--r--Android.bp42
-rw-r--r--Cargo.toml38
-rw-r--r--Cargo.toml.orig26
-rw-r--r--LICENSE23
-rw-r--r--METADATA20
-rw-r--r--MODULE_LICENSE_MIT0
-rw-r--r--OWNERS7
-rw-r--r--README.md48
-rw-r--r--build.rs263
-rw-r--r--cargo_embargo.json4
-rw-r--r--src/as_enum.rs369
-rw-r--r--src/consts.rs149
-rw-r--r--src/lib.rs438
20 files changed, 1477 insertions, 0 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
new file mode 100644
index 0000000..5f3fd70
--- /dev/null
+++ b/.cargo_vcs_info.json
@@ -0,0 +1,5 @@
+{
+ "git": {
+ "sha1": "7b9f80060ffd4b35cd236437e65a17fb517d163c"
+ }
+}
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..96ef6c0
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+/target
+Cargo.lock
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..73f69e0
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/drm-fourcc.iml b/.idea/drm-fourcc.iml
new file mode 100644
index 0000000..6f0fb4f
--- /dev/null
+++ b/.idea/drm-fourcc.iml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="CPP_MODULE" version="4">
+ <component name="FacetManager">
+ <facet type="Python" name="Python facet">
+ <configuration sdkName="Python 3.8" />
+ </facet>
+ </component>
+ <component name="NewModuleRootManager">
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" name="Python 3.8 interpreter library" level="application" />
+ </component>
+</module> \ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..689ca93
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectRootManager" version="2" project-jdk-name="Elixir 1.10.3-otp-23" project-jdk-type="Elixir SDK" />
+</project> \ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..6f41a56
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/.idea/drm-fourcc.iml" filepath="$PROJECT_DIR$/.idea/drm-fourcc.iml" />
+ </modules>
+ </component>
+</project> \ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$" vcs="Git" />
+ </component>
+</project> \ No newline at end of file
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..a5fca5b
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,42 @@
+// This file is generated by cargo_embargo.
+// Do not modify this file as changes will be overridden on upgrade.
+
+// TODO: Add license.
+rust_test {
+ name: "drm-fourcc_test_src_lib",
+ host_supported: true,
+ crate_name: "drm_fourcc",
+ cargo_env_compat: true,
+ cargo_pkg_version: "2.2.0",
+ srcs: ["src/lib.rs"],
+ test_suites: ["general-tests"],
+ auto_gen_config: true,
+ test_options: {
+ unit_test: true,
+ },
+ edition: "2018",
+ features: [
+ "default",
+ "std",
+ ],
+}
+
+rust_library {
+ name: "libdrm_fourcc",
+ host_supported: true,
+ crate_name: "drm_fourcc",
+ cargo_env_compat: true,
+ cargo_pkg_version: "2.2.0",
+ srcs: ["src/lib.rs"],
+ edition: "2018",
+ features: [
+ "default",
+ "std",
+ ],
+ apex_available: [
+ "//apex_available:platform",
+ "//apex_available:anyapex",
+ ],
+ product_available: true,
+ vendor_available: true,
+}
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..e7aa144
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,38 @@
+# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
+#
+# When uploading crates to the registry Cargo will automatically
+# "normalize" Cargo.toml files for maximal compatibility
+# with all versions of Cargo and also rewrite `path` dependencies
+# to registry (e.g., crates.io) dependencies
+#
+# If you believe there's an error in this file please file an
+# issue against the rust-lang/cargo repository. If you're
+# editing this file be aware that the upstream Cargo.toml
+# will likely look very different (and much more reasonable)
+
+[package]
+edition = "2018"
+name = "drm-fourcc"
+version = "2.2.0"
+authors = ["Daniel Franklin <daniel@danielzfranklin.org>"]
+description = "Provides an enum with every valid Direct Rendering Manager (DRM) format fourcc"
+keywords = ["drm", "fourcc", "linux"]
+categories = ["os::linux-apis"]
+license = "MIT"
+repository = "https://github.com/danielzfranklin/drm-fourcc-rs"
+[dependencies.serde]
+version = "1.0.125"
+features = ["derive"]
+optional = true
+[build-dependencies.bindgen]
+version = "0.57.0"
+optional = true
+
+[build-dependencies.regex]
+version = "1.4.3"
+optional = true
+
+[features]
+build_bindings = ["regex", "bindgen"]
+default = ["std"]
+std = []
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
new file mode 100644
index 0000000..19673bc
--- /dev/null
+++ b/Cargo.toml.orig
@@ -0,0 +1,26 @@
+[package]
+name = "drm-fourcc"
+version = "2.2.0"
+authors = ["Daniel Franklin <daniel@danielzfranklin.org>"]
+edition = "2018"
+license = "MIT"
+description = "Provides an enum with every valid Direct Rendering Manager (DRM) format fourcc"
+repository = "https://github.com/danielzfranklin/drm-fourcc-rs"
+keywords = ["drm", "fourcc", "linux"]
+categories = ["os::linux-apis"]
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[features]
+default = ["std"]
+# Adds `Error` impls for the Unrecognized types.
+std = []
+# Re-build the bindings based on the headers on your machine. Should not be necessary
+build_bindings = ["regex", "bindgen"]
+
+[dependencies]
+serde = { version = "1.0.125", optional = true, features = ["derive"] }
+
+[build-dependencies]
+regex = { version = "1.4.3", optional = true }
+bindgen = { version = "0.57.0", optional = true }
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..31aa793
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+Permission is hereby granted, free of charge, to any
+person obtaining a copy of this software and associated
+documentation files (the "Software"), to deal in the
+Software without restriction, including without
+limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software
+is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice
+shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
+ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
+TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
+SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..4d6f467
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,20 @@
+name: "drm-fourcc"
+description: "Provides an enum with every valid Direct Rendering Manager (DRM) format fourcc"
+third_party {
+ identifier {
+ type: "crates.io"
+ value: "drm-fourcc"
+ }
+ identifier {
+ type: "Archive"
+ value: "https://static.crates.io/crates/drm-fourcc/drm-fourcc-2.2.0.crate"
+ primary_source: true
+ }
+ version: "2.2.0"
+ license_type: NOTICE
+ last_upgrade_date {
+ year: 2024
+ month: 3
+ day: 13
+ }
+}
diff --git a/MODULE_LICENSE_MIT b/MODULE_LICENSE_MIT
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_MIT
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..697f117
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,7 @@
+# Bug component: 688011
+include platform/prebuilts/rust:main:/OWNERS
+
+dextero@google.com
+vill@google.com
+nputikhin@google.com
+istvannador@google.com
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..d679abc
--- /dev/null
+++ b/README.md
@@ -0,0 +1,48 @@
+# drm-fourcc
+
+[![Crates.io](https://img.shields.io/crates/v/drm-fourcc)](https://crates.io/crates/drm-fourcc)
+![MIT Licensed](https://img.shields.io/crates/l/drm-fourcc)
+
+Provides an enums representing every pixel format and format modifier supported
+by DRM (as of kernel version 5.10.0).
+
+A [fourcc][fourcc_wiki] is four bytes of ascii representing some data format. This enum contains
+every fourcc representing a pixel format supported by [DRM][drm_wiki], the Linux Direct
+Rendering Manager.
+
+To get the bytes of the fourcc representing the format, cast to `u32`.
+
+```rust
+assert_eq!(DrmFourcc::Xrgb8888 as u32, 875713112);
+```
+
+To get the string form of the fourcc, use [`DrmFourcc::string_form`].
+
+```rust
+assert_eq!(DrmFourcc::Xrgb8888.string_form(), "XR24");
+```
+
+We also provide a type for representing a fourcc/modifier pair
+
+```rust
+let format = DrmFormat {
+ code: DrmFourcc::Xrgb8888,
+ modifier: DrmModifier::Linear,
+};
+```
+
+The enums are autogenerated from the [canonical list][canonical] in the Linux source code.
+
+## Features
+
+- `std`: Enable functionality that requires the standard library. Enabled by default
+- `build_bindings`: Build the bindings based on the headers on your machine. Should not be necessary in most cases.
+
+## Contributors
+
+- [Daniel Franklin](https://github.com/danielzfranklin)
+- [Victor Brekenfeld](https://github.com/Drakulix)
+
+[fourcc_wiki]: https://en.wikipedia.org/wiki/FourCC
+[drm_wiki]: https://en.wikipedia.org/wiki/Direct_Rendering_Managerz
+[canonical]: https://github.com/torvalds/linux/blame/master/include/uapi/drm/drm_fourcc.h
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..61fce85
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,263 @@
+#[cfg(not(feature = "build_bindings"))]
+fn main() {
+ println!("cargo:rerun-if-changed=build.rs"); // never rerun
+}
+
+#[cfg(feature = "build_bindings")]
+fn main() {
+ println!("cargo:rerun-if-changed=build.rs"); // avoids double-build when we output into src
+ generate::generate().unwrap();
+}
+
+#[cfg(feature = "build_bindings")]
+mod generate {
+ use std::error::Error;
+ use std::io::Write;
+ use std::process::{Command, Stdio};
+
+ use regex::Regex;
+ use std::env;
+ use std::fs::File;
+ use std::path::Path;
+
+ static CONST_PREFIX: &'static str = "DRM_FOURCC_";
+
+ pub fn generate() -> Result<(), Box<dyn Error + Sync + Send>> {
+ let out_dir = env::var("OUT_DIR").unwrap();
+ let wrapper_path = Path::new(&out_dir).join("wrapper.h");
+
+ // First get all the macros in drm_fourcc.h
+
+ let mut cmd = Command::new("clang")
+ .arg("-E") // run pre-processor only
+ .arg("-dM") // output all macros defined
+ .arg("-") // take input from stdin
+ .stdin(Stdio::piped())
+ .stdout(Stdio::piped())
+ .spawn()?;
+
+ {
+ let stdin = cmd.stdin.as_mut().expect("failed to open stdin");
+ stdin.write_all(b"#include <drm/drm_fourcc.h>\n")?;
+ }
+
+ let result = cmd.wait_with_output()?;
+ let stdout = String::from_utf8(result.stdout)?;
+ if !result.status.success() {
+ panic!("Clang failed with output: {}", stdout)
+ }
+
+ // Then get the names of the format macros
+
+ let fmt_re = Regex::new(r"^\s*#define (?P<full>DRM_FORMAT_(?P<short>[A-Z0-9_]+)) ")?;
+ let format_names: Vec<(&str, &str)> = stdout
+ .lines()
+ .filter_map(|line| {
+ if line.contains("DRM_FORMAT_RESERVED")
+ || line.contains("INVALID")
+ || line.contains("_MOD_")
+ {
+ return None;
+ }
+
+ fmt_re.captures(line).map(|caps| {
+ let full = caps.name("full").unwrap().as_str();
+ let short = caps.name("short").unwrap().as_str();
+
+ (full, short)
+ })
+ })
+ .collect();
+
+ let vendor_re =
+ Regex::new(r"^\s*#define (?P<full>DRM_FORMAT_MOD_VENDOR_(?P<short>[A-Z0-9_]+)) ")?;
+ let vendor_names: Vec<(&str, &str)> = stdout
+ .lines()
+ .filter_map(|line| {
+ if line.contains("DRM_FORMAT_MOD_VENDOR_NONE") {
+ return None;
+ }
+
+ vendor_re.captures(line).map(|caps| {
+ let full = caps.name("full").unwrap().as_str();
+ let short = caps.name("short").unwrap().as_str();
+
+ (full, short)
+ })
+ })
+ .collect();
+
+ let mod_re =
+ Regex::new(r"^\s*#define (?P<full>(DRM|I915)_FORMAT_MOD_(?P<short>[A-Z0-9_]+)) ")?;
+ let modifier_names: Vec<(&str, String)> = stdout
+ .lines()
+ .filter_map(|line| {
+ if line.contains("DRM_FORMAT_MOD_NONE")
+ || line.contains("DRM_FORMAT_MOD_RESERVED")
+ || line.contains("VENDOR")
+ // grrr..
+ || line.contains("ARM_TYPE")
+ {
+ return None;
+ }
+
+ mod_re.captures(line).map(|caps| {
+ let full = caps.name("full").unwrap().as_str();
+ let short = caps.name("short").unwrap().as_str();
+
+ (
+ full,
+ if full.contains("I915") {
+ format!("I915_{}", short)
+ } else {
+ String::from(short)
+ },
+ )
+ })
+ })
+ .collect();
+
+ // Then create a file with a variable defined for every format macro
+
+ let mut wrapper = File::create(&wrapper_path)?;
+
+ wrapper.write_all(b"#include <stdint.h>\n")?;
+ wrapper.write_all(b"#include <drm/drm_fourcc.h>\n")?;
+
+ for (full, short) in &format_names {
+ writeln!(wrapper, "uint32_t {}{} = {};\n", CONST_PREFIX, short, full)?;
+ }
+ for (full, short) in &vendor_names {
+ writeln!(wrapper, "uint8_t {}{} = {};\n", CONST_PREFIX, short, full)?;
+ }
+ for (full, short) in &modifier_names {
+ writeln!(wrapper, "uint64_t {}{} = {};\n", CONST_PREFIX, short, full)?;
+ }
+
+ wrapper.flush()?;
+
+ // Then generate bindings from that file
+ bindgen::builder()
+ .ctypes_prefix("crate::_fake_ctypes")
+ .header(wrapper_path.as_os_str().to_str().unwrap())
+ .whitelist_var("DRM_FOURCC_.*")
+ .generate()
+ .unwrap()
+ .write_to_file("src/consts.rs")?;
+
+ // Then generate our enums
+ fn write_enum(
+ as_enum: &mut File,
+ name: &str,
+ repr: &str,
+ names: Vec<(&str, &str)>,
+ ) -> Result<(), std::io::Error> {
+ as_enum.write_all(b"#[derive(Copy, Clone, Eq, PartialEq, Hash)]")?;
+ as_enum.write_all(
+ b"#[cfg_attr(feature = \"serde\", derive(serde::Serialize, serde::Deserialize))]",
+ )?;
+ writeln!(as_enum, "#[repr({})]", repr)?;
+ writeln!(as_enum, "pub enum {} {{", name)?;
+
+ let members: Vec<(String, String)> = names
+ .iter()
+ .map(|(_, short)| {
+ (
+ enum_member_case(short),
+ format!("consts::{}{}", CONST_PREFIX, short),
+ )
+ })
+ .collect();
+
+ for (member, value) in &members {
+ writeln!(as_enum, "{} = {},", member, value)?;
+ }
+
+ as_enum.write_all(b"}\n")?;
+
+ writeln!(as_enum, "impl {} {{", name)?;
+ writeln!(
+ as_enum,
+ "pub(crate) fn from_{}(n: {}) -> Option<Self> {{\n",
+ repr, repr
+ )?;
+ as_enum.write_all(b"match n {\n")?;
+
+ for (member, value) in &members {
+ writeln!(as_enum, "{} => Some(Self::{}),", value, member)?;
+ }
+
+ writeln!(as_enum, "_ => None")?;
+ as_enum.write_all(b"}}}\n")?;
+
+ Ok(())
+ }
+
+ let as_enum_path = "src/as_enum.rs";
+ {
+ let mut as_enum = File::create(as_enum_path)?;
+
+ as_enum.write_all(b"// Automatically generated by build.rs\n")?;
+ as_enum.write_all(b"use crate::consts;")?;
+
+ write_enum(&mut as_enum, "DrmFourcc", "u32", format_names)?;
+
+ as_enum.write_all(b"#[derive(Debug)]")?;
+ write_enum(&mut as_enum, "DrmVendor", "u8", vendor_names)?;
+
+ // modifiers can overlap
+
+ as_enum.write_all(b"#[derive(Debug, Copy, Clone)]")?;
+ as_enum.write_all(
+ b"#[cfg_attr(feature = \"serde\", derive(serde::Serialize, serde::Deserialize))]",
+ )?;
+ as_enum.write_all(b"pub enum DrmModifier {\n")?;
+
+ let modifier_members: Vec<(String, String)> = modifier_names
+ .iter()
+ .map(|(_, short)| {
+ (
+ enum_member_case(short),
+ format!("consts::{}{}", CONST_PREFIX, short),
+ )
+ })
+ .collect();
+ for (member, _) in &modifier_members {
+ writeln!(as_enum, "{},", member)?;
+ }
+ as_enum.write_all(b"Unrecognized(u64)")?;
+
+ as_enum.write_all(b"}\n")?;
+
+ as_enum.write_all(b"impl DrmModifier {\n")?;
+ as_enum.write_all(b"pub(crate) fn from_u64(n: u64) -> Self {\n")?;
+ as_enum.write_all(b"#[allow(unreachable_patterns)]\n")?;
+ as_enum.write_all(b"match n {\n")?;
+
+ for (member, value) in &modifier_members {
+ writeln!(as_enum, "{} => Self::{},", value, member)?;
+ }
+ as_enum.write_all(b"x => Self::Unrecognized(x)\n")?;
+
+ as_enum.write_all(b"}}\n")?;
+ as_enum.write_all(b"pub(crate) fn into_u64(&self) -> u64 {\n")?;
+ as_enum.write_all(b"match self {\n")?;
+
+ for (member, value) in &modifier_members {
+ writeln!(as_enum, "Self::{} => {},", member, value)?;
+ }
+ as_enum.write_all(b"Self::Unrecognized(x) => *x,\n")?;
+
+ as_enum.write_all(b"}}}\n")?;
+ }
+
+ Command::new("rustfmt").arg(as_enum_path).spawn()?.wait()?;
+
+ Ok(())
+ }
+
+ fn enum_member_case(s: &str) -> String {
+ let (first, rest) = s.split_at(1);
+ format!("{}{}", first, rest.to_ascii_lowercase())
+ }
+}
diff --git a/cargo_embargo.json b/cargo_embargo.json
new file mode 100644
index 0000000..c8842d1
--- /dev/null
+++ b/cargo_embargo.json
@@ -0,0 +1,4 @@
+{
+ "run_cargo": false,
+ "tests": true
+}
diff --git a/src/as_enum.rs b/src/as_enum.rs
new file mode 100644
index 0000000..abcc750
--- /dev/null
+++ b/src/as_enum.rs
@@ -0,0 +1,369 @@
+// Automatically generated by build.rs
+use crate::consts;
+#[derive(Copy, Clone, Eq, PartialEq, Hash)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+#[repr(u32)]
+pub enum DrmFourcc {
+ Abgr1555 = consts::DRM_FOURCC_ABGR1555,
+ Abgr16161616f = consts::DRM_FOURCC_ABGR16161616F,
+ Abgr2101010 = consts::DRM_FOURCC_ABGR2101010,
+ Abgr4444 = consts::DRM_FOURCC_ABGR4444,
+ Abgr8888 = consts::DRM_FOURCC_ABGR8888,
+ Argb1555 = consts::DRM_FOURCC_ARGB1555,
+ Argb16161616f = consts::DRM_FOURCC_ARGB16161616F,
+ Argb2101010 = consts::DRM_FOURCC_ARGB2101010,
+ Argb4444 = consts::DRM_FOURCC_ARGB4444,
+ Argb8888 = consts::DRM_FOURCC_ARGB8888,
+ Axbxgxrx106106106106 = consts::DRM_FOURCC_AXBXGXRX106106106106,
+ Ayuv = consts::DRM_FOURCC_AYUV,
+ Bgr233 = consts::DRM_FOURCC_BGR233,
+ Bgr565 = consts::DRM_FOURCC_BGR565,
+ Bgr565_a8 = consts::DRM_FOURCC_BGR565_A8,
+ Bgr888 = consts::DRM_FOURCC_BGR888,
+ Bgr888_a8 = consts::DRM_FOURCC_BGR888_A8,
+ Bgra1010102 = consts::DRM_FOURCC_BGRA1010102,
+ Bgra4444 = consts::DRM_FOURCC_BGRA4444,
+ Bgra5551 = consts::DRM_FOURCC_BGRA5551,
+ Bgra8888 = consts::DRM_FOURCC_BGRA8888,
+ Bgrx1010102 = consts::DRM_FOURCC_BGRX1010102,
+ Bgrx4444 = consts::DRM_FOURCC_BGRX4444,
+ Bgrx5551 = consts::DRM_FOURCC_BGRX5551,
+ Bgrx8888 = consts::DRM_FOURCC_BGRX8888,
+ Bgrx8888_a8 = consts::DRM_FOURCC_BGRX8888_A8,
+ Big_endian = consts::DRM_FOURCC_BIG_ENDIAN,
+ C8 = consts::DRM_FOURCC_C8,
+ Gr1616 = consts::DRM_FOURCC_GR1616,
+ Gr88 = consts::DRM_FOURCC_GR88,
+ Nv12 = consts::DRM_FOURCC_NV12,
+ Nv15 = consts::DRM_FOURCC_NV15,
+ Nv16 = consts::DRM_FOURCC_NV16,
+ Nv21 = consts::DRM_FOURCC_NV21,
+ Nv24 = consts::DRM_FOURCC_NV24,
+ Nv42 = consts::DRM_FOURCC_NV42,
+ Nv61 = consts::DRM_FOURCC_NV61,
+ P010 = consts::DRM_FOURCC_P010,
+ P012 = consts::DRM_FOURCC_P012,
+ P016 = consts::DRM_FOURCC_P016,
+ P210 = consts::DRM_FOURCC_P210,
+ Q401 = consts::DRM_FOURCC_Q401,
+ Q410 = consts::DRM_FOURCC_Q410,
+ R16 = consts::DRM_FOURCC_R16,
+ R8 = consts::DRM_FOURCC_R8,
+ Rg1616 = consts::DRM_FOURCC_RG1616,
+ Rg88 = consts::DRM_FOURCC_RG88,
+ Rgb332 = consts::DRM_FOURCC_RGB332,
+ Rgb565 = consts::DRM_FOURCC_RGB565,
+ Rgb565_a8 = consts::DRM_FOURCC_RGB565_A8,
+ Rgb888 = consts::DRM_FOURCC_RGB888,
+ Rgb888_a8 = consts::DRM_FOURCC_RGB888_A8,
+ Rgba1010102 = consts::DRM_FOURCC_RGBA1010102,
+ Rgba4444 = consts::DRM_FOURCC_RGBA4444,
+ Rgba5551 = consts::DRM_FOURCC_RGBA5551,
+ Rgba8888 = consts::DRM_FOURCC_RGBA8888,
+ Rgbx1010102 = consts::DRM_FOURCC_RGBX1010102,
+ Rgbx4444 = consts::DRM_FOURCC_RGBX4444,
+ Rgbx5551 = consts::DRM_FOURCC_RGBX5551,
+ Rgbx8888 = consts::DRM_FOURCC_RGBX8888,
+ Rgbx8888_a8 = consts::DRM_FOURCC_RGBX8888_A8,
+ Uyvy = consts::DRM_FOURCC_UYVY,
+ Vuy101010 = consts::DRM_FOURCC_VUY101010,
+ Vuy888 = consts::DRM_FOURCC_VUY888,
+ Vyuy = consts::DRM_FOURCC_VYUY,
+ X0l0 = consts::DRM_FOURCC_X0L0,
+ X0l2 = consts::DRM_FOURCC_X0L2,
+ Xbgr1555 = consts::DRM_FOURCC_XBGR1555,
+ Xbgr16161616f = consts::DRM_FOURCC_XBGR16161616F,
+ Xbgr2101010 = consts::DRM_FOURCC_XBGR2101010,
+ Xbgr4444 = consts::DRM_FOURCC_XBGR4444,
+ Xbgr8888 = consts::DRM_FOURCC_XBGR8888,
+ Xbgr8888_a8 = consts::DRM_FOURCC_XBGR8888_A8,
+ Xrgb1555 = consts::DRM_FOURCC_XRGB1555,
+ Xrgb16161616f = consts::DRM_FOURCC_XRGB16161616F,
+ Xrgb2101010 = consts::DRM_FOURCC_XRGB2101010,
+ Xrgb4444 = consts::DRM_FOURCC_XRGB4444,
+ Xrgb8888 = consts::DRM_FOURCC_XRGB8888,
+ Xrgb8888_a8 = consts::DRM_FOURCC_XRGB8888_A8,
+ Xvyu12_16161616 = consts::DRM_FOURCC_XVYU12_16161616,
+ Xvyu16161616 = consts::DRM_FOURCC_XVYU16161616,
+ Xvyu2101010 = consts::DRM_FOURCC_XVYU2101010,
+ Xyuv8888 = consts::DRM_FOURCC_XYUV8888,
+ Y0l0 = consts::DRM_FOURCC_Y0L0,
+ Y0l2 = consts::DRM_FOURCC_Y0L2,
+ Y210 = consts::DRM_FOURCC_Y210,
+ Y212 = consts::DRM_FOURCC_Y212,
+ Y216 = consts::DRM_FOURCC_Y216,
+ Y410 = consts::DRM_FOURCC_Y410,
+ Y412 = consts::DRM_FOURCC_Y412,
+ Y416 = consts::DRM_FOURCC_Y416,
+ Yuv410 = consts::DRM_FOURCC_YUV410,
+ Yuv411 = consts::DRM_FOURCC_YUV411,
+ Yuv420 = consts::DRM_FOURCC_YUV420,
+ Yuv420_10bit = consts::DRM_FOURCC_YUV420_10BIT,
+ Yuv420_8bit = consts::DRM_FOURCC_YUV420_8BIT,
+ Yuv422 = consts::DRM_FOURCC_YUV422,
+ Yuv444 = consts::DRM_FOURCC_YUV444,
+ Yuyv = consts::DRM_FOURCC_YUYV,
+ Yvu410 = consts::DRM_FOURCC_YVU410,
+ Yvu411 = consts::DRM_FOURCC_YVU411,
+ Yvu420 = consts::DRM_FOURCC_YVU420,
+ Yvu422 = consts::DRM_FOURCC_YVU422,
+ Yvu444 = consts::DRM_FOURCC_YVU444,
+ Yvyu = consts::DRM_FOURCC_YVYU,
+}
+impl DrmFourcc {
+ pub(crate) fn from_u32(n: u32) -> Option<Self> {
+ match n {
+ consts::DRM_FOURCC_ABGR1555 => Some(Self::Abgr1555),
+ consts::DRM_FOURCC_ABGR16161616F => Some(Self::Abgr16161616f),
+ consts::DRM_FOURCC_ABGR2101010 => Some(Self::Abgr2101010),
+ consts::DRM_FOURCC_ABGR4444 => Some(Self::Abgr4444),
+ consts::DRM_FOURCC_ABGR8888 => Some(Self::Abgr8888),
+ consts::DRM_FOURCC_ARGB1555 => Some(Self::Argb1555),
+ consts::DRM_FOURCC_ARGB16161616F => Some(Self::Argb16161616f),
+ consts::DRM_FOURCC_ARGB2101010 => Some(Self::Argb2101010),
+ consts::DRM_FOURCC_ARGB4444 => Some(Self::Argb4444),
+ consts::DRM_FOURCC_ARGB8888 => Some(Self::Argb8888),
+ consts::DRM_FOURCC_AXBXGXRX106106106106 => Some(Self::Axbxgxrx106106106106),
+ consts::DRM_FOURCC_AYUV => Some(Self::Ayuv),
+ consts::DRM_FOURCC_BGR233 => Some(Self::Bgr233),
+ consts::DRM_FOURCC_BGR565 => Some(Self::Bgr565),
+ consts::DRM_FOURCC_BGR565_A8 => Some(Self::Bgr565_a8),
+ consts::DRM_FOURCC_BGR888 => Some(Self::Bgr888),
+ consts::DRM_FOURCC_BGR888_A8 => Some(Self::Bgr888_a8),
+ consts::DRM_FOURCC_BGRA1010102 => Some(Self::Bgra1010102),
+ consts::DRM_FOURCC_BGRA4444 => Some(Self::Bgra4444),
+ consts::DRM_FOURCC_BGRA5551 => Some(Self::Bgra5551),
+ consts::DRM_FOURCC_BGRA8888 => Some(Self::Bgra8888),
+ consts::DRM_FOURCC_BGRX1010102 => Some(Self::Bgrx1010102),
+ consts::DRM_FOURCC_BGRX4444 => Some(Self::Bgrx4444),
+ consts::DRM_FOURCC_BGRX5551 => Some(Self::Bgrx5551),
+ consts::DRM_FOURCC_BGRX8888 => Some(Self::Bgrx8888),
+ consts::DRM_FOURCC_BGRX8888_A8 => Some(Self::Bgrx8888_a8),
+ consts::DRM_FOURCC_BIG_ENDIAN => Some(Self::Big_endian),
+ consts::DRM_FOURCC_C8 => Some(Self::C8),
+ consts::DRM_FOURCC_GR1616 => Some(Self::Gr1616),
+ consts::DRM_FOURCC_GR88 => Some(Self::Gr88),
+ consts::DRM_FOURCC_NV12 => Some(Self::Nv12),
+ consts::DRM_FOURCC_NV15 => Some(Self::Nv15),
+ consts::DRM_FOURCC_NV16 => Some(Self::Nv16),
+ consts::DRM_FOURCC_NV21 => Some(Self::Nv21),
+ consts::DRM_FOURCC_NV24 => Some(Self::Nv24),
+ consts::DRM_FOURCC_NV42 => Some(Self::Nv42),
+ consts::DRM_FOURCC_NV61 => Some(Self::Nv61),
+ consts::DRM_FOURCC_P010 => Some(Self::P010),
+ consts::DRM_FOURCC_P012 => Some(Self::P012),
+ consts::DRM_FOURCC_P016 => Some(Self::P016),
+ consts::DRM_FOURCC_P210 => Some(Self::P210),
+ consts::DRM_FOURCC_Q401 => Some(Self::Q401),
+ consts::DRM_FOURCC_Q410 => Some(Self::Q410),
+ consts::DRM_FOURCC_R16 => Some(Self::R16),
+ consts::DRM_FOURCC_R8 => Some(Self::R8),
+ consts::DRM_FOURCC_RG1616 => Some(Self::Rg1616),
+ consts::DRM_FOURCC_RG88 => Some(Self::Rg88),
+ consts::DRM_FOURCC_RGB332 => Some(Self::Rgb332),
+ consts::DRM_FOURCC_RGB565 => Some(Self::Rgb565),
+ consts::DRM_FOURCC_RGB565_A8 => Some(Self::Rgb565_a8),
+ consts::DRM_FOURCC_RGB888 => Some(Self::Rgb888),
+ consts::DRM_FOURCC_RGB888_A8 => Some(Self::Rgb888_a8),
+ consts::DRM_FOURCC_RGBA1010102 => Some(Self::Rgba1010102),
+ consts::DRM_FOURCC_RGBA4444 => Some(Self::Rgba4444),
+ consts::DRM_FOURCC_RGBA5551 => Some(Self::Rgba5551),
+ consts::DRM_FOURCC_RGBA8888 => Some(Self::Rgba8888),
+ consts::DRM_FOURCC_RGBX1010102 => Some(Self::Rgbx1010102),
+ consts::DRM_FOURCC_RGBX4444 => Some(Self::Rgbx4444),
+ consts::DRM_FOURCC_RGBX5551 => Some(Self::Rgbx5551),
+ consts::DRM_FOURCC_RGBX8888 => Some(Self::Rgbx8888),
+ consts::DRM_FOURCC_RGBX8888_A8 => Some(Self::Rgbx8888_a8),
+ consts::DRM_FOURCC_UYVY => Some(Self::Uyvy),
+ consts::DRM_FOURCC_VUY101010 => Some(Self::Vuy101010),
+ consts::DRM_FOURCC_VUY888 => Some(Self::Vuy888),
+ consts::DRM_FOURCC_VYUY => Some(Self::Vyuy),
+ consts::DRM_FOURCC_X0L0 => Some(Self::X0l0),
+ consts::DRM_FOURCC_X0L2 => Some(Self::X0l2),
+ consts::DRM_FOURCC_XBGR1555 => Some(Self::Xbgr1555),
+ consts::DRM_FOURCC_XBGR16161616F => Some(Self::Xbgr16161616f),
+ consts::DRM_FOURCC_XBGR2101010 => Some(Self::Xbgr2101010),
+ consts::DRM_FOURCC_XBGR4444 => Some(Self::Xbgr4444),
+ consts::DRM_FOURCC_XBGR8888 => Some(Self::Xbgr8888),
+ consts::DRM_FOURCC_XBGR8888_A8 => Some(Self::Xbgr8888_a8),
+ consts::DRM_FOURCC_XRGB1555 => Some(Self::Xrgb1555),
+ consts::DRM_FOURCC_XRGB16161616F => Some(Self::Xrgb16161616f),
+ consts::DRM_FOURCC_XRGB2101010 => Some(Self::Xrgb2101010),
+ consts::DRM_FOURCC_XRGB4444 => Some(Self::Xrgb4444),
+ consts::DRM_FOURCC_XRGB8888 => Some(Self::Xrgb8888),
+ consts::DRM_FOURCC_XRGB8888_A8 => Some(Self::Xrgb8888_a8),
+ consts::DRM_FOURCC_XVYU12_16161616 => Some(Self::Xvyu12_16161616),
+ consts::DRM_FOURCC_XVYU16161616 => Some(Self::Xvyu16161616),
+ consts::DRM_FOURCC_XVYU2101010 => Some(Self::Xvyu2101010),
+ consts::DRM_FOURCC_XYUV8888 => Some(Self::Xyuv8888),
+ consts::DRM_FOURCC_Y0L0 => Some(Self::Y0l0),
+ consts::DRM_FOURCC_Y0L2 => Some(Self::Y0l2),
+ consts::DRM_FOURCC_Y210 => Some(Self::Y210),
+ consts::DRM_FOURCC_Y212 => Some(Self::Y212),
+ consts::DRM_FOURCC_Y216 => Some(Self::Y216),
+ consts::DRM_FOURCC_Y410 => Some(Self::Y410),
+ consts::DRM_FOURCC_Y412 => Some(Self::Y412),
+ consts::DRM_FOURCC_Y416 => Some(Self::Y416),
+ consts::DRM_FOURCC_YUV410 => Some(Self::Yuv410),
+ consts::DRM_FOURCC_YUV411 => Some(Self::Yuv411),
+ consts::DRM_FOURCC_YUV420 => Some(Self::Yuv420),
+ consts::DRM_FOURCC_YUV420_10BIT => Some(Self::Yuv420_10bit),
+ consts::DRM_FOURCC_YUV420_8BIT => Some(Self::Yuv420_8bit),
+ consts::DRM_FOURCC_YUV422 => Some(Self::Yuv422),
+ consts::DRM_FOURCC_YUV444 => Some(Self::Yuv444),
+ consts::DRM_FOURCC_YUYV => Some(Self::Yuyv),
+ consts::DRM_FOURCC_YVU410 => Some(Self::Yvu410),
+ consts::DRM_FOURCC_YVU411 => Some(Self::Yvu411),
+ consts::DRM_FOURCC_YVU420 => Some(Self::Yvu420),
+ consts::DRM_FOURCC_YVU422 => Some(Self::Yvu422),
+ consts::DRM_FOURCC_YVU444 => Some(Self::Yvu444),
+ consts::DRM_FOURCC_YVYU => Some(Self::Yvyu),
+ _ => None,
+ }
+ }
+}
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+#[repr(u8)]
+pub enum DrmVendor {
+ Allwinner = consts::DRM_FOURCC_ALLWINNER,
+ Amd = consts::DRM_FOURCC_AMD,
+ Amlogic = consts::DRM_FOURCC_AMLOGIC,
+ Arm = consts::DRM_FOURCC_ARM,
+ Broadcom = consts::DRM_FOURCC_BROADCOM,
+ Intel = consts::DRM_FOURCC_INTEL,
+ Nvidia = consts::DRM_FOURCC_NVIDIA,
+ Qcom = consts::DRM_FOURCC_QCOM,
+ Samsung = consts::DRM_FOURCC_SAMSUNG,
+ Vivante = consts::DRM_FOURCC_VIVANTE,
+}
+impl DrmVendor {
+ pub(crate) fn from_u8(n: u8) -> Option<Self> {
+ match n {
+ consts::DRM_FOURCC_ALLWINNER => Some(Self::Allwinner),
+ consts::DRM_FOURCC_AMD => Some(Self::Amd),
+ consts::DRM_FOURCC_AMLOGIC => Some(Self::Amlogic),
+ consts::DRM_FOURCC_ARM => Some(Self::Arm),
+ consts::DRM_FOURCC_BROADCOM => Some(Self::Broadcom),
+ consts::DRM_FOURCC_INTEL => Some(Self::Intel),
+ consts::DRM_FOURCC_NVIDIA => Some(Self::Nvidia),
+ consts::DRM_FOURCC_QCOM => Some(Self::Qcom),
+ consts::DRM_FOURCC_SAMSUNG => Some(Self::Samsung),
+ consts::DRM_FOURCC_VIVANTE => Some(Self::Vivante),
+ _ => None,
+ }
+ }
+}
+#[derive(Debug, Copy, Clone)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub enum DrmModifier {
+ Allwinner_tiled,
+ Broadcom_sand128,
+ Broadcom_sand256,
+ Broadcom_sand32,
+ Broadcom_sand64,
+ Broadcom_uif,
+ Broadcom_vc4_t_tiled,
+ Generic_16_16_tile,
+ Invalid,
+ Linear,
+ Nvidia_16bx2_block_eight_gob,
+ Nvidia_16bx2_block_four_gob,
+ Nvidia_16bx2_block_one_gob,
+ Nvidia_16bx2_block_sixteen_gob,
+ Nvidia_16bx2_block_thirtytwo_gob,
+ Nvidia_16bx2_block_two_gob,
+ Nvidia_tegra_tiled,
+ Qcom_compressed,
+ Samsung_16_16_tile,
+ Samsung_64_32_tile,
+ Vivante_split_super_tiled,
+ Vivante_split_tiled,
+ Vivante_super_tiled,
+ Vivante_tiled,
+ I915_x_tiled,
+ I915_y_tiled,
+ I915_y_tiled_ccs,
+ I915_y_tiled_gen12_mc_ccs,
+ I915_y_tiled_gen12_rc_ccs,
+ Unrecognized(u64),
+}
+impl DrmModifier {
+ pub(crate) fn from_u64(n: u64) -> Self {
+ #[allow(unreachable_patterns)]
+ match n {
+ consts::DRM_FOURCC_ALLWINNER_TILED => Self::Allwinner_tiled,
+ consts::DRM_FOURCC_BROADCOM_SAND128 => Self::Broadcom_sand128,
+ consts::DRM_FOURCC_BROADCOM_SAND256 => Self::Broadcom_sand256,
+ consts::DRM_FOURCC_BROADCOM_SAND32 => Self::Broadcom_sand32,
+ consts::DRM_FOURCC_BROADCOM_SAND64 => Self::Broadcom_sand64,
+ consts::DRM_FOURCC_BROADCOM_UIF => Self::Broadcom_uif,
+ consts::DRM_FOURCC_BROADCOM_VC4_T_TILED => Self::Broadcom_vc4_t_tiled,
+ consts::DRM_FOURCC_GENERIC_16_16_TILE => Self::Generic_16_16_tile,
+ consts::DRM_FOURCC_INVALID => Self::Invalid,
+ consts::DRM_FOURCC_LINEAR => Self::Linear,
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_EIGHT_GOB => Self::Nvidia_16bx2_block_eight_gob,
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_FOUR_GOB => Self::Nvidia_16bx2_block_four_gob,
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_ONE_GOB => Self::Nvidia_16bx2_block_one_gob,
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB => {
+ Self::Nvidia_16bx2_block_sixteen_gob
+ }
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB => {
+ Self::Nvidia_16bx2_block_thirtytwo_gob
+ }
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_TWO_GOB => Self::Nvidia_16bx2_block_two_gob,
+ consts::DRM_FOURCC_NVIDIA_TEGRA_TILED => Self::Nvidia_tegra_tiled,
+ consts::DRM_FOURCC_QCOM_COMPRESSED => Self::Qcom_compressed,
+ consts::DRM_FOURCC_SAMSUNG_16_16_TILE => Self::Samsung_16_16_tile,
+ consts::DRM_FOURCC_SAMSUNG_64_32_TILE => Self::Samsung_64_32_tile,
+ consts::DRM_FOURCC_VIVANTE_SPLIT_SUPER_TILED => Self::Vivante_split_super_tiled,
+ consts::DRM_FOURCC_VIVANTE_SPLIT_TILED => Self::Vivante_split_tiled,
+ consts::DRM_FOURCC_VIVANTE_SUPER_TILED => Self::Vivante_super_tiled,
+ consts::DRM_FOURCC_VIVANTE_TILED => Self::Vivante_tiled,
+ consts::DRM_FOURCC_I915_X_TILED => Self::I915_x_tiled,
+ consts::DRM_FOURCC_I915_Y_TILED => Self::I915_y_tiled,
+ consts::DRM_FOURCC_I915_Y_TILED_CCS => Self::I915_y_tiled_ccs,
+ consts::DRM_FOURCC_I915_Y_TILED_GEN12_MC_CCS => Self::I915_y_tiled_gen12_mc_ccs,
+ consts::DRM_FOURCC_I915_Y_TILED_GEN12_RC_CCS => Self::I915_y_tiled_gen12_rc_ccs,
+ x => Self::Unrecognized(x),
+ }
+ }
+ pub(crate) fn into_u64(self) -> u64 {
+ match self {
+ Self::Allwinner_tiled => consts::DRM_FOURCC_ALLWINNER_TILED,
+ Self::Broadcom_sand128 => consts::DRM_FOURCC_BROADCOM_SAND128,
+ Self::Broadcom_sand256 => consts::DRM_FOURCC_BROADCOM_SAND256,
+ Self::Broadcom_sand32 => consts::DRM_FOURCC_BROADCOM_SAND32,
+ Self::Broadcom_sand64 => consts::DRM_FOURCC_BROADCOM_SAND64,
+ Self::Broadcom_uif => consts::DRM_FOURCC_BROADCOM_UIF,
+ Self::Broadcom_vc4_t_tiled => consts::DRM_FOURCC_BROADCOM_VC4_T_TILED,
+ Self::Generic_16_16_tile => consts::DRM_FOURCC_GENERIC_16_16_TILE,
+ Self::Invalid => consts::DRM_FOURCC_INVALID,
+ Self::Linear => consts::DRM_FOURCC_LINEAR,
+ Self::Nvidia_16bx2_block_eight_gob => consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_EIGHT_GOB,
+ Self::Nvidia_16bx2_block_four_gob => consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_FOUR_GOB,
+ Self::Nvidia_16bx2_block_one_gob => consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_ONE_GOB,
+ Self::Nvidia_16bx2_block_sixteen_gob => {
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB
+ }
+ Self::Nvidia_16bx2_block_thirtytwo_gob => {
+ consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB
+ }
+ Self::Nvidia_16bx2_block_two_gob => consts::DRM_FOURCC_NVIDIA_16BX2_BLOCK_TWO_GOB,
+ Self::Nvidia_tegra_tiled => consts::DRM_FOURCC_NVIDIA_TEGRA_TILED,
+ Self::Qcom_compressed => consts::DRM_FOURCC_QCOM_COMPRESSED,
+ Self::Samsung_16_16_tile => consts::DRM_FOURCC_SAMSUNG_16_16_TILE,
+ Self::Samsung_64_32_tile => consts::DRM_FOURCC_SAMSUNG_64_32_TILE,
+ Self::Vivante_split_super_tiled => consts::DRM_FOURCC_VIVANTE_SPLIT_SUPER_TILED,
+ Self::Vivante_split_tiled => consts::DRM_FOURCC_VIVANTE_SPLIT_TILED,
+ Self::Vivante_super_tiled => consts::DRM_FOURCC_VIVANTE_SUPER_TILED,
+ Self::Vivante_tiled => consts::DRM_FOURCC_VIVANTE_TILED,
+ Self::I915_x_tiled => consts::DRM_FOURCC_I915_X_TILED,
+ Self::I915_y_tiled => consts::DRM_FOURCC_I915_Y_TILED,
+ Self::I915_y_tiled_ccs => consts::DRM_FOURCC_I915_Y_TILED_CCS,
+ Self::I915_y_tiled_gen12_mc_ccs => consts::DRM_FOURCC_I915_Y_TILED_GEN12_MC_CCS,
+ Self::I915_y_tiled_gen12_rc_ccs => consts::DRM_FOURCC_I915_Y_TILED_GEN12_RC_CCS,
+ Self::Unrecognized(x) => x,
+ }
+ }
+}
diff --git a/src/consts.rs b/src/consts.rs
new file mode 100644
index 0000000..a9aef01
--- /dev/null
+++ b/src/consts.rs
@@ -0,0 +1,149 @@
+/* automatically generated by rust-bindgen 0.57.0 */
+
+pub type __uint8_t = crate::_fake_ctypes::c_uchar;
+pub type __uint32_t = crate::_fake_ctypes::c_uint;
+pub type __uint64_t = crate::_fake_ctypes::c_ulong;
+pub const DRM_FOURCC_ABGR1555: u32 = 892420673;
+pub const DRM_FOURCC_ABGR16161616F: u32 = 1211384385;
+pub const DRM_FOURCC_ABGR2101010: u32 = 808665665;
+pub const DRM_FOURCC_ABGR4444: u32 = 842089025;
+pub const DRM_FOURCC_ABGR8888: u32 = 875708993;
+pub const DRM_FOURCC_ARGB1555: u32 = 892424769;
+pub const DRM_FOURCC_ARGB16161616F: u32 = 1211388481;
+pub const DRM_FOURCC_ARGB2101010: u32 = 808669761;
+pub const DRM_FOURCC_ARGB4444: u32 = 842093121;
+pub const DRM_FOURCC_ARGB8888: u32 = 875713089;
+pub const DRM_FOURCC_AXBXGXRX106106106106: u32 = 808534593;
+pub const DRM_FOURCC_AYUV: u32 = 1448433985;
+pub const DRM_FOURCC_BGR233: u32 = 944916290;
+pub const DRM_FOURCC_BGR565: u32 = 909199170;
+pub const DRM_FOURCC_BGR565_A8: u32 = 943797570;
+pub const DRM_FOURCC_BGR888: u32 = 875710274;
+pub const DRM_FOURCC_BGR888_A8: u32 = 943798338;
+pub const DRM_FOURCC_BGRA1010102: u32 = 808665410;
+pub const DRM_FOURCC_BGRA4444: u32 = 842088770;
+pub const DRM_FOURCC_BGRA5551: u32 = 892420418;
+pub const DRM_FOURCC_BGRA8888: u32 = 875708738;
+pub const DRM_FOURCC_BGRX1010102: u32 = 808671298;
+pub const DRM_FOURCC_BGRX4444: u32 = 842094658;
+pub const DRM_FOURCC_BGRX5551: u32 = 892426306;
+pub const DRM_FOURCC_BGRX8888: u32 = 875714626;
+pub const DRM_FOURCC_BGRX8888_A8: u32 = 943806530;
+pub const DRM_FOURCC_BIG_ENDIAN: u32 = 2147483648;
+pub const DRM_FOURCC_C8: u32 = 538982467;
+pub const DRM_FOURCC_GR1616: u32 = 842224199;
+pub const DRM_FOURCC_GR88: u32 = 943215175;
+pub const DRM_FOURCC_NV12: u32 = 842094158;
+pub const DRM_FOURCC_NV15: u32 = 892425806;
+pub const DRM_FOURCC_NV16: u32 = 909203022;
+pub const DRM_FOURCC_NV21: u32 = 825382478;
+pub const DRM_FOURCC_NV24: u32 = 875714126;
+pub const DRM_FOURCC_NV42: u32 = 842290766;
+pub const DRM_FOURCC_NV61: u32 = 825644622;
+pub const DRM_FOURCC_P010: u32 = 808530000;
+pub const DRM_FOURCC_P012: u32 = 842084432;
+pub const DRM_FOURCC_P016: u32 = 909193296;
+pub const DRM_FOURCC_P210: u32 = 808530512;
+pub const DRM_FOURCC_Q401: u32 = 825242705;
+pub const DRM_FOURCC_Q410: u32 = 808531025;
+pub const DRM_FOURCC_R16: u32 = 540422482;
+pub const DRM_FOURCC_R8: u32 = 538982482;
+pub const DRM_FOURCC_RG1616: u32 = 842221394;
+pub const DRM_FOURCC_RG88: u32 = 943212370;
+pub const DRM_FOURCC_RGB332: u32 = 943867730;
+pub const DRM_FOURCC_RGB565: u32 = 909199186;
+pub const DRM_FOURCC_RGB565_A8: u32 = 943797586;
+pub const DRM_FOURCC_RGB888: u32 = 875710290;
+pub const DRM_FOURCC_RGB888_A8: u32 = 943798354;
+pub const DRM_FOURCC_RGBA1010102: u32 = 808665426;
+pub const DRM_FOURCC_RGBA4444: u32 = 842088786;
+pub const DRM_FOURCC_RGBA5551: u32 = 892420434;
+pub const DRM_FOURCC_RGBA8888: u32 = 875708754;
+pub const DRM_FOURCC_RGBX1010102: u32 = 808671314;
+pub const DRM_FOURCC_RGBX4444: u32 = 842094674;
+pub const DRM_FOURCC_RGBX5551: u32 = 892426322;
+pub const DRM_FOURCC_RGBX8888: u32 = 875714642;
+pub const DRM_FOURCC_RGBX8888_A8: u32 = 943806546;
+pub const DRM_FOURCC_UYVY: u32 = 1498831189;
+pub const DRM_FOURCC_VUY101010: u32 = 808670550;
+pub const DRM_FOURCC_VUY888: u32 = 875713878;
+pub const DRM_FOURCC_VYUY: u32 = 1498765654;
+pub const DRM_FOURCC_X0L0: u32 = 810299480;
+pub const DRM_FOURCC_X0L2: u32 = 843853912;
+pub const DRM_FOURCC_XBGR1555: u32 = 892420696;
+pub const DRM_FOURCC_XBGR16161616F: u32 = 1211384408;
+pub const DRM_FOURCC_XBGR2101010: u32 = 808665688;
+pub const DRM_FOURCC_XBGR4444: u32 = 842089048;
+pub const DRM_FOURCC_XBGR8888: u32 = 875709016;
+pub const DRM_FOURCC_XBGR8888_A8: u32 = 943800920;
+pub const DRM_FOURCC_XRGB1555: u32 = 892424792;
+pub const DRM_FOURCC_XRGB16161616F: u32 = 1211388504;
+pub const DRM_FOURCC_XRGB2101010: u32 = 808669784;
+pub const DRM_FOURCC_XRGB4444: u32 = 842093144;
+pub const DRM_FOURCC_XRGB8888: u32 = 875713112;
+pub const DRM_FOURCC_XRGB8888_A8: u32 = 943805016;
+pub const DRM_FOURCC_XVYU12_16161616: u32 = 909334104;
+pub const DRM_FOURCC_XVYU16161616: u32 = 942954072;
+pub const DRM_FOURCC_XVYU2101010: u32 = 808670808;
+pub const DRM_FOURCC_XYUV8888: u32 = 1448434008;
+pub const DRM_FOURCC_Y0L0: u32 = 810299481;
+pub const DRM_FOURCC_Y0L2: u32 = 843853913;
+pub const DRM_FOURCC_Y210: u32 = 808530521;
+pub const DRM_FOURCC_Y212: u32 = 842084953;
+pub const DRM_FOURCC_Y216: u32 = 909193817;
+pub const DRM_FOURCC_Y410: u32 = 808531033;
+pub const DRM_FOURCC_Y412: u32 = 842085465;
+pub const DRM_FOURCC_Y416: u32 = 909194329;
+pub const DRM_FOURCC_YUV410: u32 = 961959257;
+pub const DRM_FOURCC_YUV411: u32 = 825316697;
+pub const DRM_FOURCC_YUV420: u32 = 842093913;
+pub const DRM_FOURCC_YUV420_10BIT: u32 = 808539481;
+pub const DRM_FOURCC_YUV420_8BIT: u32 = 942691673;
+pub const DRM_FOURCC_YUV422: u32 = 909202777;
+pub const DRM_FOURCC_YUV444: u32 = 875713881;
+pub const DRM_FOURCC_YUYV: u32 = 1448695129;
+pub const DRM_FOURCC_YVU410: u32 = 961893977;
+pub const DRM_FOURCC_YVU411: u32 = 825316953;
+pub const DRM_FOURCC_YVU420: u32 = 842094169;
+pub const DRM_FOURCC_YVU422: u32 = 909203033;
+pub const DRM_FOURCC_YVU444: u32 = 875714137;
+pub const DRM_FOURCC_YVYU: u32 = 1431918169;
+pub const DRM_FOURCC_ALLWINNER: u8 = 9;
+pub const DRM_FOURCC_AMD: u8 = 2;
+pub const DRM_FOURCC_AMLOGIC: u8 = 10;
+pub const DRM_FOURCC_ARM: u8 = 8;
+pub const DRM_FOURCC_BROADCOM: u8 = 7;
+pub const DRM_FOURCC_INTEL: u8 = 1;
+pub const DRM_FOURCC_NVIDIA: u8 = 3;
+pub const DRM_FOURCC_QCOM: u8 = 5;
+pub const DRM_FOURCC_SAMSUNG: u8 = 4;
+pub const DRM_FOURCC_VIVANTE: u8 = 6;
+pub const DRM_FOURCC_ALLWINNER_TILED: u64 = 648518346341351425;
+pub const DRM_FOURCC_BROADCOM_SAND128: u64 = 504403158265495556;
+pub const DRM_FOURCC_BROADCOM_SAND256: u64 = 504403158265495557;
+pub const DRM_FOURCC_BROADCOM_SAND32: u64 = 504403158265495554;
+pub const DRM_FOURCC_BROADCOM_SAND64: u64 = 504403158265495555;
+pub const DRM_FOURCC_BROADCOM_UIF: u64 = 504403158265495558;
+pub const DRM_FOURCC_BROADCOM_VC4_T_TILED: u64 = 504403158265495553;
+pub const DRM_FOURCC_GENERIC_16_16_TILE: u64 = 288230376151711746;
+pub const DRM_FOURCC_INVALID: u64 = 72057594037927935;
+pub const DRM_FOURCC_LINEAR: u64 = 0;
+pub const DRM_FOURCC_NVIDIA_16BX2_BLOCK_EIGHT_GOB: u64 = 216172782113783827;
+pub const DRM_FOURCC_NVIDIA_16BX2_BLOCK_FOUR_GOB: u64 = 216172782113783826;
+pub const DRM_FOURCC_NVIDIA_16BX2_BLOCK_ONE_GOB: u64 = 216172782113783824;
+pub const DRM_FOURCC_NVIDIA_16BX2_BLOCK_SIXTEEN_GOB: u64 = 216172782113783828;
+pub const DRM_FOURCC_NVIDIA_16BX2_BLOCK_THIRTYTWO_GOB: u64 = 216172782113783829;
+pub const DRM_FOURCC_NVIDIA_16BX2_BLOCK_TWO_GOB: u64 = 216172782113783825;
+pub const DRM_FOURCC_NVIDIA_TEGRA_TILED: u64 = 216172782113783809;
+pub const DRM_FOURCC_QCOM_COMPRESSED: u64 = 360287970189639681;
+pub const DRM_FOURCC_SAMSUNG_16_16_TILE: u64 = 288230376151711746;
+pub const DRM_FOURCC_SAMSUNG_64_32_TILE: u64 = 288230376151711745;
+pub const DRM_FOURCC_VIVANTE_SPLIT_SUPER_TILED: u64 = 432345564227567620;
+pub const DRM_FOURCC_VIVANTE_SPLIT_TILED: u64 = 432345564227567619;
+pub const DRM_FOURCC_VIVANTE_SUPER_TILED: u64 = 432345564227567618;
+pub const DRM_FOURCC_VIVANTE_TILED: u64 = 432345564227567617;
+pub const DRM_FOURCC_I915_X_TILED: u64 = 72057594037927937;
+pub const DRM_FOURCC_I915_Y_TILED: u64 = 72057594037927938;
+pub const DRM_FOURCC_I915_Y_TILED_CCS: u64 = 72057594037927940;
+pub const DRM_FOURCC_I915_Y_TILED_GEN12_MC_CCS: u64 = 72057594037927943;
+pub const DRM_FOURCC_I915_Y_TILED_GEN12_RC_CCS: u64 = 72057594037927942;
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..addb978
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,438 @@
+#![allow(non_camel_case_types)]
+#![warn(clippy::cargo)]
+#![cfg_attr(not(feature = "std"), no_std)]
+
+//! [`DrmFourcc`] is an enum representing every pixel format supported by DRM
+//! (as of kernel version 5.10.0).
+//!
+//! A [fourcc][fourcc_wiki] is four bytes of ascii representing some data format. This enum contains
+//! every fourcc representing a pixel format supported by [DRM][drm_wiki], the Linux Direct
+//! Rendering Manager. The names of pixel formats generally provide clues as to
+//! how they work, for more information you may find
+//! [this guide][drm_format_guide] helpful.
+//!
+//! To get the bytes of the fourcc representing the format, cast to `u32`.
+//!
+//! ```
+//! # use drm_fourcc::DrmFourcc;
+//! assert_eq!(DrmFourcc::Xrgb8888 as u32, 875713112);
+//! ```
+//!
+//! To get the string form of the fourcc, use [`ToString::to_string`].
+//!
+//! ```
+//! # use drm_fourcc::DrmFourcc;
+//! assert_eq!(DrmFourcc::Xrgb8888.to_string(), "XR24");
+//! ```
+//!
+//!
+//! We also provide a type for representing a fourcc/modifier pair
+//!
+//! ```
+//! # use drm_fourcc::{DrmFormat, DrmFourcc, DrmModifier};
+//! let format = DrmFormat {
+//! code: DrmFourcc::Xrgb8888,
+//! modifier: DrmModifier::Linear,
+//! };
+//! ```
+//!
+//! The enums are autogenerated from the [canonical list][canonical] in the Linux source code.
+//!
+//! ## Features
+//! - `serde` - Derive Serialize/Deserialize where it makes sense
+//! - `build_bindings` - Re-generate autogenerated code. Useful if you need varients added in a
+//! more recent kernel version.
+//!
+//! [fourcc_wiki]: https://en.wikipedia.org/wiki/FourCC
+//! [drm_wiki]: https://en.wikipedia.org/wiki/Direct_Rendering_Managerz
+//! [canonical]: https://github.com/torvalds/linux/blame/master/include/uapi/drm/drm_fourcc.h
+//! [drm_format_guide]: https://afrantzis.com/pixel-format-guide/drm.html
+use core::convert::TryFrom;
+use core::fmt;
+use core::fmt::{Debug, Display, Formatter};
+use core::hash::{Hash, Hasher};
+
+#[cfg(feature = "std")]
+use std::string::{String, ToString};
+
+#[cfg(feature = "std")]
+use std::error::Error;
+
+pub use as_enum::{DrmFourcc, DrmModifier, DrmVendor};
+
+mod as_enum;
+mod consts;
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct DrmFormat {
+ pub code: DrmFourcc,
+ pub modifier: DrmModifier,
+}
+
+impl DrmFourcc {
+ /// Get the string representation of the format's fourcc.
+ #[cfg(feature = "std")]
+ #[deprecated(since = "2.2.0", note = "Use `ToString::to_string` instead")]
+ pub fn string_form(&self) -> String {
+ self.display_form().to_string()
+ }
+
+ // Internal helper to clarify it always has Display.
+ fn display_form(&self) -> impl Display + Debug {
+ fourcc_display_form(*self as u32).expect("Must be valid fourcc")
+ }
+}
+
+impl Debug for DrmFourcc {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ f.debug_tuple("DrmFourcc")
+ .field(&self.display_form())
+ .finish()
+ }
+}
+
+impl Display for DrmFourcc {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ Display::fmt(&self.display_form(), f)
+ }
+}
+
+impl TryFrom<u32> for DrmFourcc {
+ type Error = UnrecognizedFourcc;
+
+ /// Convert from an u32
+ ///
+ #[cfg_attr(feature = "std", doc = "```")]
+ #[cfg_attr(not(feature = "std"), doc = "```ignore")]
+ /// # use drm_fourcc::DrmFourcc;
+ /// # use std::convert::TryFrom;
+ /// assert_eq!(DrmFourcc::try_from(875710274).unwrap(), DrmFourcc::Bgr888);
+ ///
+ /// assert!(DrmFourcc::try_from(0).is_err());
+ ///
+ /// // If the u32 is in the valid format to be a fourcc, you can see its string form
+ /// assert_eq!(DrmFourcc::try_from(828601953).unwrap_err().string_form(), Some("avc1".to_string()));
+ /// ```
+ fn try_from(value: u32) -> Result<Self, Self::Error> {
+ Self::from_u32(value).ok_or(UnrecognizedFourcc(value))
+ }
+}
+
+/// Wraps some u32 that isn't a DRM fourcc we recognize
+///
+#[cfg_attr(feature = "std", doc = "```")]
+#[cfg_attr(not(feature = "std"), doc = "```ignore")]
+/// # use drm_fourcc::{DrmFourcc, UnrecognizedFourcc};
+/// # use std::convert::TryFrom;
+/// // Get the u32
+/// assert_eq!(UnrecognizedFourcc(42).0, 42);
+///
+/// // Get the string form
+/// assert_eq!(UnrecognizedFourcc(828601953).string_form(), Some("avc1".to_string()));
+/// assert_eq!(UnrecognizedFourcc(0).string_form(), None);
+/// ```
+#[derive(Copy, Clone, Eq, PartialEq)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct UnrecognizedFourcc(pub u32);
+
+impl UnrecognizedFourcc {
+ /// If the u32 is in a valid format to be a fourcc, get its string form.
+ ///
+ /// Note that this requires the `std` feature to be enabled. The [`display`] method is an
+ /// alternative that does not require this dependency.
+ #[cfg(feature = "std")]
+ pub fn string_form(&self) -> Option<String> {
+ fourcc_string_form(self.0)
+ }
+
+ /// If the u32 is in a valid format to be a fourcc, get an opaque type to display it.
+ ///
+ /// This can be treated as a slightly generalized form of [`string_form`] that is also
+ /// available when the crate does not depend on the standard or `alloc` crate.
+ ///
+ /// ```
+ /// # use drm_fourcc::UnrecognizedFourcc;
+ /// assert!(UnrecognizedFourcc(828601953).display().is_some());
+ /// assert!(UnrecognizedFourcc(0).display().is_none());
+ /// ```
+ pub fn display(&self) -> Option<impl Display> {
+ fourcc_display_form(self.0)
+ }
+}
+
+impl Debug for UnrecognizedFourcc {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ let mut debug = &mut f.debug_tuple("UnrecognizedFourcc");
+
+ if let Some(string_form) = fourcc_display_form(self.0) {
+ debug = debug.field(&string_form);
+ }
+
+ debug.field(&self.0).finish()
+ }
+}
+
+impl Display for UnrecognizedFourcc {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ Debug::fmt(&self, f)
+ }
+}
+
+#[cfg(feature = "std")]
+impl Error for UnrecognizedFourcc {}
+
+#[cfg(feature = "std")]
+fn fourcc_string_form(fourcc: u32) -> Option<String> {
+ fourcc_display_form(fourcc).map(|val| val.to_string())
+}
+
+fn fourcc_display_form(fourcc: u32) -> Option<impl Display + Debug> {
+ let raw_bytes = fourcc.to_le_bytes();
+ let mut chars = ::core::str::from_utf8(&raw_bytes).ok()?.chars();
+
+ let first = chars.next().unwrap();
+ let second = chars.next().unwrap();
+
+ // first two bytes must be characters
+ for char in [first, second].iter().copied() {
+ if !char.is_ascii_alphanumeric() {
+ return None;
+ }
+ }
+
+ let mut bytes = raw_bytes;
+ // Bytes in tail are allowed to be NUL
+ for byte in &mut bytes[4 - chars.as_str().len()..] {
+ if *byte == b'\0' {
+ *byte = b' ';
+ }
+ }
+
+ /// A pre-formatted string representing a valid FourCC format.
+ ///
+ /// This differs from the byte representation only in that NUL-characters beyond the leading
+ /// two have been replaced by spaces.
+ struct FormatFourccRaw {
+ bytes: [u8; 4],
+ }
+
+ impl Display for FormatFourccRaw {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let chars = ::core::str::from_utf8(&self.bytes[..]).expect("validated previously");
+ f.write_str(chars)
+ }
+ }
+
+ impl Debug for FormatFourccRaw {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ Display::fmt(self, f)
+ }
+ }
+
+ Some(FormatFourccRaw { bytes })
+}
+
+impl TryFrom<u8> for DrmVendor {
+ type Error = UnrecognizedVendor;
+
+ /// Convert from an u8
+ ///
+ /// ```
+ /// # use drm_fourcc::DrmVendor;
+ /// # use std::convert::TryFrom;
+ /// assert_eq!(DrmVendor::try_from(2).unwrap(), DrmVendor::Amd);
+ ///
+ /// assert!(DrmVendor::try_from(0).is_err());
+ /// ```
+ fn try_from(value: u8) -> Result<Self, Self::Error> {
+ Self::from_u8(value).ok_or(UnrecognizedVendor(value))
+ }
+}
+
+/// Wraps some u8 that isn't a DRM vendor we recognize
+///
+/// ```
+/// # use drm_fourcc::{DrmVendor, UnrecognizedVendor};
+/// # use std::convert::TryFrom;
+/// // Get the u8
+/// assert_eq!(UnrecognizedVendor(42).0, 42);
+/// ```
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct UnrecognizedVendor(pub u8);
+
+impl Display for UnrecognizedVendor {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ Debug::fmt(&self, f)
+ }
+}
+
+#[cfg(feature = "std")]
+impl Error for UnrecognizedVendor {}
+
+impl From<u64> for DrmModifier {
+ /// Convert from an u64
+ ///
+ /// ```
+ /// # use drm_fourcc::DrmModifier;
+ /// assert_eq!(DrmModifier::from(0), DrmModifier::Linear);
+ /// ```
+ fn from(value: u64) -> Self {
+ Self::from_u64(value)
+ }
+}
+
+/// Wraps some u64 that isn't a DRM modifier we recognize
+///
+/// ```
+/// # use drm_fourcc::{DrmModifier, UnrecognizedModifier};
+/// # use std::convert::TryFrom;
+/// // Get the u64
+/// assert_eq!(UnrecognizedModifier(42).0, 42);
+/// ```
+#[derive(Debug, Copy, Clone, Eq, PartialEq)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct UnrecognizedModifier(pub u64);
+
+impl Display for UnrecognizedModifier {
+ fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+ Debug::fmt(&self, f)
+ }
+}
+
+#[cfg(feature = "std")]
+impl Error for UnrecognizedModifier {}
+
+impl UnrecognizedModifier {
+ /// Get the vendor of the unrecognized modifier, if any
+ ///
+ /// ```
+ /// # use drm_fourcc::{DrmModifier, DrmVendor, UnrecognizedModifier, UnrecognizedVendor};
+ /// assert_eq!(UnrecognizedModifier(216172782113783827).vendor(), Ok(Some(DrmVendor::Nvidia)));
+ /// assert_eq!(UnrecognizedModifier(2).vendor(), Ok(None));
+ /// assert_eq!(UnrecognizedModifier(8646911284551352320).vendor(), Err(UnrecognizedVendor(120)));
+ /// ```
+ pub fn vendor(&self) -> Result<Option<DrmVendor>, UnrecognizedVendor> {
+ let vendor = (self.0 >> 56) as u8;
+ if vendor == 0 {
+ Ok(None)
+ } else {
+ DrmVendor::try_from(vendor).map(Some)
+ }
+ }
+}
+
+impl From<DrmModifier> for u64 {
+ /// Convert to an u64
+ ///
+ /// ```
+ /// # use drm_fourcc::DrmModifier;
+ /// assert_eq!(0u64, DrmModifier::Linear.into());
+ /// ```
+ fn from(val: DrmModifier) -> u64 {
+ val.into_u64()
+ }
+}
+
+impl PartialEq for DrmModifier {
+ fn eq(&self, other: &Self) -> bool {
+ self.into_u64() == other.into_u64()
+ }
+}
+impl Eq for DrmModifier {}
+
+impl PartialEq<u64> for DrmModifier {
+ fn eq(&self, other: &u64) -> bool {
+ &self.into_u64() == other
+ }
+}
+
+impl Hash for DrmModifier {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.into_u64().hash(state);
+ }
+}
+
+impl DrmModifier {
+ /// Get the vendor of the modifier, if any
+ ///
+ /// ```
+ /// # use drm_fourcc::{DrmModifier, DrmVendor, UnrecognizedVendor};
+ /// assert_eq!(DrmModifier::I915_x_tiled.vendor(), Ok(Some(DrmVendor::Intel)));
+ /// assert_eq!(DrmModifier::Linear.vendor(), Ok(None));
+ /// assert_eq!(DrmModifier::Unrecognized(8646911284551352320).vendor(), Err(UnrecognizedVendor(120)));
+ /// ```
+ pub fn vendor(&self) -> Result<Option<DrmVendor>, UnrecognizedVendor> {
+ let vendor = (self.into_u64() >> 56) as u8;
+ if vendor == 0 {
+ Ok(None)
+ } else {
+ DrmVendor::try_from(vendor).map(Some)
+ }
+ }
+}
+
+// Bindgen will always insert `use` statements for these types even though we seriously never use
+// them in normal compilation. Instead, we only use fixed-size types that translate to pure Rust
+// types.
+#[allow(dead_code)]
+pub(crate) mod _fake_ctypes {
+ pub struct c_uchar;
+ pub struct c_uint;
+ pub struct c_ulong;
+}
+
+#[cfg(test)]
+pub mod tests {
+ use super::*;
+
+ #[test]
+ fn a_specific_var_has_correct_value() {
+ assert_eq!(consts::DRM_FOURCC_AYUV, 1448433985);
+ }
+
+ #[test]
+ fn enum_member_casts_to_const() {
+ assert_eq!(
+ DrmFourcc::Xrgb8888 as u32,
+ consts::DRM_FOURCC_XRGB8888 as u32
+ );
+ }
+
+ #[test]
+ #[cfg(feature = "std")]
+ fn enum_member_has_correct_string_format() {
+ assert_eq!(DrmFourcc::Xrgb8888.to_string(), "XR24");
+ }
+
+ #[test]
+ #[cfg(feature = "std")]
+ fn fourcc_string_form_handles_valid() {
+ assert_eq!(fourcc_string_form(875713112).unwrap(), "XR24");
+ assert_eq!(fourcc_string_form(828601953).unwrap(), "avc1");
+ assert_eq!(fourcc_string_form(0x316376).unwrap(), "vc1 ");
+ }
+
+ #[test]
+ #[cfg(feature = "std")]
+ fn unrecognized_handles_valid_fourcc() {
+ assert_eq!(
+ UnrecognizedFourcc(828601953).to_string(),
+ "UnrecognizedFourcc(avc1, 828601953)"
+ );
+ }
+
+ #[test]
+ #[cfg(feature = "std")]
+ fn unrecognized_handles_invalid_fourcc() {
+ assert_eq!(UnrecognizedFourcc(0).to_string(), "UnrecognizedFourcc(0)");
+ }
+
+ #[test]
+ fn can_clone_result() {
+ let a = DrmFourcc::try_from(0);
+ let b = a;
+ assert_eq!(a, b);
+ }
+}