From e422ccfb1dd65155902c69e4284de2fa2b1308b4 Mon Sep 17 00:00:00 2001 From: Colin Cornaby Date: Sun, 13 Oct 2024 14:22:12 -0700 Subject: [PATCH] More display helpers changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit plClient does querying of the possible display modes in it’s constructor. For now - using a singleton as a way to set a global display helper before this process starts. Keeping display helpers in the plPipeline family. It’s possible it belongs at a lower level alongside hsG3DDeviceMode in since display helpers are platform and not render specific. --- Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm | 2 +- .../Apps/plClient/Mac-Cocoa/plMacDisplayHelper.h | 6 ++++-- .../Apps/plClient/Mac-Cocoa/plMacDisplayHelper.mm | 10 +++++++++- .../pfMetalPipeline/plMetalEnumerate.cpp | 14 ++++++++------ .../FeatureLib/pfMetalPipeline/plMetalPipeline.cpp | 2 +- Sources/Plasma/NucleusLib/inc/plPipeline.h | 9 ++++++++- Sources/Plasma/NucleusLib/inc/pnSingletons.cpp | 2 ++ 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm index 43a72952ca..abba2a0bf4 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm @@ -200,6 +200,7 @@ - (id)init _displayHelper = std::make_shared(); _displayHelper->SetCurrentScreen([window screen]); + _displayHelper->MakeCurrentDisplayHelper(); gClient.SetClientWindow((__bridge void *)view.layer); gClient.SetClientDisplay((hsWindowHndl)NULL); @@ -398,7 +399,6 @@ - (void)initializeClient [NSRunLoop.mainRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } - gClient->GetPipeline()->SetDisplayHelper(_displayHelper); if (!gClient || gClient->GetDone()) { [NSApp terminate:self]; diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.h b/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.h index e451adf94b..784ace4de0 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.h +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.h @@ -51,7 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include #include -#include "plPipeline.h" +#include "plPipeline/hsG3DDeviceSelector.h" class plMacDisplayHelper: public plDisplayHelper { @@ -61,11 +61,13 @@ class plMacDisplayHelper: public plDisplayHelper void SetCurrentScreen(NSScreen* screen); plDisplayMode DefaultDisplayMode() override { return fDefaultDisplayMode; }; - void GetSupportedDisplayModes(std::vector *res, int ColorDepth = 32) override; + void GetSupportedDisplayModes(std::vector *res, int ColorDepth = 32) const override; + std::vector GetDisplayModes() const override { return fDisplayModes; } MTL::Device* RenderDevice() { return fRenderDevice; } plMacDisplayHelper(); + plMacDisplayHelper(hsWindowHndl window); ~plMacDisplayHelper(); private: CGDirectDisplayID fCurrentDisplay; diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.mm index 880774115d..3c110333c0 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.mm @@ -40,6 +40,7 @@ *==LICENSE==*/ +#include "plPipeline.h" #include "plMacDisplayHelper.h" // CGDirectDisplayCopyCurrentMetalDevice only declared in Metal.h? @@ -133,7 +134,7 @@ } } -void plMacDisplayHelper::GetSupportedDisplayModes(std::vector *res, int ColorDepth) +void plMacDisplayHelper::GetSupportedDisplayModes(std::vector *res, int ColorDepth) const { *res = fDisplayModes; } @@ -143,6 +144,13 @@ }; +plMacDisplayHelper::plMacDisplayHelper(hsWindowHndl window) +: plMacDisplayHelper() +{ + NSWindow* nsWindow = (__bridge NSWindow*)(window); + SetCurrentScreen(nsWindow.screen); +} + plMacDisplayHelper::~plMacDisplayHelper() { fRenderDevice->release(); diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalEnumerate.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalEnumerate.cpp index d0b6e323e0..911550676e 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalEnumerate.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalEnumerate.cpp @@ -76,12 +76,14 @@ void plMetalEnumerate::Enumerate(std::vector& records) devRec.SetLayersAtOnce(8); - // Just make a fake mode so the device selector will let it through - hsG3DDeviceMode devMode; - devMode.SetWidth(hsG3DDeviceSelector::kDefaultWidth); - devMode.SetHeight(hsG3DDeviceSelector::kDefaultHeight); - devMode.SetColorDepth(hsG3DDeviceSelector::kDefaultDepth); - devRec.GetModes().emplace_back(devMode); + const plDisplayHelper* displayHelper = plDisplayHelper::CurrentDisplayHelper(); + for (const auto& mode : displayHelper->GetDisplayModes()) { + hsG3DDeviceMode devMode; + devMode.SetWidth(mode.Width); + devMode.SetHeight(mode.Height); + devMode.SetColorDepth(mode.ColorDepth); + devRec.GetModes().emplace_back(devMode); + } records.emplace_back(devRec); } diff --git a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp index 07d4174af2..a6a531abec 100644 --- a/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp +++ b/Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalPipeline.cpp @@ -970,7 +970,7 @@ plMipmap* plMetalPipeline::ExtractMipMap(plRenderTarget* targ) void plMetalPipeline::GetSupportedDisplayModes(std::vector* res, int ColorDepth) { - fDisplayHelper->GetSupportedDisplayModes(res); + plDisplayHelper::CurrentDisplayHelper()->GetSupportedDisplayModes(res); } int plMetalPipeline::GetMaxAnisotropicSamples() diff --git a/Sources/Plasma/NucleusLib/inc/plPipeline.h b/Sources/Plasma/NucleusLib/inc/plPipeline.h index 28468e8297..280c32a0e6 100644 --- a/Sources/Plasma/NucleusLib/inc/plPipeline.h +++ b/Sources/Plasma/NucleusLib/inc/plPipeline.h @@ -142,10 +142,17 @@ class plDisplayHelper { public: virtual plDisplayMode DefaultDisplayMode() = 0; - virtual void GetSupportedDisplayModes(std::vector *res, int ColorDepth = 32) = 0; + virtual void GetSupportedDisplayModes(std::vector *res, int ColorDepth = 32) const = 0; + virtual std::vector GetDisplayModes() const = 0; plDisplayHelper() = default; virtual ~plDisplayHelper() = default; + + static const plDisplayHelper* CurrentDisplayHelper() { return _currentDisplayHelper; } + void MakeCurrentDisplayHelper() { _currentDisplayHelper = this; } + +private: + static plDisplayHelper* _currentDisplayHelper; }; class plPipeline : public plCreatable diff --git a/Sources/Plasma/NucleusLib/inc/pnSingletons.cpp b/Sources/Plasma/NucleusLib/inc/pnSingletons.cpp index 9ba38bf26f..0c712d416b 100644 --- a/Sources/Plasma/NucleusLib/inc/pnSingletons.cpp +++ b/Sources/Plasma/NucleusLib/inc/pnSingletons.cpp @@ -43,7 +43,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plgDispatch.h" #include "hsResMgr.h" #include "plPipeResReq.h" +#include "plPipeline.h" +plDisplayHelper* plDisplayHelper::_currentDisplayHelper = nullptr; hsResMgr* hsgResMgr::fResMgr = nullptr; plDispatchBase* plgDispatch::Dispatch()