-
Notifications
You must be signed in to change notification settings - Fork 0
/
android_native_test_app.cpp
54 lines (41 loc) · 1.27 KB
/
android_native_test_app.cpp
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
#include "san_activity.hpp"
class app : public san::android::activity_base {
public:
app() {} // Main (GUI) thread!
virtual ~app() {}
void on_start() override {}
void on_stop() override {}
void on_redraw() override { on_idle(); }
void on_window_init( ANativeWindow * p_window ) override {
ANativeWindow_setBuffersGeometry( p_window, 0, 0, WINDOW_FORMAT_RGBX_8888 );
}
void on_window_term() override {}
bool on_input_event( const AInputEvent * p_event ) override {
quit();
return true; // Is event handled?
}
void on_idle() override {
ANativeWindow_Buffer buffer;
if ( ANativeWindow_lock( get_window(), &buffer, nullptr ) < 0 ) {
LOG( "Unable to lock window buffer" );
return;
}
static bool is_first_frame = false;
if ( !is_first_frame ) {
LOG( "w = %d, h = %d, s = %d\n", buffer.width, buffer.height, buffer.stride );
is_first_frame = true;
}
static uint32_t c = 0;
for ( int i = 0; i < buffer.stride * buffer.height; ++i ) {
static_cast<uint32_t *>( buffer.bits )[i] = c;
}
c += 0x01020304;
ANativeWindow_unlockAndPost( get_window() );
}
};
namespace san::android {
activity_base * main( ANativeActivity * p_activity, void * p_preempted_state, size_t zu_preempted_state_size ) {
static app a;
return &a;
}
} // namespace san::android