12
12
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
13
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
14
14
*
15
- * In no event and under no legal theory, whether in tort (including negligence),
16
- * contract, or otherwise, unless required by applicable law (such as deliberate
15
+ * In no event and under no legal theory, whether in tort (including negligence),
16
+ * contract, or otherwise, unless required by applicable law (such as deliberate
17
17
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
18
- * liable for any damages, including any direct, indirect, special, incidental,
19
- * or consequential damages of any character arising as a result of this License or
20
- * out of the use or inability to use the software (including but not limited to damages
21
- * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
22
- * all other commercial damages or losses), even if such Contributor has been advised
18
+ * liable for any damages, including any direct, indirect, special, incidental,
19
+ * or consequential damages of any character arising as a result of this License or
20
+ * out of the use or inability to use the software (including but not limited to damages
21
+ * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
22
+ * all other commercial damages or losses), even if such Contributor has been advised
23
23
* of the possibility of such damages.
24
24
*/
25
25
26
26
#pragma once
27
27
28
28
#include < memory>
29
+ #include < mutex>
29
30
30
31
#include < android_native_app_glue.h>
32
+ #include < FlagEnum.h>
31
33
#include " AppBase.hpp"
32
34
33
35
#include " NDKHelper.h"
@@ -38,62 +40,92 @@ namespace Diligent
38
40
{
39
41
40
42
// / Base class for Android applications.
41
- class AndroidAppBase : public AppBase
42
- {
43
+ class AndroidAppBase : public AppBase {
43
44
public:
44
- int InitDisplay ();
45
- void SetState (android_app* state, const char * native_activity_class_name);
46
- void InitSensors ();
47
- void ProcessSensors (int32_t id);
48
- virtual void DrawFrame ();
49
- bool IsReady ();
50
- virtual void TrimMemory () = 0;
51
- virtual void TermDisplay () = 0;
52
- static int32_t HandleInput (android_app* app, AInputEvent* event);
53
- static void HandleCmd (android_app* app, int32_t cmd);
45
+ int InitDisplay ();
46
+
47
+ void SetState (android_app *state, const char *native_activity_class_name);
48
+
49
+ void InitSensors ();
50
+
51
+ void ProcessSensors (int32_t id);
52
+
53
+ virtual void DrawFrame ();
54
+
55
+ bool IsReady ();
56
+
57
+ virtual void TrimMemory () = 0;
58
+
59
+ virtual void TermDisplay () = 0;
60
+
61
+ static int32_t HandleInput (android_app *app, AInputEvent *event);
54
62
63
+ static void HandleCmd (android_app *app, int32_t cmd);
64
+
65
+ enum APP_STATUS_FLAGS {
66
+ APP_STATUS_FLAG_NONE = 0x00000000 ,
67
+ // Android lifecycle status flags. Not app-specific
68
+ // Set between onCreate and onDestroy
69
+ APP_STATUS_FLAG_RUNNING = 0x00000001 ,
70
+ // Set between onResume and onPause
71
+ APP_STATUS_FLAG_ACTIVE = 0x00000002 ,
72
+ // Set between onWindowFocusChanged(true) and (false)
73
+ APP_STATUS_FLAG_FOCUSED = 0x00000004 ,
74
+ // Set when the app's SurfaceHolder points to a
75
+ // valid, nonzero-sized surface
76
+ APP_STATUS_FLAG_HAS_REAL_SURFACE = 0x00000008 ,
77
+ };
78
+
79
+ APP_STATUS_FLAGS app_status_ = APP_STATUS_FLAG_NONE;
55
80
protected:
56
- virtual void Initialize ()
57
- {
81
+ virtual void Initialize () {
58
82
}
59
83
60
- virtual int Resume (ANativeWindow* window) = 0;
84
+ virtual int Resume (ANativeWindow * window) = 0;
61
85
62
- virtual int32_t HandleInput (AInputEvent* event) { return 0 ; }
86
+ virtual int32_t HandleInput (AInputEvent * event) { return 0 ; }
63
87
64
- virtual void LoadResources ()
65
- {
88
+ virtual void LoadResources () {
66
89
// renderer_.Init();
67
90
// renderer_.Bind( &tap_camera_ );
68
91
}
69
92
70
- virtual void UnloadResources ()
71
- {
93
+ virtual void UnloadResources () {
72
94
// renderer_.Unload();
73
95
}
74
96
75
97
ndk_helper::DoubletapDetector doubletap_detector_;
76
- ndk_helper::PinchDetector pinch_detector_;
77
- ndk_helper::DragDetector drag_detector_;
78
- ndk_helper::PerfMonitor monitor_;
98
+ ndk_helper::PinchDetector pinch_detector_;
99
+ ndk_helper::DragDetector drag_detector_;
100
+ ndk_helper::PerfMonitor monitor_;
79
101
80
102
// ndk_helper::TapCamera tap_camera_;
81
- android_app* app_ = nullptr ;
82
- std::string native_activity_class_name_;
103
+ android_app *app_ = nullptr ;
104
+ std::string native_activity_class_name_;
105
+
106
+ std::mutex mutex;
83
107
84
108
private:
85
- void UpdatePosition (AInputEvent* event, int32_t iIndex, float & fX , float & fY );
109
+ void UpdatePosition (AInputEvent *event, int32_t iIndex, float &fX , float &fY );
110
+
86
111
void SuspendSensors ();
112
+
87
113
void ResumeSensors ();
114
+
88
115
void ShowUI ();
116
+
89
117
void UpdateFPS (float fFPS );
90
118
91
119
bool initialized_resources_ = false ;
92
- bool has_focus_ = false ;
120
+
121
+ int32_t window_width_ = 0 ;
122
+ int32_t window_height_ = 0 ;
93
123
94
124
ASensorManager* sensor_manager_ = nullptr ;
95
125
const ASensor* accelerometer_sensor_ = nullptr ;
96
126
ASensorEventQueue* sensor_event_queue_ = nullptr ;
97
127
};
98
128
129
+ DEFINE_FLAG_ENUM_OPERATORS (AndroidAppBase::APP_STATUS_FLAGS)
130
+
99
131
} // namespace Diligent
0 commit comments