Skip to content

Commit 1d7c377

Browse files
Android fixes
1 parent f956d79 commit 1d7c377

File tree

5 files changed

+75
-67
lines changed

5 files changed

+75
-67
lines changed

include/nbl/system/CApplicationAndroid.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace nbl::system
1414
#include <android/sensor.h>
1515
#include <android/log.h>
1616

17-
class CApplicationAndroid : public IApplicationFramework
17+
class CApplicationAndroid : public IApplicationFramework
1818
{
1919
public:
2020
void onStateSaved(android_app* params)

include/nbl/ui/CGraphicalApplicationAndroid.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#ifndef _NBL_UI_C_GRAPHICAL_APPLICATION_ANDROID_H_INCLUDED_
22
#define _NBL_UI_C_GRAPHICAL_APPLICATION_ANDROID_H_INCLUDED_
3-
#ifdef _NBL_PLATFORM_ANDROID_
3+
44
#include "nbl/system/CApplicationAndroid.h"
55
#include "nbl/system/CSystemAndroid.h"
6-
#include "nbl/system/CSystemLinux.h"
7-
#include "nbl/system/CSystemCallerPOSIX.h"
6+
87
#include "nbl/ui/IGraphicalApplicationFramework.h"
98
#include "nbl/ui/IWindow.h"
109
#include "nbl/ui/CWindowManagerAndroid.h"
10+
11+
#ifdef _NBL_PLATFORM_ANDROID_
1112
#include <jni.h>
1213
#include <fstream>
1314
namespace nbl::ui

include/nbl/ui/CWindowAndroid.h

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __NBL_C_WINDOW_ANDROID_H_INCLUDED__
2-
#define __NBL_C_WINDOW_ANDROID_H_INCLUDED__
1+
#ifndef _NBL_C_WINDOW_ANDROID_H_INCLUDED_
2+
#define _NBL_C_WINDOW_ANDROID_H_INCLUDED_
33

44
#include "nbl/ui/IWindowAndroid.h"
55

@@ -13,59 +13,60 @@ namespace nbl::ui
1313

1414
class CWindowAndroid : public IWindowAndroid
1515
{
16-
public:
17-
constexpr static uint32_t CIRCULAR_BUFFER_CAPACITY = 256;
18-
explicit CWindowAndroid(SCreationParams&& params, native_handle_t anw) : m_native(anw), IWindowAndroid(std::move(params))
19-
{
20-
m_width = ANativeWindow_getWidth(anw);
21-
m_height = ANativeWindow_getHeight(anw);
22-
}
16+
public:
17+
constexpr static uint32_t CIRCULAR_BUFFER_CAPACITY = 256;
18+
explicit CWindowAndroid(SCreationParams&& params, native_handle_t anw) : m_native(anw), IWindowAndroid(std::move(params))
19+
{
20+
m_width = ANativeWindow_getWidth(anw);
21+
m_height = ANativeWindow_getHeight(anw);
22+
}
23+
24+
virtual IClipboardManager* getClipboardManager() override { return nullptr; }
25+
virtual ICursorControl* getCursorControl() override { return nullptr; }
2326

24-
virtual IClipboardManager* getClipboardManager() { return nullptr; }
25-
virtual ICursorControl* getCursorControl() { return nullptr; }
26-
const native_handle_t& getNativeHandle() const override { return m_native; }
27-
void setCaption(const std::string_view& caption) override {}
28-
core::map<uint32_t, core::smart_refctd_ptr<IMouseEventChannel>> m_mouseEventChannels;
29-
core::map<uint32_t, core::smart_refctd_ptr<IKeyboardEventChannel>> m_keyboardEventChannels;
30-
bool hasMouseEventChannel(uint32_t deviceId)
31-
{
32-
return m_mouseEventChannels.find(deviceId) != m_mouseEventChannels.end();
33-
}
34-
bool hasKeyboardEventChannel(uint32_t deviceId)
35-
{
36-
return m_keyboardEventChannels.find(deviceId) != m_keyboardEventChannels.end();
37-
}
38-
bool addMouseEventChannel(uint32_t deviceId, const core::smart_refctd_ptr<IMouseEventChannel>& channel)
39-
{
40-
if (m_mouseEventChannels.find(deviceId) == m_mouseEventChannels.end())
27+
const native_handle_t& getNativeHandle() const override { return m_native; }
28+
void setCaption(const std::string_view& caption) override {}
29+
core::map<uint32_t, core::smart_refctd_ptr<IMouseEventChannel>> m_mouseEventChannels;
30+
core::map<uint32_t, core::smart_refctd_ptr<IKeyboardEventChannel>> m_keyboardEventChannels;
31+
bool hasMouseEventChannel(uint32_t deviceId)
4132
{
42-
m_mouseEventChannels.emplace(deviceId, channel);
43-
return true;
33+
return m_mouseEventChannels.find(deviceId) != m_mouseEventChannels.end();
4434
}
45-
return false;
46-
}
47-
bool addKeyboardEventChannel(uint32_t deviceId, const core::smart_refctd_ptr<IKeyboardEventChannel>& channel)
48-
{
49-
if (m_keyboardEventChannels.find(deviceId) == m_keyboardEventChannels.end())
35+
bool hasKeyboardEventChannel(uint32_t deviceId)
5036
{
51-
m_keyboardEventChannels.emplace(deviceId, channel);
52-
return true;
37+
return m_keyboardEventChannels.find(deviceId) != m_keyboardEventChannels.end();
38+
}
39+
bool addMouseEventChannel(uint32_t deviceId, const core::smart_refctd_ptr<IMouseEventChannel>& channel)
40+
{
41+
if (m_mouseEventChannels.find(deviceId) == m_mouseEventChannels.end())
42+
{
43+
m_mouseEventChannels.emplace(deviceId, channel);
44+
return true;
45+
}
46+
return false;
47+
}
48+
bool addKeyboardEventChannel(uint32_t deviceId, const core::smart_refctd_ptr<IKeyboardEventChannel>& channel)
49+
{
50+
if (m_keyboardEventChannels.find(deviceId) == m_keyboardEventChannels.end())
51+
{
52+
m_keyboardEventChannels.emplace(deviceId, channel);
53+
return true;
54+
}
55+
return false;
56+
}
57+
IMouseEventChannel* getMouseEventChannel(uint32_t deviceId)
58+
{
59+
auto ch = m_mouseEventChannels.find(deviceId);
60+
return m_mouseEventChannels.find(deviceId)->second.get();
5361
}
54-
return false;
55-
}
56-
IMouseEventChannel* getMouseEventChannel(uint32_t deviceId)
57-
{
58-
auto ch = m_mouseEventChannels.find(deviceId);
59-
return m_mouseEventChannels.find(deviceId)->second.get();
60-
}
6162

62-
IKeyboardEventChannel* getKeyboardEventChannel(uint32_t deviceId)
63-
{
64-
auto ch = m_keyboardEventChannels.find(deviceId);
65-
return m_keyboardEventChannels.find(deviceId)->second.get();
66-
}
67-
private:
68-
native_handle_t m_native;
63+
IKeyboardEventChannel* getKeyboardEventChannel(uint32_t deviceId)
64+
{
65+
auto ch = m_keyboardEventChannels.find(deviceId);
66+
return m_keyboardEventChannels.find(deviceId)->second.get();
67+
}
68+
private:
69+
native_handle_t m_native;
6970
};
7071

7172
}

