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
85
86
87
88
89
90
91
92
93
94
95
96
|
use ::raw::services::gsp;
use core::convert::From;
pub enum Event {
Psc0,
Psc1,
VBlank0,
VBlank1,
PPF,
P3D,
DMA
}
#[derive(Copy, Clone)]
pub enum FramebufferFormat {
Rgba8,
Bgr8,
Rgb565,
Rgb5A1,
Rgba4
}
impl FramebufferFormat {
pub fn pixel_depth_bytes(&self) -> usize {
use self::FramebufferFormat::*;
match *self {
Rgba8 => 4usize,
Bgr8 => 3usize,
Rgb565 => 2usize,
Rgb5A1 => 2usize,
Rgba4 => 2usize
}
}
}
impl From<gsp::GSP_FramebufferFormats> for FramebufferFormat {
#[inline] fn from(g: gsp::GSP_FramebufferFormats) -> FramebufferFormat {
use ::raw::services::gsp::GSP_FramebufferFormats::*;
use self::FramebufferFormat::*;
match g {
GSP_RGBA8_OES => Rgba8,
GSP_BGR8_OES => Bgr8,
GSP_RGB565_OES => Rgb565,
GSP_RGB5_A1_OES => Rgb5A1,
GSP_RGBA4_OES => Rgba4
}
}
}
impl From<FramebufferFormat> for gsp::GSP_FramebufferFormats {
#[inline] fn from(g: FramebufferFormat) -> gsp::GSP_FramebufferFormats {
use ::raw::services::gsp::GSP_FramebufferFormats::*;
use self::FramebufferFormat::*;
match g {
Rgba8 => GSP_RGBA8_OES,
Bgr8 => GSP_BGR8_OES,
Rgb565 => GSP_RGB565_OES,
Rgb5A1 => GSP_RGB5_A1_OES,
Rgba4 => GSP_RGBA4_OES
}
}
}
fn to_raw_event(ev: Event) -> gsp::GSP_Event {
use ::raw::services::gsp::GSP_Event::*;
use self::Event::*;
match ev {
Psc0 => GSPEVENT_PSC0,
Psc1 => GSPEVENT_PSC1,
VBlank0 => GSPEVENT_VBlank0,
VBlank1 => GSPEVENT_VBlank1,
PPF => GSPEVENT_PPF,
P3D => GSPEVENT_P3D,
DMA => GSPEVENT_DMA
}
}
/// Sleep until GSP event fires.
///
/// # Examples
///
/// Wait for VBlank.
///
/// ```
/// use ctru::services::apt;
/// apt::main_loop(|| {
/// wait_for_event(Event::VBlank0);
/// });
pub fn wait_for_event(ev: Event) -> () {
unsafe {
// TODO second argument?
gsp::gspWaitForEvent(to_raw_event(ev), 0);
}
}
|