Skip to content

Commit

Permalink
More display helpers changes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
colincornaby committed Oct 13, 2024
1 parent 8421682 commit e422ccf
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ - (id)init

_displayHelper = std::make_shared<plMacDisplayHelper>();
_displayHelper->SetCurrentScreen([window screen]);
_displayHelper->MakeCurrentDisplayHelper();

gClient.SetClientWindow((__bridge void *)view.layer);
gClient.SetClientDisplay((hsWindowHndl)NULL);
Expand Down Expand Up @@ -398,7 +399,6 @@ - (void)initializeClient
[NSRunLoop.mainRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
}

gClient->GetPipeline()->SetDisplayHelper(_displayHelper);

if (!gClient || gClient->GetDone()) {
[NSApp terminate:self];
Expand Down
6 changes: 4 additions & 2 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <Metal/Metal.hpp>
#include <QuartzCore/QuartzCore.h>

#include "plPipeline.h"
#include "plPipeline/hsG3DDeviceSelector.h"

class plMacDisplayHelper: public plDisplayHelper
{
Expand All @@ -61,11 +61,13 @@ class plMacDisplayHelper: public plDisplayHelper
void SetCurrentScreen(NSScreen* screen);

plDisplayMode DefaultDisplayMode() override { return fDefaultDisplayMode; };
void GetSupportedDisplayModes(std::vector<plDisplayMode> *res, int ColorDepth = 32) override;
void GetSupportedDisplayModes(std::vector<plDisplayMode> *res, int ColorDepth = 32) const override;
std::vector<plDisplayMode> GetDisplayModes() const override { return fDisplayModes; }

MTL::Device* RenderDevice() { return fRenderDevice; }

plMacDisplayHelper();
plMacDisplayHelper(hsWindowHndl window);
~plMacDisplayHelper();
private:
CGDirectDisplayID fCurrentDisplay;
Expand Down
10 changes: 9 additions & 1 deletion Sources/Plasma/Apps/plClient/Mac-Cocoa/plMacDisplayHelper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*==LICENSE==*/

#include "plPipeline.h"
#include "plMacDisplayHelper.h"

// CGDirectDisplayCopyCurrentMetalDevice only declared in Metal.h?
Expand Down Expand Up @@ -133,7 +134,7 @@
}
}

void plMacDisplayHelper::GetSupportedDisplayModes(std::vector<plDisplayMode> *res, int ColorDepth)
void plMacDisplayHelper::GetSupportedDisplayModes(std::vector<plDisplayMode> *res, int ColorDepth) const
{
*res = fDisplayModes;
}
Expand All @@ -143,6 +144,13 @@

};

plMacDisplayHelper::plMacDisplayHelper(hsWindowHndl window)
: plMacDisplayHelper()
{
NSWindow* nsWindow = (__bridge NSWindow*)(window);
SetCurrentScreen(nsWindow.screen);
}

plMacDisplayHelper::~plMacDisplayHelper()
{
fRenderDevice->release();
Expand Down
14 changes: 8 additions & 6 deletions Sources/Plasma/FeatureLib/pfMetalPipeline/plMetalEnumerate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ void plMetalEnumerate::Enumerate(std::vector<hsG3DDeviceRecord>& 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ plMipmap* plMetalPipeline::ExtractMipMap(plRenderTarget* targ)

void plMetalPipeline::GetSupportedDisplayModes(std::vector<plDisplayMode>* res, int ColorDepth)
{
fDisplayHelper->GetSupportedDisplayModes(res);
plDisplayHelper::CurrentDisplayHelper()->GetSupportedDisplayModes(res);
}

int plMetalPipeline::GetMaxAnisotropicSamples()
Expand Down
9 changes: 8 additions & 1 deletion Sources/Plasma/NucleusLib/inc/plPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,17 @@ class plDisplayHelper
{
public:
virtual plDisplayMode DefaultDisplayMode() = 0;
virtual void GetSupportedDisplayModes(std::vector<plDisplayMode> *res, int ColorDepth = 32) = 0;
virtual void GetSupportedDisplayModes(std::vector<plDisplayMode> *res, int ColorDepth = 32) const = 0;
virtual std::vector<plDisplayMode> 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
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/NucleusLib/inc/pnSingletons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e422ccf

Please sign in to comment.