mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
init
This commit is contained in:
13
libs/hwcodec/dev/tool/Cargo.toml
Normal file
13
libs/hwcodec/dev/tool/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "tool"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
log = "0.4"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
bindgen = "0.59"
|
||||
39
libs/hwcodec/dev/tool/build.rs
Normal file
39
libs/hwcodec/dev/tool/build.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
use cc::Build;
|
||||
use std::{
|
||||
env,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
fn main() {
|
||||
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
println!("cargo:rerun-if-changed=src");
|
||||
let ffi_header = "src/tool_ffi.h";
|
||||
bindgen::builder()
|
||||
.header(ffi_header)
|
||||
.rustified_enum("*")
|
||||
.generate()
|
||||
.unwrap()
|
||||
.write_to_file(Path::new(&env::var_os("OUT_DIR").unwrap()).join("tool_ffi.rs"))
|
||||
.unwrap();
|
||||
|
||||
let mut builder = Build::new();
|
||||
|
||||
builder.include(
|
||||
manifest_dir
|
||||
.parent()
|
||||
.unwrap()
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join("cpp")
|
||||
.join("common"),
|
||||
);
|
||||
|
||||
builder.file("src/tool.cpp");
|
||||
|
||||
// crate
|
||||
builder
|
||||
.cpp(false)
|
||||
.static_crt(true)
|
||||
.warnings(false)
|
||||
.compile("tool");
|
||||
}
|
||||
44
libs/hwcodec/dev/tool/src/lib.rs
Normal file
44
libs/hwcodec/dev/tool/src/lib.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
#![allow(non_upper_case_globals)]
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::os::raw::c_void;
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/tool_ffi.rs"));
|
||||
|
||||
pub struct Tool {
|
||||
inner: *mut c_void,
|
||||
}
|
||||
|
||||
impl Tool {
|
||||
pub fn new(luid: i64) -> Result<Self, ()> {
|
||||
let inner = unsafe { tool_new(luid) };
|
||||
if inner.is_null() {
|
||||
Err(())
|
||||
} else {
|
||||
Ok(Self { inner })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn device(&mut self) -> *mut c_void {
|
||||
unsafe { tool_device(self.inner) }
|
||||
}
|
||||
|
||||
pub fn get_texture(&mut self, width: i32, height: i32) -> *mut c_void {
|
||||
unsafe { tool_get_texture(self.inner, width, height) }
|
||||
}
|
||||
|
||||
pub fn get_texture_size(&mut self, texture: *mut c_void) -> (i32, i32) {
|
||||
let mut width = 0;
|
||||
let mut height = 0;
|
||||
unsafe { tool_get_texture_size(self.inner, texture, &mut width, &mut height) }
|
||||
(width, height)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Tool {
|
||||
fn drop(&mut self) {
|
||||
unsafe { tool_destroy(self.inner) }
|
||||
self.inner = std::ptr::null_mut();
|
||||
}
|
||||
}
|
||||
67
libs/hwcodec/dev/tool/src/tool.cpp
Normal file
67
libs/hwcodec/dev/tool/src/tool.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <memory.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "system.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class Tool {
|
||||
public:
|
||||
std::unique_ptr<NativeDevice> native_;
|
||||
bool initialized_ = false;
|
||||
|
||||
public:
|
||||
Tool(int64_t luid) {
|
||||
native_ = std::make_unique<NativeDevice>();
|
||||
initialized_ = native_->Init(luid, nullptr, 1);
|
||||
}
|
||||
|
||||
ID3D11Texture2D *GetTexture(int width, int height) {
|
||||
native_->EnsureTexture(width, height);
|
||||
return native_->GetCurrentTexture();
|
||||
}
|
||||
|
||||
void getSize(ID3D11Texture2D *texture, int *width, int *height) {
|
||||
D3D11_TEXTURE2D_DESC desc;
|
||||
texture->GetDesc(&desc);
|
||||
*width = desc.Width;
|
||||
*height = desc.Height;
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
extern "C" {
|
||||
|
||||
void *tool_new(int64_t luid) {
|
||||
Tool *t = new Tool(luid);
|
||||
if (t && !t->initialized_) {
|
||||
delete t;
|
||||
return nullptr;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void *tool_device(void *tool) {
|
||||
Tool *t = (Tool *)tool;
|
||||
return t->native_->device_.Get();
|
||||
}
|
||||
|
||||
void *tool_get_texture(void *tool, int width, int height) {
|
||||
Tool *t = (Tool *)tool;
|
||||
return t->GetTexture(width, height);
|
||||
}
|
||||
|
||||
void tool_get_texture_size(void *tool, void *texture, int *width, int *height) {
|
||||
Tool *t = (Tool *)tool;
|
||||
t->getSize((ID3D11Texture2D *)texture, width, height);
|
||||
}
|
||||
|
||||
void tool_destroy(void *tool) {
|
||||
Tool *t = (Tool *)tool;
|
||||
if (t) {
|
||||
delete t;
|
||||
t = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
12
libs/hwcodec/dev/tool/src/tool_ffi.h
Normal file
12
libs/hwcodec/dev/tool/src/tool_ffi.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef TOOL_FFI_H
|
||||
#define TOOL_FFI_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void *tool_new(int64_t luid);
|
||||
void *tool_device(void *tool);
|
||||
void *tool_get_texture(void *tool, int width, int height);
|
||||
void tool_get_texture_size(void *tool, void *texture, int *width, int *height);
|
||||
void tool_destroy(void *tool);
|
||||
|
||||
#endif // TOOL_FFI_H
|
||||
Reference in New Issue
Block a user