Skip to content

Commit 34c1bf9

Browse files
committed
Merge branch 'danylo_system' into baw
2 parents 64ea0bc + a75c840 commit 34c1bf9

File tree

11 files changed

+124
-16
lines changed

11 files changed

+124
-16
lines changed

examples_tests/common/CommonAPI.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,13 @@ class CommonAPI
392392
#ifdef _NBL_PLATFORM_WINDOWS_
393393
caller = nbl::core::make_smart_refctd_ptr<nbl::system::CSystemCallerWin32>();
394394
#endif
395-
return nbl::core::make_smart_refctd_ptr<nbl::system::ISystem>(std::move(caller));
395+
#ifdef _NBL_PLATFORM_WINDOWS_
396+
return nbl::core::make_smart_refctd_ptr<nbl::system::CSystemWin32>(std::move(caller));
397+
#elif defined(_NBL_PLATFORM_ANDROID_)
398+
return nbl::core::make_smart_refctd_ptr<nbl::system::CSystemAndroid>(std::move(caller));
399+
#else
400+
return nullptr;
401+
#endif
396402
}
397403

398404
// Used to help with queue selection

include/nbl/system/CSystemWin32.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef _NBL_SYSTEM_CSYSTEMWIN32_H_INCLUDED_
22
#define _NBL_SYSTEM_CSYSTEMWIN32_H_INCLUDED_
33
#ifdef _NBL_PLATFORM_WINDOWS_
4+
#include <windows.h>
5+
#include <powerbase.h>
46
#include "ISystem.h"
57
#include "CFileWin32.h"
68

@@ -22,7 +24,31 @@ class CSystemCallerWin32 final : public ISystemCaller
2224

2325
class CSystemWin32 : public ISystem
2426
{
27+
public:
28+
CSystemWin32(core::smart_refctd_ptr<ISystemCaller>&& caller) : ISystem(std::move(caller)) {}
29+
//LOL the struct definition wasn't added to winapi headers do they ask to declare them yourself
30+
typedef struct _PROCESSOR_POWER_INFORMATION {
31+
ULONG Number;
32+
ULONG MaxMhz;
33+
ULONG CurrentMhz;
34+
ULONG MhzLimit;
35+
ULONG MaxIdleState;
36+
ULONG CurrentIdleState;
37+
} PROCESSOR_POWER_INFORMATION, * PPROCESSOR_POWER_INFORMATION;
2538

39+
SystemInfo getSystemInfo() const override
40+
{
41+
SystemInfo info;
42+
LARGE_INTEGER speed;
43+
QueryPerformanceFrequency(&speed);
44+
45+
info.cpuFrequency = speed.QuadPart;
46+
47+
info.desktopResX = GetSystemMetrics(SM_CXSCREEN);
48+
info.desktopResY = GetSystemMetrics(SM_CYSCREEN);
49+
50+
return info;
51+
}
2652
};
2753

2854
}

include/nbl/system/IApplicationFramework.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,35 @@ class IApplicationFramework : public core::IReferenceCounted
4141
virtual void onAppInitialized_impl() {}
4242
virtual void onAppTerminated_impl() {}
4343

44-
system::path localInputCWD, localOutputCWD, sharedInputCWD, sharedOutputCWD;
44+
/*
45+
****************** Current Working Directories ********************
46+
Each Nabla app has 4 pre-defined working directories. You can change them to your liking.
47+
*******************************************************************
48+
*/
49+
50+
51+
/*
52+
This is a CWD which is used for reading app-local assets.
53+
Do NOT try writing to this path if you wan't your app to work on Android because on Android this CWD is located inside a readonly APK archive.
54+
55+
To add files to your assets directory, create an "assets" directory in your app's source directory
56+
*/
57+
system::path localInputCWD;
58+
59+
/*
60+
This is a CWD used to output app-local data e.g. screenshots
61+
*/
62+
system::path localOutputCWD;
63+
64+
/*
65+
The CWD for input data that can be shared among apps, like the "examples_tests/media" directory for Nabla examples
66+
*/
67+
system::path sharedInputCWD;
68+
69+
/*
70+
This CWD is used to output data that can be shared between apps e.g. quantization cache
71+
*/
72+
system::path sharedOutputCWD;
4573
};
4674

4775
}

include/nbl/system/ISystem.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,17 @@ class ISystem : public core::IReferenceCounted
521521

522522
return systemMemory;
523523
}
524+
525+
struct SystemInfo
526+
{
527+
uint64_t cpuFrequency;
528+
//TODO others
529+
530+
uint32_t desktopResX;
531+
uint32_t desktopResY;
532+
std::string OSFullName;
533+
};
534+
virtual SystemInfo getSystemInfo() const = 0;
524535
};
525536

526537
template<typename T>

