Skip to content

Commit 079334a

Browse files
reorganise Android and Linux
Also integrate most of 9d86c03
1 parent 22cc5e3 commit 079334a

File tree

7 files changed

+124
-41
lines changed

7 files changed

+124
-41
lines changed

include/nbl/system/CSystemAndroid.h

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
11
#ifndef _NBL_SYSTEM_C_SYSTEM_ANDROID_H_INCLUDED_
22
#define _NBL_SYSTEM_C_SYSTEM_ANDROID_H_INCLUDED_
33

4-
#ifdef _NBL_PLATFORM_ANDROID_
4+
55
#include "nbl/system/ISystem.h"
6-
#include "nbl/system/CAPKResourcesArchive.h"
7-
#include <android_native_app_glue.h>
8-
#include <jni.h>
6+
7+
98
namespace nbl::system
109
{
11-
class CSystemAndroid final : public ISystem
12-
{
13-
ANativeActivity* nativeActivity = nullptr;
14-
core::smart_refctd_ptr<IFileArchive> androidAssetArchive = nullptr;
15-
JNIEnv* env;
10+
#ifdef _NBL_PLATFORM_ANDROID_
11+
#include "nbl/system/ISystemPOSIX.h"
12+
13+
struct ANativeActivity;
14+
struct JNIEnv;
15+
16+
class CSystemAndroid final : public ISystemPOSIX
17+
{
18+
ANativeActivity* m_nativeActivity;
19+
JNIEnv* m_jniEnv;
1620
public:
17-
CSystemAndroid(core::smart_refctd_ptr<ISystemCaller>&& caller, ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath) :
18-
ISystem(std::move(caller)), nativeActivity(activity), env(jni)
19-
{
20-
auto archive = core::make_smart_refctd_ptr<CAPKResourcesArchive>(
21-
core::smart_refctd_ptr<ISystem>(this),
22-
nullptr,
23-
activity->assetManager,
24-
nativeActivity,
25-
env
26-
);
27-
m_cachedArchiveFiles.insert(APKResourcesPath, std::move(archive));
28-
29-
}
30-
SystemInfo getSystemInfo() const override
31-
{
32-
assert(false); // TODO: @sadiuk
33-
return SystemInfo();
34-
}
35-
};
36-
}
21+
CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath);
22+
23+
//
24+
SystemInfo getSystemInfo() const override;
25+
};
26+
3727
#endif
28+
}
3829

3930
#endif

include/nbl/system/CSystemLinux.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#ifndef _NBL_SYSTEM_C_SYSTEM_LINUX_H_INCLUDED_
22
#define _NBL_SYSTEM_C_SYSTEM_LINUX_H_INCLUDED_
3-
#ifdef _NBL_PLATFORM_LINUX_
3+
4+
45
#include "nbl/system/ISystem.h"
6+
57
namespace nbl::system
68
{
7-
class CSystemLinux : public ISystem
8-
{
9+
#ifdef _NBL_PLATFORM_LINUX_
10+
#include "nbl/system/ISystemPOSIX.h"
11+
12+
class CSystemLinux final : public ISystemPOSIX
13+
{
14+
public:
15+
CSystemLinux() : ISystemPOSIX() {}
916

10-
};
11-
}
17+
SystemInfo getSystemInfo() const override;
18+
};
1219
#endif
20+
}
21+
1322
#endif

src/nbl/system/CSystemCallerPOSIX.h renamed to include/nbl/system/ISystemPOSIX.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_
22
#define _NBL_SYSTEM_C_SYSTEM_CALLER_POSIX_INCLUDED_
33

4-
#include "ISystem.h"
4+
#include "nbl/system/ISystem.h"
55

66
namespace nbl::system
77
{
@@ -15,6 +15,8 @@ class ISystemPOSIX : public ISystem
1515
public:
1616
core::smart_refctd_ptr<IFile> createFile_impl(const std::filesystem::path& filename, core::bitflag<IFile::E_CREATE_FLAGS> flags) override final;
1717
};
18+
19+
ISystemPOSIX() : ISystem(core::make_smart_refctd_ptr<CCaller>(this)) {}
1820
};
1921
#endif
2022

