use jni::JNIEnv;
use yog_abi::YogStr;
use yog_gfx::{Color, Rect};
use crate::jni::call::jcall;
pub(crate) fn register(env: &mut JNIEnv, id: &str, w: u32, h: u32, rgba: &[u8]) -> bool {
let ok: Option<bool> = unsafe {
jcall!(
env,
"dev/yog/render/NativeDraw",
"registerTexture",
[
S(YogStr::from_str(id)),
I(w as i32),
I(h as i32),
Bytes(rgba)
]
)
};
ok == Some(true)
}
pub(crate) fn update(env: &mut JNIEnv, id: &str, w: u32, h: u32, rgba: &[u8]) -> bool {
let ok: Option<bool> = unsafe {
jcall!(
env,
"dev/yog/render/NativeDraw",
"updateTexture",
[
S(YogStr::from_str(id)),
I(w as i32),
I(h as i32),
Bytes(rgba)
]
)
};
ok == Some(true)
}
pub(crate) fn release(env: &mut JNIEnv, id: &str) {
let _: Option<()> = unsafe {
jcall!(
env,
"dev/yog/render/NativeDraw",
"releaseTexture",
[S(YogStr::from_str(id))]
)
};
}
pub(crate) fn draw(env: &mut JNIEnv, id: &str, size: (u32, u32), dest: Rect, tint: Color) {
let (fw, fh) = (size.0 as f32, size.1 as f32);
let Rect { x, y, w, h } = dest;
let _: Option<()> = unsafe {
jcall!(
env,
"dev/yog/render/NativeDraw",
"drawImage",
[
S(YogStr::from_str(id)),
F(x),
F(y),
F(w),
F(h),
F(0.0),
F(0.0),
F(fw),
F(fh),
F(fw),
F(fh),
I(tint.0 as i32)
]
)
};
}