1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Textures the runtime makes (rasterized SVGs, text in Yog's fonts):
//! handed to the host as dynamic textures, drawn like any other.
use jni::JNIEnv;
use yog_abi::YogStr;
use yog_gfx::{Color, Rect};
use crate::jcall::jcall;
/// Hands the host texture `id`: `w`×`h` RGBA pixels (straight alpha); whether it took it.
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/NativeDraw",
"registerTexture",
[
S(YogStr::from_str(id)),
I(w as i32),
I(h as i32),
Bytes(rgba)
]
)
};
ok == Some(true)
}
/// Replaces texture `id`'s pixels (`w`×`h` RGBA) — kept when its size is
/// the same, else made anew (a video's frame each frame); whether it took them.
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/NativeDraw",
"updateTexture",
[
S(YogStr::from_str(id)),
I(w as i32),
I(h as i32),
Bytes(rgba)
]
)
};
ok == Some(true)
}
/// Lets go of texture `id`.
pub(crate) fn release(env: &mut JNIEnv, id: &str) {
let _: Option<()> = unsafe {
jcall!(
env,
"dev/yog/NativeDraw",
"releaseTexture",
[S(YogStr::from_str(id))]
)
};
}
/// Draws the whole of texture `id` (`size` its pixels) into `dest` GUI pixels, colors times `tint`.
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/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)
]
)
};
}