Skip to content

Commit 96ead7d

Browse files
committed
fix possible rendering edge cases
1 parent 7ecb18d commit 96ead7d

File tree

3 files changed

+223
-78
lines changed

3 files changed

+223
-78
lines changed

NativeApp/include/Android/AndroidAppBase.hpp

Lines changed: 66 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@
1212
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1313
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
1414
*
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
1717
* 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
2323
* of the possibility of such damages.
2424
*/
2525

2626
#pragma once
2727

2828
#include <memory>
29+
#include <mutex>
2930

3031
#include <android_native_app_glue.h>
32+
#include <FlagEnum.h>
3133
#include "AppBase.hpp"
3234

3335
#include "NDKHelper.h"
@@ -38,62 +40,92 @@ namespace Diligent
3840
{
3941

4042
/// Base class for Android applications.
41-
class AndroidAppBase : public AppBase
42-
{
43+
class AndroidAppBase : public AppBase {
4344
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);
5462

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;
5580
protected:
56-
virtual void Initialize()
57-
{
81+
virtual void Initialize() {
5882
}
5983

60-
virtual int Resume(ANativeWindow* window) = 0;
84+
virtual int Resume(ANativeWindow *window) = 0;
6185

62-
virtual int32_t HandleInput(AInputEvent* event) { return 0; }
86+
virtual int32_t HandleInput(AInputEvent *event) { return 0; }
6387

64-
virtual void LoadResources()
65-
{
88+
virtual void LoadResources() {
6689
//renderer_.Init();
6790
//renderer_.Bind( &tap_camera_ );
6891
}
6992

70-
virtual void UnloadResources()
71-
{
93+
virtual void UnloadResources() {
7294
//renderer_.Unload();
7395
}
7496

7597
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_;
79101

80102
//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;
83107

84108
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+
86111
void SuspendSensors();
112+
87113
void ResumeSensors();
114+
88115
void ShowUI();
116+
89117
void UpdateFPS(float fFPS);
90118

91119
bool initialized_resources_ = false;
92-
bool has_focus_ = false;
120+
121+
int32_t window_width_ = 0;
122+
int32_t window_height_ = 0;
93123

94124
ASensorManager* sensor_manager_ = nullptr;
95125
const ASensor* accelerometer_sensor_ = nullptr;
96126
ASensorEventQueue* sensor_event_queue_ = nullptr;
97127
};
98128

129+
DEFINE_FLAG_ENUM_OPERATORS(AndroidAppBase::APP_STATUS_FLAGS)
130+
99131
} // namespace Diligent

0 commit comments

Comments
 (0)