diff --git a/.codecov.yml b/.codecov.yml index 64c08511f..c18181072 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -55,20 +55,24 @@ component_management: - component_id: platform-utils name: Platform Utils paths: - - Modules/Platform/Utils/** + - Modules/Platform/*/Utils/** - component_id: platform-input name: Platform Input paths: - - Modules/Platform/Input/** + - Modules/Platform/*/Input/** + - Modules/Platform/Apple/*/Input/** - Tests/Platform/Input/** - component_id: platform-app-view name: Platform App-View paths: - - Modules/Platform/AppView/** + - Modules/Platform/*/AppView/** + - Modules/Platform/Apple/*/AppView/** - component_id: platform-app name: Platform App paths: - - Modules/Platform/App/** + - Modules/Platform/*/App/** + - Modules/Platform/Apple/*/App/** + - Modules/Platform/*/AppController/** - component_id: graphics-types name: Graphics Types paths: diff --git a/Apps/01-HelloTriangle/README.md b/Apps/01-HelloTriangle/README.md index e5fd39637..f6b666a74 100644 --- a/Apps/01-HelloTriangle/README.md +++ b/Apps/01-HelloTriangle/README.md @@ -18,7 +18,7 @@ The tutorial covers the following Methane Kit features and techniques: ## Application Controls Common keyboard controls are enabled by the `Platform` and `Graphics` application controllers: -- [Methane::Platform::AppController](/Modules/Platform/App/README.md#platform-application-controller) +- [Methane::Platform::AppController](/Modules/Platform/Impl/App/README.md#platform-application-controller) - [Methane::Graphics::AppController, AppContextController](/Modules/Graphics/App/README.md#graphics-application-controllers) ## Application and Frame Class Definitions diff --git a/Apps/02-HelloCube/README.md b/Apps/02-HelloCube/README.md index 40b9c8c35..00470b4cd 100644 --- a/Apps/02-HelloCube/README.md +++ b/Apps/02-HelloCube/README.md @@ -24,7 +24,7 @@ The tutorial demonstrates the following Methane Kit features and techniques in a ## Application Controls Common keyboard controls are enabled by the `Platform` and `Graphics` application controllers: -- [Methane::Platform::AppController](/Modules/Platform/App/README.md#platform-application-controller) +- [Methane::Platform::AppController](/Modules/Platform/Impl/App/README.md#platform-application-controller) - [Methane::Graphics::AppController, AppContextController](/Modules/Graphics/App/README.md#graphics-application-controllers) ## Simple Cube Vertices Transformation on CPU diff --git a/Apps/03-TexturedCube/README.md b/Apps/03-TexturedCube/README.md index f98413502..99f17c61c 100644 --- a/Apps/03-TexturedCube/README.md +++ b/Apps/03-TexturedCube/README.md @@ -20,7 +20,7 @@ Tutorial demonstrates the following Methane Kit features in addition to those de ## Application Controls Common keyboard controls are enabled by the `Platform`, `Graphics` and `UserInterface` application controllers: -- [Methane::Platform::AppController](/Modules/Platform/App/README.md#platform-application-controller) +- [Methane::Platform::AppController](/Modules/Platform/Impl/App/README.md#platform-application-controller) - [Methane::Graphics::AppController, AppContextController](/Modules/Graphics/App/README.md#graphics-application-controllers) - [Methane::UserInterface::AppController](/Modules/UserInterface/App/README.md#user-interface-application-controllers) diff --git a/Apps/04-ShadowCube/README.md b/Apps/04-ShadowCube/README.md index d537d79a2..a003f29dd 100644 --- a/Apps/04-ShadowCube/README.md +++ b/Apps/04-ShadowCube/README.md @@ -22,7 +22,7 @@ Tutorial demonstrates the use of the following Methane Kit features in addition ## Application Controls Common keyboard controls are enabled by the `Platform`, `Graphics` and `UserInterface` application controllers: -- [Methane::Platform::AppController](/Modules/Platform/App/README.md#platform-application-controller) +- [Methane::Platform::AppController](/Modules/Platform/Impl/App/README.md#platform-application-controller) - [Methane::Graphics::AppController, AppContextController](/Modules/Graphics/App/README.md#graphics-application-controllers) - [Methane::UserInterface::AppController](/Modules/UserInterface/App/README.md#user-interface-application-controllers) diff --git a/Apps/05-Typography/README.md b/Apps/05-Typography/README.md index 2a057242e..141944470 100644 --- a/Apps/05-Typography/README.md +++ b/Apps/05-Typography/README.md @@ -16,7 +16,7 @@ characters and words. Right-to-left and Arabic language character layout is not ## Application Controls Keyboard actions are enabled with [TypographyAppController](TypographyAppController.h) class -derived from [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp): +derived from [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp): | Typography App Action | Keyboard Shortcut | |-----------------------------------------------------------------|-------------------| @@ -29,7 +29,7 @@ derived from [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform | Slowdown Typing | `-` | Common keyboard controls are enabled by the `Platform`, `Graphics` and `UserInterface` application controllers: -- [Methane::Platform::AppController](/Modules/Platform/App/README.md#platform-application-controller) +- [Methane::Platform::AppController](/Modules/Platform/Impl/App/README.md#platform-application-controller) - [Methane::Graphics::AppController, AppContextController](/Modules/Graphics/App/README.md#graphics-application-controllers) - [Methane::UserInterface::AppController](/Modules/UserInterface/App/README.md#user-interface-application-controllers) diff --git a/Apps/06-CubeMapArray/README.md b/Apps/06-CubeMapArray/README.md index 2824f1743..6a48adfaf 100644 --- a/Apps/06-CubeMapArray/README.md +++ b/Apps/06-CubeMapArray/README.md @@ -21,7 +21,7 @@ Tutorial demonstrates the following techniques: ## Application Controls Common keyboard controls are enabled by the `Platform`, `Graphics` and `UserInterface` application controllers: -- [Methane::Platform::AppController](/Modules/Platform/App/README.md#platform-application-controller) +- [Methane::Platform::AppController](/Modules/Platform/Impl/App/README.md#platform-application-controller) - [Methane::Graphics::AppController, AppContextController](/Modules/Graphics/App/README.md#graphics-application-controllers) - [Methane::UserInterface::AppController](/Modules/UserInterface/App/README.md#user-interface-application-controllers) diff --git a/Apps/07-ParallelRendering/README.md b/Apps/07-ParallelRendering/README.md index 3982be766..71e2adadb 100644 --- a/Apps/07-ParallelRendering/README.md +++ b/Apps/07-ParallelRendering/README.md @@ -30,7 +30,7 @@ Tutorial demonstrates the following techniques: ## Application Controls Keyboard actions are enabled with [ParallelRenderingAppController](ParallelRenderingAppController.h) class -derived from [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp): +derived from [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp): | Parallel Rendering App Action | Keyboard Shortcut | |-------------------------------|-------------------| @@ -41,7 +41,7 @@ derived from [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform | Decrease Render Threads Count | `[` | Common keyboard controls are enabled by the `Platform`, `Graphics` and `UserInterface` application controllers: -- [Methane::Platform::AppController](/Modules/Platform/App/README.md#platform-application-controller) +- [Methane::Platform::AppController](/Modules/Platform/Impl/App/README.md#platform-application-controller) - [Methane::Graphics::AppController, AppContextController](/Modules/Graphics/App/README.md#graphics-application-controllers) - [Methane::UserInterface::AppController](/Modules/UserInterface/App/README.md#user-interface-application-controllers) diff --git a/Modules/Graphics/App/Include/Methane/Graphics/AppBase.h b/Modules/Graphics/App/Include/Methane/Graphics/AppBase.h index 0142c5e58..ad4fe2a99 100644 --- a/Modules/Graphics/App/Include/Methane/Graphics/AppBase.h +++ b/Modules/Graphics/App/Include/Methane/Graphics/AppBase.h @@ -94,7 +94,7 @@ class AppBase // NOSONAR void CompleteInitialization() const; void WaitForRenderComplete() const; - // Platform::AppBase interface + // Platform::Base::App interface Platform::AppView GetView() const override { return m_context.GetAppView(); } // IContextCallback implementation diff --git a/Modules/Graphics/App/README.md b/Modules/Graphics/App/README.md index bafe1d355..c0949137f 100644 --- a/Modules/Graphics/App/README.md +++ b/Modules/Graphics/App/README.md @@ -1,6 +1,6 @@ # Graphics App -Graphics application rendering infrastructure implemented on top of [application platform abstraction](../../Platform/App) +Graphics application rendering infrastructure implemented on top of [application platform abstraction](../../Platform/Impl/App) and [graphics RHI API](../RHI). ## Graphics Application Base Class @@ -28,7 +28,7 @@ The following settings are available: ### [Graphics::App](Include/Methane/Graphics/App.hpp) -Graphics application base template class `Graphics::App` is derived from [Platform::App](../../Platform/App) +Graphics application base template class `Graphics::App` is derived from [Platform::App](../../Platform/Impl/App) extending it with common graphics application functionality implemented with [Graphics::RHI](../RHI) API: - Parsing graphics app and context settings from command line arguments. - Graphics render context initialization using provided settings. @@ -44,7 +44,7 @@ and extended with other frame-dependent resources in final applications. `Graphics::AppSettings` structure aggregates 3 setting structures passed all together to the `Graphics::App` constructor: - [Graphics::IApp::Settings](#graphicsiappincludemethanegraphicsapph) - graphics app settings described above -- [Platform::AppBase::Settings](../../Platform/App/README.md#platformappbaseincludemethaneplatformappbaseh) - platform app settings +- [Platform::AppSettings](../../Platform/Impl/App/README.md#platform-application-base-class) - platform app settings - [Graphics::RenderContextSettings](../RHI/Interface/Include/Methane/Graphics/IRenderContext.h) - render context settings Some parameters of the render context settings can be also changed with command line flags: @@ -60,7 +60,7 @@ Some parameters of the render context settings can be also changed with command ### [Graphics::AppController](Include/Methane/Graphics/AppController.h) -Graphics **application** controller is derived from [Platform application controller](../../Platform/App/README.md#platformappcontrollerincludemethaneplatformappcontrollerh) and +Graphics **application** controller is derived from [Platform application controller](../../Platform/Impl/App/README.md#platform-application-controller) and extends it with the following actions: | Application Action | Keyboard Shortcut | diff --git a/Modules/Graphics/App/Sources/Methane/Graphics/AppController.cpp b/Modules/Graphics/App/Sources/Methane/Graphics/AppController.cpp index de0f983df..707fda4a2 100644 --- a/Modules/Graphics/App/Sources/Methane/Graphics/AppController.cpp +++ b/Modules/Graphics/App/Sources/Methane/Graphics/AppController.cpp @@ -31,7 +31,7 @@ namespace Methane::Graphics AppController::AppController(IApp& application, const std::string& application_help, const Platform::AppController::ActionByKeyboardState& platform_action_by_keyboard_state, const Graphics::AppController::ActionByKeyboardState& graphics_action_by_keyboard_state) - : Platform::AppController(dynamic_cast(application), application_help, platform_action_by_keyboard_state) + : Platform::AppController(dynamic_cast(application), application_help, platform_action_by_keyboard_state) , pin::Keyboard::ActionControllerBase(graphics_action_by_keyboard_state, {}) , m_application(application) { } diff --git a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/CommandList.hpp b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/CommandList.hpp index 4a2c18a9c..3c74c6740 100644 --- a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/CommandList.hpp +++ b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/CommandList.hpp @@ -151,7 +151,7 @@ class CommandList : public CommandListBaseT if (!CommandListBaseT::SetName(name)) return false; - m_ns_name = MacOS::ConvertToNsString(name); + m_ns_name = Platform::Apple::ConvertToNsString(name); if (m_mtl_cmd_encoder != nil) { diff --git a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/Context.hpp b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/Context.hpp index 2e28328e9..9c19dff42 100644 --- a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/Context.hpp +++ b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/Context.hpp @@ -138,7 +138,7 @@ class Context if (!Base::Context::SetName(name)) return false; - m_ns_name = MacOS::ConvertToNsString(name); + m_ns_name = Platform::Apple::ConvertToNsString(name); return true; } diff --git a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/RenderContextAppView.hh b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/RenderContextAppView.hh index 32a8c2fb9..7f7e25374 100644 --- a/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/RenderContextAppView.hh +++ b/Modules/Graphics/RHI/Metal/Include/Methane/Graphics/Metal/RenderContextAppView.hh @@ -46,7 +46,7 @@ inline AppViewMetal* CreateRenderContextAppView(const Platform::AppEnvironment& appWindow: env.ns_app_delegate.window pixelFormat: TypeConverter::DataFormatToMetalPixelType(settings.color_format) drawableCount: settings.frame_buffers_count - vsyncEnabled: MacOS::ConvertToNsBool(settings.vsync_enabled) + vsyncEnabled: Platform::Apple::ConvertToNsBool(settings.vsync_enabled) #ifdef APPLE_MACOS unsyncRefreshInterval: 1.0 / settings.unsync_max_fps #endif diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Buffer.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Buffer.mm index 1daa6bb5e..eb2bfbc74 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Buffer.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Buffer.mm @@ -66,7 +66,7 @@ static MTLResourceOptions GetNativeResourceOptions(Rhi::BufferStorageMode storag if (!Resource::SetName(name)) return false; - m_mtl_buffer.label = MacOS::ConvertToNsString(name); + m_mtl_buffer.label = Platform::Apple::ConvertToNsString(name); return true; } diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandListDebugGroup.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandListDebugGroup.mm index 0d97c38bd..68ce31efa 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandListDebugGroup.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandListDebugGroup.mm @@ -42,7 +42,7 @@ CommandListDebugGroup::CommandListDebugGroup(std::string_view name) : Base::CommandListDebugGroup(name) - , m_ns_name(MacOS::ConvertToNsString(Base::Object::GetName())) + , m_ns_name(Platform::Apple::ConvertToNsString(Base::Object::GetName())) { } } // namespace Methane::Graphics::Metal diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandQueue.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandQueue.mm index c9cf9daba..824d3753b 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandQueue.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/CommandQueue.mm @@ -98,7 +98,7 @@ return false; META_CHECK_NOT_NULL(m_mtl_command_queue); - m_mtl_command_queue.label = MacOS::ConvertToNsString(name); + m_mtl_command_queue.label = Platform::Apple::ConvertToNsString(name); return true; } diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ComputeState.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ComputeState.mm index 9f022b467..1907760bf 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ComputeState.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ComputeState.mm @@ -78,7 +78,7 @@ if (!Base::ComputeState::SetName(name)) return false; - NSString* ns_name = MacOS::ConvertToNsString(name); + NSString* ns_name = Platform::Apple::ConvertToNsString(name); m_mtl_pipeline_state_desc.label = ns_name; ResetNativeState(); @@ -98,7 +98,7 @@ error: &ns_error]; META_CHECK_NOT_NULL_DESCR(m_mtl_pipeline_state, "failed to create Metal compute pipeline state: {}", - MacOS::ConvertFromNsString([ns_error localizedDescription])); + Platform::Apple::ConvertFromNsString([ns_error localizedDescription])); } id ComputeState::GetNativePipelineState() diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/DebugMessages.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/DebugMessages.mm index 4f90c577f..50beee212 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/DebugMessages.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/DebugMessages.mm @@ -60,7 +60,7 @@ static bool IsEnvironmentVariableEnabled(const char* variable_name) static std::string GetNsStringOrDefault(NSString* ns_string, std::string_view default_value) { META_FUNCTION_TASK(); - return ns_string ? MacOS::ConvertFromNsString(ns_string) : std::string(default_value); + return ns_string ? Platform::Apple::ConvertFromNsString(ns_string) : std::string(default_value); } static std::string_view GetLogLevelSeverityName(NSInteger log_level) diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Device.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Device.mm index d017d5ae2..e9d4f18e7 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Device.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Device.mm @@ -44,7 +44,7 @@ } Device::Device(const id& mtl_device, const Capabilities& capabilities) - : Base::Device(MacOS::ConvertFromNsString(mtl_device.name), false, capabilities) + : Base::Device(Platform::Apple::ConvertFromNsString(mtl_device.name), false, capabilities) , m_mtl_device(mtl_device) , m_mtl_log_state(CreateDebugLogState(mtl_device)) { } diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Fence.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Fence.mm index 6f48c5127..6b886c248 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Fence.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Fence.mm @@ -105,7 +105,7 @@ if (!Base::Object::SetName(name)) return false; - m_mtl_event.label = MacOS::ConvertToNsString(name); + m_mtl_event.label = Platform::Apple::ConvertToNsString(name); return true; } diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Program.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Program.mm index f479d7d98..4b1b1dee5 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Program.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Program.mm @@ -132,7 +132,7 @@ META_CHECK_NOT_NULL_DESCR(mtl_render_pipeline_state, "Failed to create dummy pipeline state for program reflection: {}", - MacOS::ConvertFromNsString([ns_error localizedDescription])); + Platform::Apple::ConvertFromNsString([ns_error localizedDescription])); if (!mtl_render_pipeline_reflection) return; @@ -162,7 +162,7 @@ META_CHECK_NOT_NULL_DESCR(mtl_compute_pipeline_state, "Failed to create compute pipeline state for program reflection: {}", - MacOS::ConvertFromNsString([ns_error localizedDescription])); + Platform::Apple::ConvertFromNsString([ns_error localizedDescription])); if (!mtl_compute_pipeline_reflection) return; diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramLibrary.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramLibrary.mm index a3923b021..b02449b0f 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramLibrary.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/ProgramLibrary.mm @@ -37,7 +37,7 @@ static NSString* GetLibraryFullPath(std::string_view library_name) { const std::string library_path = fmt::format("{}/{}.metallib", Platform::GetResourceDir(), library_name); - return MacOS::ConvertToNsString(library_path); + return Platform::Apple::ConvertToNsString(library_path); } ProgramLibrary::ProgramLibrary(const Device& metal_device, std::string_view library_name) @@ -55,7 +55,7 @@ META_CHECK_NOT_NULL_DESCR(m_mtl_library, "Failed to create {} Metal library: {}", library_name.empty() ? std::string_view("default") : library_name, - MacOS::ConvertFromNsString([ns_error localizedDescription])); + Platform::Apple::ConvertFromNsString([ns_error localizedDescription])); } } diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderContext.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderContext.mm index d01fa7e1e..b7509ef3e 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderContext.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderContext.mm @@ -49,7 +49,7 @@ { META_FUNCTION_TASK(); - m_frame_capture_scope.label = MacOS::ConvertToNsString(fmt::format("{} Frame Scope", device.GetName())); + m_frame_capture_scope.label = Platform::Apple::ConvertToNsString(fmt::format("{} Frame Scope", device.GetName())); [MTLCaptureManager sharedCaptureManager].defaultCaptureScope = m_frame_capture_scope; #ifdef CAPTURE_INITIALIZATION_SCOPE @@ -241,8 +241,8 @@ NSError* ns_error = nil; const bool capture_success = [mtl_capture_manager startCaptureWithDescriptor:mtl_capture_desc error:&ns_error]; META_CHECK_TRUE_DESCR(capture_success, "failed to capture Metal scope '{}', error: {}", - MacOS::ConvertFromNsString(mtl_capture_scope.label), - MacOS::ConvertFromNsString([ns_error localizedDescription])); + Platform::Apple::ConvertFromNsString(mtl_capture_scope.label), + Platform::Apple::ConvertFromNsString([ns_error localizedDescription])); } } // namespace Methane::Graphics::Metal diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderState.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderState.mm index f69d5da1a..716602e1e 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderState.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/RenderState.mm @@ -275,7 +275,7 @@ static MTLWinding ConvertRasterizerFrontWindingToMetal(bool is_front_counter_clo if (!Base::RenderState::SetName(name)) return false; - NSString* ns_name = MacOS::ConvertToNsString(name); + NSString* ns_name = Platform::Apple::ConvertToNsString(name); m_mtl_pipeline_state_desc.label = ns_name; m_mtl_depth_stencil_state_desc.label = ns_name; @@ -300,7 +300,7 @@ static MTLWinding ConvertRasterizerFrontWindingToMetal(bool is_front_counter_clo m_mtl_pipeline_state = [GetMetalRenderContext().GetMetalDevice().GetNativeDevice() newRenderPipelineStateWithDescriptor:m_mtl_pipeline_state_desc error:&ns_error]; META_CHECK_NOT_NULL_DESCR(m_mtl_pipeline_state, "failed to create Metal render pipeline state: {}", - MacOS::ConvertFromNsString([ns_error localizedDescription])); + Platform::Apple::ConvertFromNsString([ns_error localizedDescription])); } void RenderState::InitializeNativeDepthStencilState() diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Sampler.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Sampler.mm index a7aefaa87..e71fed83b 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Sampler.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Sampler.mm @@ -128,7 +128,7 @@ static MTLSamplerBorderColor ConvertBorderColorToMetal(const Rhi::SamplerBorderC return false; META_CHECK_NOT_NULL(m_mtl_sampler_desc); - m_mtl_sampler_desc.label = MacOS::ConvertToNsString(name); + m_mtl_sampler_desc.label = Platform::Apple::ConvertToNsString(name); ResetSamplerState(); return true; diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Shader.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Shader.mm index 230b03328..3573ab382 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Shader.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Shader.mm @@ -239,7 +239,7 @@ static bool IsArgumentBufferName(std::string_view argument_name, Rhi::ProgramArg for(MTLStructMember* mtl_struct_member in mtl_element_struct_type.members) { member_by_name.try_emplace( - MacOS::ConvertFromNsString(mtl_struct_member.name), + Platform::Apple::ConvertFromNsString(mtl_struct_member.name), ArgumentBufferMember(mtl_struct_member) ); } @@ -264,7 +264,7 @@ static bool IsArgumentBufferName(std::string_view argument_name, Rhi::ProgramArg #ifdef METAL_LIBRARY_SPLIT_BY_SHADER_ENTRY_FUNCTION NSString* ns_shader_function_name = mtl_shader_library.functionNames.firstObject; #else - NSString* ns_shader_function_name = Methane::MacOS::ConvertToNsString(compiled_entry_function_name); + NSString* ns_shader_function_name = Methane::Platform::Apple::ConvertToNsString(compiled_entry_function_name); #endif return [mtl_shader_library newFunctionWithName: ns_shader_function_name]; @@ -281,7 +281,7 @@ static bool IsArgumentBufferName(std::string_view argument_name, Rhi::ProgramArg // Regex matching suffix of the input attributes "...123" static const std::regex s_attr_suffix_regex("\\d+$"); - std::string attrib_name = MacOS::ConvertFromNsString(ns_reflect_attrib_name); + std::string attrib_name = Platform::Apple::ConvertFromNsString(ns_reflect_attrib_name); attrib_name = std::regex_replace(attrib_name, s_attr_prefix_regex, ""); attrib_name = std::regex_replace(attrib_name, s_attr_suffix_regex, ""); @@ -350,7 +350,7 @@ static bool IsArgumentBufferName(std::string_view argument_name, Rhi::ProgramArg if (!mtl_binding.argument || !mtl_binding.used) continue; - const std::string argument_name = MacOS::ConvertFromNsString(mtl_binding.name); + const std::string argument_name = Platform::Apple::ConvertFromNsString(mtl_binding.name); if (argument_name.find("vertexBuffer.") == 0) { // Skip input vertex buffers, since they are set with a separate IRenderCommandList call, not through resource bindings @@ -403,7 +403,7 @@ static bool IsArgumentBufferName(std::string_view argument_name, Rhi::ProgramArg for(id mtl_binding in m_mtl_bindings) { Rhi::ProgramArgumentAccessType arg_access_type = Rhi::ProgramArgumentAccessType::Mutable; - const std::string argument_name = MacOS::ConvertFromNsString(mtl_binding.name); + const std::string argument_name = Platform::Apple::ConvertFromNsString(mtl_binding.name); if (mtl_binding.argument && mtl_binding.used && mtl_binding.type == MTLBindingTypeBuffer && IsArgumentBufferName(argument_name, arg_access_type)) diff --git a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Texture.mm b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Texture.mm index c9538d6cc..dd363b9d1 100644 --- a/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Texture.mm +++ b/Modules/Graphics/RHI/Metal/Sources/Methane/Graphics/Metal/Texture.mm @@ -250,7 +250,7 @@ static MTLRegion GetTextureRegion(const Dimensions& dimensions, Rhi::TextureDime const Settings& settings = GetSettings(); const MTLPixelFormat mtl_pixel_format = TypeConverter::DataFormatToMetalPixelType(settings.pixel_format); - const BOOL is_tex_mipmapped = MacOS::ConvertToNsBool(settings.mipmapped); + const BOOL is_tex_mipmapped = Platform::Apple::ConvertToNsBool(settings.mipmapped); MTLTextureDescriptor* mtl_tex_desc = nil; switch(settings.dimension_type) diff --git a/Modules/Platform/App/CMakeLists.txt b/Modules/Platform/App/CMakeLists.txt deleted file mode 100644 index 35f63828c..000000000 --- a/Modules/Platform/App/CMakeLists.txt +++ /dev/null @@ -1,151 +0,0 @@ -set(TARGET MethanePlatformApp) - -include(MethaneModules) - -get_module_dirs("Methane/Platform") - -if (WIN32) - - list(APPEND PLATFORM_HEADERS - ${INCLUDE_PLATFORM_OS_DIR}/AppWin.h - ) - - list(APPEND PLATFORM_SOURCES - ${SOURCES_PLATFORM_OS_DIR}/AppWin.cpp - ${SOURCES_PLATFORM_OS_DIR}/ConsoleStreams.h - ${SOURCES_PLATFORM_OS_DIR}/ConsoleStreams.cpp - ) - - list(APPEND PLATFORM_LIBRARIES - Shcore - ) - -elseif(APPLE) - - if (APPLE_MACOS) - list(APPEND PLATFORM_HEADERS - ${INCLUDE_PLATFORM_OS_DIR}/AppMac.hh - ${SOURCES_PLATFORM_OS_DIR}/WindowDelegate.hh - ) - list(APPEND PLATFORM_SOURCES - ${SOURCES_PLATFORM_OS_DIR}/AppMac.mm - ${SOURCES_PLATFORM_OS_DIR}/WindowDelegate.mm - ) - list(APPEND PLATFORM_LIBRARIES "-framework AppKit") - else() # iOS - list(APPEND PLATFORM_HEADERS - ${INCLUDE_PLATFORM_OS_DIR}/AppIOS.hh - ) - list(APPEND PLATFORM_SOURCES - ${SOURCES_PLATFORM_OS_DIR}/AppIOS.mm - ) - list(APPEND PLATFORM_LIBRARIES "-framework UIKit") - endif() # APPLE_MACOS - - list(APPEND PLATFORM_HEADERS - ${SOURCES_PLATFORM_OS_DIR}/AppDelegate.hh - ${SOURCES_PLATFORM_OS_DIR}/AppViewController.hh - ) - list(APPEND PLATFORM_SOURCES - ${SOURCES_PLATFORM_OS_DIR}/AppDelegate.mm - ${SOURCES_PLATFORM_OS_DIR}/AppViewController.mm - ) - -else(LINUX) - - list(APPEND PLATFORM_HEADERS - ${INCLUDE_PLATFORM_OS_DIR}/AppLin.h - ) - - list(APPEND PLATFORM_SOURCES - ${SOURCES_PLATFORM_OS_DIR}/AppLin.cpp - ${SOURCES_PLATFORM_OS_DIR}/MessageBox.h - ${SOURCES_PLATFORM_OS_DIR}/MessageBox.cpp - ${SOURCES_PLATFORM_OS_DIR}/XcbUtils.h - ${SOURCES_PLATFORM_OS_DIR}/XcbUtils.cpp - ) - - set(PLATFORM_LIBRARIES X11::X11 X11::X11_xcb X11::xcb X11::xcb_randr X11::xcb_sync STB) - -endif() - -list(APPEND HEADERS ${PLATFORM_HEADERS} - ${INCLUDE_DIR}/IApp.h - ${INCLUDE_DIR}/App.h - ${INCLUDE_DIR}/AppBase.h - ${INCLUDE_DIR}/AppController.h -) - -list(APPEND SOURCES ${PLATFORM_SOURCES} - ${SOURCES_DIR}/IApp.cpp - ${SOURCES_DIR}/AppBase.cpp - ${SOURCES_DIR}/AppController.cpp -) - -add_library(${TARGET} STATIC - ${HEADERS} - ${SOURCES} -) - -target_link_libraries(${TARGET} - PUBLIC - CLI11 - MethanePrimitives - MethaneInstrumentation - MethaneDataTypes - MethanePlatformAppView - MethanePlatformInputActionControllers - PRIVATE - MethaneBuildOptions - MethaneCommonPrecompiledHeaders - MethanePlatformUtils - MethaneDataProvider - TaskFlow - fmt - nowide - ${PLATFORM_LIBRARIES} -) - -target_compile_definitions(${TARGET} - PRIVATE - METHANE_RENDER_APP -) - -if(METHANE_PRECOMPILED_HEADERS_ENABLED) - target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) -endif() - -target_include_directories(${TARGET} - PRIVATE - Sources - PUBLIC - Include -) - -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) - -set_target_properties(${TARGET} - PROPERTIES - FOLDER Modules/Platform - PUBLIC_HEADER "${HEADERS}" -) - -if (APPLE) - # Disable precompiled headers on MacOS for Objective-C files: - set_source_files_properties( - ${PLATFORM_SOURCES} - PROPERTIES - COMPILE_FLAGS -fobjc-arc - SKIP_PRECOMPILE_HEADERS ON - ) -endif() - -install(TARGETS ${TARGET} - PUBLIC_HEADER - DESTINATION ${INSTALL_INCLUDE_DIR} - COMPONENT Development - ARCHIVE - DESTINATION lib - COMPONENT Development -) - diff --git a/Modules/Platform/App/README.md b/Modules/Platform/App/README.md deleted file mode 100644 index 3f203b502..000000000 --- a/Modules/Platform/App/README.md +++ /dev/null @@ -1,55 +0,0 @@ -# Platform App - -Platform abstraction of the windowed application with main purpose for graphics content rendering. -Graphics rendering infrastructure itself is split into derived class defined in a separate library. - -### [Platform::App](Include/Methane/Platform/App.h) - -Defines alias type `Platform::App` pointing to one of platform-specific implementations of the `AppBase` abstract class: -- [Platform::AppWin](Include/Methane/Platform/Windows/AppWin.h) - Windows app implementation -- [Platform::AppLin](Include/Methane/Platform/Linux/AppLin.h) - Linux app implementation -- [Platform::AppMac](Include/Methane/Platform/MacOS/AppMac.hh) - MacOS app implementation -- [Platform::AppIOS](Include/Methane/Platform/iOS/AppIOS.hh) - iOS app implementation - -`Platform::App` should be used as a base class for any windowed Methane application. - -## Platform Application Base Classes - -### [Platform::AppBase](Include/Methane/Platform/AppBase.h) - -Base interface and platform-abstraction implementation of the application class with the following functionality: -- Initial application settings setup (see table below) -- Running application with a given command line arguments and parsing platform app settings from cmd arguments -- Live window resizing with frame re-render on resize iterations -- Switching window to full-screen mode -- Processing keyboard and mouse input via `Platform::Input::State` -- Adding [platform application controller](#platform-application-controller) to input state processor -- Setting title in window header -- Showing user alert in message box dialog -- Displaying application controls and command line help -- Shared parallel task execution engine with thread pool [Taskflow::Executor](../../../Externals/TaskFlow) - -The following settings are available in `Platform::AppBase::Settings` structure: - -| Setting | Type | Default Value | Cmd-Line Option | Description | -|----------------|----------|---------------|------------------|-----------------------| -| name | uint32_t | "" | | Application name displayed in window header | -| width | double | 0.8 | -w,--width | Main window width (if < 1.0 it is a ratio of desktop size; else size in pixels/dots) | -| height | double | 0.8 | -x,--height | Main window height (if < 1.0 it is a ratio of desktop size; else size in pixels/dots) | -| min_width | uint32_t | 640 | | Minimum window width in pixels/dots limited for resizing | -| min_height | uint32_t | 480 | | Minimum window height in pixels/dots limited for resizing | -| is_full_screen | bool | false | -f,--full-screen | Full-screen state of the main window | - -## Platform Application Controller - -### [Platform::AppController](Include/Methane/Platform/AppController.h) - -Platform application controller implements the following actions: - -| Action | Keyboard Shortcut | -|------------------------|---------------------| -| Show controls help | F1 | -| Show command-line help | F2 | -| Show parameters | F3 | -| Switch full-screen | LCtrl + F | -| Close application | LCtrl/LCmd + Q | diff --git a/Modules/Platform/App/Sources/Methane/Platform/IApp.cpp b/Modules/Platform/App/Sources/Methane/Platform/IApp.cpp deleted file mode 100644 index a261c9f3c..000000000 --- a/Modules/Platform/App/Sources/Methane/Platform/IApp.cpp +++ /dev/null @@ -1,3 +0,0 @@ -// -// Created by egorodet on 11/19/2022. -// diff --git a/Modules/Platform/AppView/CMakeLists.txt b/Modules/Platform/AppView/CMakeLists.txt deleted file mode 100644 index 1f1a9cc31..000000000 --- a/Modules/Platform/AppView/CMakeLists.txt +++ /dev/null @@ -1,107 +0,0 @@ -set(TARGET MethanePlatformAppView) - -include(MethaneModules) - -get_module_dirs("Methane/Platform") - -if (WIN32) - - list(APPEND PLATFORM_HEADERS - ${INCLUDE_PLATFORM_OS_DIR}/AppEnvironment.h - ) - -elseif(APPLE) - - list(APPEND PLATFORM_HEADERS - ${INCLUDE_PLATFORM_OS_DIR}/AppViewMetal.hh - ${INCLUDE_PLATFORM_OS_DIR}/AppEnvironment.hh - ) - - list(APPEND PLATFORM_SOURCES - ${SOURCES_PLATFORM_OS_DIR}/AppViewMetal.mm - ) - - list(APPEND PLATFORM_LIBRARIES - "-framework $,AppKit,UIKit>" - "-framework Metal" - "-framework QuartzCore" - ) - - # CLANG_ENABLE_OBJC_WEAK = YES - set_source_files_properties( - ${PLATFORM_SOURCES} - PROPERTIES - COMPILE_FLAGS -fobjc-weak - ) - -else() # Linux - - list(APPEND PLATFORM_HEADERS - ${INCLUDE_PLATFORM_OS_DIR}/AppEnvironment.h - ) - -endif() - -list(APPEND HEADERS - ${PLATFORM_HEADERS} - ${INCLUDE_DIR}/AppView.h - ${INCLUDE_DIR}/AppEnvironment.h -) - -list(APPEND SOURCES - ${PLATFORM_SOURCES} - ${SOURCES_DIR}/AppView.cpp -) - -add_library(${TARGET} STATIC - ${HEADERS} - ${SOURCES} -) - -target_link_libraries(${TARGET} - PRIVATE - MethaneBuildOptions - MethaneInstrumentation - MethaneDataTypes - ${PLATFORM_LIBRARIES} -) - -target_include_directories(${TARGET} - PRIVATE - Sources - PUBLIC - Include -) - -target_compile_definitions(${TARGET} - PRIVATE - $<$:METHANE_GPU_INSTRUMENTATION_ENABLED> -) - -source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) - -set_target_properties(${TARGET} - PROPERTIES - FOLDER Modules/Platform - PUBLIC_HEADER "${HEADERS}" -) - -if (APPLE) - # Disable precompiled headers and enable ARC on MacOS for Objective-C files: - set_source_files_properties( - ${PLATFORM_SOURCES} - PROPERTIES - COMPILE_FLAGS -fobjc-arc - SKIP_PRECOMPILE_HEADERS ON - ) -endif() - -install(TARGETS ${TARGET} - PUBLIC_HEADER - DESTINATION ${INSTALL_INCLUDE_DIR} - COMPONENT Development - ARCHIVE - DESTINATION lib - COMPONENT Development -) - diff --git a/Modules/Platform/Apple/CMakeLists.txt b/Modules/Platform/Apple/CMakeLists.txt new file mode 100644 index 000000000..d4ab7d4a4 --- /dev/null +++ b/Modules/Platform/Apple/CMakeLists.txt @@ -0,0 +1,9 @@ +# Modules shared by all Apple platforms: +add_subdirectory(Utils) + +# Modules of the particular Apple platform: +if(APPLE_MACOS) + add_subdirectory(MacOS) +else() # iOS / tvOS + add_subdirectory(iOS) +endif() diff --git a/Modules/Platform/Apple/MacOS/App/CMakeLists.txt b/Modules/Platform/Apple/MacOS/App/CMakeLists.txt new file mode 100644 index 000000000..410d286f6 --- /dev/null +++ b/Modules/Platform/Apple/MacOS/App/CMakeLists.txt @@ -0,0 +1,81 @@ +set(TARGET MethanePlatformAppMacOS) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/App.hh + ${SOURCES_PLATFORM_OS_DIR}/AppDelegate.hh + ${SOURCES_PLATFORM_OS_DIR}/AppViewController.hh + ${SOURCES_PLATFORM_OS_DIR}/WindowDelegate.hh +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/App.mm + ${SOURCES_PLATFORM_OS_DIR}/AppDelegate.mm + ${SOURCES_PLATFORM_OS_DIR}/AppViewController.mm + ${SOURCES_PLATFORM_OS_DIR}/WindowDelegate.mm +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformAppBase + MethanePlatformAppViewMacOS + MethanePlatformInputKeyboardMacOS + "-framework AppKit" + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePlatformUtilsApple + MethaneDataProvider + fmt + nowide +) + +target_compile_definitions(${TARGET} + PRIVATE + METHANE_RENDER_APP +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + ${SOURCES_PLATFORM_OS_DIR} + PUBLIC + Include +) + +# Disable precompiled headers and enable ARC for Objective-C sources: +set_source_files_properties( + ${SOURCES} + PROPERTIES + COMPILE_FLAGS -fobjc-arc + SKIP_PRECOMPILE_HEADERS ON +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Apple/MacOS + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/MacOS/AppMac.hh b/Modules/Platform/Apple/MacOS/App/Include/Methane/Platform/MacOS/App.hh similarity index 82% rename from Modules/Platform/App/Include/Methane/Platform/MacOS/AppMac.hh rename to Modules/Platform/Apple/MacOS/App/Include/Methane/Platform/MacOS/App.hh index f535e4aeb..b9cccd0c7 100644 --- a/Modules/Platform/App/Include/Methane/Platform/MacOS/AppMac.hh +++ b/Modules/Platform/Apple/MacOS/App/Include/Methane/Platform/MacOS/App.hh @@ -16,14 +16,14 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/MacOS/AppMac.h +FILE: Methane/Platform/MacOS/App.hh MacOS application implementation. ******************************************************************************/ #pragma once -#include +#include #include #ifdef __OBJC__ @@ -46,17 +46,17 @@ using NSWindow = void; #endif // __OBJC__ -namespace Methane::Platform +namespace Methane::Platform::MacOS { -class AppMac : public AppBase +class App : public Base::App { public: - static AppMac* GetInstance(); + static App* GetInstance(); - explicit AppMac(const AppBase::Settings& settings); + explicit App(const Base::App::Settings& settings); - // AppBase interface + // Base::App interface void InitContext(const Platform::AppEnvironment& env, const Data::FrameSize& frame_size) override; int Run(const RunArgs& args) override; void Alert(const Message& msg, bool deferred = false) override; @@ -67,11 +67,11 @@ public: void Close() override; void SetWindow(NSWindow* ns_window); - bool SetFullScreenInternal(bool is_full_screen) { return AppBase::SetFullScreen(is_full_screen); } + bool SetFullScreenInternal(bool is_full_screen) { return Base::App::SetFullScreen(is_full_screen); } NSWindow* GetWindow() { return m_ns_window; } // NOSONAR protected: - // AppBase interface + // Base::App interface void ShowAlert(const Message& msg) override; private: @@ -79,7 +79,7 @@ private: AppDelegateType* m_ns_app_delegate = nullptr; // NOSONAR NSWindow* m_ns_window = nullptr; // NOSONAR - static AppMac* s_instance_ptr; + static App* s_instance_ptr; }; -} // namespace Methane::Platform +} // namespace Methane::Platform::MacOS diff --git a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppMac.mm b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/App.mm similarity index 68% rename from Modules/Platform/App/Sources/Methane/Platform/MacOS/AppMac.mm rename to Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/App.mm index 9dabede0f..c03691e3d 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppMac.mm +++ b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/App.mm @@ -16,41 +16,42 @@ ******************************************************************************* -FILE: Methane/Platform/MacOS/AppMac.mm +FILE: Methane/Platform/MacOS/App.mm MacOS application implementation. ******************************************************************************/ -#include +#include #include #include #include -namespace Methane::Platform +namespace Methane::Platform::MacOS { -AppMac* AppMac::s_instance_ptr = nullptr; +App* App::s_instance_ptr = nullptr; -static NSAlertStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Type msg_type) +static NSAlertStyle ConvertMessageTypeToNsAlertStyle(Base::App::Message::Type msg_type) { META_FUNCTION_TASK(); switch(msg_type) { - case AppBase::Message::Type::Information: return NSAlertStyleInformational; - case AppBase::Message::Type::Warning: return NSAlertStyleWarning; - case AppBase::Message::Type::Error: return NSAlertStyleCritical; + using enum Base::App::Message::Type; + case Information: return NSAlertStyleInformational; + case Warning: return NSAlertStyleWarning; + case Error: return NSAlertStyleCritical; default: META_UNEXPECTED_RETURN(msg_type, NSAlertStyleInformational); } } -AppMac* AppMac::GetInstance() +App* App::GetInstance() { META_FUNCTION_TASK(); return s_instance_ptr; } -AppMac::AppMac(const AppBase::Settings& settings) - : AppBase(settings) +App::App(const Base::App::Settings& settings) + : Base::App(settings) , m_ns_app([NSApplication sharedApplication]) { META_FUNCTION_TASK(); @@ -58,7 +59,7 @@ static NSAlertStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Type msg_ s_instance_ptr = this; } -void AppMac::InitContext(const Platform::AppEnvironment& /*env*/, const Data::FrameSize& /*frame_size*/) +void App::InitContext(const Platform::AppEnvironment& /*env*/, const Data::FrameSize& /*frame_size*/) { META_FUNCTION_TASK(); AppView app_view = GetView(); @@ -68,10 +69,10 @@ static NSAlertStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Type msg_ [m_ns_window.contentView addSubview: app_view.native_view_ptr]; } -int AppMac::Run(const RunArgs& args) +int App::Run(const RunArgs& args) { META_FUNCTION_TASK(); - const int base_return_code = AppBase::Run(args); + const int base_return_code = Base::App::Run(args); if (base_return_code) return base_return_code; @@ -82,7 +83,7 @@ static NSAlertStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Type msg_ return 0; } -void AppMac::Alert(const Message& msg, bool deferred) +void App::Alert(const Message& msg, bool deferred) { META_FUNCTION_TASK(); if (deferred) @@ -100,40 +101,40 @@ static NSAlertStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Type msg_ ShowAlert(msg); } - AppBase::Alert(msg, deferred); + Base::App::Alert(msg, deferred); } -void AppMac::SetWindowTitle(const std::string& title_text) +void App::SetWindowTitle(const std::string& title_text) { META_FUNCTION_TASK(); - NSString* ns_title_text = MacOS::ConvertToNsString(title_text); + NSString* ns_title_text = Apple::ConvertToNsString(title_text); dispatch_async(dispatch_get_main_queue(), ^(void){ m_ns_window.title = ns_title_text; }); } -void AppMac::SetWindow(NSWindow* ns_window) +void App::SetWindow(NSWindow* ns_window) { META_FUNCTION_TASK(); m_ns_window = ns_window; } -void AppMac::ShowAlert(const Message& msg) +void App::ShowAlert(const Message& msg) { META_FUNCTION_TASK(); META_CHECK_NOT_NULL(m_ns_app_delegate); - [m_ns_app_delegate alert: MacOS::ConvertToNsString(msg.title) - withInformation: MacOS::ConvertToNsString(msg.information) + [m_ns_app_delegate alert: Apple::ConvertToNsString(msg.title) + withInformation: Apple::ConvertToNsString(msg.information) andStyle: ConvertMessageTypeToNsAlertStyle(msg.type)]; - AppBase::ShowAlert(msg); + Base::App::ShowAlert(msg); } -bool AppMac::SetFullScreen(bool is_full_screen) +bool App::SetFullScreen(bool is_full_screen) { META_FUNCTION_TASK(); - if (!AppBase::SetFullScreen(is_full_screen)) + if (!Base::App::SetFullScreen(is_full_screen)) return false; const NSApplicationPresentationOptions app_options = [m_ns_app presentationOptions]; @@ -145,22 +146,22 @@ static NSAlertStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Type msg_ return true; } -float AppMac::GetContentScalingFactor() const +float App::GetContentScalingFactor() const { META_FUNCTION_TASK(); return static_cast(m_ns_window.backingScaleFactor); } -uint32_t AppMac::GetFontResolutionDpi() const +uint32_t App::GetFontResolutionDpi() const { META_FUNCTION_TASK(); return 72U * GetContentScalingFactor(); } -void AppMac::Close() +void App::Close() { META_FUNCTION_TASK(); [m_ns_window close]; } -} // namespace Methane::Platform +} // namespace Methane::Platform::MacOS diff --git a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppDelegate.hh b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppDelegate.hh similarity index 83% rename from Modules/Platform/App/Sources/Methane/Platform/MacOS/AppDelegate.hh rename to Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppDelegate.hh index bb21d58b6..f43a74cd7 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppDelegate.hh +++ b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppDelegate.hh @@ -23,18 +23,18 @@ MacOS application delegate implementation. #include "AppViewController.hh" -#include +#include #import -namespace Methane::Platform { class AppMac; } +namespace Methane::Platform::MacOS { class App; } @interface AppDelegate : NSObject @property (nonatomic, strong, nonnull) IBOutlet AppViewController* viewController; @property (nonatomic, readwrite, nullable, retain) NSWindow* window; -- (id _Nullable) initWithApp : (Methane::Platform::AppMac* _Nonnull) app_ptr andSettings : (const Methane::Platform::AppBase::Settings* _Nonnull) settings_ptr; +- (id _Nullable) initWithApp : (Methane::Platform::MacOS::App* _Nonnull) app_ptr andSettings : (const Methane::Platform::Base::App::Settings* _Nonnull) settings_ptr; - (void) run; - (void) alert : (nonnull NSString*) ns_title withInformation: (nonnull NSString*) ns_info andStyle: (NSAlertStyle) ns_alert_style; diff --git a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppDelegate.mm b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppDelegate.mm similarity index 94% rename from Modules/Platform/App/Sources/Methane/Platform/MacOS/AppDelegate.mm rename to Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppDelegate.mm index 4dadad607..950f8fc10 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppDelegate.mm +++ b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppDelegate.mm @@ -25,7 +25,7 @@ #import "WindowDelegate.hh" -#include +#include #include #include #include @@ -40,7 +40,7 @@ @implementation AppDelegate @synthesize window = m_window; -- (id) initWithApp : (AppMac*) app_ptr andSettings : (const AppBase::Settings*) settings_ptr +- (id) initWithApp : (MacOS::App*) app_ptr andSettings : (const Base::App::Settings*) settings_ptr { META_FUNCTION_TASK(); self = [super init]; @@ -70,7 +70,7 @@ - (id) initWithApp : (AppMac*) app_ptr andSettings : (const AppBase::Settings*) m_window = [[NSWindow alloc] initWithContentRect:frame styleMask:style_mask backing:backing defer:YES]; m_window.contentMinSize = NSMakeSize(static_cast(min_frame_size.GetWidth()), static_cast(min_frame_size.GetHeight())); - m_window.title = MacOS::ConvertToNsString(settings_ptr->name); + m_window.title = Apple::ConvertToNsString(settings_ptr->name); // Window state restoration is not implemented and window size and position are set from application settings, // so it is disabled to stop AppKit from persisting the saved state of the window which is never restored @@ -133,7 +133,7 @@ - (void) windowWillEnterFullScreen:(NSNotification *)notification { META_FUNCTION_TASK(); #pragma unused(notification) - AppMac* app_ptr = [self.viewController getApp]; + MacOS::App* app_ptr = [self.viewController getApp]; META_CHECK_NOT_NULL(app_ptr); app_ptr->SetFullScreenInternal(true); } @@ -142,7 +142,7 @@ - (void) windowWillExitFullScreen:(NSNotification *)notification { META_FUNCTION_TASK(); #pragma unused(notification) - AppMac* app_ptr = [self.viewController getApp]; + MacOS::App* app_ptr = [self.viewController getApp]; META_CHECK_NOT_NULL(app_ptr); app_ptr->SetFullScreenInternal(false); } diff --git a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppViewController.hh b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppViewController.hh similarity index 83% rename from Modules/Platform/App/Sources/Methane/Platform/MacOS/AppViewController.hh rename to Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppViewController.hh index 816169ed7..135444100 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppViewController.hh +++ b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppViewController.hh @@ -23,13 +23,13 @@ MacOS application view controller implementation. #import -namespace Methane::Platform { class AppMac; } +namespace Methane::Platform::MacOS { class App; } @interface AppViewController : NativeViewController @property (nonatomic, readonly, nullable) NSWindow* window; -- (id _Nullable) initWithApp : (Methane::Platform::AppMac* _Nonnull) app_ptr andFrameRect : (NSRect) frame; -- (Methane::Platform::AppMac* _Nonnull) getApp; +- (id _Nullable) initWithApp : (Methane::Platform::MacOS::App* _Nonnull) app_ptr andFrameRect : (NSRect) frame; +- (Methane::Platform::MacOS::App* _Nonnull) getApp; @end diff --git a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppViewController.mm b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppViewController.mm similarity index 95% rename from Modules/Platform/App/Sources/Methane/Platform/MacOS/AppViewController.mm rename to Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppViewController.mm index ce3b142e7..c225453b7 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/MacOS/AppViewController.mm +++ b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/AppViewController.mm @@ -23,7 +23,8 @@ #import "AppViewController.hh" -#include +#include +#include #include #include #include @@ -36,13 +37,13 @@ @implementation AppViewController { - pal::AppMac* m_app_ptr; - NSRect m_frame_rect; - bool m_is_initialized; - std::string m_error; + pal::MacOS::App* m_app_ptr; + NSRect m_frame_rect; + bool m_is_initialized; + std::string m_error; } -- (id) initWithApp : (pal::AppMac*) app_ptr andFrameRect : (NSRect) frame_rect +- (id) initWithApp : (pal::MacOS::App*) app_ptr andFrameRect : (NSRect) frame_rect { META_FUNCTION_TASK(); @@ -63,7 +64,7 @@ -(NSWindow*) window return m_app_ptr ? m_app_ptr->GetWindow() : nil; } -- (pal::AppMac*) getApp +- (pal::MacOS::App*) getApp { return m_app_ptr; } diff --git a/Modules/Platform/App/Sources/Methane/Platform/MacOS/WindowDelegate.hh b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/WindowDelegate.hh similarity index 87% rename from Modules/Platform/App/Sources/Methane/Platform/MacOS/WindowDelegate.hh rename to Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/WindowDelegate.hh index b65081b99..6017b7fcc 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/MacOS/WindowDelegate.hh +++ b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/WindowDelegate.hh @@ -23,10 +23,10 @@ MacOS application delegate implementation. #import -namespace Methane { namespace Platform { class AppMac; } } +namespace Methane::Platform::MacOS { class App; } @interface WindowDelegate : NSObject -- (id _Nullable) initWithApp : (Methane::Platform::AppMac* _Nonnull) app_ptr; +- (id _Nullable) initWithApp : (Methane::Platform::MacOS::App* _Nonnull) app_ptr; @end diff --git a/Modules/Platform/App/Sources/Methane/Platform/MacOS/WindowDelegate.mm b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/WindowDelegate.mm similarity index 96% rename from Modules/Platform/App/Sources/Methane/Platform/MacOS/WindowDelegate.mm rename to Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/WindowDelegate.mm index f261a1344..892640179 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/MacOS/WindowDelegate.mm +++ b/Modules/Platform/Apple/MacOS/App/Sources/Methane/Platform/MacOS/WindowDelegate.mm @@ -23,7 +23,7 @@ #import "WindowDelegate.hh" -#include +#include #include #include @@ -32,11 +32,11 @@ @implementation WindowDelegate { - AppMac* m_app_ptr; + MacOS::App* m_app_ptr; Data::FrameSize m_frame_size; } -- (id) initWithApp : (AppMac*) app_ptr +- (id) initWithApp : (MacOS::App*) app_ptr { META_FUNCTION_TASK(); diff --git a/Modules/Platform/Apple/MacOS/AppView/CMakeLists.txt b/Modules/Platform/Apple/MacOS/AppView/CMakeLists.txt new file mode 100644 index 000000000..ea0488831 --- /dev/null +++ b/Modules/Platform/Apple/MacOS/AppView/CMakeLists.txt @@ -0,0 +1,67 @@ +set(TARGET MethanePlatformAppViewMacOS) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/AppEnvironment.hh + ${INCLUDE_PLATFORM_OS_DIR}/AppViewMetal.hh +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/AppViewMetal.mm +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + "-framework AppKit" + "-framework Metal" + "-framework QuartzCore" + PRIVATE + MethaneBuildOptions + MethaneInstrumentation + MethaneDataTypes +) + +target_compile_definitions(${TARGET} + PRIVATE + $<$:METHANE_GPU_INSTRUMENTATION_ENABLED> +) + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +# Disable precompiled headers, enable ARC and weak Objective-C references: +set_source_files_properties( + ${SOURCES} + PROPERTIES + COMPILE_FLAGS "-fobjc-arc -fobjc-weak" + SKIP_PRECOMPILE_HEADERS ON +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Apple/MacOS + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/AppView/Include/Methane/Platform/MacOS/AppEnvironment.hh b/Modules/Platform/Apple/MacOS/AppView/Include/Methane/Platform/MacOS/AppEnvironment.hh similarity index 100% rename from Modules/Platform/AppView/Include/Methane/Platform/MacOS/AppEnvironment.hh rename to Modules/Platform/Apple/MacOS/AppView/Include/Methane/Platform/MacOS/AppEnvironment.hh diff --git a/Modules/Platform/AppView/Include/Methane/Platform/MacOS/AppViewMetal.hh b/Modules/Platform/Apple/MacOS/AppView/Include/Methane/Platform/MacOS/AppViewMetal.hh similarity index 100% rename from Modules/Platform/AppView/Include/Methane/Platform/MacOS/AppViewMetal.hh rename to Modules/Platform/Apple/MacOS/AppView/Include/Methane/Platform/MacOS/AppViewMetal.hh diff --git a/Modules/Platform/AppView/Sources/Methane/Platform/MacOS/AppViewMetal.mm b/Modules/Platform/Apple/MacOS/AppView/Sources/Methane/Platform/MacOS/AppViewMetal.mm similarity index 100% rename from Modules/Platform/AppView/Sources/Methane/Platform/MacOS/AppViewMetal.mm rename to Modules/Platform/Apple/MacOS/AppView/Sources/Methane/Platform/MacOS/AppViewMetal.mm diff --git a/Modules/Platform/Apple/MacOS/CMakeLists.txt b/Modules/Platform/Apple/MacOS/CMakeLists.txt new file mode 100644 index 000000000..421717e6f --- /dev/null +++ b/Modules/Platform/Apple/MacOS/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(Input) +add_subdirectory(AppView) +add_subdirectory(App) diff --git a/Modules/Platform/Apple/MacOS/Input/CMakeLists.txt b/Modules/Platform/Apple/MacOS/Input/CMakeLists.txt new file mode 100644 index 000000000..df28aa576 --- /dev/null +++ b/Modules/Platform/Apple/MacOS/Input/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Keyboard) diff --git a/Modules/Platform/Apple/MacOS/Input/Keyboard/CMakeLists.txt b/Modules/Platform/Apple/MacOS/Input/Keyboard/CMakeLists.txt new file mode 100644 index 000000000..778877812 --- /dev/null +++ b/Modules/Platform/Apple/MacOS/Input/Keyboard/CMakeLists.txt @@ -0,0 +1,66 @@ +set(TARGET MethanePlatformInputKeyboardMacOS) + +include(MethaneModules) + +get_module_dirs("Methane/Platform/Input") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/Keyboard.h +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/Keyboard.mm +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformInputKeyboardBase + "-framework AppKit" + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePrimitives + MethaneInstrumentation + magic_enum +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +# Disable precompiled headers and enable ARC for Objective-C sources: +set_source_files_properties( + ${SOURCES} + PROPERTIES + COMPILE_FLAGS -fobjc-arc + SKIP_PRECOMPILE_HEADERS ON +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Apple/MacOS/Input + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/MacOS/Keyboard.h b/Modules/Platform/Apple/MacOS/Input/Keyboard/Include/Methane/Platform/Input/MacOS/Keyboard.h similarity index 100% rename from Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/MacOS/Keyboard.h rename to Modules/Platform/Apple/MacOS/Input/Keyboard/Include/Methane/Platform/Input/MacOS/Keyboard.h diff --git a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/MacOS/Keyboard.mm b/Modules/Platform/Apple/MacOS/Input/Keyboard/Sources/Methane/Platform/Input/MacOS/Keyboard.mm similarity index 96% rename from Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/MacOS/Keyboard.mm rename to Modules/Platform/Apple/MacOS/Input/Keyboard/Sources/Methane/Platform/Input/MacOS/Keyboard.mm index e0a6c56df..af47d2113 100644 --- a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/MacOS/Keyboard.mm +++ b/Modules/Platform/Apple/MacOS/Input/Keyboard/Sources/Methane/Platform/Input/MacOS/Keyboard.mm @@ -21,6 +21,7 @@ ******************************************************************************/ +#include #include #include @@ -181,4 +182,9 @@ return modifiers_mask; } +KeyConverter::KeyConverter(const NativeKey& native_key) + : m_key(GetKeyByNativeCode(native_key)) + , m_modifiers(GetModifiersByNativeCode(native_key)) +{ } + } // namespace Methane::Platform::Input::Keyboard \ No newline at end of file diff --git a/Modules/Platform/Apple/MacOS/README.md b/Modules/Platform/Apple/MacOS/README.md new file mode 100644 index 000000000..c61d6cc8c --- /dev/null +++ b/Modules/Platform/Apple/MacOS/README.md @@ -0,0 +1,57 @@ +# Methane Platform MacOS + +MacOS implementation of the [Platform modules](../../README.md), in namespace +`Methane::Platform::MacOS`, built on **AppKit**. Added to the build by +[Apple/CMakeLists.txt](../CMakeLists.txt) when `APPLE_MACOS` is set, alongside the shared +[Apple](../README.md) modules. + +| Module | CMake Target | Content | +|----------------------------------|-----------------------------------|-----------------------------------------------| +| [App](App) | MethanePlatformAppMacOS | `MacOS::App` AppKit windowed application | +| [AppView](AppView) | MethanePlatformAppViewMacOS | `AppViewMetal` view and `AppEnvironment` | +| [Input/Keyboard](Input/Keyboard) | MethanePlatformInputKeyboardMacOS | `Keyboard::NativeKey` and its key translation | + +Linked frameworks: `AppKit`, `Metal`, `QuartzCore`. + +## App + +[`MacOS::App`](App/Include/Methane/Platform/MacOS/App.hh) derives from [`Base::App`](../../Base/App) +and owns the AppKit object graph, which is split across several Objective-C classes in +[App/Sources](App/Sources/Methane/Platform/MacOS): + +| Class | Role | +|----------------------|--------------------------------------------------------------------------| +| `AppDelegate` | `NSApplicationDelegate`: creates the `NSWindow` and the view controller | +| `WindowDelegate` | `NSWindowDelegate`: window resize, move, focus and close events | +| `AppViewController` | `NSViewController`: drives drawing and input events | + +Because AppKit delegates are constructed by the framework and receive no user pointer, `MacOS::App` +exposes a **singleton** `App::GetInstance()` so the delegates can reach the application instance. + +`METHANE_RENDER_APP` is defined privately for this target and gates the `AppDelegate.hh` import in +the otherwise public `App.hh`, which keeps the delegate out of the installed public header set. + +## AppView + +`AppViewMetal` is an `NSView` backed by a `CAMetalLayer`; `Metal::RenderContext` draws into its +drawables, and `AppEnvironment` carries a `NativeViewController` +(`NSViewController`) rather than a raw window handle. The `MetalAppViewDelegate` +protocol is what lets the RHI layer hand frames back to the view and react to drawable size changes. + +`AppViewMetal.mm` is compiled with `-fobjc-weak` in addition to ARC, as it holds weak references to +its delegate. + +## Input/Keyboard + +`Keyboard::NativeKey` holds the `NSEvent` `keyCode` (`uint16_t`) and `modifierFlags` (`uint64_t`). +Note that MacOS is the **only** Apple platform with a keyboard module — see +[iOS/README.md](../iOS/README.md). + +`Input::Keyboard::OS::g_key_left_ctrl` maps to `Key::LeftSuper` on Apple platforms, so the +Command key takes the role Control plays elsewhere (for example in the `LCtrl/LCmd + Q` shortcut of +[`Platform::AppController`](../../Base/AppController)). + +## Scaling + +`GetContentScalingFactor()` returns `NSWindow.backingScaleFactor` and `GetFontResolutionDpi()` +returns `72 * scaling factor`, since macOS expresses type in points at 72 dpi. diff --git a/Modules/Platform/Apple/README.md b/Modules/Platform/Apple/README.md new file mode 100644 index 000000000..4b6d067bb --- /dev/null +++ b/Modules/Platform/Apple/README.md @@ -0,0 +1,50 @@ +# Methane Platform Apple + +Modules shared by all Apple platforms, plus the two platform sub-groups. +This group is added to the build by [Platform/CMakeLists.txt](../CMakeLists.txt) when `APPLE` is set; +[Apple/CMakeLists.txt](CMakeLists.txt) then adds `MacOS` or `iOS` on top of the shared modules, +based on `APPLE_MACOS`. + +| Module / Group | CMake Target | Content | +|--------------------|---------------------------|---------------------------------------------------| +| [Utils](Utils) | MethanePlatformUtilsApple | Utilities and type conversions shared by all Apple platforms | +| [MacOS](MacOS) | *see [MacOS/README.md](MacOS/README.md)* | AppKit application, view and keyboard | +| [iOS](iOS) | *see [iOS/README.md](iOS/README.md)* | UIKit application and view (iOS and tvOS) | + +`APPLE_IOS` and `APPLE_TVOS` are set in [MethaneGlobalOptions.cmake](/CMake/MethaneGlobalOptions.cmake) +and exposed as compile definitions by [MethaneBuildOptions.cmake](/CMake/MethaneBuildOptions.cmake); +tvOS reuses the `iOS` group unchanged. + +## Objective-C++ conventions + +Apple platform code is Objective-C++ and follows the repository conventions: + +- Headers that contain Objective-C constructs use the `.hh` extension, sources use `.mm`. + `.hh` is mapped to Objective-C++ for GitHub language detection in [.gitattributes](/.gitattributes). +- Every Objective-C++ source is compiled with `-fobjc-arc`, and `AppViewMetal.mm` additionally with + `-fobjc-weak`. +- Precompiled headers are disabled for these translation units (`SKIP_PRECOMPILE_HEADERS ON`), since + the shared C++ PCH cannot be reused from an Objective-C++ compilation. +- Public headers guard their Objective-C parts with `#ifdef __OBJC__` and fall back to `void` + aliases, so plain C++ translation units can still include them. + +## Utils + +[Utils](Utils) implements the platform-independent functions declared in +[`Methane/Platform/Utils.h`](../Base/Utils/Include/Methane/Platform/Utils.h) and adds the `NSString` +conversions in [`Types.hh`](Utils/Include/Methane/Platform/Apple/Types.hh). +`Methane/Platform/Apple/Utils.hh` itself declares no Apple-only API. + +`PrintToDebugOutput` writes through `NSLog`, which goes to the *system* log rather than to the +terminal — this is why `--print_debug_messages_to_console` exists; with it, the same messages go to +`std::cout` instead. + +These helpers live in namespace `Methane::Platform::Apple`, matching the directory. They used to +sit in `Methane::MacOS`, which clashed with the `Methane::Platform::MacOS` application namespace +introduced by the platform grouping: an unqualified `MacOS::ConvertToNsString(...)` resolved to the +wrong namespace, and in a file with both `using namespace Methane;` and +`using namespace Methane::Platform;` the name `MacOS` was ambiguous. With the namespace renamed, +`Apple::ConvertToNsString` is unambiguous from any `Methane::Platform::*` scope, and the Metal RHI +backend refers to it as `Platform::Apple::ConvertToNsString`. + +Links the `Foundation` framework. diff --git a/Modules/Platform/Apple/Utils/CMakeLists.txt b/Modules/Platform/Apple/Utils/CMakeLists.txt new file mode 100644 index 000000000..6c829e754 --- /dev/null +++ b/Modules/Platform/Apple/Utils/CMakeLists.txt @@ -0,0 +1,65 @@ +set(TARGET MethanePlatformUtilsApple) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_DIR}/Types.hh + ${INCLUDE_PLATFORM_DIR}/Utils.hh +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_DIR}/Utils.mm +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformUtilsBase + "-framework Foundation" + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethaneInstrumentation +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +# Disable precompiled headers and enable ARC for Objective-C sources: +set_source_files_properties( + ${SOURCES} + PROPERTIES + COMPILE_FLAGS -fobjc-arc + SKIP_PRECOMPILE_HEADERS ON +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Apple + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/Utils/Include/Methane/Platform/Apple/Types.hh b/Modules/Platform/Apple/Utils/Include/Methane/Platform/Apple/Types.hh similarity index 91% rename from Modules/Platform/Utils/Include/Methane/Platform/Apple/Types.hh rename to Modules/Platform/Apple/Utils/Include/Methane/Platform/Apple/Types.hh index fa0c80ac2..81db17752 100644 --- a/Modules/Platform/Utils/Include/Methane/Platform/Apple/Types.hh +++ b/Modules/Platform/Apple/Utils/Include/Methane/Platform/Apple/Types.hh @@ -16,8 +16,8 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/MacOS/Types.h -MacOS platform type converters. +FILE: Methane/Platform/Apple/Types.hh +Apple platform type converters. ******************************************************************************/ @@ -27,7 +27,7 @@ MacOS platform type converters. #include -namespace Methane::MacOS +namespace Methane::Platform::Apple { // =============================== @@ -58,4 +58,4 @@ inline std::string ConvertFromNsString(const NSString* ns_str_ptr) return ns_str_ptr ? std::string([ns_str_ptr UTF8String]) : std::string(); } -} // namespace Methane::MacOS +} // namespace Methane::Platform::Apple diff --git a/Modules/Platform/Utils/Include/Methane/Platform/Apple/Utils.hh b/Modules/Platform/Apple/Utils/Include/Methane/Platform/Apple/Utils.hh similarity index 91% rename from Modules/Platform/Utils/Include/Methane/Platform/Apple/Utils.hh rename to Modules/Platform/Apple/Utils/Include/Methane/Platform/Apple/Utils.hh index 7435cdd4a..4d553ee62 100644 --- a/Modules/Platform/Utils/Include/Methane/Platform/Apple/Utils.hh +++ b/Modules/Platform/Apple/Utils/Include/Methane/Platform/Apple/Utils.hh @@ -16,8 +16,8 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/MacOS/Utils.h -MacOS platform utility functions. +FILE: Methane/Platform/Apple/Utils.hh +Apple platform utility functions. ******************************************************************************/ diff --git a/Modules/Platform/Utils/Sources/Methane/Platform/Apple/Utils.mm b/Modules/Platform/Apple/Utils/Sources/Methane/Platform/Apple/Utils.mm similarity index 100% rename from Modules/Platform/Utils/Sources/Methane/Platform/Apple/Utils.mm rename to Modules/Platform/Apple/Utils/Sources/Methane/Platform/Apple/Utils.mm diff --git a/Modules/Platform/Apple/iOS/App/CMakeLists.txt b/Modules/Platform/Apple/iOS/App/CMakeLists.txt new file mode 100644 index 000000000..27959501f --- /dev/null +++ b/Modules/Platform/Apple/iOS/App/CMakeLists.txt @@ -0,0 +1,78 @@ +set(TARGET MethanePlatformAppIOS) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/App.hh + ${SOURCES_PLATFORM_OS_DIR}/AppDelegate.hh + ${SOURCES_PLATFORM_OS_DIR}/AppViewController.hh +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/App.mm + ${SOURCES_PLATFORM_OS_DIR}/AppDelegate.mm + ${SOURCES_PLATFORM_OS_DIR}/AppViewController.mm +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformAppBase + MethanePlatformAppViewIOS + "-framework UIKit" + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePlatformUtilsApple + MethaneDataProvider + fmt + nowide +) + +target_compile_definitions(${TARGET} + PRIVATE + METHANE_RENDER_APP +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + ${SOURCES_PLATFORM_OS_DIR} + PUBLIC + Include +) + +# Disable precompiled headers and enable ARC for Objective-C sources: +set_source_files_properties( + ${SOURCES} + PROPERTIES + COMPILE_FLAGS -fobjc-arc + SKIP_PRECOMPILE_HEADERS ON +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Apple/iOS + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/iOS/AppIOS.hh b/Modules/Platform/Apple/iOS/App/Include/Methane/Platform/iOS/App.hh similarity index 78% rename from Modules/Platform/App/Include/Methane/Platform/iOS/AppIOS.hh rename to Modules/Platform/Apple/iOS/App/Include/Methane/Platform/iOS/App.hh index bcb966be8..8c1c0607a 100644 --- a/Modules/Platform/App/Include/Methane/Platform/iOS/AppIOS.hh +++ b/Modules/Platform/Apple/iOS/App/Include/Methane/Platform/iOS/App.hh @@ -16,14 +16,14 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/iOS/AppIOS.h +FILE: Methane/Platform/iOS/App.hh iOS application implementation. ******************************************************************************/ #pragma once -#include +#include #include #ifndef __OBJC__ @@ -32,17 +32,17 @@ using UIWindow = void; #endif -namespace Methane::Platform +namespace Methane::Platform::iOS { -class AppIOS : public AppBase +class App : public Base::App { public: - static AppIOS* GetInstance(); + static App* GetInstance(); - explicit AppIOS(const AppBase::Settings& settings); + explicit App(const Base::App::Settings& settings); - // AppBase interface + // Base::App interface void InitContext(const Platform::AppEnvironment& env, const Data::FrameSize& frame_size) override; int Run(const RunArgs& args) override; void Alert(const Message& msg, bool deferred = false) override; @@ -53,17 +53,17 @@ public: void Close() override; void SetWindow(UIWindow* ns_window); - bool SetFullScreenInternal(bool is_full_screen) { return AppBase::SetFullScreen(is_full_screen); } + bool SetFullScreenInternal(bool is_full_screen) { return Base::App::SetFullScreen(is_full_screen); } UIWindow* GetWindow() { return m_ns_window; } protected: - // AppBase interface + // Base::App interface void ShowAlert(const Message& msg) override; private: UIWindow* m_ns_window = nullptr; - static AppIOS* s_instance_ptr; + static App* s_instance_ptr; }; -} // namespace Methane::Platform +} // namespace Methane::Platform::iOS diff --git a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppIOS.mm b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/App.mm similarity index 64% rename from Modules/Platform/App/Sources/Methane/Platform/iOS/AppIOS.mm rename to Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/App.mm index 2a57e9f69..e4343442b 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppIOS.mm +++ b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/App.mm @@ -16,56 +16,57 @@ ******************************************************************************* -FILE: Methane/Platform/iOS/AppMac.mm +FILE: Methane/Platform/iOS/App.mm iOS application implementation. ******************************************************************************/ -#include +#include #include #include #include #import "AppDelegate.hh" -namespace Methane::Platform +namespace Methane::Platform::iOS { -AppIOS* AppIOS::s_instance_ptr = nullptr; +App* App::s_instance_ptr = nullptr; -static UIAlertActionStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Type msg_type) +static UIAlertActionStyle ConvertMessageTypeToNsAlertStyle(Base::App::Message::Type msg_type) { META_FUNCTION_TASK(); switch(msg_type) { - case AppBase::Message::Type::Information: return UIAlertActionStyleDefault; - case AppBase::Message::Type::Warning: return UIAlertActionStyleCancel; - case AppBase::Message::Type::Error: return UIAlertActionStyleDestructive; + using enum Base::App::Message::Type; + case Information: return UIAlertActionStyleDefault; + case Warning: return UIAlertActionStyleCancel; + case Error: return UIAlertActionStyleDestructive; default: META_UNEXPECTED_RETURN(msg_type, UIAlertActionStyleDestructive); } } -AppIOS* AppIOS::GetInstance() +App* App::GetInstance() { META_FUNCTION_TASK(); return s_instance_ptr; } -AppIOS::AppIOS(const AppBase::Settings& settings) - : AppBase(settings) +App::App(const Base::App::Settings& settings) + : Base::App(settings) { META_FUNCTION_TASK(); META_CHECK_EQUAL_DESCR(s_instance_ptr, nullptr, "Application can have only one instance"); s_instance_ptr = this; } -void AppIOS::InitContext(const Platform::AppEnvironment& /*env*/, const Data::FrameSize& /*frame_size*/) +void App::InitContext(const Platform::AppEnvironment& /*env*/, const Data::FrameSize& /*frame_size*/) { } -int AppIOS::Run(const RunArgs& args) +int App::Run(const RunArgs& args) { META_FUNCTION_TASK(); - const int base_return_code = AppBase::Run(args); + const int base_return_code = Base::App::Run(args); if (base_return_code) return base_return_code; @@ -73,7 +74,7 @@ static UIAlertActionStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Typ NSStringFromClass([AppDelegate class])); } -void AppIOS::Alert(const Message& msg, bool deferred) +void App::Alert(const Message& msg, bool deferred) { META_FUNCTION_TASK(); if (deferred) @@ -91,57 +92,57 @@ static UIAlertActionStyle ConvertMessageTypeToNsAlertStyle(AppBase::Message::Typ ShowAlert(msg); } - AppBase::Alert(msg, deferred); + Base::App::Alert(msg, deferred); } -void AppIOS::SetWindowTitle(const std::string& title_text) +void App::SetWindowTitle(const std::string& title_text) { META_FUNCTION_TASK(); META_UNUSED(title_text); } -void AppIOS::SetWindow(UIWindow* ns_window) +void App::SetWindow(UIWindow* ns_window) { META_FUNCTION_TASK(); m_ns_window = ns_window; } -void AppIOS::ShowAlert(const Message& msg) +void App::ShowAlert(const Message& msg) { META_FUNCTION_TASK(); AppDelegate* app_delegate = static_cast([UIApplication sharedApplication].delegate); META_CHECK_NOT_NULL(app_delegate); - [app_delegate alert: MacOS::ConvertToNsString(msg.title) - withInformation: MacOS::ConvertToNsString(msg.information) + [app_delegate alert: Apple::ConvertToNsString(msg.title) + withInformation: Apple::ConvertToNsString(msg.information) andStyle: ConvertMessageTypeToNsAlertStyle(msg.type)]; - AppBase::ShowAlert(msg); + Base::App::ShowAlert(msg); } -bool AppIOS::SetFullScreen(bool is_full_screen) +bool App::SetFullScreen(bool is_full_screen) { META_FUNCTION_TASK(); - if (!AppBase::SetFullScreen(is_full_screen)) + if (!Base::App::SetFullScreen(is_full_screen)) return false; return true; } -float AppIOS::GetContentScalingFactor() const +float App::GetContentScalingFactor() const { META_FUNCTION_TASK(); return static_cast(m_ns_window.screen.nativeScale); } -uint32_t AppIOS::GetFontResolutionDpi() const +uint32_t App::GetFontResolutionDpi() const { META_FUNCTION_TASK(); return 72U * GetContentScalingFactor(); } -void AppIOS::Close() +void App::Close() { } -} // namespace Methane::Platform +} // namespace Methane::Platform::iOS diff --git a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppDelegate.hh b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppDelegate.hh similarity index 93% rename from Modules/Platform/App/Sources/Methane/Platform/iOS/AppDelegate.hh rename to Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppDelegate.hh index 92b77896d..df352abe1 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppDelegate.hh +++ b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppDelegate.hh @@ -23,11 +23,11 @@ iOS application delegate implementation. #include "AppViewController.hh" -#include +#include #import -namespace Methane::Platform { class AppIOS; } +namespace Methane::Platform::iOS { class App; } @interface AppDelegate : UIResponder diff --git a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppDelegate.mm b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppDelegate.mm similarity index 96% rename from Modules/Platform/App/Sources/Methane/Platform/iOS/AppDelegate.mm rename to Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppDelegate.mm index 4bd35b074..78e51a369 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppDelegate.mm +++ b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppDelegate.mm @@ -23,7 +23,7 @@ #import "AppDelegate.hh" -#include +#include #include #include #include @@ -45,7 +45,7 @@ - (id) init if (!self) return nil; - AppIOS* app_ptr = AppIOS::GetInstance(); + iOS::App* app_ptr = iOS::App::GetInstance(); UIScreen* ns_main_screen = [UIScreen mainScreen]; const auto& ns_frame_size = ns_main_screen.bounds.size; const CGRect backing_frame = CGRectMake(0.f, 0.f, @@ -108,7 +108,7 @@ - (UIWindow*) window navigation_controller.navigationBarHidden = YES; m_window.rootViewController = navigation_controller; - AppIOS::GetInstance()->SetWindow(m_window); + iOS::App::GetInstance()->SetWindow(m_window); } return m_window; } diff --git a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppViewController.hh b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppViewController.hh similarity index 84% rename from Modules/Platform/App/Sources/Methane/Platform/iOS/AppViewController.hh rename to Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppViewController.hh index 12f3eb14c..96fffaf87 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppViewController.hh +++ b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppViewController.hh @@ -25,13 +25,13 @@ iOS application view controller implementation. #import -namespace Methane::Platform { class AppIOS; } +namespace Methane::Platform::iOS { class App; } @interface AppViewController : UIViewController @property (nonatomic, readonly, nullable) UIWindow* window; -- (id _Nullable)initWithApp : (Methane::Platform::AppIOS* _Nonnull) app_ptr andFrameRect : (CGRect) frame; -- (Methane::Platform::AppIOS* _Nonnull) getApp; +- (id _Nullable)initWithApp : (Methane::Platform::iOS::App* _Nonnull) app_ptr andFrameRect : (CGRect) frame; +- (Methane::Platform::iOS::App* _Nonnull) getApp; @end diff --git a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppViewController.mm b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppViewController.mm similarity index 94% rename from Modules/Platform/App/Sources/Methane/Platform/iOS/AppViewController.mm rename to Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppViewController.mm index c6ffa03de..e9e93b209 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/iOS/AppViewController.mm +++ b/Modules/Platform/Apple/iOS/App/Sources/Methane/Platform/iOS/AppViewController.mm @@ -23,7 +23,7 @@ #import "AppViewController.hh" -#include +#include #include #include #include @@ -45,7 +45,7 @@ } } -} // namespace Methane::Platform +} // namespace Methane::Platform::Input namespace data = Methane::Data; namespace pal = Methane::Platform; @@ -53,13 +53,13 @@ @implementation AppViewController { - pal::AppIOS* m_app_ptr; - CGRect m_frame_rect; - bool m_is_initialized; - std::string m_error; + pal::iOS::App* m_app_ptr; + CGRect m_frame_rect; + bool m_is_initialized; + std::string m_error; } -- (id)initWithApp : (pal::AppIOS*) app_ptr andFrameRect : (CGRect) frame_rect +- (id)initWithApp : (pal::iOS::App*) app_ptr andFrameRect : (CGRect) frame_rect { META_FUNCTION_TASK(); @@ -80,7 +80,7 @@ -(nullable UIWindow*) window return m_app_ptr ? m_app_ptr->GetWindow() : nil; } -- (pal::AppIOS*) getApp +- (pal::iOS::App*) getApp { return m_app_ptr; } diff --git a/Modules/Platform/Apple/iOS/AppView/CMakeLists.txt b/Modules/Platform/Apple/iOS/AppView/CMakeLists.txt new file mode 100644 index 000000000..b36aa7ed3 --- /dev/null +++ b/Modules/Platform/Apple/iOS/AppView/CMakeLists.txt @@ -0,0 +1,67 @@ +set(TARGET MethanePlatformAppViewIOS) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/AppEnvironment.hh + ${INCLUDE_PLATFORM_OS_DIR}/AppViewMetal.hh +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/AppViewMetal.mm +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + "-framework UIKit" + "-framework Metal" + "-framework QuartzCore" + PRIVATE + MethaneBuildOptions + MethaneInstrumentation + MethaneDataTypes +) + +target_compile_definitions(${TARGET} + PRIVATE + $<$:METHANE_GPU_INSTRUMENTATION_ENABLED> +) + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +# Disable precompiled headers, enable ARC and weak Objective-C references: +set_source_files_properties( + ${SOURCES} + PROPERTIES + COMPILE_FLAGS "-fobjc-arc -fobjc-weak" + SKIP_PRECOMPILE_HEADERS ON +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Apple/iOS + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/AppView/Include/Methane/Platform/iOS/AppEnvironment.hh b/Modules/Platform/Apple/iOS/AppView/Include/Methane/Platform/iOS/AppEnvironment.hh similarity index 100% rename from Modules/Platform/AppView/Include/Methane/Platform/iOS/AppEnvironment.hh rename to Modules/Platform/Apple/iOS/AppView/Include/Methane/Platform/iOS/AppEnvironment.hh diff --git a/Modules/Platform/AppView/Include/Methane/Platform/iOS/AppViewMetal.hh b/Modules/Platform/Apple/iOS/AppView/Include/Methane/Platform/iOS/AppViewMetal.hh similarity index 100% rename from Modules/Platform/AppView/Include/Methane/Platform/iOS/AppViewMetal.hh rename to Modules/Platform/Apple/iOS/AppView/Include/Methane/Platform/iOS/AppViewMetal.hh diff --git a/Modules/Platform/AppView/Sources/Methane/Platform/iOS/AppViewMetal.mm b/Modules/Platform/Apple/iOS/AppView/Sources/Methane/Platform/iOS/AppViewMetal.mm similarity index 100% rename from Modules/Platform/AppView/Sources/Methane/Platform/iOS/AppViewMetal.mm rename to Modules/Platform/Apple/iOS/AppView/Sources/Methane/Platform/iOS/AppViewMetal.mm diff --git a/Modules/Platform/Apple/iOS/CMakeLists.txt b/Modules/Platform/Apple/iOS/CMakeLists.txt new file mode 100644 index 000000000..70176e31f --- /dev/null +++ b/Modules/Platform/Apple/iOS/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(AppView) +add_subdirectory(App) diff --git a/Modules/Platform/Apple/iOS/README.md b/Modules/Platform/Apple/iOS/README.md new file mode 100644 index 000000000..f09934b63 --- /dev/null +++ b/Modules/Platform/Apple/iOS/README.md @@ -0,0 +1,66 @@ +# Methane Platform iOS + +iOS **and tvOS** implementation of the [Platform modules](../../README.md), in namespace +`Methane::Platform::iOS`, built on **UIKit**. Added to the build by +[Apple/CMakeLists.txt](../CMakeLists.txt) when `APPLE` is set and `APPLE_MACOS` is not, alongside the +shared [Apple](../README.md) modules. tvOS reuses this group unchanged — `APPLE_IOS` and +`APPLE_TVOS` only differ in the SDK and deployment target chosen by +[MethaneGlobalOptions.cmake](/CMake/MethaneGlobalOptions.cmake). + +| Module | CMake Target | Content | +|--------------------|---------------------------|------------------------------------------| +| [App](App) | MethanePlatformAppIOS | `iOS::App` UIKit application | +| [AppView](AppView) | MethanePlatformAppViewIOS | `AppViewMetal` view and `AppEnvironment` | + +Linked frameworks: `UIKit`, `Metal`, `QuartzCore`. + +## App + +[`iOS::App`](App/Include/Methane/Platform/iOS/App.hh) derives from [`Base::App`](../../Base/App) and, +like the macOS implementation, relies on a **singleton** `App::GetInstance()` so that UIKit-constructed +delegates can reach it. Two Objective-C classes in +[App/Sources](App/Sources/Methane/Platform/iOS): + +| Class | Role | +|---------------------|---------------------------------------------------------------------------| +| `AppDelegate` | `UIApplicationDelegate`: creates the `UIWindow` and the view controller | +| `AppViewController` | `UIViewController`: drives drawing and touch input | + +Alerts are shown with `UIAlertController` instead of the `NSAlert` used on macOS. + +## No keyboard module + +There is deliberately **no `Input/Keyboard` module here**: iOS and tvOS have no native key-event +translation in Methane. Consequently: + +- [`Impl/Input/Keyboard`](../../Impl/Input/Keyboard) links only + [`MethanePlatformInputKeyboardBase`](../../Base/Input/Keyboard) on these platforms, with no + platform target behind it. +- `Keyboard::NativeKey` is left undefined, so `Keyboard::KeyConverter`'s native-key constructor and + its `GetKeyByNativeCode` / `GetModifiersByNativeCode` statics are not available. The + platform-independent parts of `Keyboard::Key`, `Keyboard::State` and the action controllers still + build and link, which is what the shared application and UI code needs. + +## Touch input + +`AppViewController` maps touches onto the platform-independent mouse abstraction by touch count: + +| Touches | Mouse button | +|---------|-----------------------| +| 1 | `Mouse::Button::Left` | +| 2 | `Mouse::Button::Right` | +| 3 | `Mouse::Button::Middle` | + +More than three simultaneous touches are not supported and raise an unexpected-value check. + +## AppView and scaling + +`AppViewMetal` is a `UIView` backed by a `CAMetalLayer`, and `AppEnvironment` carries a +`NativeViewController` (`UIViewController`), mirroring the macOS design. + +`GetContentScalingFactor()` returns `UIScreen.nativeScale` — note this is the *native* scale, not +`UIScreen.scale`, so it reflects the physical panel rather than the logical rendering scale. +`GetFontResolutionDpi()` returns `72 * scaling factor`. + +Applications are always full-screen on these platforms, so `SetFullScreen()` only keeps the base +class bookkeeping in step and changes nothing on screen. diff --git a/Modules/Platform/Base/App/CMakeLists.txt b/Modules/Platform/Base/App/CMakeLists.txt new file mode 100644 index 000000000..f78c5168d --- /dev/null +++ b/Modules/Platform/Base/App/CMakeLists.txt @@ -0,0 +1,65 @@ +set(TARGET MethanePlatformAppBase) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_DIR}/Base/App.h +) + +list(APPEND SOURCES + ${SOURCES_DIR}/Base/App.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + CLI11 + MethanePrimitives + MethaneInstrumentation + MethaneDataTypes + MethanePlatformAppInterface + MethanePlatformAppView + MethanePlatformInputActionControllers + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePlatformUtils + MethaneDataProvider + TaskFlow + fmt + nowide +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Base + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/Base + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/AppBase.h b/Modules/Platform/Base/App/Include/Methane/Platform/Base/App.h similarity index 90% rename from Modules/Platform/App/Include/Methane/Platform/AppBase.h rename to Modules/Platform/Base/App/Include/Methane/Platform/Base/App.h index de1f2d9e4..12de95b92 100644 --- a/Modules/Platform/App/Include/Methane/Platform/AppBase.h +++ b/Modules/Platform/Base/App/Include/Methane/Platform/Base/App.h @@ -16,14 +16,14 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/AppBase.h +FILE: Methane/Platform/Base/App.h Base application interface and platform-independent implementation. ******************************************************************************/ #pragma once -#include "IApp.h" +#include #include #include @@ -41,22 +41,22 @@ namespace tf // NOSONAR class Executor; } -namespace Methane::Platform +namespace Methane::Platform::Base { -class AppBase // NOSONAR +class App // NOSONAR : public CLI::App , public IApp { public: - explicit AppBase(const Settings& settings); - ~AppBase() override; + explicit App(const Settings& settings); + ~App() override; - AppBase(const AppBase&) = delete; - AppBase(AppBase&&) = delete; + App(const App&) = delete; + App(App&&) = delete; - AppBase& operator=(const AppBase&) = delete; - AppBase& operator=(AppBase&&) = delete; + App& operator=(const App&) = delete; + App& operator=(App&&) = delete; // IApp overrides int Run(const RunArgs& args) override; @@ -73,10 +73,10 @@ class AppBase // NOSONAR void ShowParameters() override { /* no parameters are displayed by default, but can be overridden */ } bool InitContextWithErrorHandling(const Platform::AppEnvironment& env, const Data::FrameSize& frame_size) - { return ExecuteWithErrorHandling("Render Context Initialization", true, *this, &AppBase::InitContext, env, frame_size); } + { return ExecuteWithErrorHandling("Render Context Initialization", true, *this, &App::InitContext, env, frame_size); } - bool InitWithErrorHandling() { return ExecuteWithErrorHandling("Application Initialization", true, *this, &AppBase::Init); } - bool UpdateAndRenderWithErrorHandling() { return ExecuteWithErrorHandling("Application Rendering", false, *this, &AppBase::UpdateAndRender); } + bool InitWithErrorHandling() { return ExecuteWithErrorHandling("Application Initialization", true, *this, &App::Init); } + bool UpdateAndRenderWithErrorHandling() { return ExecuteWithErrorHandling("Application Rendering", false, *this, &App::UpdateAndRender); } template void ProcessInputWithErrorHandling(FuncType&& func_ptr, ArgTypes&&... args) @@ -92,7 +92,7 @@ class AppBase // NOSONAR bool HasError() const noexcept; protected: - // AppBase interface + // App interface virtual AppView GetView() const = 0; virtual void ShowAlert(const Message& msg); @@ -162,4 +162,4 @@ class AppBase // NOSONAR mutable UniquePtr m_parallel_executor_ptr; }; -} // namespace Methane::Platform +} // namespace Methane::Platform::Base diff --git a/Modules/Platform/App/Sources/Methane/Platform/AppBase.cpp b/Modules/Platform/Base/App/Sources/Methane/Platform/Base/App.cpp similarity index 83% rename from Modules/Platform/App/Sources/Methane/Platform/AppBase.cpp rename to Modules/Platform/Base/App/Sources/Methane/Platform/Base/App.cpp index 1cf1a4de2..6ad415b41 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/AppBase.cpp +++ b/Modules/Platform/Base/App/Sources/Methane/Platform/Base/App.cpp @@ -16,12 +16,12 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/AppBase.cpp +FILE: Methane/Platform/Base/App.cpp Base application interface and platform-independent implementation. ******************************************************************************/ -#include +#include #include #include #include @@ -39,7 +39,7 @@ Base application interface and platform-independent implementation. #include #include -namespace Methane::Platform +namespace Methane::Platform::Base { static bool WriteControllerHeaderToHelpStream(std::stringstream& help_stream, const Input::Controller& controller, bool is_first_controller) @@ -114,42 +114,7 @@ static CLI::Option& AddRectSizeOption(CLI::App &app, const std::string& name, Da return *option_ptr; } -IApp::Settings& IApp::Settings::SetName(std::string&& new_name) noexcept -{ - META_FUNCTION_TASK(); - name = std::move(new_name); - return *this; -} - -IApp::Settings& IApp::Settings::SetSize(Data::FloatSize&& new_size) noexcept -{ - META_FUNCTION_TASK(); - size = std::move(new_size); - return *this; -} - -IApp::Settings& IApp::Settings::SetMinSize(Data::FrameSize&& new_min_size) noexcept -{ - META_FUNCTION_TASK(); - min_size = std::move(new_min_size); - return *this; -} - -IApp::Settings& IApp::Settings::SetFullScreen(bool new_full_screen) noexcept -{ - META_FUNCTION_TASK(); - is_full_screen = new_full_screen; - return *this; -} - -IApp::Settings& IApp::Settings::SetIconProvider(Data::IProvider* new_icon_provider) noexcept -{ - META_FUNCTION_TASK(); - icon_provider_ptr = new_icon_provider; - return *this; -} - -AppBase::AppBase(const AppBase::Settings& settings) +App::App(const App::Settings& settings) : CLI::App(settings.name, GetExecutableFileName()) , m_settings(settings) { @@ -170,14 +135,14 @@ AppBase::AppBase(const AppBase::Settings& settings) #endif } -AppBase::~AppBase() +App::~App() { META_FUNCTION_TASK(); if (m_parallel_executor_ptr) m_parallel_executor_ptr->wait_for_all(); } -int AppBase::Run(const RunArgs& args) +int App::Run(const RunArgs& args) { META_FUNCTION_TASK(); try @@ -200,19 +165,19 @@ int AppBase::Run(const RunArgs& args) return 0; } -void AppBase::Init() +void App::Init() { META_FUNCTION_TASK(); m_initialized = true; } -void AppBase::ChangeWindowBounds(const Data::FrameRect& window_bounds) +void App::ChangeWindowBounds(const Data::FrameRect& window_bounds) { META_FUNCTION_TASK(); m_window_bounds = window_bounds; } -void AppBase::StartResizing() +void App::StartResizing() { META_FUNCTION_TASK(); META_CHECK_FALSE(m_is_resizing); @@ -221,7 +186,7 @@ void AppBase::StartResizing() META_LOG("\n========================== START RESIZING =========================="); } -void AppBase::EndResizing() +void App::EndResizing() { META_FUNCTION_TASK(); META_CHECK_TRUE(m_is_resizing); @@ -230,7 +195,7 @@ void AppBase::EndResizing() META_LOG("\n========================== END RESIZING =========================="); } -bool AppBase::Resize(const Data::FrameSize& frame_size, bool is_minimized) +bool App::Resize(const Data::FrameSize& frame_size, bool is_minimized) { META_FUNCTION_TASK(); const bool is_resizing = !is_minimized && m_frame_size != frame_size; @@ -249,7 +214,7 @@ bool AppBase::Resize(const Data::FrameSize& frame_size, bool is_minimized) return m_initialized && is_resizing && !HasError(); } -void AppBase::Alert(const Message& msg, bool deferred) +void App::Alert(const Message& msg, bool deferred) { META_FUNCTION_TASK(); if (!deferred) @@ -258,7 +223,7 @@ void AppBase::Alert(const Message& msg, bool deferred) m_deferred_message_ptr.reset(new Message(msg)); } -void AppBase::ShowAlert(const Message&) +void App::ShowAlert(const Message&) { META_FUNCTION_TASK(); @@ -267,13 +232,13 @@ void AppBase::ShowAlert(const Message&) m_input_state.ReleaseAllKeys(); } -bool AppBase::HasError() const noexcept +bool App::HasError() const noexcept { META_FUNCTION_TASK(); return m_deferred_message_ptr ? m_deferred_message_ptr->type == Message::Type::Error : false; } -tf::Executor& AppBase::GetParallelExecutor() const +tf::Executor& App::GetParallelExecutor() const { META_FUNCTION_TASK(); if (!m_parallel_executor_ptr) @@ -282,7 +247,7 @@ tf::Executor& AppBase::GetParallelExecutor() const return *m_parallel_executor_ptr; } -bool AppBase::SetFullScreen(bool is_full_screen) +bool App::SetFullScreen(bool is_full_screen) { META_FUNCTION_TASK(); if (m_settings.is_full_screen == is_full_screen) @@ -294,7 +259,7 @@ bool AppBase::SetFullScreen(bool is_full_screen) return true; } -bool AppBase::SetKeyboardFocus(bool has_keyboard_focus) +bool App::SetKeyboardFocus(bool has_keyboard_focus) { META_FUNCTION_TASK(); if (m_has_keyboard_focus == has_keyboard_focus) @@ -306,7 +271,7 @@ bool AppBase::SetKeyboardFocus(bool has_keyboard_focus) return true; } -std::string AppBase::GetControlsHelp() const +std::string App::GetControlsHelp() const { META_FUNCTION_TASK(); std::stringstream help_stream; @@ -344,34 +309,34 @@ std::string AppBase::GetControlsHelp() const return help_stream.str(); } -void AppBase::ShowControlsHelp() +void App::ShowControlsHelp() { META_FUNCTION_TASK(); Alert({ - AppBase::Message::Type::Information, + App::Message::Type::Information, "Application Controls Help", GetControlsHelp() }); } -void AppBase::ShowCommandLineHelp() +void App::ShowCommandLineHelp() { META_FUNCTION_TASK(); Alert({ - AppBase::Message::Type::Information, + App::Message::Type::Information, "Application Command-Line Help", GetCommandLineHelp() }); } -const AppBase::Message& AppBase::GetDeferredMessage() const +const App::Message& App::GetDeferredMessage() const { META_FUNCTION_TASK(); META_CHECK_NOT_NULL(m_deferred_message_ptr); return *m_deferred_message_ptr; } -bool AppBase::UpdateAndRender() +bool App::UpdateAndRender() { META_FUNCTION_TASK(); if (HasError() || m_is_resize_required_to_render) @@ -393,4 +358,4 @@ bool AppBase::UpdateAndRender() return true; } -} // namespace Methane::Platform +} // namespace Methane::Platform::Base diff --git a/Modules/Platform/Base/AppController/CMakeLists.txt b/Modules/Platform/Base/AppController/CMakeLists.txt new file mode 100644 index 000000000..1da1026b3 --- /dev/null +++ b/Modules/Platform/Base/AppController/CMakeLists.txt @@ -0,0 +1,57 @@ +set(TARGET MethanePlatformAppController) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_DIR}/AppController.h +) + +list(APPEND SOURCES + ${SOURCES_DIR}/AppController.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformAppBase + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethaneInstrumentation + MethanePlatformUtils + fmt +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Base + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/AppController.h b/Modules/Platform/Base/AppController/Include/Methane/Platform/AppController.h similarity index 94% rename from Modules/Platform/App/Include/Methane/Platform/AppController.h rename to Modules/Platform/Base/AppController/Include/Methane/Platform/AppController.h index 74311e34f..4e949ba0b 100644 --- a/Modules/Platform/App/Include/Methane/Platform/AppController.h +++ b/Modules/Platform/Base/AppController/Include/Methane/Platform/AppController.h @@ -23,7 +23,7 @@ Base application controller providing commands like app close and help. #pragma once -#include +#include #include namespace Methane::Platform @@ -52,7 +52,7 @@ class AppController { { Input::Keyboard::OS::g_key_left_ctrl, Input::Keyboard::Key::Q }, AppAction::CloseApp }, }; - AppController(AppBase& application, const std::string& application_help, + AppController(Base::App& application, const std::string& application_help, const ActionByKeyboardState& action_by_keyboard_state = default_action_by_keyboard_state); // Input::Controller implementation @@ -66,7 +66,7 @@ class AppController std::string GetKeyboardActionName(AppAction action) const override; private: - AppBase& m_application; + Base::App& m_application; }; } // namespace Methane::Platform diff --git a/Modules/Platform/App/Sources/Methane/Platform/AppController.cpp b/Modules/Platform/Base/AppController/Sources/Methane/Platform/AppController.cpp similarity index 95% rename from Modules/Platform/App/Sources/Methane/Platform/AppController.cpp rename to Modules/Platform/Base/AppController/Sources/Methane/Platform/AppController.cpp index 71a21b5f9..614965c08 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/AppController.cpp +++ b/Modules/Platform/Base/AppController/Sources/Methane/Platform/AppController.cpp @@ -29,7 +29,7 @@ Base application controller providing commands like app close and help. namespace Methane::Platform { -AppController::AppController(AppBase& application, const std::string& application_help, const ActionByKeyboardState& action_by_keyboard_state) +AppController::AppController(Base::App& application, const std::string& application_help, const ActionByKeyboardState& action_by_keyboard_state) : Controller(application_help) , Input::Keyboard::ActionControllerBase(action_by_keyboard_state, {}) , m_application(application) diff --git a/Modules/Platform/Base/CMakeLists.txt b/Modules/Platform/Base/CMakeLists.txt new file mode 100644 index 000000000..a669895d5 --- /dev/null +++ b/Modules/Platform/Base/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(Utils) +add_subdirectory(Input) +add_subdirectory(App) +add_subdirectory(AppController) diff --git a/Modules/Platform/Input/ActionControllers/CMakeLists.txt b/Modules/Platform/Base/Input/ActionControllers/CMakeLists.txt similarity index 95% rename from Modules/Platform/Input/ActionControllers/CMakeLists.txt rename to Modules/Platform/Base/Input/ActionControllers/CMakeLists.txt index 4dce0311e..7679dfef9 100644 --- a/Modules/Platform/Input/ActionControllers/CMakeLists.txt +++ b/Modules/Platform/Base/Input/ActionControllers/CMakeLists.txt @@ -33,7 +33,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS}) set_target_properties(${TARGET} PROPERTIES - FOLDER Modules/Platform/Input + FOLDER Modules/Platform/Base/Input PUBLIC_HEADER "${HEADERS}" ) diff --git a/Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp b/Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp similarity index 100% rename from Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp rename to Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp diff --git a/Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/MouseActionControllerBase.hpp b/Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/MouseActionControllerBase.hpp similarity index 100% rename from Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/MouseActionControllerBase.hpp rename to Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/MouseActionControllerBase.hpp diff --git a/Modules/Platform/Input/CMakeLists.txt b/Modules/Platform/Base/Input/CMakeLists.txt similarity index 100% rename from Modules/Platform/Input/CMakeLists.txt rename to Modules/Platform/Base/Input/CMakeLists.txt diff --git a/Modules/Platform/Input/Controllers/CMakeLists.txt b/Modules/Platform/Base/Input/Controllers/CMakeLists.txt similarity index 96% rename from Modules/Platform/Input/Controllers/CMakeLists.txt rename to Modules/Platform/Base/Input/Controllers/CMakeLists.txt index 6a468e2f0..6044c9a45 100644 --- a/Modules/Platform/Input/Controllers/CMakeLists.txt +++ b/Modules/Platform/Base/Input/Controllers/CMakeLists.txt @@ -48,7 +48,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) set_target_properties(${TARGET} PROPERTIES - FOLDER Modules/Platform/Input + FOLDER Modules/Platform/Base/Input PUBLIC_HEADER "${HEADERS}" ) diff --git a/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/Controller.h b/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/Controller.h similarity index 100% rename from Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/Controller.h rename to Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/Controller.h diff --git a/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/ControllersPool.h b/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/ControllersPool.h similarity index 100% rename from Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/ControllersPool.h rename to Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/ControllersPool.h diff --git a/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/IActionController.h b/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/IActionController.h similarity index 100% rename from Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/IActionController.h rename to Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/IActionController.h diff --git a/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/IController.h b/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/IController.h similarity index 100% rename from Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/IController.h rename to Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/IController.h diff --git a/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/IHelpProvider.h b/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/IHelpProvider.h similarity index 100% rename from Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/IHelpProvider.h rename to Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/IHelpProvider.h diff --git a/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/State.h b/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/State.h similarity index 100% rename from Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/State.h rename to Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/State.h diff --git a/Modules/Platform/Input/Controllers/Sources/Methane/Platform/Input/ControllersPool.cpp b/Modules/Platform/Base/Input/Controllers/Sources/Methane/Platform/Input/ControllersPool.cpp similarity index 100% rename from Modules/Platform/Input/Controllers/Sources/Methane/Platform/Input/ControllersPool.cpp rename to Modules/Platform/Base/Input/Controllers/Sources/Methane/Platform/Input/ControllersPool.cpp diff --git a/Modules/Platform/Input/Controllers/Sources/Methane/Platform/Input/State.cpp b/Modules/Platform/Base/Input/Controllers/Sources/Methane/Platform/Input/State.cpp similarity index 100% rename from Modules/Platform/Input/Controllers/Sources/Methane/Platform/Input/State.cpp rename to Modules/Platform/Base/Input/Controllers/Sources/Methane/Platform/Input/State.cpp diff --git a/Modules/Platform/Input/Keyboard/CMakeLists.txt b/Modules/Platform/Base/Input/Keyboard/CMakeLists.txt similarity index 52% rename from Modules/Platform/Input/Keyboard/CMakeLists.txt rename to Modules/Platform/Base/Input/Keyboard/CMakeLists.txt index 30e0deed9..faacc05d9 100644 --- a/Modules/Platform/Input/Keyboard/CMakeLists.txt +++ b/Modules/Platform/Base/Input/Keyboard/CMakeLists.txt @@ -1,21 +1,16 @@ -set(TARGET MethanePlatformInputKeyboard) +set(TARGET MethanePlatformInputKeyboardBase) include(MethaneModules) get_module_dirs("Methane/Platform/Input") -list(APPEND HEADERS ${INCLUDE_DIR}/Keyboard.h) -list(APPEND SOURCES ${SOURCES_DIR}/Keyboard.cpp) - -if (APPLE_MACOS) - list(APPEND HEADERS ${INCLUDE_PLATFORM_OS_DIR}/Keyboard.h) - list(APPEND PLATFORM_LIBRARIES "-framework AppKit") -endif() +list(APPEND HEADERS + ${INCLUDE_DIR}/Keyboard.h +) -if (NOT (APPLE_IOS OR APPLE_TVOS)) - list(APPEND HEADERS ${INCLUDE_PLATFORM_OS_DIR}/Keyboard.h) - list(APPEND SOURCES ${SOURCES_PLATFORM_OS_DIR}/Keyboard.${CPP_EXT}) -endif() +list(APPEND SOURCES + ${SOURCES_DIR}/Keyboard.cpp +) add_library(${TARGET} STATIC ${HEADERS} @@ -32,7 +27,6 @@ target_link_libraries(${TARGET} MethanePrimitives MethanePlatformUtils magic_enum - ${PLATFORM_LIBRARIES} ) if(METHANE_PRECOMPILED_HEADERS_ENABLED) @@ -42,7 +36,6 @@ endif() target_include_directories(${TARGET} PRIVATE Sources - $<$:${X11_xcb_INCLUDE_PATH} ${X11_X11_INCLUDE_PATH}> PUBLIC Include ) @@ -51,20 +44,10 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) set_target_properties(${TARGET} PROPERTIES - FOLDER Modules/Platform/Input + FOLDER Modules/Platform/Base/Input PUBLIC_HEADER "${HEADERS}" ) -if (APPLE) - # Disable precompiled headers on MacOS for Objective-C files: - set_source_files_properties( - ${SOURCES_PLATFORM_OS_DIR}/Keyboard.mm - PROPERTIES - COMPILE_FLAGS -fobjc-arc - SKIP_PRECOMPILE_HEADERS ON - ) -endif() - install(TARGETS ${TARGET} PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR} diff --git a/Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h b/Modules/Platform/Base/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h similarity index 97% rename from Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h rename to Modules/Platform/Base/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h index 27d82ebe7..fd87f9f2d 100644 --- a/Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h +++ b/Modules/Platform/Base/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h @@ -23,19 +23,8 @@ Platform abstraction of keyboard events. #pragma once -#if defined _WIN32 - -#include "Windows/Keyboard.h" - -#elif defined __APPLE__ - -#include "MacOS/Keyboard.h" - -#else - -#include "Linux/Keyboard.h" - -#endif +// NOTE: platform-specific Keyboard::NativeKey definition is provided by the +// /Keyboard.h> header of the platform module. #include #include diff --git a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Keyboard.cpp b/Modules/Platform/Base/Input/Keyboard/Sources/Methane/Platform/Input/Keyboard.cpp similarity index 98% rename from Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Keyboard.cpp rename to Modules/Platform/Base/Input/Keyboard/Sources/Methane/Platform/Input/Keyboard.cpp index 612eae06d..a6ebb4cf5 100644 --- a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Keyboard.cpp +++ b/Modules/Platform/Base/Input/Keyboard/Sources/Methane/Platform/Input/Keyboard.cpp @@ -50,11 +50,6 @@ KeyConverter::KeyConverter(Key key, ModifierMask modifiers) , m_modifiers(modifiers) { } -KeyConverter::KeyConverter(const NativeKey& native_key) - : m_key(GetKeyByNativeCode(native_key)) - , m_modifiers(GetModifiersByNativeCode(native_key)) -{ } - Opt KeyConverter::GetModifierKey() const noexcept { META_FUNCTION_TASK(); diff --git a/Modules/Platform/Input/Mouse/CMakeLists.txt b/Modules/Platform/Base/Input/Mouse/CMakeLists.txt similarity index 95% rename from Modules/Platform/Input/Mouse/CMakeLists.txt rename to Modules/Platform/Base/Input/Mouse/CMakeLists.txt index 015763c6c..a632735ec 100644 --- a/Modules/Platform/Input/Mouse/CMakeLists.txt +++ b/Modules/Platform/Base/Input/Mouse/CMakeLists.txt @@ -36,7 +36,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) set_target_properties(${TARGET} PROPERTIES - FOLDER Modules/Platform/Input + FOLDER Modules/Platform/Base/Input PUBLIC_HEADER "${HEADERS}" ) diff --git a/Modules/Platform/Input/Mouse/Include/Methane/Platform/Input/Mouse.h b/Modules/Platform/Base/Input/Mouse/Include/Methane/Platform/Input/Mouse.h similarity index 100% rename from Modules/Platform/Input/Mouse/Include/Methane/Platform/Input/Mouse.h rename to Modules/Platform/Base/Input/Mouse/Include/Methane/Platform/Input/Mouse.h diff --git a/Modules/Platform/Input/Mouse/Sources/Methane/Platform/Input/Mouse.cpp b/Modules/Platform/Base/Input/Mouse/Sources/Methane/Platform/Input/Mouse.cpp similarity index 100% rename from Modules/Platform/Input/Mouse/Sources/Methane/Platform/Input/Mouse.cpp rename to Modules/Platform/Base/Input/Mouse/Sources/Methane/Platform/Input/Mouse.cpp diff --git a/Modules/Platform/Base/README.md b/Modules/Platform/Base/README.md new file mode 100644 index 000000000..c6752c909 --- /dev/null +++ b/Modules/Platform/Base/README.md @@ -0,0 +1,79 @@ +# Methane Platform Base + +All **platform-independent** implementations of the [Platform modules](../README.md). +This group is always added to the build, on every platform. + +| Module | CMake Target | Namespace | +|----------------------------------------------|---------------------------------------|--------------------------------------| +| [App](App) | MethanePlatformAppBase | `Methane::Platform::Base` | +| [AppController](AppController) | MethanePlatformAppController | `Methane::Platform` | +| [Input/Keyboard](Input/Keyboard) | MethanePlatformInputKeyboardBase | `Methane::Platform::Input::Keyboard` | +| [Input/Mouse](Input/Mouse) | MethanePlatformInputMouse | `Methane::Platform::Input::Mouse` | +| [Input/Controllers](Input/Controllers) | MethanePlatformInputControllers | `Methane::Platform::Input` | +| [Input/ActionControllers](Input/ActionControllers) | MethanePlatformInputActionControllers | `Methane::Platform::Input` | +| [Utils](Utils) | MethanePlatformUtilsBase | `Methane::Platform` | + +## Two kinds of module in this group + +The `Base` group holds every platform-independent implementation, but not all of them play the same role: + +- **Modules with platform counterparts** — `App`, `Input/Keyboard` and `Utils` — carry a `Base` target + suffix. Each has a matching module in every platform group, and an + [`Impl`](../Impl) facade target that binds the two together. Other domains link the facade + (`MethanePlatformApp`, `MethanePlatformInputKeyboard`, `MethanePlatformUtils`), never these targets + directly. +- **Fully platform-independent modules** — `AppController`, `Input/Mouse`, `Input/Controllers` and + `Input/ActionControllers` — have no platform counterpart, so they carry no suffix and need no facade. + They are linked directly by name from other domains. + +Only `App` puts its code in a nested `Methane::Platform::Base` namespace, because `Base::App` and the +platform `App` classes would otherwise collide. The other modules define types whose names are already +unique (`AppController`, `Keyboard::Key`, `Mouse::Button`, `Input::State`, …) and stay in their natural +namespace, so their public include paths are unchanged by the grouping. + +## Base/App + +[`Base::App`](App/Include/Methane/Platform/Base/App.h) implements everything about a windowed +application that does not need the native API: settings parsing, the update/render loop, resize and +full-screen bookkeeping, input state dispatch, alerts, help text and the shared +[Taskflow](/Externals/TaskFlow.cmake) executor. It derives from both +[`Platform::IApp`](../Interfaces/App) and `CLI::App`, the latter giving every Methane application its +command-line parsing for free. + +Error handling is centralised here: `ExecuteWithErrorHandling` wraps context initialisation, app +initialisation, input processing and rendering, converting exceptions into deferred user alerts. In +`_DEBUG` builds the wrapper deliberately does **not** catch, so a debugger breaks at the throw site. + +Platform implementations derive from `Base::App` and override `GetView()`, `SetWindowTitle()`, +`GetContentScalingFactor()`, `GetFontResolutionDpi()`, `Run()` and `Close()`, plus `ShowAlert()` to +use the native dialog. + +## Base/Input/Keyboard + +This module declares the whole keyboard abstraction — `Keyboard::Key`, `Keyboard::ModifierMask`, +`Keyboard::State`, `Keyboard::StateChange` and `Keyboard::KeyConverter` — while the native key +representation lives in the platform groups. + +`Keyboard.h` only **forward-declares** `struct NativeKey`, which is what lets this module compile +with no knowledge of any platform. Two consequences worth knowing: + +- Code that constructs a `NativeKey` must include + `/Keyboard.h>` itself; the shared header does not pull it in. +- `KeyConverter`'s native-key constructor and its `GetKeyByNativeCode` / `GetModifiersByNativeCode` + statics are implemented **in the platform modules, not here**, so that this target never references + a symbol the platform group owns. Defining that constructor here previously made `Base` and the + platform module mutually dependent, which GNU `ld` rejects even though the MSVC linker tolerates it. + +`Keyboard::OS::g_key_left_ctrl` resolves to `Key::LeftSuper` on Apple platforms and `Key::LeftControl` +elsewhere, which is how one shortcut definition serves both the Control and Command conventions. + +## Base/Utils + +`Methane/Platform/Utils.h` declares the functions every platform implements — +`PrintToDebugOutput`, `GetExecutableDir`, `GetExecutableFileName`, `GetResourceDir` — and this module +implements only the genuinely shared ones (`SplitString` and the print-to-console flag). It therefore +has unresolved symbols on its own; they are satisfied by the platform `Utils` module, which the +[`Impl/Utils`](../Impl/Utils) facade links alongside it. + +Like the keyboard header, `Utils.h` carries no platform dispatch include: platform-specific functions +are declared in `/Utils.h>` and included directly where needed. diff --git a/Modules/Platform/Utils/CMakeLists.txt b/Modules/Platform/Base/Utils/CMakeLists.txt similarity index 51% rename from Modules/Platform/Utils/CMakeLists.txt rename to Modules/Platform/Base/Utils/CMakeLists.txt index ee8b4eb5c..4058741f9 100644 --- a/Modules/Platform/Utils/CMakeLists.txt +++ b/Modules/Platform/Base/Utils/CMakeLists.txt @@ -1,33 +1,16 @@ -set(TARGET MethanePlatformUtils) +set(TARGET MethanePlatformUtilsBase) include(MethaneModules) get_module_dirs("Methane/Platform") -if(WIN32) - set(PLATFORM_HEADERS - ${INCLUDE_PLATFORM_DIR}/Utils.h - ) -elseif(APPLE) - set(PLATFORM_HEADERS - ${INCLUDE_PLATFORM_DIR}/Types.hh - ${INCLUDE_PLATFORM_DIR}/Utils.hh - ) -endif() - -set(HEADERS +list(APPEND HEADERS ${INCLUDE_DIR}/Utils.h ${INCLUDE_DIR}/Logger.h - ${PLATFORM_HEADERS} -) - -set(PLATFORM_SOURCES - ${SOURCES_PLATFORM_DIR}/Utils.${CPP_EXT} ) -set(SOURCES +list(APPEND SOURCES ${SOURCES_DIR}/Utils.cpp - ${PLATFORM_SOURCES} ) add_library(${TARGET} STATIC @@ -35,13 +18,6 @@ add_library(${TARGET} STATIC ${SOURCES} ) -target_include_directories(${TARGET} - PRIVATE - Sources - PUBLIC - Include -) - target_link_libraries(${TARGET} PUBLIC MethaneBuildOptions @@ -54,38 +30,21 @@ if(METHANE_PRECOMPILED_HEADERS_ENABLED) target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) endif() -if(APPLE) - - target_sources(${TARGET} - PRIVATE - ${INCLUDE_PLATFORM_DIR}/Types.hh - ) - - target_link_libraries(${TARGET} - PUBLIC - "-framework Foundation" - ) - -endif() +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) set_target_properties(${TARGET} PROPERTIES - FOLDER Modules/Platform + FOLDER Modules/Platform/Base PUBLIC_HEADER "${HEADERS}" ) -if (APPLE) - # Disable precompiled headers on MacOS for Objective-C files: - set_source_files_properties( - ${PLATFORM_SOURCES} - PROPERTIES - COMPILE_FLAGS -fobjc-arc - SKIP_PRECOMPILE_HEADERS ON - ) -endif() - install(TARGETS ${TARGET} PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR} @@ -94,4 +53,3 @@ install(TARGETS ${TARGET} DESTINATION lib COMPONENT Development ) - diff --git a/Modules/Platform/Utils/Include/Methane/Platform/Logger.h b/Modules/Platform/Base/Utils/Include/Methane/Platform/Logger.h similarity index 100% rename from Modules/Platform/Utils/Include/Methane/Platform/Logger.h rename to Modules/Platform/Base/Utils/Include/Methane/Platform/Logger.h diff --git a/Modules/Platform/Utils/Include/Methane/Platform/Utils.h b/Modules/Platform/Base/Utils/Include/Methane/Platform/Utils.h similarity index 91% rename from Modules/Platform/Utils/Include/Methane/Platform/Utils.h rename to Modules/Platform/Base/Utils/Include/Methane/Platform/Utils.h index e76064716..88819f721 100644 --- a/Modules/Platform/Utils/Include/Methane/Platform/Utils.h +++ b/Modules/Platform/Base/Utils/Include/Methane/Platform/Utils.h @@ -23,19 +23,8 @@ Methane platform utility functions #pragma once -#if defined _WIN32 - -#include "Windows/Utils.h" - -#elif defined __APPLE__ - -#include "Apple/Utils.hh" - -#elif defined __linux__ - -#include "Linux/Utils.h" - -#endif +// NOTE: platform-specific utility functions are declared in the +// /Utils.h> header of the platform module. #include #include diff --git a/Modules/Platform/Utils/Sources/Methane/Platform/Utils.cpp b/Modules/Platform/Base/Utils/Sources/Methane/Platform/Utils.cpp similarity index 100% rename from Modules/Platform/Utils/Sources/Methane/Platform/Utils.cpp rename to Modules/Platform/Base/Utils/Sources/Methane/Platform/Utils.cpp diff --git a/Modules/Platform/CMakeLists.txt b/Modules/Platform/CMakeLists.txt index c4a08b63b..6b7813dc4 100644 --- a/Modules/Platform/CMakeLists.txt +++ b/Modules/Platform/CMakeLists.txt @@ -1,4 +1,15 @@ -add_subdirectory(App) -add_subdirectory(AppView) -add_subdirectory(Input) -add_subdirectory(Utils) +# Platform-independent module layers: +add_subdirectory(Interfaces) +add_subdirectory(Base) + +# Platform-specific module layer (only one is added depending on the target platform): +if(WIN32) + add_subdirectory(Windows) +elseif(APPLE) + add_subdirectory(Apple) +else() # Linux + add_subdirectory(Linux) +endif() + +# Final implementation layer binding platform-independent and platform-specific modules together: +add_subdirectory(Impl) diff --git a/Modules/Platform/Impl/App/CMakeLists.txt b/Modules/Platform/Impl/App/CMakeLists.txt new file mode 100644 index 000000000..e95932fd6 --- /dev/null +++ b/Modules/Platform/Impl/App/CMakeLists.txt @@ -0,0 +1,51 @@ +set(TARGET MethanePlatformApp) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +if(WIN32) + set(PLATFORM_APP_TARGET MethanePlatformAppWindows) +elseif(APPLE_MACOS) + set(PLATFORM_APP_TARGET MethanePlatformAppMacOS) +elseif(APPLE) + set(PLATFORM_APP_TARGET MethanePlatformAppIOS) +else() # Linux + set(PLATFORM_APP_TARGET MethanePlatformAppLinux) +endif() + +list(APPEND HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}/App.h +) + +add_library(${TARGET} INTERFACE) + +target_sources(${TARGET} + INTERFACE + ${HEADERS} +) + +target_include_directories(${TARGET} + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/Include +) + +target_link_libraries(${TARGET} + INTERFACE + ${PLATFORM_APP_TARGET} + MethanePlatformAppController +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Impl + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR} + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/App.h b/Modules/Platform/Impl/App/Include/Methane/Platform/App.h similarity index 71% rename from Modules/Platform/App/Include/Methane/Platform/App.h rename to Modules/Platform/Impl/App/Include/Methane/Platform/App.h index b85cc89f2..d0934636f 100644 --- a/Modules/Platform/App/Include/Methane/Platform/App.h +++ b/Modules/Platform/Impl/App/Include/Methane/Platform/App.h @@ -1,6 +1,6 @@ /****************************************************************************** -Copyright 2019-2020 Evgeny Gorodetskiy +Copyright 2019-2025 Evgeny Gorodetskiy Licensed under the Apache License, Version 2.0 (the "License"), you may not use this file except in compliance with the License. @@ -17,7 +17,8 @@ limitations under the License. ******************************************************************************* FILE: Methane/Platform/App.h -Methane platform application alias. +Methane platform application final implementation alias, which is bound to the +application class of the platform the library is built for. ******************************************************************************/ @@ -25,19 +26,19 @@ Methane platform application alias. #if defined _WIN32 -#include +#include #elif defined __APPLE__ #ifdef APPLE_MACOS -#include +#include #else -#include +#include #endif #elif defined __linux__ -#include +#include #endif @@ -46,19 +47,19 @@ namespace Methane::Platform #if defined _WIN32 -using App = AppWin; +using App = Windows::App; #elif defined __APPLE__ #ifdef APPLE_MACOS -using App = AppMac; +using App = MacOS::App; #else -using App = AppIOS; +using App = iOS::App; #endif #elif defined __linux__ -using App = AppLin; +using App = Linux::App; #endif diff --git a/Modules/Platform/Impl/App/README.md b/Modules/Platform/Impl/App/README.md new file mode 100644 index 000000000..933516f93 --- /dev/null +++ b/Modules/Platform/Impl/App/README.md @@ -0,0 +1,90 @@ +# Platform App + +Platform abstraction of the windowed application with main purpose for graphics content rendering. +Graphics rendering infrastructure itself is split into derived class defined in a separate library. + +Platform application modules are grouped by platform support, similar to [Graphics RHI](../../../Graphics/RHI): + +``` +Interfaces/App ──> Base/App ──> { Windows | Linux | Apple/MacOS | Apple/iOS }/App ──> Impl/App + Base/AppController ──┘ +``` + +| Module | CMake Target | Description | +|------------------------------------------------|-----------------------------|---------------------------------------------| +| [Interfaces/App](../../Interfaces/App) | MethanePlatformAppInterface | `Platform::IApp` interface and app settings | +| [Base/App](../../Base/App) | MethanePlatformAppBase | `Platform::Base::App` implementation | +| [Windows/App](../../Windows/App) | MethanePlatformAppWindows | `Platform::Windows::App` implementation | +| [Linux/App](../../Linux/App) | MethanePlatformAppLinux | `Platform::Linux::App` implementation | +| [Apple/MacOS/App](../../Apple/MacOS/App) | MethanePlatformAppMacOS | `Platform::MacOS::App` implementation | +| [Apple/iOS/App](../../Apple/iOS/App) | MethanePlatformAppIOS | `Platform::iOS::App` implementation | +| [Base/AppController](../../Base/AppController) | MethanePlatformAppController | `Platform::AppController` implementation | +| [Impl/App](.) | MethanePlatformApp | `Platform::App` final implementation alias | + +## Platform Application + +### Platform::App + +[Methane/Platform/App.h](Include/Methane/Platform/App.h) defines alias type `Platform::App` pointing +to one of the platform-specific implementations of the [Platform::Base::App](#platform-application-base-class) class: + +- [Platform::Windows::App](../../Windows/App/Include/Methane/Platform/Windows/App.h) - Windows app implementation +- [Platform::Linux::App](../../Linux/App/Include/Methane/Platform/Linux/App.h) - Linux app implementation +- [Platform::MacOS::App](../../Apple/MacOS/App/Include/Methane/Platform/MacOS/App.hh) - MacOS app implementation +- [Platform::iOS::App](../../Apple/iOS/App/Include/Methane/Platform/iOS/App.hh) - iOS app implementation + +`Platform::App` should be used as a base class for any windowed Methane application. + +## Platform Application Interface + +### Platform::IApp + +[Methane/Platform/IApp.h](../../Interfaces/App/Include/Methane/Platform/IApp.h) declares the `Platform::IApp` +interface implemented by the application classes, along with the `Platform::AppSettings`, `Platform::AppRunArgs` +and `Platform::AppMessage` structures shared by all application layers. + +## Platform Application Base Class + +### Platform::Base::App + +[Methane/Platform/Base/App.h](../../Base/App/Include/Methane/Platform/Base/App.h) contains the +platform-abstraction implementation of the application class with the following functionality: + +- Initial application settings setup (see table below) +- Running application with a given command line arguments and parsing platform app settings from cmd arguments +- Live window resizing with frame re-render on resize iterations +- Switching window to full-screen mode +- Processing keyboard and mouse input via `Platform::Input::State` +- Adding [platform application controller](#platform-application-controller) to input state processor +- Setting title in window header +- Showing user alert in message box dialog +- Displaying application controls and command line help +- Shared parallel task execution engine with thread pool [Taskflow::Executor](../../../../Externals/TaskFlow.cmake) + +The following settings are available in `Platform::AppSettings` structure: + +| Setting | Type | Default Value | Cmd-Line Option | Description | +|-------------------|--------------------|---------------|------------------|---------------------------------------------------------------------------------------------------| +| name | `std::string` | "" | | Application name displayed in window header | +| size | `Data::FloatSize` | 0.8 x 0.8 | -w,--wnd-size | Main window size (if a dimension < 1.0 it is a ratio of desktop size; else size in pixels/dots) | +| min_size | `Data::FrameSize` | 640 x 480 | | Minimum main window size in pixels/dots limited for resizing | +| is_full_screen | `bool` | false | -f,--full-screen | Full-screen state of the main window | +| icon_provider_ptr | `Data::IProvider*` | nullptr | | Provider of the window icon resources | + +Additionally the `--print_debug_messages_to_console` flag redirects debug messages, including graphics API +validation errors and warnings, to the console output instead of the platform debug output. + +## Platform Application Controller + +### Platform::AppController + +[Methane/Platform/AppController.h](../../Base/AppController/Include/Methane/Platform/AppController.h) implements +the following platform-independent actions: + +| Action | Keyboard Shortcut | +|------------------------|---------------------| +| Show controls help | F1 | +| Show command-line help | F2 | +| Show parameters | F3 | +| Switch full-screen | LCtrl + F | +| Close application | LCtrl/LCmd + Q | diff --git a/Modules/Platform/Impl/AppView/CMakeLists.txt b/Modules/Platform/Impl/AppView/CMakeLists.txt new file mode 100644 index 000000000..501752280 --- /dev/null +++ b/Modules/Platform/Impl/AppView/CMakeLists.txt @@ -0,0 +1,62 @@ +set(TARGET MethanePlatformAppView) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +if(WIN32) + set(PLATFORM_APP_VIEW_TARGET MethanePlatformAppViewWindows) +elseif(APPLE_MACOS) + set(PLATFORM_APP_VIEW_TARGET MethanePlatformAppViewMacOS) +elseif(APPLE) + set(PLATFORM_APP_VIEW_TARGET MethanePlatformAppViewIOS) +else() # Linux + set(PLATFORM_APP_VIEW_TARGET MethanePlatformAppViewLinux) +endif() + +list(APPEND HEADERS + ${INCLUDE_DIR}/AppView.h + ${INCLUDE_DIR}/AppEnvironment.h +) + +list(APPEND SOURCES + ${SOURCES_DIR}/AppView.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + ${PLATFORM_APP_VIEW_TARGET} + PRIVATE + MethaneBuildOptions + MethaneInstrumentation + MethaneDataTypes +) + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Impl + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/AppView/Include/Methane/Platform/AppEnvironment.h b/Modules/Platform/Impl/AppView/Include/Methane/Platform/AppEnvironment.h similarity index 83% rename from Modules/Platform/AppView/Include/Methane/Platform/AppEnvironment.h rename to Modules/Platform/Impl/AppView/Include/Methane/Platform/AppEnvironment.h index 1422cc17c..7bdb33270 100644 --- a/Modules/Platform/AppView/Include/Methane/Platform/AppEnvironment.h +++ b/Modules/Platform/Impl/AppView/Include/Methane/Platform/AppEnvironment.h @@ -25,18 +25,18 @@ Methane application environment. #if defined(_WIN32) -#include "Windows/AppEnvironment.h" +#include #elif defined(__APPLE__) #ifdef APPLE_MACOS -#include "MacOS/AppEnvironment.hh" +#include #else -#include "iOS/AppEnvironment.hh" +#include #endif #elif defined __linux__ -#include "Linux/AppEnvironment.h" +#include #endif diff --git a/Modules/Platform/AppView/Include/Methane/Platform/AppView.h b/Modules/Platform/Impl/AppView/Include/Methane/Platform/AppView.h similarity index 94% rename from Modules/Platform/AppView/Include/Methane/Platform/AppView.h rename to Modules/Platform/Impl/AppView/Include/Methane/Platform/AppView.h index 58f478f88..b67872934 100644 --- a/Modules/Platform/AppView/Include/Methane/Platform/AppView.h +++ b/Modules/Platform/Impl/AppView/Include/Methane/Platform/AppView.h @@ -27,9 +27,9 @@ and by Methane App implementations. #ifdef __OBJC__ #ifdef APPLE_MACOS -#import "MacOS/AppViewMetal.hh" +#import #else -#import "iOS/AppViewMetal.hh" +#import #endif #else // __OBJC__ diff --git a/Modules/Platform/AppView/Sources/Methane/Platform/AppView.cpp b/Modules/Platform/Impl/AppView/Sources/Methane/Platform/AppView.cpp similarity index 100% rename from Modules/Platform/AppView/Sources/Methane/Platform/AppView.cpp rename to Modules/Platform/Impl/AppView/Sources/Methane/Platform/AppView.cpp diff --git a/Modules/Platform/Impl/CMakeLists.txt b/Modules/Platform/Impl/CMakeLists.txt new file mode 100644 index 000000000..2b7f51c09 --- /dev/null +++ b/Modules/Platform/Impl/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(Utils) +add_subdirectory(Input) +add_subdirectory(AppView) +add_subdirectory(App) diff --git a/Modules/Platform/Impl/Input/CMakeLists.txt b/Modules/Platform/Impl/Input/CMakeLists.txt new file mode 100644 index 000000000..df28aa576 --- /dev/null +++ b/Modules/Platform/Impl/Input/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Keyboard) diff --git a/Modules/Platform/Impl/Input/Keyboard/CMakeLists.txt b/Modules/Platform/Impl/Input/Keyboard/CMakeLists.txt new file mode 100644 index 000000000..4cf6301d3 --- /dev/null +++ b/Modules/Platform/Impl/Input/Keyboard/CMakeLists.txt @@ -0,0 +1,23 @@ +set(TARGET MethanePlatformInputKeyboard) + +# NOTE: iOS and tvOS have no native keyboard event translation implementation +if(WIN32) + set(PLATFORM_KEYBOARD_TARGET MethanePlatformInputKeyboardWindows) +elseif(APPLE_MACOS) + set(PLATFORM_KEYBOARD_TARGET MethanePlatformInputKeyboardMacOS) +elseif(NOT APPLE) + set(PLATFORM_KEYBOARD_TARGET MethanePlatformInputKeyboardLinux) +endif() + +add_library(${TARGET} INTERFACE) + +target_link_libraries(${TARGET} + INTERFACE + MethanePlatformInputKeyboardBase + ${PLATFORM_KEYBOARD_TARGET} +) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Impl +) diff --git a/Modules/Platform/Impl/Utils/CMakeLists.txt b/Modules/Platform/Impl/Utils/CMakeLists.txt new file mode 100644 index 000000000..378777e4b --- /dev/null +++ b/Modules/Platform/Impl/Utils/CMakeLists.txt @@ -0,0 +1,22 @@ +set(TARGET MethanePlatformUtils) + +if(WIN32) + set(PLATFORM_UTILS_TARGET MethanePlatformUtilsWindows) +elseif(APPLE) + set(PLATFORM_UTILS_TARGET MethanePlatformUtilsApple) +else() # Linux + set(PLATFORM_UTILS_TARGET MethanePlatformUtilsLinux) +endif() + +add_library(${TARGET} INTERFACE) + +target_link_libraries(${TARGET} + INTERFACE + MethanePlatformUtilsBase + ${PLATFORM_UTILS_TARGET} +) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Impl +) diff --git a/Modules/Platform/Interfaces/App/CMakeLists.txt b/Modules/Platform/Interfaces/App/CMakeLists.txt new file mode 100644 index 000000000..9a8671db2 --- /dev/null +++ b/Modules/Platform/Interfaces/App/CMakeLists.txt @@ -0,0 +1,55 @@ +set(TARGET MethanePlatformAppInterface) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_DIR}/IApp.h +) + +list(APPEND SOURCES + ${SOURCES_DIR}/IApp.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethaneDataTypes + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethaneInstrumentation +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Interfaces + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/IApp.h b/Modules/Platform/Interfaces/App/Include/Methane/Platform/IApp.h similarity index 100% rename from Modules/Platform/App/Include/Methane/Platform/IApp.h rename to Modules/Platform/Interfaces/App/Include/Methane/Platform/IApp.h diff --git a/Modules/Platform/Interfaces/App/Sources/Methane/Platform/IApp.cpp b/Modules/Platform/Interfaces/App/Sources/Methane/Platform/IApp.cpp new file mode 100644 index 000000000..c1a938679 --- /dev/null +++ b/Modules/Platform/Interfaces/App/Sources/Methane/Platform/IApp.cpp @@ -0,0 +1,65 @@ +/****************************************************************************** + +Copyright 2022-2025 Evgeny Gorodetskiy + +Licensed under the Apache License, Version 2.0 (the "License"), +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +******************************************************************************* + +FILE: Methane/Platform/IApp.cpp +Platform application settings implementation. + +******************************************************************************/ + +#include +#include + +namespace Methane::Platform +{ + +AppSettings& AppSettings::SetName(std::string&& new_name) noexcept +{ + META_FUNCTION_TASK(); + name = std::move(new_name); + return *this; +} + +AppSettings& AppSettings::SetSize(Data::FloatSize&& new_size) noexcept +{ + META_FUNCTION_TASK(); + size = std::move(new_size); + return *this; +} + +AppSettings& AppSettings::SetMinSize(Data::FrameSize&& new_min_size) noexcept +{ + META_FUNCTION_TASK(); + min_size = std::move(new_min_size); + return *this; +} + +AppSettings& AppSettings::SetFullScreen(bool new_full_screen) noexcept +{ + META_FUNCTION_TASK(); + is_full_screen = new_full_screen; + return *this; +} + +AppSettings& AppSettings::SetIconProvider(Data::IProvider* new_icon_provider) noexcept +{ + META_FUNCTION_TASK(); + icon_provider_ptr = new_icon_provider; + return *this; +} + +} // namespace Methane::Platform diff --git a/Modules/Platform/Interfaces/CMakeLists.txt b/Modules/Platform/Interfaces/CMakeLists.txt new file mode 100644 index 000000000..14c361067 --- /dev/null +++ b/Modules/Platform/Interfaces/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(App) diff --git a/Modules/Platform/Linux/App/CMakeLists.txt b/Modules/Platform/Linux/App/CMakeLists.txt new file mode 100644 index 000000000..ea07fb836 --- /dev/null +++ b/Modules/Platform/Linux/App/CMakeLists.txt @@ -0,0 +1,76 @@ +set(TARGET MethanePlatformAppLinux) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/App.h +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/App.cpp + ${SOURCES_PLATFORM_OS_DIR}/MessageBox.h + ${SOURCES_PLATFORM_OS_DIR}/MessageBox.cpp + ${SOURCES_PLATFORM_OS_DIR}/XcbUtils.h + ${SOURCES_PLATFORM_OS_DIR}/XcbUtils.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformAppBase + MethanePlatformAppViewLinux + MethanePlatformInputKeyboardLinux + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePlatformUtilsLinux + MethaneDataProvider + fmt + nowide + X11::X11 + X11::X11_xcb + X11::xcb + X11::xcb_randr + X11::xcb_sync + STB +) + +target_compile_definitions(${TARGET} + PRIVATE + METHANE_RENDER_APP +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + ${SOURCES_PLATFORM_OS_DIR} + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Linux + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/Linux/AppLin.h b/Modules/Platform/Linux/App/Include/Methane/Platform/Linux/App.h similarity index 91% rename from Modules/Platform/App/Include/Methane/Platform/Linux/AppLin.h rename to Modules/Platform/Linux/App/Include/Methane/Platform/Linux/App.h index 14c322647..61e5a29b5 100644 --- a/Modules/Platform/App/Include/Methane/Platform/Linux/AppLin.h +++ b/Modules/Platform/Linux/App/Include/Methane/Platform/Linux/App.h @@ -16,14 +16,14 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/Linux/AppLin.h +FILE: Methane/Platform/Linux/App.h Linux application implementation. ******************************************************************************/ #pragma once -#include +#include #include #include #include @@ -34,18 +34,18 @@ Linux application implementation. #include #include -namespace Methane::Platform +namespace Methane::Platform::Linux { class MessageBox; -class AppLin : public AppBase // NOSONAR - this class requires destructor +class App : public Base::App // NOSONAR - this class requires destructor { public: - explicit AppLin(const Settings& settings); - ~AppLin() override; + explicit App(const Settings& settings); + ~App() override; - // AppBase interface + // Base::App interface int Run(const RunArgs& args) override; void Alert(const Message& msg, bool deferred = false) override; void SetWindowTitle(const std::string& title_text) override; @@ -55,7 +55,7 @@ class AppLin : public AppBase // NOSONAR - this class requires destructor void Close() override; protected: - // AppBase interface + // Base::App interface void ShowAlert(const Message& msg) override; private: @@ -98,4 +98,4 @@ class AppLin : public AppBase // NOSONAR - this class requires destructor Data::FrameSize m_windowed_frame_size; }; -} // namespace Methane::Platform +} // namespace Methane::Platform::Linux diff --git a/Modules/Platform/App/Sources/Methane/Platform/Linux/AppLin.cpp b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/App.cpp similarity index 90% rename from Modules/Platform/App/Sources/Methane/Platform/Linux/AppLin.cpp rename to Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/App.cpp index eb725b518..1d85f72be 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Linux/AppLin.cpp +++ b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/App.cpp @@ -16,7 +16,7 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/Linux/AppLin.cpp +FILE: Methane/Platform/Linux/App.cpp Linux application implementation. ******************************************************************************/ @@ -24,7 +24,7 @@ Linux application implementation. #include "MessageBox.h" #include "XcbUtils.h" -#include +#include #include #include #include @@ -38,11 +38,11 @@ Linux application implementation. #include #include -namespace Methane::Platform +namespace Methane::Platform::Linux { -AppLin::AppLin(const AppBase::Settings& settings) - : AppBase(settings) +App::App(const Base::App::Settings& settings) + : Base::App(settings) { META_FUNCTION_TASK(); @@ -66,7 +66,7 @@ AppLin::AppLin(const AppBase::Settings& settings) m_is_sync_supported = reply && reply->present; } -AppLin::~AppLin() +App::~App() { META_FUNCTION_TASK(); if (m_env.window) @@ -76,10 +76,10 @@ AppLin::~AppLin() xcb_disconnect(m_env.connection); } -int AppLin::Run(const RunArgs& args) +int App::Run(const RunArgs& args) { // Skip instrumentation META_FUNCTION_TASK() since this is the only root function running till application close - if (const int base_return_code = AppBase::Run(args); + if (const int base_return_code = Base::App::Run(args); base_return_code) return base_return_code; @@ -129,17 +129,17 @@ int AppLin::Run(const RunArgs& args) return 0; } -void AppLin::Alert(const Message& msg, bool deferred) +void App::Alert(const Message& msg, bool deferred) { META_FUNCTION_TASK(); - AppBase::Alert(msg, deferred); + Base::App::Alert(msg, deferred); if (!deferred) { ShowAlert(msg); } } -void AppLin::SetWindowTitle(const std::string& title_text) +void App::SetWindowTitle(const std::string& title_text) { META_FUNCTION_TASK(); if (!m_env.window) @@ -148,10 +148,10 @@ void AppLin::SetWindowTitle(const std::string& title_text) Linux::SetXcbWindowStringProperty(m_env.connection, m_env.window, XCB_ATOM_WM_NAME, title_text); } -bool AppLin::SetFullScreen(bool is_full_screen) +bool App::SetFullScreen(bool is_full_screen) { META_FUNCTION_TASK(); - if (!AppBase::SetFullScreen(is_full_screen) || !m_env.window) + if (!Base::App::SetFullScreen(is_full_screen) || !m_env.window) return false; xcb_client_message_event_t msg{0}; @@ -187,13 +187,13 @@ bool AppLin::SetFullScreen(bool is_full_screen) return true; } -float AppLin::GetContentScalingFactor() const +float App::GetContentScalingFactor() const { META_FUNCTION_TASK(); return static_cast(GetFontResolutionDpi()) / 96.F; } -uint32_t AppLin::GetFontResolutionDpi() const +uint32_t App::GetFontResolutionDpi() const { META_FUNCTION_TASK(); if (const char* display_res_str = XResourceManagerString(m_env.display); @@ -213,17 +213,17 @@ uint32_t AppLin::GetFontResolutionDpi() const return std::max(dpi_hor, dpi_ver); } -void AppLin::Close() +void App::Close() { META_FUNCTION_TASK(); m_is_event_processing = false; } -void AppLin::ShowAlert(const Message& message) +void App::ShowAlert(const Message& message) { META_FUNCTION_TASK(); GetMessageBox().Show(message); - AppBase::ShowAlert(message); + Base::App::ShowAlert(message); if (message.type == Message::Type::Error) { @@ -231,7 +231,7 @@ void AppLin::ShowAlert(const Message& message) } } -Data::FrameSize AppLin::InitWindow() +Data::FrameSize App::InitWindow() { META_FUNCTION_TASK(); const IApp::Settings& settings = GetPlatformAppSettings(); @@ -253,10 +253,10 @@ Data::FrameSize AppLin::InitWindow() // Calculate frame size relative to screen_id size in case of floating point value const uint16_t frame_width = settings.is_full_screen ? static_cast(m_env.primary_screen_rect.width) - : static_cast(AppBase::GetScaledSize(settings.size.GetWidth(), m_env.primary_screen_rect.width)); + : static_cast(Base::App::GetScaledSize(settings.size.GetWidth(), m_env.primary_screen_rect.width)); const uint16_t frame_height = settings.is_full_screen ? static_cast(m_env.primary_screen_rect.height) - : static_cast(AppBase::GetScaledSize(settings.size.GetHeight(), m_env.primary_screen_rect.height)); + : static_cast(Base::App::GetScaledSize(settings.size.GetHeight(), m_env.primary_screen_rect.height)); const int16_t pos_x = settings.is_full_screen ? static_cast(m_env.primary_screen_rect.x) @@ -320,7 +320,7 @@ Data::FrameSize AppLin::InitWindow() xcb_flush(m_env.connection); Data::FrameSize frame_size(frame_width, frame_height); - AppBase::Resize(frame_size, false); + Base::App::Resize(frame_size, false); return frame_size; } @@ -359,7 +359,7 @@ static void AddIconData(const Data::Chunk& icon_data, std::vector& com } } -void AppLin::SetWindowIcon(const Data::IProvider& icon_provider) +void App::SetWindowIcon(const Data::IProvider& icon_provider) { META_FUNCTION_TASK(); META_CHECK_NOT_NULL(m_env.window); @@ -376,7 +376,7 @@ void AppLin::SetWindowIcon(const Data::IProvider& icon_provider) Linux::SetXcbWindowAtomProperty(m_env.connection, m_env.window, "_NET_WM_ICON", XCB_ATOM_CARDINAL, combined_icons_data); } -void AppLin::ResizeWindow(const Data::FrameSize& frame_size, const Data::FrameSize& min_size, const Data::Point2I* position) +void App::ResizeWindow(const Data::FrameSize& frame_size, const Data::FrameSize& min_size, const Data::Point2I* position) { META_FUNCTION_TASK(); META_CHECK_NOT_NULL(m_env.window); @@ -413,7 +413,7 @@ void AppLin::ResizeWindow(const Data::FrameSize& frame_size, const Data::FrameSi xcb_flush(m_env.connection); } -void AppLin::HandleEvent(const xcb_generic_event_t& event) +void App::HandleEvent(const xcb_generic_event_t& event) { META_FUNCTION_TASK(); const uint8_t event_type = event.response_type & 0x7f; // NOSONAR @@ -472,7 +472,7 @@ void AppLin::HandleEvent(const xcb_generic_event_t& event) } } -void AppLin::OnClientEvent(const xcb_client_message_event_t& event) +void App::OnClientEvent(const xcb_client_message_event_t& event) { META_FUNCTION_TASK(); if (event.format != 32 || event.type != m_protocols_atom) @@ -493,7 +493,7 @@ void AppLin::OnClientEvent(const xcb_client_message_event_t& event) } } -void AppLin::UpdateSyncCounter() +void App::UpdateSyncCounter() { META_FUNCTION_TASK(); if (!m_is_sync_supported || (m_sync_value.lo == 0 && m_sync_value.hi == 0U)) @@ -508,7 +508,7 @@ void AppLin::UpdateSyncCounter() m_sync_state = SyncState::NotNeeded; } -void AppLin::OnWindowConfigured(const xcb_configure_notify_event_t& conf_event) +void App::OnWindowConfigured(const xcb_configure_notify_event_t& conf_event) { META_FUNCTION_TASK(); if (conf_event.window != m_env.window || @@ -524,7 +524,7 @@ void AppLin::OnWindowConfigured(const xcb_configure_notify_event_t& conf_event) Resize(Data::FrameSize(conf_event.width, conf_event.height), false); } -void AppLin::OnPropertyChanged(const xcb_property_notify_event_t& prop_event) +void App::OnPropertyChanged(const xcb_property_notify_event_t& prop_event) { META_FUNCTION_TASK(); if (prop_event.atom != m_state_atom || prop_event.window != m_env.window) @@ -546,14 +546,14 @@ void AppLin::OnPropertyChanged(const xcb_property_notify_event_t& prop_event) } } -void AppLin::OnKeyboardChanged(const xcb_key_press_event_t& key_press_event, Input::Keyboard::KeyState key_state) +void App::OnKeyboardChanged(const xcb_key_press_event_t& key_press_event, Input::Keyboard::KeyState key_state) { META_FUNCTION_TASK(); const Input::Keyboard::Key key = Linux::ConvertXcbKey(m_env.display, m_env.window, key_press_event.detail, key_press_event.state); ProcessInputWithErrorHandling(&Input::IActionController::OnKeyboardChanged, key, key_state); } -void AppLin::OnKeyboardMappingChanged(const xcb_mapping_notify_event_t& mapping_event) +void App::OnKeyboardMappingChanged(const xcb_mapping_notify_event_t& mapping_event) { META_FUNCTION_TASK(); XMappingEvent x_mapping_event{ 0 }; @@ -568,7 +568,7 @@ void AppLin::OnKeyboardMappingChanged(const xcb_mapping_notify_event_t& mapping_ XRefreshKeyboardMapping(&x_mapping_event); } -void AppLin::OnMouseButtonChanged(const xcb_button_press_event_t& button_press_event, Input::Mouse::ButtonState button_state) +void App::OnMouseButtonChanged(const xcb_button_press_event_t& button_press_event, Input::Mouse::ButtonState button_state) { META_FUNCTION_TASK(); using enum Input::Mouse::Button; @@ -592,21 +592,21 @@ void AppLin::OnMouseButtonChanged(const xcb_button_press_event_t& button_press_e } } -void AppLin::OnMouseMoved(const xcb_motion_notify_event_t& motion_event) +void App::OnMouseMoved(const xcb_motion_notify_event_t& motion_event) { META_FUNCTION_TASK(); const Input::Mouse::Position mouse_pos(motion_event.event_x, motion_event.event_y); ProcessInputWithErrorHandling(&Input::IActionController::OnMousePositionChanged, mouse_pos); } -void AppLin::OnMouseInWindowChanged(const xcb_enter_notify_event_t& enter_event, bool mouse_in_window) +void App::OnMouseInWindowChanged(const xcb_enter_notify_event_t& enter_event, bool mouse_in_window) { META_FUNCTION_TASK(); META_UNUSED(enter_event); ProcessInputWithErrorHandling(&Input::IActionController::OnMouseInWindowChanged, mouse_in_window); } -MessageBox& AppLin::GetMessageBox() +MessageBox& App::GetMessageBox() { META_FUNCTION_TASK(); if (!m_message_box_ptr) @@ -616,4 +616,4 @@ MessageBox& AppLin::GetMessageBox() return *m_message_box_ptr; } -} // namespace Methane::Platform \ No newline at end of file +} // namespace Methane::Platform::Linux \ No newline at end of file diff --git a/Modules/Platform/App/Sources/Methane/Platform/Linux/MessageBox.cpp b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/MessageBox.cpp similarity index 99% rename from Modules/Platform/App/Sources/Methane/Platform/Linux/MessageBox.cpp rename to Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/MessageBox.cpp index 009a8dbdb..acb376dd1 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Linux/MessageBox.cpp +++ b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/MessageBox.cpp @@ -34,7 +34,7 @@ Linux message box implementation with X11/XCB. #include -namespace Methane::Platform +namespace Methane::Platform::Linux { static const std::string_view g_default_font_name = "-*-fixed-medium-r-*--15-*-*-*-*-*-*-*"; @@ -375,4 +375,4 @@ void MessageBox::OnMouseButtonChanged(const xcb_button_press_event_t& button_pre } } -} // namespace Methane::Platform +} // namespace Methane::Platform::Linux diff --git a/Modules/Platform/App/Sources/Methane/Platform/Linux/MessageBox.h b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/MessageBox.h similarity index 96% rename from Modules/Platform/App/Sources/Methane/Platform/Linux/MessageBox.h rename to Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/MessageBox.h index ce4f7c362..ea7ef884b 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Linux/MessageBox.h +++ b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/MessageBox.h @@ -29,7 +29,7 @@ Linux message box implementation with X11/XCB. #include -namespace Methane::Platform +namespace Methane::Platform::Linux { class MessageBox // NOSONAR @@ -69,4 +69,4 @@ class MessageBox // NOSONAR bool m_is_event_processing = false; }; -} // namespace Methane::Platform +} // namespace Methane::Platform::Linux diff --git a/Modules/Platform/App/Sources/Methane/Platform/Linux/XcbUtils.cpp b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/XcbUtils.cpp similarity index 99% rename from Modules/Platform/App/Sources/Methane/Platform/Linux/XcbUtils.cpp rename to Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/XcbUtils.cpp index 9c5b21fe9..b3c11a408 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Linux/XcbUtils.cpp +++ b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/XcbUtils.cpp @@ -228,5 +228,5 @@ ScreenRect GetPrimaryMonitorRect(xcb_connection_t* connection, xcb_window_t root #endif } -} // namespace Methane::Platform +} // namespace Methane::Platform::Linux ; \ No newline at end of file diff --git a/Modules/Platform/App/Sources/Methane/Platform/Linux/XcbUtils.h b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/XcbUtils.h similarity index 99% rename from Modules/Platform/App/Sources/Methane/Platform/Linux/XcbUtils.h rename to Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/XcbUtils.h index c562ad81e..f4338f440 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Linux/XcbUtils.h +++ b/Modules/Platform/Linux/App/Sources/Methane/Platform/Linux/XcbUtils.h @@ -25,6 +25,7 @@ X11/XCB utility functions. #include #include +#include #include #include diff --git a/Modules/Platform/Linux/AppView/CMakeLists.txt b/Modules/Platform/Linux/AppView/CMakeLists.txt new file mode 100644 index 000000000..144f5835c --- /dev/null +++ b/Modules/Platform/Linux/AppView/CMakeLists.txt @@ -0,0 +1,35 @@ +set(TARGET MethanePlatformAppViewLinux) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_PLATFORM_OS_DIR}/AppEnvironment.h +) + +add_library(${TARGET} INTERFACE) + +target_sources(${TARGET} + INTERFACE + ${HEADERS} +) + +target_include_directories(${TARGET} + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Linux + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development +) diff --git a/Modules/Platform/AppView/Include/Methane/Platform/Linux/AppEnvironment.h b/Modules/Platform/Linux/AppView/Include/Methane/Platform/Linux/AppEnvironment.h similarity index 100% rename from Modules/Platform/AppView/Include/Methane/Platform/Linux/AppEnvironment.h rename to Modules/Platform/Linux/AppView/Include/Methane/Platform/Linux/AppEnvironment.h diff --git a/Modules/Platform/Linux/CMakeLists.txt b/Modules/Platform/Linux/CMakeLists.txt new file mode 100644 index 000000000..2b7f51c09 --- /dev/null +++ b/Modules/Platform/Linux/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(Utils) +add_subdirectory(Input) +add_subdirectory(AppView) +add_subdirectory(App) diff --git a/Modules/Platform/Linux/Input/CMakeLists.txt b/Modules/Platform/Linux/Input/CMakeLists.txt new file mode 100644 index 000000000..df28aa576 --- /dev/null +++ b/Modules/Platform/Linux/Input/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Keyboard) diff --git a/Modules/Platform/Linux/Input/Keyboard/CMakeLists.txt b/Modules/Platform/Linux/Input/Keyboard/CMakeLists.txt new file mode 100644 index 000000000..c6b96913d --- /dev/null +++ b/Modules/Platform/Linux/Input/Keyboard/CMakeLists.txt @@ -0,0 +1,59 @@ +set(TARGET MethanePlatformInputKeyboardLinux) + +include(MethaneModules) + +get_module_dirs("Methane/Platform/Input") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/Keyboard.h +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/Keyboard.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformInputKeyboardBase + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePrimitives + MethaneInstrumentation + magic_enum +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + ${X11_xcb_INCLUDE_PATH} + ${X11_X11_INCLUDE_PATH} + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Linux/Input + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Linux/Keyboard.h b/Modules/Platform/Linux/Input/Keyboard/Include/Methane/Platform/Input/Linux/Keyboard.h similarity index 100% rename from Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Linux/Keyboard.h rename to Modules/Platform/Linux/Input/Keyboard/Include/Methane/Platform/Input/Linux/Keyboard.h diff --git a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Linux/Keyboard.cpp b/Modules/Platform/Linux/Input/Keyboard/Sources/Methane/Platform/Input/Linux/Keyboard.cpp similarity index 96% rename from Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Linux/Keyboard.cpp rename to Modules/Platform/Linux/Input/Keyboard/Sources/Methane/Platform/Input/Linux/Keyboard.cpp index fac129afc..e4b8fe75b 100644 --- a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Linux/Keyboard.cpp +++ b/Modules/Platform/Linux/Input/Keyboard/Sources/Methane/Platform/Input/Linux/Keyboard.cpp @@ -21,6 +21,7 @@ Linux platform specific types and implementation of Keyboard abstractions. ******************************************************************************/ +#include #include #include @@ -187,4 +188,9 @@ ModifierMask KeyConverter::GetModifiersByNativeCode(const NativeKey& native_key) return modifiers_mask; } +KeyConverter::KeyConverter(const NativeKey& native_key) + : m_key(GetKeyByNativeCode(native_key)) + , m_modifiers(GetModifiersByNativeCode(native_key)) +{ } + } // namespace Methane::Platform::Input::Keyboard \ No newline at end of file diff --git a/Modules/Platform/Linux/README.md b/Modules/Platform/Linux/README.md new file mode 100644 index 000000000..301bf6137 --- /dev/null +++ b/Modules/Platform/Linux/README.md @@ -0,0 +1,60 @@ +# Methane Platform Linux + +Linux implementation of the [Platform modules](../README.md), in namespace `Methane::Platform::Linux`. +This group is added to the build by [Platform/CMakeLists.txt](../CMakeLists.txt) when the target is +neither Windows nor Apple. Linux always uses the Vulkan RHI backend. + +| Module | CMake Target | Content | +|----------------------------------|-----------------------------------|-------------------------------------------------| +| [App](App) | MethanePlatformAppLinux | `Linux::App` XCB windowed application | +| [AppView](AppView) | MethanePlatformAppViewLinux | `AppEnvironment` with the XCB/X11 handles | +| [Input/Keyboard](Input/Keyboard) | MethanePlatformInputKeyboardLinux | `Keyboard::NativeKey` and its key translation | +| [Utils](Utils) | MethanePlatformUtilsLinux | Linux implementation of the platform utilities | + +## Windowing with XCB + +The window is created and driven with **XCB** rather than Xlib, because XCB's explicit request/reply +model suits the single-threaded render loop better. An Xlib `Display*` is nevertheless kept in +`AppEnvironment` alongside the XCB handles, since some Vulkan loaders and drivers still expect it. + +`AppEnvironment` holds the `xcb_connection_t*`, the `xcb_window_t`, the `_XDisplay*`, the +`xcb_screen_t*` and the primary screen rectangle. The primary monitor geometry is queried through +`xcb_randr`, so the window can be sized as a ratio of the actual monitor rather than of the whole +X screen, which may span several monitors. + +Linked X libraries: `X11::X11`, `X11::X11_xcb`, `X11::xcb`, `X11::xcb_randr`, `X11::xcb_sync`. + +## App implementation details + +[`Linux::App`](App/Include/Methane/Platform/Linux/App.h) derives from [`Base::App`](../Base/App) and +runs its own XCB event loop. Points worth knowing: + +- **`XcbUtils`** ([header](App/Sources/Methane/Platform/Linux/XcbUtils.h)) collects the low-level + helpers: interning atoms, setting string and atom window properties, filling `WMSizeHints`, and + translating XCB key/button/motion events into Methane input events. +- **Resize synchronisation** uses the `_NET_WM_SYNC_REQUEST` protocol with an `xcb_sync` counter, so + the compositor waits for the application to finish a frame before showing the resized window. This + is what keeps live resizing from tearing or lagging behind the pointer. +- **`MessageBox`** ([header](App/Sources/Methane/Platform/Linux/MessageBox.h)) is drawn by hand with + XCB and runs a nested event loop. X11 has no native message dialog, so alerts cannot be delegated + to the system the way they are on Windows and macOS. +- **Window icon** is published as `_NET_WM_ICON` from images decoded with STB, which is why the + module links `STB`. +- Full-screen switching is a `_NET_WM_STATE` / `_NET_WM_STATE_FULLSCREEN` client message to the + window manager, so the result depends on the WM honouring it. + +## Input/Keyboard + +`Keyboard::NativeKey` holds an X11 `KeySym` plus the event state flags. `Keyboard::KeyConverter` +maps keysyms (`X11/keysym.h`) to platform-independent `Keyboard::Key` values. The module needs the +`xcb` and `X11` include paths for this translation. + +## Utils + +`Methane/Platform/Linux/Utils.h` declares no Linux-only API — unlike Windows, this group only +implements the platform-independent functions declared in +[`Methane/Platform/Utils.h`](../Base/Utils/Include/Methane/Platform/Utils.h): + +- `GetExecutableDir()` / `GetExecutableFileName()` resolve `/proc/self/exe` with `readlink`. +- `PrintToDebugOutput` has no platform debug channel to write to and is effectively a no-op; use + `--print_debug_messages_to_console` to see debug output on Linux. diff --git a/Modules/Platform/Linux/Utils/CMakeLists.txt b/Modules/Platform/Linux/Utils/CMakeLists.txt new file mode 100644 index 000000000..3264dc860 --- /dev/null +++ b/Modules/Platform/Linux/Utils/CMakeLists.txt @@ -0,0 +1,56 @@ +set(TARGET MethanePlatformUtilsLinux) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/Utils.h +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/Utils.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformUtilsBase + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethaneInstrumentation + nowide +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Linux + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/Utils/Include/Methane/Platform/Linux/Utils.h b/Modules/Platform/Linux/Utils/Include/Methane/Platform/Linux/Utils.h similarity index 100% rename from Modules/Platform/Utils/Include/Methane/Platform/Linux/Utils.h rename to Modules/Platform/Linux/Utils/Include/Methane/Platform/Linux/Utils.h diff --git a/Modules/Platform/Utils/Sources/Methane/Platform/Linux/Utils.cpp b/Modules/Platform/Linux/Utils/Sources/Methane/Platform/Linux/Utils.cpp similarity index 100% rename from Modules/Platform/Utils/Sources/Methane/Platform/Linux/Utils.cpp rename to Modules/Platform/Linux/Utils/Sources/Methane/Platform/Linux/Utils.cpp diff --git a/Modules/Platform/README.md b/Modules/Platform/README.md index 82abcbb1c..593e065c5 100644 --- a/Modules/Platform/README.md +++ b/Modules/Platform/README.md @@ -1,25 +1,154 @@ # Methane Platform +Code of these modules is located in `Methane::Platform` namespace. + +Platform modules are grouped by platform support, similar to [Graphics RHI](../Graphics/RHI) modules: + +| Group | Namespace | Content | +|-----------------------------------------|------------------------------|-----------------------------------------------------------------| +| [Interfaces](Interfaces) | `Methane::Platform` | Public interfaces and settings structures with no implementation | +| [Base](Base/README.md) | `Methane::Platform[::Base]` | All platform-independent implementations | +| [Windows](Windows/README.md) | `Methane::Platform::Windows` | Windows-specific implementations | +| [Linux](Linux/README.md) | `Methane::Platform::Linux` | Linux-specific implementations | +| [Apple](Apple/README.md) | `Methane::Platform::Apple` | Implementations shared by all Apple platforms | +| [Apple/MacOS](Apple/MacOS/README.md) | `Methane::Platform::MacOS` | MacOS-specific implementations | +| [Apple/iOS](Apple/iOS/README.md) | `Methane::Platform::iOS` | iOS / tvOS-specific implementations | +| [Impl](Impl) | `Methane::Platform` | Final implementation modules binding the groups above together | + +Exactly one platform group is added to the build by [CMakeLists.txt](CMakeLists.txt), chosen by the target platform; +on Apple platforms [Apple/CMakeLists.txt](Apple/CMakeLists.txt) additionally picks `MacOS` or `iOS` on top of the +shared `Apple` modules. Each platform group has its own README with the details of that implementation. + +Within `Base`, a module which has platform counterparts carries a `Base` target suffix and sits behind an +`Impl` facade that other domains link instead of it: `MethanePlatformApp`, `MethanePlatformAppView`, +`MethanePlatformInputKeyboard` and `MethanePlatformUtils`. A module which is fully platform-independent has +no counterpart, no suffix and no facade, and is linked directly: `MethanePlatformAppController`, +`MethanePlatformInputMouse`, `MethanePlatformInputControllers` and `MethanePlatformInputActionControllers`. + ## Modules -Code of these modules is located in `Methane::Platform` namespace: +### App + +Application platform-abstraction class and platform-specific implementations — +see [Platform App description](Impl/App/README.md) for details. + +| Module | CMake Target | +|------------------------------------------|------------------------------| +| [Interfaces/App](Interfaces/App) | MethanePlatformAppInterface | +| [Base/App](Base/App) | MethanePlatformAppBase | +| [Base/AppController](Base/AppController) | MethanePlatformAppController | +| [Windows/App](Windows/App) | MethanePlatformAppWindows | +| [Linux/App](Linux/App) | MethanePlatformAppLinux | +| [Apple/MacOS/App](Apple/MacOS/App) | MethanePlatformAppMacOS | +| [Apple/iOS/App](Apple/iOS/App) | MethanePlatformAppIOS | +| [Impl/App](Impl/App) | MethanePlatformApp | + +### AppView + +Application view and environment platform-abstraction classes. + +| Module | CMake Target | +|----------------------------------------------|-------------------------------| +| [Windows/AppView](Windows/AppView) | MethanePlatformAppViewWindows | +| [Linux/AppView](Linux/AppView) | MethanePlatformAppViewLinux | +| [Apple/MacOS/AppView](Apple/MacOS/AppView) | MethanePlatformAppViewMacOS | +| [Apple/iOS/AppView](Apple/iOS/AppView) | MethanePlatformAppViewIOS | +| [Impl/AppView](Impl/AppView) | MethanePlatformAppView | + +### Input + +Application input with mouse and keyboard and platform-specific handling implementations. + +| Module | CMake Target | +|---------------------------------------------------------------------|---------------------------------------| +| [Base/Input/Keyboard](Base/Input/Keyboard) | MethanePlatformInputKeyboardBase | +| [Windows/Input/Keyboard](Windows/Input/Keyboard) | MethanePlatformInputKeyboardWindows | +| [Linux/Input/Keyboard](Linux/Input/Keyboard) | MethanePlatformInputKeyboardLinux | +| [Apple/MacOS/Input/Keyboard](Apple/MacOS/Input/Keyboard) | MethanePlatformInputKeyboardMacOS | +| [Impl/Input/Keyboard](Impl/Input/Keyboard) | MethanePlatformInputKeyboard | +| [Base/Input/Mouse](Base/Input/Mouse) | MethanePlatformInputMouse | +| [Base/Input/Controllers](Base/Input/Controllers) | MethanePlatformInputControllers | +| [Base/Input/ActionControllers](Base/Input/ActionControllers) | MethanePlatformInputActionControllers | + +The platform-specific `Keyboard::NativeKey` structure is defined in the +`/Keyboard.h>` header of the platform group, while the +platform-independent `Keyboard::Key`, `Keyboard::KeyConverter` and `Keyboard::State` classes +are defined in `` of the `Base` group. +iOS and tvOS have no native keyboard event translation implementation. + +### Utils -- [AppView](AppView) - application view and environment platform-abstraction classes -- [App](App) - application platform-abstraction class and platform-specific implementations -- [Input](Input) - application input with mouse and keyboard and platform-specific handling implementations. -- [Utils](Utils) - platform utilities +Platform utilities. + +| Module | CMake Target | +|--------------------------------|-----------------------------| +| [Base/Utils](Base/Utils) | MethanePlatformUtilsBase | +| [Windows/Utils](Windows/Utils) | MethanePlatformUtilsWindows | +| [Linux/Utils](Linux/Utils) | MethanePlatformUtilsLinux | +| [Apple/Utils](Apple/Utils) | MethanePlatformUtilsApple | +| [Impl/Utils](Impl/Utils) | MethanePlatformUtils | + +Platform-independent functions are declared in `` of the `Base` group, +while platform-specific ones are declared in `/Utils.h>` of the platform group. +Only Windows actually adds such functions; see the per-platform READMEs. ## Intra-Domain Modules Dependencies +`Platform/...` in the graph below stands for the single platform group added to the build. + ```mermaid graph TD; - Utils-->Input/Keyboard; - Input/Keyboard-->Input/Controllers; - Input/Mouse-->Input/Controllers; - Input/Controllers-->Input/ActionControlls; - Input/ActionControlls-->App - AppView-->App - Utils-->App + subgraph Utils + utils_base([Base/Utils]) + utils_os([Platform/Utils]) + utils_impl([Impl/Utils]) + end + + subgraph Input + key_base([Base/Input/Keyboard]) + key_os([Platform/Input/Keyboard]) + key_impl([Impl/Input/Keyboard]) + mouse([Base/Input/Mouse]) + cont([Base/Input/Controllers]) + action([Base/Input/ActionControllers]) + end + + subgraph AppView + view_os([Platform/AppView]) + view_impl([Impl/AppView]) + end + + subgraph App + app_iface([Interfaces/App]) + app_base([Base/App]) + app_os([Platform/App]) + app_ctrl([Base/AppController]) + app_impl([Impl/App]) + end + + utils_base-->utils_os + utils_base-->utils_impl + utils_os-->utils_impl + + utils_impl-->key_base + key_base-->key_os + key_base-->key_impl + key_os-->key_impl + + key_impl-->cont + mouse-->cont + cont-->action + + view_os-->view_impl + + app_iface-->app_base + action-->app_base + view_impl-->app_base + utils_impl-->app_base + app_base-->app_os + app_base-->app_ctrl + app_os-->app_impl + app_ctrl-->app_impl ``` ## Cross-Domain Modules Dependencies @@ -32,13 +161,13 @@ graph TD; end subgraph Platform - pal_util([Utils]) - pal_key([Input/Keyboard]) - pal_mouse([Input/Mouse]) - pal_cont([Input/Controllers]) - pal_action([Input/ActionControllers]) - pal_view([AppView]) - pal_app([App]) + pal_util([Impl/Utils]) + pal_key([Impl/Input/Keyboard]) + pal_mouse([Base/Input/Mouse]) + pal_cont([Base/Input/Controllers]) + pal_action([Base/Input/ActionControllers]) + pal_view([Impl/AppView]) + pal_app([Impl/App]) end pal_util-->pal_key diff --git a/Modules/Platform/Windows/App/CMakeLists.txt b/Modules/Platform/Windows/App/CMakeLists.txt new file mode 100644 index 000000000..608f0d241 --- /dev/null +++ b/Modules/Platform/Windows/App/CMakeLists.txt @@ -0,0 +1,69 @@ +set(TARGET MethanePlatformAppWindows) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/App.h +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/App.cpp + ${SOURCES_PLATFORM_OS_DIR}/ConsoleStreams.h + ${SOURCES_PLATFORM_OS_DIR}/ConsoleStreams.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformAppBase + MethanePlatformAppViewWindows + MethanePlatformInputKeyboardWindows + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePlatformUtilsWindows + MethaneDataProvider + fmt + nowide + Shcore +) + +target_compile_definitions(${TARGET} + PRIVATE + METHANE_RENDER_APP +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + ${SOURCES_PLATFORM_OS_DIR} + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Windows + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/App/Include/Methane/Platform/Windows/AppWin.h b/Modules/Platform/Windows/App/Include/Methane/Platform/Windows/App.h similarity index 89% rename from Modules/Platform/App/Include/Methane/Platform/Windows/AppWin.h rename to Modules/Platform/Windows/App/Include/Methane/Platform/Windows/App.h index 84c5979d4..d90e95366 100644 --- a/Modules/Platform/App/Include/Methane/Platform/Windows/AppWin.h +++ b/Modules/Platform/Windows/App/Include/Methane/Platform/Windows/App.h @@ -16,14 +16,14 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/Windows/AppWin.h +FILE: Methane/Platform/Windows/App.h Windows application implementation. ******************************************************************************/ #pragma once -#include +#include #include #include #include @@ -33,18 +33,18 @@ Windows application implementation. #include #include -namespace Methane::Platform +namespace Methane::Platform::Windows { class ConsoleStreams; -class AppWin : public AppBase +class App : public Base::App { public: - explicit AppWin(const Settings& settings); - ~AppWin() override; + explicit App(const Settings& settings); + ~App() override; - // AppBase interface + // Base::App interface int Run(const RunArgs& args) override; void Alert(const Message& msg, bool deferred = false) override; void SetWindowTitle(const std::string& title_text) override; @@ -54,7 +54,7 @@ class AppWin : public AppBase void Close() override; protected: - // AppBase interface + // Base::App interface void ShowAlert(const Message& msg) override; void ScheduleAlert(); @@ -81,4 +81,4 @@ class AppWin : public AppBase UniquePtr m_console_streams_ptr; }; -} // namespace Methane::Platform +} // namespace Methane::Platform::Windows diff --git a/Modules/Platform/App/Sources/Methane/Platform/Windows/AppWin.cpp b/Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/App.cpp similarity index 91% rename from Modules/Platform/App/Sources/Methane/Platform/Windows/AppWin.cpp rename to Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/App.cpp index 7c82cb8bf..511b9b0d7 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Windows/AppWin.cpp +++ b/Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/App.cpp @@ -16,14 +16,16 @@ limitations under the License. ******************************************************************************* -FILE: Methane/Platform/Windows/AppWin.cpp +FILE: Methane/Platform/Windows/App.cpp Windows application implementation. ******************************************************************************/ #include "ConsoleStreams.h" -#include +#include +#include +#include #include #include #include @@ -32,7 +34,7 @@ Windows application implementation. #include #include -namespace Methane::Platform +namespace Methane::Platform::Windows { constexpr auto WM_ALERT = WM_USER + 1; @@ -40,12 +42,12 @@ constexpr auto WM_ALERT = WM_USER + 1; static const wchar_t* const g_window_class = L"MethaneWindowClass"; static const wchar_t* const g_window_icon = L"IDI_APP_ICON"; -static UINT ConvertMessageTypeToFlags(AppBase::Message::Type msg_type) +static UINT ConvertMessageTypeToFlags(Base::App::Message::Type msg_type) { META_FUNCTION_TASK(); switch (msg_type) { - using enum AppBase::Message::Type; + using enum Base::App::Message::Type; case Information: return MB_ICONINFORMATION | MB_OK; case Warning: return MB_ICONWARNING | MB_OK; case Error: return MB_ICONERROR | MB_OK; @@ -81,20 +83,20 @@ static float GetDeviceScaleRatio(DEVICE_SCALE_FACTOR device_scale_factor) } } -AppWin::AppWin(const AppBase::Settings& settings) - : AppBase(settings) +App::App(const Base::App::Settings& settings) + : Base::App(settings) , m_console_streams_ptr(std::make_unique()) // NOSONAR { META_FUNCTION_TASK(); m_console_streams_ptr->Attach(); } -AppWin::~AppWin() = default; +App::~App() = default; -int AppWin::Run(const RunArgs& args) +int App::Run(const RunArgs& args) { // Skip instrumentation META_FUNCTION_TASK() since this is the only root function running till application close - if (const int base_return_code = AppBase::Run(args); + if (const int base_return_code = Base::App::Run(args); base_return_code) return base_return_code; @@ -112,7 +114,7 @@ int AppWin::Run(const RunArgs& args) uint32_t desktop_width = 0U; uint32_t desktop_height = 0U; - Windows::GetDesktopResolution(desktop_width, desktop_height); + GetDesktopResolution(desktop_width, desktop_height); const Settings& app_settings = GetPlatformAppSettings(); const Data::FrameSize frame_size( @@ -178,10 +180,10 @@ int AppWin::Run(const RunArgs& args) return static_cast(msg.wParam); } -void AppWin::Alert(const Message& msg, bool deferred) +void App::Alert(const Message& msg, bool deferred) { META_FUNCTION_TASK(); - AppBase::Alert(msg, deferred); + Base::App::Alert(msg, deferred); if (deferred) { @@ -193,7 +195,7 @@ void AppWin::Alert(const Message& msg, bool deferred) } } -void AppWin::OnWindowAlert() +void App::OnWindowAlert() { META_FUNCTION_TASK(); if (!HasDeferredMessage()) @@ -203,7 +205,7 @@ void AppWin::OnWindowAlert() ResetDeferredMessage(); } -LRESULT AppWin::OnWindowDestroy() +LRESULT App::OnWindowDestroy() { META_FUNCTION_TASK(); StopMessageProcessing(); @@ -211,7 +213,7 @@ LRESULT AppWin::OnWindowDestroy() return 0; } -void AppWin::OnWindowResized(WPARAM w_param, LPARAM l_param) +void App::OnWindowResized(WPARAM w_param, LPARAM l_param) { META_FUNCTION_TASK(); META_UNUSED(l_param); @@ -242,7 +244,7 @@ void AppWin::OnWindowResized(WPARAM w_param, LPARAM l_param) } } -LRESULT AppWin::OnWindowResizing(WPARAM w_param, LPARAM l_param) +LRESULT App::OnWindowResizing(WPARAM w_param, LPARAM l_param) { META_FUNCTION_TASK(); META_UNUSED(w_param); @@ -283,7 +285,7 @@ LRESULT AppWin::OnWindowResizing(WPARAM w_param, LPARAM l_param) return TRUE; } -void AppWin::OnWindowKeyboardEvent(WPARAM w_param, LPARAM l_param) +void App::OnWindowKeyboardEvent(WPARAM w_param, LPARAM l_param) { META_FUNCTION_TASK(); using enum Input::Keyboard::KeyState; @@ -313,7 +315,7 @@ void AppWin::OnWindowKeyboardEvent(WPARAM w_param, LPARAM l_param) } } -LRESULT AppWin::OnWindowMouseButtonEvent(UINT msg_id, WPARAM w_param, LPARAM l_param) +LRESULT App::OnWindowMouseButtonEvent(UINT msg_id, WPARAM w_param, LPARAM l_param) { META_FUNCTION_TASK(); META_UNUSED(l_param); @@ -353,7 +355,7 @@ LRESULT AppWin::OnWindowMouseButtonEvent(UINT msg_id, WPARAM w_param, LPARAM l_p return FALSE; } -LRESULT AppWin::OnWindowMouseMoveEvent(WPARAM w_param, LPARAM l_param) +LRESULT App::OnWindowMouseMoveEvent(WPARAM w_param, LPARAM l_param) { META_FUNCTION_TASK(); META_UNUSED(w_param); @@ -378,7 +380,7 @@ LRESULT AppWin::OnWindowMouseMoveEvent(WPARAM w_param, LPARAM l_param) return 0; } -LRESULT AppWin::OnWindowMouseWheelEvent(bool is_vertical_scroll, WPARAM w_param, LPARAM l_param) +LRESULT App::OnWindowMouseWheelEvent(bool is_vertical_scroll, WPARAM w_param, LPARAM l_param) { META_FUNCTION_TASK(); META_UNUSED(w_param); @@ -399,14 +401,14 @@ LRESULT AppWin::OnWindowMouseWheelEvent(bool is_vertical_scroll, WPARAM w_param, return 0; } -LRESULT AppWin::OnWindowMouseLeave() +LRESULT App::OnWindowMouseLeave() { META_FUNCTION_TASK(); ProcessInputWithErrorHandling(&Input::IActionController::OnMouseInWindowChanged, false); return 0; } -LRESULT CALLBACK AppWin::WindowProc(HWND h_wnd, UINT msg_id, WPARAM w_param, LPARAM l_param) +LRESULT CALLBACK App::WindowProc(HWND h_wnd, UINT msg_id, WPARAM w_param, LPARAM l_param) { META_FUNCTION_TASK(); @@ -416,7 +418,7 @@ LRESULT CALLBACK AppWin::WindowProc(HWND h_wnd, UINT msg_id, WPARAM w_param, LPA return 0; } - auto app_ptr = reinterpret_cast(GetWindowLongPtr(h_wnd, GWLP_USERDATA)); // NOSONAR + auto app_ptr = reinterpret_cast(GetWindowLongPtr(h_wnd, GWLP_USERDATA)); // NOSONAR if (!app_ptr || !app_ptr->IsMessageProcessing()) { return DefWindowProc(h_wnd, msg_id, w_param, l_param); @@ -477,7 +479,7 @@ LRESULT CALLBACK AppWin::WindowProc(HWND h_wnd, UINT msg_id, WPARAM w_param, LPA return DefWindowProc(h_wnd, msg_id, w_param, l_param); } -void AppWin::ShowAlert(const Message& msg) +void App::ShowAlert(const Message& msg) { META_FUNCTION_TASK(); @@ -488,7 +490,7 @@ void AppWin::ShowAlert(const Message& msg) ConvertMessageTypeToFlags(msg.type) ); - AppBase::ShowAlert(msg); + Base::App::ShowAlert(msg); if (msg.type == Message::Type::Error) { @@ -496,7 +498,7 @@ void AppWin::ShowAlert(const Message& msg) } } -void AppWin::ScheduleAlert() +void App::ScheduleAlert() { META_FUNCTION_TASK(); if (!m_env.window_handle) @@ -506,7 +508,7 @@ void AppWin::ScheduleAlert() META_CHECK_TRUE_DESCR(post_result, "failed to post window message"); } -void AppWin::SetWindowTitle(const std::string& title_text) +void App::SetWindowTitle(const std::string& title_text) { META_FUNCTION_TASK(); if (!m_env.window_handle) @@ -516,10 +518,10 @@ void AppWin::SetWindowTitle(const std::string& title_text) META_CHECK_TRUE_DESCR(set_result, "failed to update window title"); } -bool AppWin::SetFullScreen(bool is_full_screen) +bool App::SetFullScreen(bool is_full_screen) { META_FUNCTION_TASK(); - if (!AppBase::SetFullScreen(is_full_screen)) + if (!Base::App::SetFullScreen(is_full_screen)) return false; META_CHECK_NOT_NULL(m_env.window_handle); @@ -562,7 +564,7 @@ bool AppWin::SetFullScreen(bool is_full_screen) return true; } -float AppWin::GetContentScalingFactor() const +float App::GetContentScalingFactor() const { META_FUNCTION_TASK(); DEVICE_SCALE_FACTOR device_scale_factor = DEVICE_SCALE_FACTOR_INVALID; @@ -571,7 +573,7 @@ float AppWin::GetContentScalingFactor() const return GetDeviceScaleRatio(device_scale_factor); } -uint32_t AppWin::GetFontResolutionDpi() const +uint32_t App::GetFontResolutionDpi() const { META_FUNCTION_TASK(); const HDC window_device_context = GetDC(m_env.window_handle); @@ -582,7 +584,7 @@ uint32_t AppWin::GetFontResolutionDpi() const return dpi_y; } -void AppWin::Close() +void App::Close() { META_FUNCTION_TASK(); if (m_env.window_handle && PostMessage(m_env.window_handle, WM_CLOSE, 0, 0)) @@ -591,4 +593,4 @@ void AppWin::Close() ExitProcess(0); } -} // namespace Methane::Platform \ No newline at end of file +} // namespace Methane::Platform::Windows \ No newline at end of file diff --git a/Modules/Platform/App/Sources/Methane/Platform/Windows/ConsoleStreams.cpp b/Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/ConsoleStreams.cpp similarity index 96% rename from Modules/Platform/App/Sources/Methane/Platform/Windows/ConsoleStreams.cpp rename to Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/ConsoleStreams.cpp index a9554905f..64e039a04 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Windows/ConsoleStreams.cpp +++ b/Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/ConsoleStreams.cpp @@ -27,7 +27,7 @@ IO Stream class used for standard and error output redirection from GUI app to c #include -namespace Methane::Platform +namespace Methane::Platform::Windows { static bool IsMappedToFile(FILE* std_stream) @@ -78,4 +78,4 @@ bool ConsoleStreams::Attach() m_error_stream.RedirectToFile("CONOUT$", "w"); } -} // namespace Methane::Platform \ No newline at end of file +} // namespace Methane::Platform::Windows \ No newline at end of file diff --git a/Modules/Platform/App/Sources/Methane/Platform/Windows/ConsoleStreams.h b/Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/ConsoleStreams.h similarity index 96% rename from Modules/Platform/App/Sources/Methane/Platform/Windows/ConsoleStreams.h rename to Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/ConsoleStreams.h index b3b1b6369..eb4f48569 100644 --- a/Modules/Platform/App/Sources/Methane/Platform/Windows/ConsoleStreams.h +++ b/Modules/Platform/Windows/App/Sources/Methane/Platform/Windows/ConsoleStreams.h @@ -28,7 +28,7 @@ IOStream class is used for standard and error output redirection #include #include -namespace Methane::Platform +namespace Methane::Platform::Windows { class IOStream // NOSONAR - destructor is required in this class @@ -66,4 +66,4 @@ class ConsoleStreams IOStream m_error_stream = { stderr, STD_ERROR_HANDLE }; }; -} // namespace Methane::Platform \ No newline at end of file +} // namespace Methane::Platform::Windows \ No newline at end of file diff --git a/Modules/Platform/Windows/AppView/CMakeLists.txt b/Modules/Platform/Windows/AppView/CMakeLists.txt new file mode 100644 index 000000000..17a7c7dce --- /dev/null +++ b/Modules/Platform/Windows/AppView/CMakeLists.txt @@ -0,0 +1,35 @@ +set(TARGET MethanePlatformAppViewWindows) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_PLATFORM_OS_DIR}/AppEnvironment.h +) + +add_library(${TARGET} INTERFACE) + +target_sources(${TARGET} + INTERFACE + ${HEADERS} +) + +target_include_directories(${TARGET} + INTERFACE + ${CMAKE_CURRENT_SOURCE_DIR}/Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Windows + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development +) diff --git a/Modules/Platform/AppView/Include/Methane/Platform/Windows/AppEnvironment.h b/Modules/Platform/Windows/AppView/Include/Methane/Platform/Windows/AppEnvironment.h similarity index 100% rename from Modules/Platform/AppView/Include/Methane/Platform/Windows/AppEnvironment.h rename to Modules/Platform/Windows/AppView/Include/Methane/Platform/Windows/AppEnvironment.h diff --git a/Modules/Platform/Windows/CMakeLists.txt b/Modules/Platform/Windows/CMakeLists.txt new file mode 100644 index 000000000..2b7f51c09 --- /dev/null +++ b/Modules/Platform/Windows/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(Utils) +add_subdirectory(Input) +add_subdirectory(AppView) +add_subdirectory(App) diff --git a/Modules/Platform/Windows/Input/CMakeLists.txt b/Modules/Platform/Windows/Input/CMakeLists.txt new file mode 100644 index 000000000..df28aa576 --- /dev/null +++ b/Modules/Platform/Windows/Input/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Keyboard) diff --git a/Modules/Platform/Windows/Input/Keyboard/CMakeLists.txt b/Modules/Platform/Windows/Input/Keyboard/CMakeLists.txt new file mode 100644 index 000000000..cb71b2a4c --- /dev/null +++ b/Modules/Platform/Windows/Input/Keyboard/CMakeLists.txt @@ -0,0 +1,57 @@ +set(TARGET MethanePlatformInputKeyboardWindows) + +include(MethaneModules) + +get_module_dirs("Methane/Platform/Input") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/Keyboard.h +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/Keyboard.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformInputKeyboardBase + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethanePrimitives + MethaneInstrumentation + magic_enum +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Windows/Input + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Windows/Keyboard.h b/Modules/Platform/Windows/Input/Keyboard/Include/Methane/Platform/Input/Windows/Keyboard.h similarity index 100% rename from Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Windows/Keyboard.h rename to Modules/Platform/Windows/Input/Keyboard/Include/Methane/Platform/Input/Windows/Keyboard.h diff --git a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Windows/Keyboard.cpp b/Modules/Platform/Windows/Input/Keyboard/Sources/Methane/Platform/Input/Windows/Keyboard.cpp similarity index 97% rename from Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Windows/Keyboard.cpp rename to Modules/Platform/Windows/Input/Keyboard/Sources/Methane/Platform/Input/Windows/Keyboard.cpp index 393f7ba99..112df8847 100644 --- a/Modules/Platform/Input/Keyboard/Sources/Methane/Platform/Input/Windows/Keyboard.cpp +++ b/Modules/Platform/Windows/Input/Keyboard/Sources/Methane/Platform/Input/Windows/Keyboard.cpp @@ -21,6 +21,7 @@ Windows platform specific types and implementation of Keyboard abstractions. ******************************************************************************/ +#include #include #include @@ -209,4 +210,9 @@ ModifierMask KeyConverter::GetModifiersByNativeCode(const NativeKey& native_key) } } +KeyConverter::KeyConverter(const NativeKey& native_key) + : m_key(GetKeyByNativeCode(native_key)) + , m_modifiers(GetModifiersByNativeCode(native_key)) +{ } + } // namespace Methane::Platform::Input::Keyboard diff --git a/Modules/Platform/Windows/README.md b/Modules/Platform/Windows/README.md new file mode 100644 index 000000000..b17e15029 --- /dev/null +++ b/Modules/Platform/Windows/README.md @@ -0,0 +1,54 @@ +# Methane Platform Windows + +Windows implementation of the [Platform modules](../README.md), in namespace `Methane::Platform::Windows`. +This group is added to the build by [Platform/CMakeLists.txt](../CMakeLists.txt) when `WIN32` is set. + +| Module | CMake Target | Content | +|--------------------------------------------------|-------------------------------------|-----------------------------------------------------| +| [App](App) | MethanePlatformAppWindows | `Windows::App` Win32 windowed application | +| [AppView](AppView) | MethanePlatformAppViewWindows | `AppEnvironment` with the native window handle | +| [Input/Keyboard](Input/Keyboard) | MethanePlatformInputKeyboardWindows | `Keyboard::NativeKey` and its key translation | +| [Utils](Utils) | MethanePlatformUtilsWindows | Windows-specific utility functions | + +## App + +[`Windows::App`](App/Include/Methane/Platform/Windows/App.h) derives from +[`Base::App`](../Base/App) and drives a classic Win32 window: + +- The window is registered under the `MethaneWindowClass` class name and takes its icon from the + `IDI_APP_ICON` resource embedded by [MethaneResources.cmake](/CMake/MethaneResources.cmake). +- `WindowProc` is a static callback, as Win32 requires; it recovers the `App` instance from the + window's `GWLP_USERDATA` slot and forwards each message to the matching `OnWindow*` method. +- Alerts are deferred through a custom `WM_ALERT` (`WM_USER + 1`) message rather than shown from + inside a message handler, which would otherwise re-enter the message loop from an unexpected state. +- Full-screen switching saves the window rectangle and style, then restores them when leaving. +- `ConsoleStreams` attaches `stdout`/`stderr` to the parent console. Methane applications are built + as GUI-subsystem executables, so without this the `--print_debug_messages_to_console` output would + go nowhere when the application is started from a terminal. + +DPI handling uses two different sources: `GetContentScalingFactor()` asks `Shcore` for +`GetScaleFactorForMonitor` of the monitor the window is on, while `GetFontResolutionDpi()` reads +`LOGPIXELSY` through `GetDeviceCaps`. The module therefore links the `Shcore` library. + +## AppView + +`AppEnvironment` carries a single `HWND window_handle`, which the DirectX and Vulkan RHI backends use +to create a swap chain or a `VkSurfaceKHR` respectively. + +## Input/Keyboard + +`Keyboard::NativeKey` holds the raw `WPARAM` and `LPARAM` of a `WM_KEYDOWN` / `WM_KEYUP` / +`WM_SYSKEYDOWN` / `WM_SYSKEYUP` message, which `Keyboard::KeyConverter` turns into a +platform-independent `Keyboard::Key` and modifier mask. Extended-key and left/right modifier +disambiguation is done from the `LPARAM` bits. + +## Utils + +Besides the platform-independent functions declared in +[`Methane/Platform/Utils.h`](../Base/Utils/Include/Methane/Platform/Utils.h) — where +`PrintToDebugOutput` maps to `OutputDebugString` — this module declares two Windows-only functions in +[`Methane/Platform/Windows/Utils.h`](Utils/Include/Methane/Platform/Windows/Utils.h): + +- `GetDesktopResolution(width, height)` — used to size the main window from a ratio of the desktop. +- `IsDeveloperModeEnabled()` — read from the registry; the DirectX backend requires Developer Mode to + call `ID3D12Device::SetStablePowerState`, which it does only in GPU-instrumented builds. diff --git a/Modules/Platform/Windows/Utils/CMakeLists.txt b/Modules/Platform/Windows/Utils/CMakeLists.txt new file mode 100644 index 000000000..fa8391f75 --- /dev/null +++ b/Modules/Platform/Windows/Utils/CMakeLists.txt @@ -0,0 +1,56 @@ +set(TARGET MethanePlatformUtilsWindows) + +include(MethaneModules) + +get_module_dirs("Methane/Platform") + +list(APPEND HEADERS + ${INCLUDE_PLATFORM_OS_DIR}/Utils.h +) + +list(APPEND SOURCES + ${SOURCES_PLATFORM_OS_DIR}/Utils.cpp +) + +add_library(${TARGET} STATIC + ${HEADERS} + ${SOURCES} +) + +target_link_libraries(${TARGET} + PUBLIC + MethanePlatformUtilsBase + PRIVATE + MethaneBuildOptions + MethaneCommonPrecompiledHeaders + MethaneInstrumentation + nowide +) + +if(METHANE_PRECOMPILED_HEADERS_ENABLED) + target_precompile_headers(${TARGET} REUSE_FROM MethaneCommonPrecompiledHeaders) +endif() + +target_include_directories(${TARGET} + PRIVATE + Sources + PUBLIC + Include +) + +source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) + +set_target_properties(${TARGET} + PROPERTIES + FOLDER Modules/Platform/Windows + PUBLIC_HEADER "${HEADERS}" +) + +install(TARGETS ${TARGET} + PUBLIC_HEADER + DESTINATION ${INSTALL_INCLUDE_DIR}/${PLATFORM_OS_DIR} + COMPONENT Development + ARCHIVE + DESTINATION lib + COMPONENT Development +) diff --git a/Modules/Platform/Utils/Include/Methane/Platform/Windows/Utils.h b/Modules/Platform/Windows/Utils/Include/Methane/Platform/Windows/Utils.h similarity index 100% rename from Modules/Platform/Utils/Include/Methane/Platform/Windows/Utils.h rename to Modules/Platform/Windows/Utils/Include/Methane/Platform/Windows/Utils.h diff --git a/Modules/Platform/Utils/Sources/Methane/Platform/Windows/Utils.cpp b/Modules/Platform/Windows/Utils/Sources/Methane/Platform/Windows/Utils.cpp similarity index 100% rename from Modules/Platform/Utils/Sources/Methane/Platform/Windows/Utils.cpp rename to Modules/Platform/Windows/Utils/Sources/Methane/Platform/Windows/Utils.cpp diff --git a/Modules/UserInterface/App/Include/Methane/UserInterface/App.hpp b/Modules/UserInterface/App/Include/Methane/UserInterface/App.hpp index 7156e5e42..9dd6774c1 100644 --- a/Modules/UserInterface/App/Include/Methane/UserInterface/App.hpp +++ b/Modules/UserInterface/App/Include/Methane/UserInterface/App.hpp @@ -134,18 +134,18 @@ class App SetParametersText(GetParametersString()); } - // Platform::AppBase overrides + // Platform::Base::App overrides void ShowControlsHelp() final { META_FUNCTION_TASK(); - if (!SetHelpText(Platform::AppBase::GetControlsHelp())) + if (!SetHelpText(Platform::Base::App::GetControlsHelp())) SetHelpText(""); } void ShowCommandLineHelp() final { META_FUNCTION_TASK(); - if (!SetHelpText(Platform::AppBase::GetCommandLineHelp())) + if (!SetHelpText(Platform::Base::App::GetCommandLineHelp())) SetHelpText(""); } diff --git a/Tests/Platform/Input/README.md b/Tests/Platform/Input/README.md index ec4770593..57f1c5d46 100644 --- a/Tests/Platform/Input/README.md +++ b/Tests/Platform/Input/README.md @@ -2,10 +2,10 @@ | Type Class | Unit Test | |-----------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------| -| [Platform::Input::Mouse](/Modules/Platform/Input/Mouse/Include/Methane/Platform/Input/Mouse.h) | :white_check_mark: [MouseTest](MouseTest.cpp) | -| [Platform::Input::Mouse::ActionControllerBase](/Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp) | :warning: not covered yet | -| [Platform::Input::Keyboard](/Modules/Platform/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h) | :white_check_mark: [KeyboardTest](KeyboardTest.cpp) | -| [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform/Input/ActionControllers/Include/Methane/Platform/Input/MouseActionControllerBase.hpp) | :warning: not covered yet | -| [Platform::Input::Controller](/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/Controller.h) | :warning: not covered yet | -| [Platform::Input::ControllersPool](/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/ControllersPool.h) | :warning: not covered yet | -| [Platform::Input::State](/Modules/Platform/Input/Controllers/Include/Methane/Platform/Input/State.h) | :warning: not covered yet | +| [Platform::Input::Mouse](/Modules/Platform/Base/Input/Mouse/Include/Methane/Platform/Input/Mouse.h) | :white_check_mark: [MouseTest](MouseTest.cpp) | +| [Platform::Input::Mouse::ActionControllerBase](/Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/KeyboardActionControllerBase.hpp) | :warning: not covered yet | +| [Platform::Input::Keyboard](/Modules/Platform/Base/Input/Keyboard/Include/Methane/Platform/Input/Keyboard.h) | :white_check_mark: [KeyboardTest](KeyboardTest.cpp) | +| [Platform::Input::Keyboard::ActionControllerBase](/Modules/Platform/Base/Input/ActionControllers/Include/Methane/Platform/Input/MouseActionControllerBase.hpp) | :warning: not covered yet | +| [Platform::Input::Controller](/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/Controller.h) | :warning: not covered yet | +| [Platform::Input::ControllersPool](/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/ControllersPool.h) | :warning: not covered yet | +| [Platform::Input::State](/Modules/Platform/Base/Input/Controllers/Include/Methane/Platform/Input/State.h) | :warning: not covered yet | diff --git a/Tests/Platform/README.md b/Tests/Platform/README.md index 84d90b197..76bd51bd6 100644 --- a/Tests/Platform/README.md +++ b/Tests/Platform/README.md @@ -1,8 +1,8 @@ # Methane Platform Modules Unit Tests -| Platform Module Name | Unit Tests Folder | -|-----------------------------------------------|-----------------------------------------| -| [Platform/App](/Modules/Platform/App) | :warning: not covered yet | -| [Platform/AppView](/Modules/Platform/AppView) | :warning: not covered yet | -| [Platform/Input](/Modules/Platform/Input) | :white_check_mark: [Input](Input) tests | -| [Platform/Utils](/Modules/Platform/Utils) | :warning: not covered yet | +| Platform Module Name | Unit Tests Folder | +|----------------------------------------------------|-----------------------------------------| +| [Platform/App](/Modules/Platform/Impl/App) | :warning: not covered yet | +| [Platform/AppView](/Modules/Platform/Impl/AppView) | :warning: not covered yet | +| [Platform/Input](/Modules/Platform/Base/Input) | :white_check_mark: [Input](Input) tests | +| [Platform/Utils](/Modules/Platform/Impl/Utils) | :warning: not covered yet |