src/nbl/CMakeLists.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,19 @@ set(NBL_CORE_SOURCES
189189
)
190190
set(NBL_SYSTEM_SOURCES
191191
${NBL_ROOT_PATH}/src/nbl/system/IFileBase.cpp
192-
${NBL_ROOT_PATH}/src/nbl/system/CSystemWin32.cpp
193-
${NBL_ROOT_PATH}/src/nbl/system/CFileWin32.cpp
194-
${NBL_ROOT_PATH}/src/nbl/system/CFilePOSIX.cpp
195192
${NBL_ROOT_PATH}/src/nbl/system/ILogger.cpp
196193
${NBL_ROOT_PATH}/src/nbl/system/CArchiveLoaderZip.cpp
197194
${NBL_ROOT_PATH}/src/nbl/system/CArchiveLoaderTar.cpp
198195
${NBL_ROOT_PATH}/src/nbl/system/ISystem.cpp
199196
${NBL_ROOT_PATH}/src/nbl/system/IFileArchive.cpp
197+
${NBL_ROOT_PATH}/src/nbl/system/CStdoutLoggerAndroid.cpp
200198
${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorWin32.cpp
201199
${NBL_ROOT_PATH}/src/nbl/system/CFileViewVirtualAllocatorPOSIX.cpp
202-
${NBL_ROOT_PATH}/src/nbl/system/CStdoutLoggerAndroid.cpp
200+
${NBL_ROOT_PATH}/src/nbl/system/CFileWin32.cpp
201+
${NBL_ROOT_PATH}/src/nbl/system/CFilePOSIX.cpp
202+
${NBL_ROOT_PATH}/src/nbl/system/CSystemWin32.cpp
203+
${NBL_ROOT_PATH}/src/nbl/system/CSystemAndroid.cpp
204+
${NBL_ROOT_PATH}/src/nbl/system/CSystemLinux.cpp
203205
)
204206
set(NBL_UI_SOURCES
205207
${NBL_ROOT_PATH}/src/nbl/ui/CWindowWin32.cpp

src/nbl/system/CSystemAndroid.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include "nbl/system/CSystemAndroid.h"
2+
3+
using namespace nbl::system;
4+
5+
#ifdef _NBL_PLATFORM_ANDROID_
6+
#include "nbl/system/CAPKResourcesArchive.h"
7+
8+
#include <android_native_app_glue.h>
9+
#include <jni.h>
10+
#include <sys/system_properties.h>
11+
#include <sys/ioctl.h>
12+
#include <linux/fb.h>
13+
#include <unistd.h>
14+
#include <sys/stat.h>
15+
#include <fcntl.h>
16+
17+
CSystemAndroid::CSystemAndroid(ANativeActivity* activity, JNIEnv* jni, const system::path& APKResourcesPath) :
18+
ISystemPOSIX(), m_nativeActivity(activity), m_jniEnv(jni)
19+
{
20+
addArchiveLoader(core::make_smart_refctd_ptr<CArchiveLoaderTar>(core::smart_refctd_ptr<ISystem>(this), nullptr));
21+
m_cachedArchiveFiles.insert(APKResourcesPath,core::make_smart_refctd_ptr<CAPKResourcesArchive>(
22+
core::smart_refctd_ptr<ISystem>(this),
23+
nullptr,
24+
activity->assetManager,
25+
nativeActivity,
26+
env
27+
));
28+
}
29+
30+
ISystem::SystemInfo CSystemAndroid::getSystemInfo() const
31+
{
32+
SystemInfo info;
33+
// TODO: hardcoded
34+
info.cpuFrequency = 1100;
35+
info.totalMemory = 4ull<<30ull;
36+
info.availableMemory = 2ull<<30ull;
37+
38+
struct fb_var_screeninfo fb_var;
39+
int fd = open("/dev/graphics/fb0", O_RDONLY);
40+
ioctl(fd, FBIOGET_VSCREENINFO, &fb_var);
41+
close(fd);
42+
info.desktopResX = fb_var.width;
43+
info.desktopResY = fb_var.height;
44+
45+
char sdk_ver_str[92];
46+
__system_property_get("ro.build.version.sdk", sdk_ver_str);
47+
info.OSFullName = std::string("Android ") + sdk_ver_str;
48+
49+
return info;
50+
}
51+
52+
#endif

src/nbl/system/CSystemLinux.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "nbl/system/CSystemLinux.h"
2+
3+
using namespace nbl;
4+
using namespace nbl::system;
5+
6+
#ifdef _NBL_PLATFORM_LINUX_
7+
ISystem::SystemInfo CSystemLinux::getSystemInfo() const
8+
{
9+
SystemInfo info;
10+
11+
// TODO
12+
info.cpuFrequencyHz = 3000000000u;
13+
14+
sysinfo linuxSystemInfo;
15+
sysinfo(&linuxSystemInfo);
16+
info.totalMemory = linuxSystemInfo.totalram;
17+
info.availableMemory = linuxSystemInfo.freeram;
18+
info.totalMemory *= linuxSystemInfo.mem_unit;
19+
info.availableMemory *= linuxSystemInfo.mem_unit;
20+
21+
// TODO
22+
info.desktopResX = 0xdeadbeefu;
23+
info.desktopResY = 0xdeadbeefu;
24+
25+
return info;
26+
}
27+
#endif

src/nbl/system/CSystemCallerPOSIX.cpp renamed to src/nbl/system/ISystemPOSIX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "nbl/system/CSystemCallerPOSIX.h"
1+
#include "nbl/system/ISystemPOSIX.h"
22
#include "nbl/system/CFilePOSIX.h"
33

44
using namespace nbl;
@@ -9,7 +9,7 @@ using namespace nbl::system;
99
#include <sys/mman.h>
1010
#include <sys/stat.h>
1111

12-
core::smart_refctd_ptr<IFile> ISystemPOSIX::CCaller::createFile_impl(const std::filesystem::path& filename, const core::bitflag<IFile::E_CREATE_FLAGS> flags)
12+
core::smart_refctd_ptr<ISystemFile> ISystemPOSIX::CCaller::createFile_impl(const std::filesystem::path& filename, const core::bitflag<IFile::E_CREATE_FLAGS> flags)
1313
{
1414
const bool writeAccess = flags.value&IFile::ECF_WRITE;
1515
int createFlags = O_LARGEFILE|(writeAccess ? O_CREAT:0);

0 commit comments

Comments
 (0)