From f228f236613792a7f7471610bf9e102d885dbae6 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Tue, 5 Dec 2017 17:20:59 -1000 Subject: [PATCH] UWP support --- CMakeLists.txt | 5 +- include/boo/IApplication.hpp | 11 +- include/boo/System.hpp | 7 ++ include/boo/graphicsdev/GL.hpp | 2 + include/boo/inputdev/DeviceBase.hpp | 2 + include/boo/inputdev/HIDParser.hpp | 4 + include/boo/inputdev/IHIDListener.hpp | 4 +- lib/audiodev/WASAPI.cpp | 134 +++++++++++++++++++- lib/graphicsdev/D3D11.cpp | 4 + lib/graphicsdev/D3D12.cpp | 4 + lib/inputdev/DeviceBase.cpp | 2 + lib/inputdev/DeviceFinder.cpp | 2 +- lib/inputdev/GenericPad.cpp | 2 + lib/inputdev/HIDDeviceUWP.cpp | 30 +++++ lib/inputdev/HIDListenerUWP.cpp | 26 ++++ lib/inputdev/HIDParser.cpp | 6 + lib/inputdev/IHIDDevice.hpp | 2 + lib/win/ApplicationUWP.cpp | 67 ++-------- lib/win/UWPCommon.hpp | 2 - lib/win/Win32Common.hpp | 4 +- lib/win/WindowUWP.cpp | 172 ++++++++++++++------------ logvisor | 2 +- test/main.cpp | 28 +++-- 23 files changed, 360 insertions(+), 162 deletions(-) create mode 100644 lib/inputdev/HIDDeviceUWP.cpp create mode 100644 lib/inputdev/HIDListenerUWP.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a0ed6e..04e7eee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,6 +37,7 @@ if(NOT GEKKO AND NOT CAFE AND NOT WINDOWS_STORE) list(APPEND PLAT_SRCS lib/graphicsdev/GL.cpp lib/graphicsdev/glew.c) +list(APPEND _BOO_SYS_DEFINES -DBOO_HAS_GL=1) list(APPEND PLAT_HDRS include/boo/graphicsdev/GLSLMacros.hpp @@ -53,8 +54,8 @@ if(WINDOWS_STORE) lib/win/WindowUWP.cpp lib/win/WinCommon.hpp lib/win/UWPCommon.hpp - lib/inputdev/HIDListenerWinUSB.cpp - lib/inputdev/HIDDeviceWinUSB.cpp + lib/inputdev/HIDListenerUWP.cpp + lib/inputdev/HIDDeviceUWP.cpp lib/graphicsdev/D3D11.cpp lib/graphicsdev/D3D12.cpp lib/audiodev/WASAPI.cpp) diff --git a/include/boo/IApplication.hpp b/include/boo/IApplication.hpp index 854c1a7..aa08db7 100644 --- a/include/boo/IApplication.hpp +++ b/include/boo/IApplication.hpp @@ -81,11 +81,12 @@ ApplicationRun(IApplication::EPlatformType platform, return ApplicationRun(platform, cb, uniqueName, friendlyName, argv[0], args, singleInstance); } -#if WINAPI_FAMILY && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP +#if WINDOWS_STORE using namespace Windows::ApplicationModel::Core; ref struct ViewProvider sealed : IFrameworkViewSource { +internal: ViewProvider(boo::IApplicationCallback& appCb, SystemStringView uniqueName, SystemStringView friendlyName, @@ -97,13 +98,15 @@ ref struct ViewProvider sealed : IFrameworkViewSource { SystemChar selfPath[1024]; GetModuleFileNameW(nullptr, selfPath, 1024); - m_args.reserve(params.size() + 1); + m_args.reserve(params->Length + 1); m_args.emplace_back(selfPath); for (Platform::String^ str : params) - m_args.emplace_back(str.Data()); + m_args.emplace_back(str->Data()); } - IFrameworkView^ CreateView(); +public: + virtual IFrameworkView^ CreateView(); +internal: boo::IApplicationCallback& m_appCb; SystemString m_uniqueName; SystemString m_friendlyName; diff --git a/include/boo/System.hpp b/include/boo/System.hpp index ff38d94..3276596 100644 --- a/include/boo/System.hpp +++ b/include/boo/System.hpp @@ -2,6 +2,13 @@ #define BOO_SYSTEM_HPP #ifdef _WIN32 +#include +#if defined(WINAPI_FAMILY) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP +#define WINDOWS_STORE 1 +#else +#define WINDOWS_STORE 0 +#endif + #include #include #include diff --git a/include/boo/graphicsdev/GL.hpp b/include/boo/graphicsdev/GL.hpp index 8cce3c9..25f2bdf 100644 --- a/include/boo/graphicsdev/GL.hpp +++ b/include/boo/graphicsdev/GL.hpp @@ -1,5 +1,6 @@ #ifndef GDEV_GL_HPP #define GDEV_GL_HPP +#if BOO_HAS_GL #include "IGraphicsDataFactory.hpp" #include "IGraphicsCommandQueue.hpp" @@ -62,4 +63,5 @@ public: } +#endif #endif // GDEV_GL_HPP diff --git a/include/boo/inputdev/DeviceBase.hpp b/include/boo/inputdev/DeviceBase.hpp index e219938..c358e31 100644 --- a/include/boo/inputdev/DeviceBase.hpp +++ b/include/boo/inputdev/DeviceBase.hpp @@ -52,7 +52,9 @@ public: /* High-Level API */ #if _WIN32 +#if !WINDOWS_STORE const PHIDP_PREPARSED_DATA getReportDescriptor(); +#endif #else std::vector getReportDescriptor(); #endif diff --git a/include/boo/inputdev/HIDParser.hpp b/include/boo/inputdev/HIDParser.hpp index 86553df..9aeb28d 100644 --- a/include/boo/inputdev/HIDParser.hpp +++ b/include/boo/inputdev/HIDParser.hpp @@ -181,9 +181,11 @@ private: ParserStatus m_status = ParserStatus::OK; #if _WIN32 +#if !WINDOWS_STORE std::vector m_itemPool; mutable std::vector m_dataList; PHIDP_PREPARSED_DATA m_descriptorData = nullptr; +#endif #else std::unique_ptr m_itemPool; using Report = std::pair>; @@ -201,7 +203,9 @@ private: public: #if _WIN32 +#if !WINDOWS_STORE ParserStatus Parse(const PHIDP_PREPARSED_DATA descriptorData); +#endif #else ParserStatus Parse(const uint8_t* descriptorData, size_t len); static size_t CalculateMaxInputReportSize(const uint8_t* descriptorData, size_t len); diff --git a/include/boo/inputdev/IHIDListener.hpp b/include/boo/inputdev/IHIDListener.hpp index 16aed35..bb5ca2f 100644 --- a/include/boo/inputdev/IHIDListener.hpp +++ b/include/boo/inputdev/IHIDListener.hpp @@ -15,7 +15,7 @@ class DeviceFinder; class IHIDListener { public: - virtual ~IHIDListener() {} + virtual ~IHIDListener() = default; /* Automatic device scanning */ virtual bool startScanning()=0; @@ -24,7 +24,7 @@ public: /* Manual device scanning */ virtual bool scanNow()=0; -#if _WIN32 +#if _WIN32 && !WINDOWS_STORE /* External listener implementation (for Windows) */ virtual bool _extDevConnect(const char* path)=0; virtual bool _extDevDisconnect(const char* path)=0; diff --git a/lib/audiodev/WASAPI.cpp b/lib/audiodev/WASAPI.cpp index 5296b16..a326196 100644 --- a/lib/audiodev/WASAPI.cpp +++ b/lib/audiodev/WASAPI.cpp @@ -8,8 +8,12 @@ #include +#if !WINDOWS_STORE const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator); const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator); +#else +using namespace Windows::Media::Devices; +#endif const IID IID_IAudioClient = __uuidof(IAudioClient); const IID IID_IAudioRenderClient = __uuidof(IAudioRenderClient); @@ -23,14 +27,17 @@ static logvisor::Module Log("boo::WASAPI"); struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine { +#if !WINDOWS_STORE ComPtr m_enumerator; ComPtr m_device; +#endif ComPtr m_audClient; ComPtr m_renderClient; size_t m_curBufFrame = 0; std::vector m_5msBuffer; +#if !WINDOWS_STORE struct NotificationClient : public IMMNotificationClient { WASAPIAudioVoiceEngine& m_parent; @@ -122,9 +129,11 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine return S_OK; } } m_notificationClient; +#endif void _buildAudioRenderClient() { +#if !WINDOWS_STORE if (FAILED(m_enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &m_device))) { Log.report(logvisor::Fatal, L"unable to obtain default audio device"); @@ -138,12 +147,15 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine m_device.Reset(); return; } +#endif WAVEFORMATEXTENSIBLE* pwfx; if (FAILED(m_audClient->GetMixFormat((WAVEFORMATEX**)&pwfx))) { Log.report(logvisor::Fatal, L"unable to obtain audio mix format from device"); +#if !WINDOWS_STORE m_device.Reset(); +#endif return; } @@ -226,7 +238,9 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine nullptr))) { Log.report(logvisor::Fatal, L"unable to initialize audio client"); +#if !WINDOWS_STORE m_device.Reset(); +#endif CoTaskMemFree(pwfx); return; } @@ -251,7 +265,9 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine else { Log.report(logvisor::Fatal, L"unsupported bits-per-sample %d", pwfx->Format.wBitsPerSample); +#if !WINDOWS_STORE m_device.Reset(); +#endif return; } } @@ -266,7 +282,9 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine else { Log.report(logvisor::Fatal, L"unsupported floating-point bits-per-sample %d", pwfx->Format.wBitsPerSample); +#if !WINDOWS_STORE m_device.Reset(); +#endif return; } } @@ -277,7 +295,9 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine if (FAILED(m_audClient->GetBufferSize(&bufferFrameCount))) { Log.report(logvisor::Fatal, L"unable to get audio buffer frame count"); +#if !WINDOWS_STORE m_device.Reset(); +#endif return; } m_mixInfo.m_periodFrames = bufferFrameCount; @@ -285,14 +305,78 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine if (FAILED(m_audClient->GetService(IID_IAudioRenderClient, &m_renderClient))) { Log.report(logvisor::Fatal, L"unable to create audio render client"); +#if !WINDOWS_STORE m_device.Reset(); +#endif return; } } - WASAPIAudioVoiceEngine() - : m_notificationClient(*this) +#if WINDOWS_STORE + struct CompletionHandler : IActivateAudioInterfaceCompletionHandler { + WASAPIAudioVoiceEngine& e; + LONG _cRef = 1; + + CompletionHandler(WASAPIAudioVoiceEngine& e) : e(e) {} + HRESULT ActivateCompleted(IActivateAudioInterfaceAsyncOperation* operation) + { + return e.ActivateCompleted(operation); + } + + ULONG STDMETHODCALLTYPE AddRef() + { + return InterlockedIncrement(&_cRef); + } + + ULONG STDMETHODCALLTYPE Release() + { + ULONG ulRef = InterlockedDecrement(&_cRef); + if (0 == ulRef) + { + delete this; + } + return ulRef; + } + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, VOID **ppvInterface) + { + if (IID_IUnknown == riid) + { + AddRef(); + *ppvInterface = (IUnknown*)this; + } + else if (__uuidof(IActivateAudioInterfaceCompletionHandler) == riid) + { + AddRef(); + *ppvInterface = (IActivateAudioInterfaceCompletionHandler*)this; + } + else + { + *ppvInterface = NULL; + return E_NOINTERFACE; + } + return S_OK; + } + } m_completion = {*this}; + HRESULT ActivateCompleted(IActivateAudioInterfaceAsyncOperation* operation) + { + ComPtr punkAudioInterface; + HRESULT hrActivateResult; + operation->GetActivateResult(&hrActivateResult, &punkAudioInterface); + punkAudioInterface.As(&m_audClient); + _buildAudioRenderClient(); + return ERROR_SUCCESS; + } +#endif + + WASAPIAudioVoiceEngine() +#if !WINDOWS_STORE + : m_notificationClient(*this) +#endif + { +#if !WINDOWS_STORE /* Enumerate default audio device */ if (FAILED(CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL, IID_IMMDeviceEnumerator, @@ -310,6 +394,11 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine } _buildAudioRenderClient(); +#else + auto deviceIdStr = MediaDevice::GetDefaultAudioRenderId(Windows::Media::Devices::AudioDeviceRole::Default); + ComPtr asyncOp; + ActivateAudioInterfaceAsync(deviceIdStr->Data(), __uuidof(IAudioClient3), nullptr, &m_completion, &asyncOp); +#endif } bool m_started = false; @@ -411,6 +500,7 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine } } +#if !WINDOWS_STORE std::vector> enumerateMIDIDevices() const { std::vector> ret; @@ -681,13 +771,53 @@ struct WASAPIAudioVoiceEngine : BaseAudioVoiceEngine } bool useMIDILock() const {return true;} +#else + std::vector> enumerateMIDIDevices() const + { + return {}; + } + + std::unique_ptr newVirtualMIDIIn(ReceiveFunctor&& receiver) + { + return {}; + } + + std::unique_ptr newVirtualMIDIOut() + { + return {}; + } + + std::unique_ptr newVirtualMIDIInOut(ReceiveFunctor&& receiver) + { + return {}; + } + + std::unique_ptr newRealMIDIIn(const char* name, ReceiveFunctor&& receiver) + { + return {}; + } + + std::unique_ptr newRealMIDIOut(const char* name) + { + return {}; + } + + std::unique_ptr newRealMIDIInOut(const char* name, ReceiveFunctor&& receiver) + { + return {}; + } + + bool useMIDILock() const {return false;} +#endif }; std::unique_ptr NewAudioVoiceEngine() { std::unique_ptr ret = std::make_unique(); +#if !WINDOWS_STORE if (!static_cast(*ret).m_device) return {}; +#endif return ret; } diff --git a/lib/graphicsdev/D3D11.cpp b/lib/graphicsdev/D3D11.cpp index 773b605..768b535 100644 --- a/lib/graphicsdev/D3D11.cpp +++ b/lib/graphicsdev/D3D11.cpp @@ -41,7 +41,11 @@ static inline void ThrowIfFailed(HRESULT hr) if (FAILED(hr)) { // Set a breakpoint on this line to catch Win32 API errors. +#if !WINDOWS_STORE _com_error err(hr); +#else + _com_error err(hr, L"D3D11 fail"); +#endif LPCTSTR errMsg = err.ErrorMessage(); Log.report(logvisor::Fatal, errMsg); } diff --git a/lib/graphicsdev/D3D12.cpp b/lib/graphicsdev/D3D12.cpp index 44b939b..728dfeb 100644 --- a/lib/graphicsdev/D3D12.cpp +++ b/lib/graphicsdev/D3D12.cpp @@ -38,7 +38,11 @@ static inline void ThrowIfFailed(HRESULT hr) if (FAILED(hr)) { // Set a breakpoint on this line to catch Win32 API errors. +#if !WINDOWS_STORE _com_error err(hr); +#else + _com_error err(hr, L"D3D12 fail"); +#endif LPCTSTR errMsg = err.ErrorMessage(); Log.report(logvisor::Fatal, errMsg); } diff --git a/lib/inputdev/DeviceBase.cpp b/lib/inputdev/DeviceBase.cpp index 2c86b9f..5c7b308 100644 --- a/lib/inputdev/DeviceBase.cpp +++ b/lib/inputdev/DeviceBase.cpp @@ -55,12 +55,14 @@ size_t DeviceBase::receiveUSBInterruptTransfer(uint8_t* data, size_t length) } #if _WIN32 +#if !WINDOWS_STORE const PHIDP_PREPARSED_DATA DeviceBase::getReportDescriptor() { if (m_hidDev) return m_hidDev->_getReportDescriptor(); return {}; } +#endif #else std::vector DeviceBase::getReportDescriptor() { diff --git a/lib/inputdev/DeviceFinder.cpp b/lib/inputdev/DeviceFinder.cpp index 6483dd5..25ddf8a 100644 --- a/lib/inputdev/DeviceFinder.cpp +++ b/lib/inputdev/DeviceFinder.cpp @@ -11,7 +11,7 @@ namespace boo DeviceFinder* DeviceFinder::skDevFinder = nullptr; -#if _WIN32 +#if _WIN32 && !WINDOWS_STORE /* Windows-specific WM_DEVICECHANGED handler */ LRESULT DeviceFinder::winDevChangedHandler(WPARAM wParam, LPARAM lParam) { diff --git a/lib/inputdev/GenericPad.cpp b/lib/inputdev/GenericPad.cpp index 816b2cf..1329b7f 100644 --- a/lib/inputdev/GenericPad.cpp +++ b/lib/inputdev/GenericPad.cpp @@ -21,8 +21,10 @@ void GenericPad::deviceDisconnected() void GenericPad::initialCycle() { #if _WIN32 +#if !WINDOWS_STORE const PHIDP_PREPARSED_DATA reportDesc = getReportDescriptor(); m_parser.Parse(reportDesc); +#endif #else std::vector reportDesc = getReportDescriptor(); m_parser.Parse(reportDesc.data(), reportDesc.size()); diff --git a/lib/inputdev/HIDDeviceUWP.cpp b/lib/inputdev/HIDDeviceUWP.cpp new file mode 100644 index 0000000..d173c99 --- /dev/null +++ b/lib/inputdev/HIDDeviceUWP.cpp @@ -0,0 +1,30 @@ +#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */ +#include "IHIDDevice.hpp" +#include "boo/inputdev/DeviceToken.hpp" +#include "boo/inputdev/DeviceBase.hpp" + +namespace boo +{ + +class HIDDeviceUWP : public IHIDDevice +{ +public: + HIDDeviceUWP(DeviceToken& token, const std::shared_ptr& devImp) + { + + } + + void _deviceDisconnected() {} + bool _sendUSBInterruptTransfer(const uint8_t* data, size_t length) { return false; } + size_t _receiveUSBInterruptTransfer(uint8_t* data, size_t length) { return 0; } + bool _sendHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) { return false; } + size_t _receiveHIDReport(uint8_t* data, size_t length, HIDReportType tp, uint32_t message) { return false; } + void _startThread() {} +}; + +std::shared_ptr IHIDDeviceNew(DeviceToken& token, const std::shared_ptr& devImp) +{ + return std::make_shared(token, devImp); +} + +} diff --git a/lib/inputdev/HIDListenerUWP.cpp b/lib/inputdev/HIDListenerUWP.cpp new file mode 100644 index 0000000..e9eda97 --- /dev/null +++ b/lib/inputdev/HIDListenerUWP.cpp @@ -0,0 +1,26 @@ +#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */ +#include "boo/inputdev/IHIDListener.hpp" +#include "boo/inputdev/DeviceFinder.hpp" + +namespace boo +{ + +class HIDListenerUWP : public IHIDListener +{ +public: + HIDListenerUWP(DeviceFinder& finder) {} + + /* Automatic device scanning */ + bool startScanning() { return false; } + bool stopScanning() { return false; } + + /* Manual device scanning */ + bool scanNow() { return false; } +}; + +std::unique_ptr IHIDListenerNew(DeviceFinder& finder) +{ + return std::make_unique(finder); +} + +} diff --git a/lib/inputdev/HIDParser.cpp b/lib/inputdev/HIDParser.cpp index 66859b6..e5ce7d3 100644 --- a/lib/inputdev/HIDParser.cpp +++ b/lib/inputdev/HIDParser.cpp @@ -396,6 +396,7 @@ struct HIDReports }; #if _WIN32 +#if !WINDOWS_STORE HIDParser::ParserStatus HIDParser::Parse(const PHIDP_PREPARSED_DATA descriptorData) { /* User mode HID report descriptor isn't available on Win32. @@ -475,6 +476,7 @@ HIDParser::ParserStatus HIDParser::Parse(const PHIDP_PREPARSED_DATA descriptorDa m_status = ParserStatus::Done; return ParserStatus::Done; } +#endif #else HIDParser::ParserStatus @@ -721,6 +723,7 @@ std::pair HIDParser::GetApplicationUsage(const uint8_t* #if _WIN32 void HIDParser::EnumerateValues(const std::function& valueCB) const { +#if !WINDOWS_STORE if (m_status != ParserStatus::Done) return; @@ -731,6 +734,7 @@ void HIDParser::EnumerateValues(const std::function& valueCB) const @@ -757,6 +761,7 @@ void HIDParser::EnumerateValues(const std::function& valueCB, const uint8_t* data, size_t len) const { +#if !WINDOWS_STORE if (m_status != ParserStatus::Done) return; @@ -786,6 +791,7 @@ void HIDParser::ScanValues(const std::function virtual bool _sendUSBInterruptTransfer(const uint8_t* data, size_t length)=0; virtual size_t _receiveUSBInterruptTransfer(uint8_t* data, size_t length)=0; #if _WIN32 +#if !WINDOWS_STORE virtual const PHIDP_PREPARSED_DATA _getReportDescriptor()=0; +#endif #else virtual std::vector _getReportDescriptor()=0; #endif diff --git a/lib/win/ApplicationUWP.cpp b/lib/win/ApplicationUWP.cpp index 6536eb9..bb0b3d3 100644 --- a/lib/win/ApplicationUWP.cpp +++ b/lib/win/ApplicationUWP.cpp @@ -25,30 +25,9 @@ pD3DCreateBlob D3DCreateBlobPROC = nullptr; static bool FindBestD3DCompile() { - HMODULE d3dCompilelib = LoadLibraryW(L"D3DCompiler_47.dll"); - if (!d3dCompilelib) - { - d3dCompilelib = LoadLibraryW(L"D3DCompiler_46.dll"); - if (!d3dCompilelib) - { - d3dCompilelib = LoadLibraryW(L"D3DCompiler_45.dll"); - if (!d3dCompilelib) - { - d3dCompilelib = LoadLibraryW(L"D3DCompiler_44.dll"); - if (!d3dCompilelib) - { - d3dCompilelib = LoadLibraryW(L"D3DCompiler_43.dll"); - } - } - } - } - if (d3dCompilelib) - { - D3DCompilePROC = (pD3DCompile)GetProcAddress(d3dCompilelib, "D3DCompile"); - D3DCreateBlobPROC = (pD3DCreateBlob)GetProcAddress(d3dCompilelib, "D3DCreateBlob"); - return D3DCompilePROC != nullptr && D3DCreateBlobPROC != nullptr; - } - return false; + D3DCompilePROC = D3DCompile; + D3DCreateBlobPROC = D3DCreateBlob; + return D3DCompilePROC != nullptr && D3DCreateBlobPROC != nullptr; } namespace boo @@ -91,14 +70,8 @@ public: m_args(args), m_singleInstance(singleInstance) { - HMODULE dxgilib = LoadLibraryW(L"dxgi.dll"); - if (!dxgilib) - Log.report(logvisor::Fatal, "unable to load dxgi.dll"); - typedef HRESULT(WINAPI*CreateDXGIFactory1PROC)(REFIID riid, _COM_Outptr_ void **ppFactory); - CreateDXGIFactory1PROC MyCreateDXGIFactory1 = (CreateDXGIFactory1PROC)GetProcAddress(dxgilib, "CreateDXGIFactory1"); - if (!MyCreateDXGIFactory1) - Log.report(logvisor::Fatal, "unable to find CreateDXGIFactory1 in DXGI.dll\n"); + CreateDXGIFactory1PROC MyCreateDXGIFactory1 = CreateDXGIFactory1; bool no12 = false; for (const SystemString& arg : args) @@ -106,30 +79,15 @@ public: no12 = true; #if _WIN32_WINNT_WIN10 - HMODULE d3d12lib = LoadLibraryW(L"D3D12.dll"); - if (!no12 && d3d12lib) + if (!no12) { -#if _DEBUG - { - PFN_D3D12_GET_DEBUG_INTERFACE MyD3D12GetDebugInterface = - (PFN_D3D12_GET_DEBUG_INTERFACE)GetProcAddress(d3d12lib, "D3D12GetDebugInterface"); - ComPtr debugController; - if (SUCCEEDED(MyD3D12GetDebugInterface(IID_PPV_ARGS(&debugController)))) - { - debugController->EnableDebugLayer(); - } - } -#endif if (!FindBestD3DCompile()) Log.report(logvisor::Fatal, "unable to find D3DCompile_[43-47].dll"); - D3D12SerializeRootSignaturePROC = - (PFN_D3D12_SERIALIZE_ROOT_SIGNATURE)GetProcAddress(d3d12lib, "D3D12SerializeRootSignature"); + D3D12SerializeRootSignaturePROC = D3D12SerializeRootSignature; /* Create device */ - PFN_D3D12_CREATE_DEVICE MyD3D12CreateDevice = (PFN_D3D12_CREATE_DEVICE)GetProcAddress(d3d12lib, "D3D12CreateDevice"); - if (!MyD3D12CreateDevice) - Log.report(logvisor::Fatal, "unable to find D3D12CreateDevice in D3D12.dll"); + PFN_D3D12_CREATE_DEVICE MyD3D12CreateDevice = D3D12CreateDevice; /* Obtain DXGI Factory */ HRESULT hr = MyCreateDXGIFactory1(__uuidof(IDXGIFactory2), &m_3dCtx.m_ctx12.m_dxFactory); @@ -191,16 +149,12 @@ public: } } #endif - HMODULE d3d11lib = LoadLibraryW(L"D3D11.dll"); - if (d3d11lib) { if (!FindBestD3DCompile()) Log.report(logvisor::Fatal, "unable to find D3DCompile_[43-47].dll"); /* Create device proc */ - PFN_D3D11_CREATE_DEVICE MyD3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(d3d11lib, "D3D11CreateDevice"); - if (!MyD3D11CreateDevice) - Log.report(logvisor::Fatal, "unable to find D3D11CreateDevice in D3D11.dll"); + PFN_D3D11_CREATE_DEVICE MyD3D11CreateDevice = D3D11CreateDevice; /* Create device */ D3D_FEATURE_LEVEL level = D3D_FEATURE_LEVEL_11_0; @@ -215,9 +169,6 @@ public: FAILED(tempCtx.As(&m_3dCtx.m_ctx11.m_devCtx)) || !m_3dCtx.m_ctx11.m_devCtx || FAILED(m_3dCtx.m_ctx11.m_dev.As(&device)) || !device) { - MessageBoxW(nullptr, L"Windows 7 users should install 'Platform Update for Windows 7':\n" - L"https://www.microsoft.com/en-us/download/details.aspx?id=36805", - L"IDXGIDevice2 interface error", MB_OK | MB_ICONERROR); exit(1); } @@ -256,7 +207,7 @@ public: int clientReturn = 0; std::thread clientThread([&]() { - std::string thrName = WCSTMBS(getFriendlyName().c_str()) + " Client Thread"; + std::string thrName = WCSTMBS(getFriendlyName().data()) + " Client Thread"; logvisor::RegisterThreadName(thrName.c_str()); clientReturn = m_callback.appMain(this); }); diff --git a/lib/win/UWPCommon.hpp b/lib/win/UWPCommon.hpp index b46b449..90e54c7 100644 --- a/lib/win/UWPCommon.hpp +++ b/lib/win/UWPCommon.hpp @@ -3,8 +3,6 @@ #include "WinCommon.hpp" -using namespace Windows::ApplicationModel::Core; - struct Boo3DAppContextUWP : Boo3DAppContext { bool isFullscreen(const boo::IWindow* window) diff --git a/lib/win/Win32Common.hpp b/lib/win/Win32Common.hpp index 8c5adb8..656ad35 100644 --- a/lib/win/Win32Common.hpp +++ b/lib/win/Win32Common.hpp @@ -16,7 +16,7 @@ extern DWORD g_mainThreadId; -#if _WIN32_WINNT_WINBLUE +#if _WIN32_WINNT_WINBLUE && !WINDOWS_STORE #include typedef HRESULT (WINAPI* PFN_SetProcessDpiAwareness)( _In_ PROCESS_DPI_AWARENESS ); typedef HRESULT (WINAPI* PFN_GetScaleFactorForMonitor)( _In_ HMONITOR, _Out_ DEVICE_SCALE_FACTOR *); @@ -187,12 +187,14 @@ struct Boo3DAppContextWin32 : Boo3DAppContext return true; } +#if !WINDOWS_STORE OGLContext::Window& win = m_ctxOgl.m_windows[window]; if (fs && win.m_fs) return false; else if (!fs && !win.m_fs) return false; SetFullscreen(win, fs); +#endif return true; } }; diff --git a/lib/win/WindowUWP.cpp b/lib/win/WindowUWP.cpp index 9d16f5b..e5864ae 100644 --- a/lib/win/WindowUWP.cpp +++ b/lib/win/WindowUWP.cpp @@ -8,7 +8,10 @@ #include "boo/audiodev/IAudioVoiceEngine.hpp" using namespace Windows::UI::Core; +using namespace Windows::UI::ViewManagement; using namespace Windows::System; +using namespace Windows::Graphics::Display; +using namespace Windows::Foundation; namespace boo { @@ -178,67 +181,59 @@ public: } }; -static void genFrameDefault(MONITORINFO* screen, int& xOut, int& yOut, int& wOut, int& hOut) -{ - float width = screen->rcMonitor.right * 2.0 / 3.0; - float height = screen->rcMonitor.bottom * 2.0 / 3.0; - xOut = (screen->rcMonitor.right - width) / 2.0; - yOut = (screen->rcMonitor.bottom - height) / 2.0; - wOut = width; - hOut = height; -} - -static uint32_t translateKeysym(VirtualKey sym, ESpecialKey& specialSym, EModifierKey& modifierSym) +static uint32_t translateKeysym(CoreWindow^ window, VirtualKey sym, + ESpecialKey& specialSym, EModifierKey& modifierSym) { specialSym = ESpecialKey::None; modifierSym = EModifierKey::None; - if (sym >= VirtualKey_F1 && sym <= VirtualKey_F12) - specialSym = ESpecialKey(uint32_t(ESpecialKey::F1) + sym - VirtualKey_F1); - else if (sym == VirtualKey_Escape) + if (sym >= VirtualKey::F1 && sym <= VirtualKey::F12) + specialSym = ESpecialKey(uint32_t(ESpecialKey::F1) + uint32_t(sym - VirtualKey::F1)); + else if (sym == VirtualKey::Escape) specialSym = ESpecialKey::Esc; - else if (sym == VirtualKey_Enter) + else if (sym == VirtualKey::Enter) specialSym = ESpecialKey::Enter; - else if (sym == VirtualKey_Back) + else if (sym == VirtualKey::Back) specialSym = ESpecialKey::Backspace; - else if (sym == VirtualKey_Insert) + else if (sym == VirtualKey::Insert) specialSym = ESpecialKey::Insert; - else if (sym == VirtualKey_Delete) + else if (sym == VirtualKey::Delete) specialSym = ESpecialKey::Delete; - else if (sym == VirtualKey_Home) + else if (sym == VirtualKey::Home) specialSym = ESpecialKey::Home; - else if (sym == VirtualKey_End) + else if (sym == VirtualKey::End) specialSym = ESpecialKey::End; - else if (sym == VirtualKey_PageUp) + else if (sym == VirtualKey::PageUp) specialSym = ESpecialKey::PgUp; - else if (sym == VirtualKey_PageDown) + else if (sym == VirtualKey::PageDown) specialSym = ESpecialKey::PgDown; - else if (sym == VirtualKey_Left) + else if (sym == VirtualKey::Left) specialSym = ESpecialKey::Left; - else if (sym == VirtualKey_Right) + else if (sym == VirtualKey::Right) specialSym = ESpecialKey::Right; - else if (sym == VirtualKey_Up) + else if (sym == VirtualKey::Up) specialSym = ESpecialKey::Up; - else if (sym == VirtualKey_Down) + else if (sym == VirtualKey::Down) specialSym = ESpecialKey::Down; - else if (sym == VirtualKey_Shift) + else if (sym == VirtualKey::Shift) modifierSym = EModifierKey::Shift; - else if (sym == VirtualKey_Control) + else if (sym == VirtualKey::Control) modifierSym = EModifierKey::Ctrl; - else if (sym == VirtualKey_Menu) + else if (sym == VirtualKey::Menu) modifierSym = EModifierKey::Alt; - else if (sym >= VirtualKey_A && sym <= VirtualKey_Z) - return sym - VirtualKey_A + window->GetKeyState(VirtualKey_Shift) ? 'A' : 'a' + else if (sym >= VirtualKey::A && sym <= VirtualKey::Z) + return uint32_t(sym - VirtualKey::A) + + (window->GetKeyState(VirtualKey::Shift) != CoreVirtualKeyStates::None) ? 'A' : 'a'; return 0; } static EModifierKey translateModifiers(CoreWindow^ window) { EModifierKey retval = EModifierKey::None; - if (window->GetKeyState(VirtualKey_Shift) != None) + if (window->GetKeyState(VirtualKey::Shift) != CoreVirtualKeyStates::None) retval |= EModifierKey::Shift; - if (window->GetKeyState(VirtualKey_Control) != None) + if (window->GetKeyState(VirtualKey::Control) != CoreVirtualKeyStates::None) retval |= EModifierKey::Ctrl; - if (window->GetKeyState(LefVirtualKey_Menu) != None) + if (window->GetKeyState(VirtualKey::Menu) != CoreVirtualKeyStates::None) retval |= EModifierKey::Alt; return retval; } @@ -253,7 +248,36 @@ class WindowUWP : public IWindow public: - WindowUWP(SystemStringView title, Boo3DAppContext& b3dCtx, uint32_t sampleCount) + ref struct EventReceiver sealed + { + void OnKeyDown(CoreWindow^ window, KeyEventArgs^ keyEventArgs) + { + w.OnKeyDown(window, keyEventArgs); + } + + void OnKeyUp(CoreWindow^ window, KeyEventArgs^ keyEventArgs) + { + w.OnKeyUp(window, keyEventArgs); + } + + void OnClosed(CoreWindow^ sender, CoreWindowEventArgs^ args) + { + w.OnClosed(sender, args); + } + + internal: + WindowUWP& w; + EventReceiver(WindowUWP& w) : w(w) + { + w.m_coreWindow->KeyDown += ref new TypedEventHandler(this, &EventReceiver::OnKeyDown); + w.m_coreWindow->KeyUp += ref new TypedEventHandler(this, &EventReceiver::OnKeyUp); + w.m_coreWindow->Closed += ref new TypedEventHandler(this, &EventReceiver::OnClosed); + } + }; + EventReceiver^ m_eventReceiver; + + WindowUWP(SystemStringView title, Boo3DAppContextUWP& b3dCtx, uint32_t sampleCount) + : m_eventReceiver(ref new EventReceiver(*this)) { IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11; #if _WIN32_WINNT_WIN10 @@ -263,9 +287,6 @@ public: m_gfxCtx.reset(new GraphicsContextUWPD3D(api, this, m_coreWindow, b3dCtx, sampleCount)); setTitle(title); - m_coreWindow->KeyDown += ref new TypedEventHandler(this, &WindowUWP::OnKeyDown); - m_coreWindow->KeyUp += ref new TypedEventHandler(this, &WindowUWP::OnKeyUp); - m_coreWindow->Closed += ref new TypedEventHandler(this, &WindowUWP::OnClosed); } ~WindowUWP() @@ -293,12 +314,12 @@ public: SystemString getTitle() { - return SystemString(m_appView->Title.Data()); + return SystemString(m_appView->Title->Data()); } void setTitle(SystemStringView title) { - m_appView->Title = title.data(); + m_appView->Title = ref new Platform::String(title.data()); } void setCursor(EMouseCursor cursor) @@ -315,18 +336,18 @@ public: void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const { - xOut = m_coreWindow->bounds.X; - yOut = m_coreWindow->bounds.Y; - wOut = m_coreWindow->bounds.Width; - hOut = m_coreWindow->bounds.Height; + xOut = m_coreWindow->Bounds.X; + yOut = m_coreWindow->Bounds.Y; + wOut = m_coreWindow->Bounds.Width; + hOut = m_coreWindow->Bounds.Height; } void getWindowFrame(int& xOut, int& yOut, int& wOut, int& hOut) const { - xOut = m_coreWindow->bounds.X; - yOut = m_coreWindow->bounds.Y; - wOut = m_coreWindow->bounds.Width; - hOut = m_coreWindow->bounds.Height; + xOut = m_coreWindow->Bounds.X; + yOut = m_coreWindow->Bounds.Y; + wOut = m_coreWindow->Bounds.Width; + hOut = m_coreWindow->Bounds.Height; } void setWindowFrame(float x, float y, float w, float h) @@ -339,8 +360,8 @@ public: float getVirtualPixelFactor() const { - DisplayInformation dispInfo = DisplayInformation::GetForCurrentView(); - return dispInfo.LogicalDpi / 96.f; + DisplayInformation^ dispInfo = DisplayInformation::GetForCurrentView(); + return dispInfo->LogicalDpi / 96.f; } bool isFullscreen() const @@ -359,6 +380,7 @@ public: bool clipboardCopy(EClipboardType type, const uint8_t* data, size_t sz) { + return false; } std::unique_ptr clipboardPaste(EClipboardType type, size_t& sz) @@ -384,37 +406,31 @@ public: void OnKeyDown(CoreWindow^ window, KeyEventArgs^ keyEventArgs) { - if (auto w = m_window.lock()) - { - ESpecialKey specialKey; - EModifierKey modifierKey; - uint32_t charCode = translateKeysym(keyEventArgs->VirtualKey, specialKey, modifierKey); - EModifierKey modifierMask = translateModifiers(window); - bool repeat = keyEventArgs->KeyStatus.RepeatCount > 1; - if (charCode) - m_callback->charKeyDown(charCode, modifierMask, repeat); - else if (specialKey != ESpecialKey::None) - m_callback->specialKeyDown(specialKey, modifierMask, repeat); - else if (modifierKey != EModifierKey::None) - m_callback->modKeyDown(modifierKey, repeat); - } + ESpecialKey specialKey; + EModifierKey modifierKey; + uint32_t charCode = translateKeysym(m_coreWindow, keyEventArgs->VirtualKey, specialKey, modifierKey); + EModifierKey modifierMask = translateModifiers(window); + bool repeat = keyEventArgs->KeyStatus.RepeatCount > 1; + if (charCode) + m_callback->charKeyDown(charCode, modifierMask, repeat); + else if (specialKey != ESpecialKey::None) + m_callback->specialKeyDown(specialKey, modifierMask, repeat); + else if (modifierKey != EModifierKey::None) + m_callback->modKeyDown(modifierKey, repeat); } void OnKeyUp(CoreWindow^ window, KeyEventArgs^ keyEventArgs) { - if (auto w = m_window.lock()) - { - ESpecialKey specialKey; - EModifierKey modifierKey; - uint32_t charCode = translateKeysym(keyEventArgs->VirtualKey, specialKey, modifierKey); - EModifierKey modifierMask = translateModifiers(window); - if (charCode) - m_callback->charKeyDown(charCode, modifierMask); - else if (specialKey != ESpecialKey::None) - m_callback->specialKeyDown(specialKey, modifierMask); - else if (modifierKey != EModifierKey::None) - m_callback->modKeyDown(modifierKey); - } + ESpecialKey specialKey; + EModifierKey modifierKey; + uint32_t charCode = translateKeysym(m_coreWindow, keyEventArgs->VirtualKey, specialKey, modifierKey); + EModifierKey modifierMask = translateModifiers(window); + if (charCode) + m_callback->charKeyUp(charCode, modifierMask); + else if (specialKey != ESpecialKey::None) + m_callback->specialKeyUp(specialKey, modifierMask); + else if (modifierKey != EModifierKey::None) + m_callback->modKeyUp(modifierKey); } void OnClosed(CoreWindow ^sender, CoreWindowEventArgs ^args) @@ -459,7 +475,7 @@ public: }; -std::shared_ptr _WindowUAPNew(SystemStringView title, Boo3DAppContext& d3dCtx, +std::shared_ptr _WindowUWPNew(SystemStringView title, Boo3DAppContextUWP& d3dCtx, uint32_t sampleCount) { return std::make_shared(title, d3dCtx, sampleCount); diff --git a/logvisor b/logvisor index 59741b6..408ae92 160000 --- a/logvisor +++ b/logvisor @@ -1 +1 @@ -Subproject commit 59741b63b88ce6c1135733a326e3cbfaf8d22e0c +Subproject commit 408ae926d76128fa23a12607d0a1e0a970ab3554 diff --git a/test/main.cpp b/test/main.cpp index 00324e2..ecc9434 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -336,6 +336,7 @@ struct TestApplicationCallback : IApplicationCallback /* Make shader pipeline */ boo::ObjToken pipeline; auto plat = ctx.platform(); +#if BOO_HAS_GL if (plat == IGraphicsDataFactory::Platform::OpenGL) { GLDataFactory::Context& glF = dynamic_cast(ctx); @@ -369,9 +370,10 @@ struct TestApplicationCallback : IApplicationCallback BlendFactor::One, BlendFactor::Zero, Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, CullMode::None); - } + } else +#endif #if BOO_HAS_VULKAN - else if (plat == IGraphicsDataFactory::Platform::Vulkan) + if (plat == IGraphicsDataFactory::Platform::Vulkan) { VulkanDataFactory::Context& vkF = dynamic_cast(ctx); @@ -402,11 +404,11 @@ struct TestApplicationCallback : IApplicationCallback pipeline = vkF.newShaderPipeline(VS, FS, vfmt, BlendFactor::One, BlendFactor::Zero, Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, CullMode::None); - } + } else #endif #if _WIN32 - else if (plat == IGraphicsDataFactory::Platform::D3D12 || - plat == IGraphicsDataFactory::Platform::D3D11) + if (plat == IGraphicsDataFactory::Platform::D3D12 || + plat == IGraphicsDataFactory::Platform::D3D11) { ID3DDataFactory::Context& d3dF = dynamic_cast(ctx); @@ -434,9 +436,9 @@ struct TestApplicationCallback : IApplicationCallback BlendFactor::One, BlendFactor::Zero, Primitive::TriStrips, boo::ZTest::LEqual, true, true, false, CullMode::None); - } + } else #elif BOO_HAS_METAL - else if (plat == IGraphicsDataFactory::Platform::Metal) + if (plat == IGraphicsDataFactory::Platform::Metal) { MetalDataFactory::Context& metalF = dynamic_cast(ctx); @@ -466,8 +468,9 @@ struct TestApplicationCallback : IApplicationCallback pipeline = metalF.newShaderPipeline(VS, FS, nullptr, nullptr, vfmt, 1, BlendFactor::One, BlendFactor::Zero, Primitive::TriStrips, boo::ZTest::LEqual, true, true, true, boo::CullMode::None); - } + } else #endif + {} /* Make shader data binding */ self->m_binding = @@ -581,6 +584,7 @@ struct TestApplicationCallback : IApplicationCallback } +#if !WINDOWS_STORE #if _WIN32 int wmain(int argc, const boo::SystemChar** argv) #else @@ -596,7 +600,7 @@ int main(int argc, const boo::SystemChar** argv) return ret; } -#if WINAPI_FAMILY && !WINAPI_PARTITION_DESKTOP +#else using namespace Windows::ApplicationModel::Core; [Platform::MTAThread] @@ -605,12 +609,14 @@ int WINAPIV main(Platform::Array^ params) logvisor::RegisterStandardExceptions(); logvisor::RegisterConsoleLogger(); boo::TestApplicationCallback appCb; - auto viewProvider = ref new ViewProvider(appCb, _S("boo"), _S("boo"), params, false); + boo::ViewProvider^ viewProvider = + ref new boo::ViewProvider(appCb, _S("boo"), _S("boo"), _S("boo"), params, false); CoreApplication::Run(viewProvider); return 0; } +#endif -#elif _WIN32 +#if _WIN32 && !WINDOWS_STORE int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int) { int argc = 0;