include/nbl/ui/CWindowManagerAndroid.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
#ifndef _NBL_SYSTEM_C_WINDOW_MANAGER_ANDROID_H_INCLUDED_
22
#define _NBL_SYSTEM_C_WINDOW_MANAGER_ANDROID_H_INCLUDED_
3+
34
#include "nbl/ui/IWindowManager.h"
5+
#include "nbl/ui/CWindowAndroid.h"
46

57
#ifdef _NBL_PLATFORM_ANDROID_
68
#include <android_native_app_glue.h>
79
#include <android/sensor.h>
810
#include <android/log.h>
911

10-
#include "nbl/ui/CWindowAndroid.h"
11-
1212
#include <fcntl.h>
1313
#include <unistd.h>
1414
#include <sys/ioctl.h>
1515
#include <linux/fb.h>
1616

1717
namespace nbl::ui
1818
{
19-
class CWindowManagerAndroid : public IWindowManager
20-
{
19+
20+
class CWindowManagerAndroid : public IWindowManager
21+
{
2122
android_app* m_app;
2223
std::atomic_flag windowIsCreated;
2324
constexpr static uint32_t CIRCULAR_BUFFER_CAPACITY = CWindowAndroid::CIRCULAR_BUFFER_CAPACITY;
@@ -30,6 +31,7 @@ namespace nbl::ui
3031
windowIsCreated.clear();
3132
}
3233
~CWindowManagerAndroid() = default;
34+
3335
core::smart_refctd_ptr<IWindow> createWindow(IWindow::SCreationParams&& creationParams) override final
3436
{
3537
bool createdBefore = windowIsCreated.test_and_set();
@@ -39,6 +41,7 @@ namespace nbl::ui
3941
}
4042
return nullptr;
4143
}
44+
4245
SDisplayInfo getPrimaryDisplayInfo() const override final
4346
{
4447
struct fb_var_screeninfo fb_var;
@@ -53,14 +56,16 @@ namespace nbl::ui
5356
info.y = fb_var.yoffset;
5457
return info;
5558
}
59+
5660
void destroyWindow(IWindow* wnd) override final
5761
{
5862
}
63+
5964
void handleInput_impl(android_app* data, AInputEvent* event);
6065
void handleCommand_impl(android_app* app, int32_t cmd);
6166
static E_KEY_CODE getNablaKeyCodeFromNative(int32_t nativeKeyCode);
67+
};
6268

63-
};
6469
}
6570

6671
#endif

include/nbl/ui/IWindowAndroid.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __NBL_I_WINDOW_ANDROID_H_INCLUDED__
2-
#define __NBL_I_WINDOW_ANDROID_H_INCLUDED__
1+
#ifndef _NBL_I_WINDOW_ANDROID_H_INCLUDED_
2+
#define _NBL_I_WINDOW_ANDROID_H_INCLUDED_
33

44
#include "nbl/ui/IWindow.h"
55

@@ -12,15 +12,16 @@ namespace nbl::ui
1212

1313
class IWindowAndroid : public IWindow
1414
{
15-
protected:
16-
virtual ~IWindowAndroid() = default;
17-
IWindowAndroid(SCreationParams&& params) : IWindow(std::move(params)) {}
18-
public:
19-
using IWindow::IWindow;
15+
protected:
16+
virtual ~IWindowAndroid() = default;
17+
IWindowAndroid(SCreationParams&& params) : IWindow(std::move(params)) {}
2018

21-
using native_handle_t = struct ANativeWindow*;
19+
public:
20+
using IWindow::IWindow;
2221

23-
virtual const native_handle_t& getNativeHandle() const = 0;
22+
using native_handle_t = struct ANativeWindow*;
23+
24+
virtual const native_handle_t& getNativeHandle() const = 0;
2425
};
2526

2627
}

0 commit comments

Comments
 (0)