include/nbl/ui/CClipboardManagerWin32.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ class CClipboardManagerWin32 final : public IClipboardManager
99
{
1010
using base_t = IClipboardManager;
1111
public:
12-
CClipboardManagerWin32(core::smart_refctd_ptr<system::ISystem>&& sys) : base_t(std::move(sys))
13-
{
14-
15-
}
12+
CClipboardManagerWin32() = default;
1613
virtual std::string getClipboardText() override;
1714
virtual bool setClipboardText(const std::string_view& data) override;
18-
virtual core::smart_refctd_ptr<asset::ICPUImage> getClipboardImage() override;
19-
virtual bool setClipboardImage(asset::ICPUImage* image, asset::ICPUImage::SImageCopy data) override;
15+
//virtual core::smart_refctd_ptr<asset::ICPUImage> getClipboardImage() override;
16+
//virtual bool setClipboardImage(asset::ICPUImage* image, asset::ICPUImage::SImageCopy data) override;
2017
private:
2118
HGLOBAL* CPUImageToClipboardImage(asset::ICPUImage* image);
2219
};

include/nbl/ui/CWindowWin32.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44

55
#include "nbl/ui/IWindowWin32.h"
6+
#include "nbl/ui/CClipboardManagerWin32.h"
67

78
#include <queue>
89

@@ -36,6 +37,7 @@ class CWindowWin32 final : public IWindowWin32
3637
core::map<HANDLE, core::smart_refctd_ptr<IKeyboardEventChannel>> m_keyboardEventChannels;
3738

3839
core::smart_refctd_ptr<CCursorControlWin32> m_cursorControl;
40+
core::smart_refctd_ptr<CClipboardManagerWin32> m_clipboardManager;
3941

4042
/*
4143
* Storing this data is required for the device removal to work properly

include/nbl/ui/IClipboardManager.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ class IClipboardManager : public core::IReferenceCounted
2121
};
2222
virtual std::string getClipboardText() = 0;
2323
virtual bool setClipboardText(const std::string_view& data) = 0;
24-
virtual core::smart_refctd_ptr<asset::ICPUImage> getClipboardImage() = 0;
25-
virtual bool setClipboardImage(asset::ICPUImage* image, const SImageClipboardRegion& data) = 0;
24+
// virtual core::smart_refctd_ptr<asset::ICPUImage> getClipboardImage() = 0;
25+
// virtual bool setClipboardImage(asset::ICPUImage* image, const SImageClipboardRegion& data) = 0;
2626

2727
virtual ~IClipboardManager() = default;
2828

2929
protected:
30-
IClipboardManager(core::smart_refctd_ptr<system::ISystem>&& sys) : m_sys(std::move(sys)) {}
31-
32-
core::smart_refctd_ptr<system::ISystem> m_sys;
30+
IClipboardManager() = default;
3331
};
3432

3533
}

src/nbl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ set(NBL_UI_SOURCES
193193
${NBL_ROOT_PATH}/src/nbl/ui/CWindowWayland.cpp
194194
${NBL_ROOT_PATH}/src/nbl/ui/CWaylandCaller.cpp
195195
${NBL_ROOT_PATH}/src/nbl/ui/CCursorControlWin32.cpp
196+
${NBL_ROOT_PATH}/src/nbl/ui/CClipboardManagerWin32.cpp
196197
${NBL_ROOT_PATH}/src/nbl/ui/CWindowManagerAndroid.cpp
197198
${NBL_ROOT_PATH}/src/nbl/ui/CGraphicalApplicationAndroid.cpp
198199
)

src/nbl/system/CSystemWin32.cpp

Whitespace-only changes.

src/nbl/ui/CClipboardManagerWin32.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include "nbl/ui/CClipboardManagerWin32.h"
2+
#include <Windows.h>
3+
namespace nbl::ui
4+
{
5+
6+
std::string CClipboardManagerWin32::getClipboardText()
7+
{
8+
int32_t res = OpenClipboard(0);
9+
assert(res != 0);
10+
11+
std::string data = (const char*)GetClipboardData(CF_TEXT);
12+
13+
CloseClipboard();
14+
15+
return data;
16+
}
17+
18+
bool CClipboardManagerWin32::setClipboardText(const std::string_view& str)
19+
{
20+
int32_t res = OpenClipboard(0);
21+
if (res == 0) return false;
22+
23+
EmptyClipboard();
24+
const char* data = str.data();
25+
const size_t data_size = strlen(data) + 1;
26+
HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE, data_size);
27+
strcpy((char*)GlobalLock(h), LPCSTR(data));
28+
GlobalUnlock(h);
29+
SetClipboardData(CF_TEXT, h);
30+
31+
CloseClipboard();
32+
33+
return true;
34+
}
35+
}

0 commit comments

Comments
 (0)