1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Direct2D: Remove redundant adapter member from Direct2DGraphicsContext

This commit is contained in:
reuk 2024-08-12 18:46:52 +01:00
parent 45305dbfa7
commit e2b9dd9a05
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
5 changed files with 21 additions and 36 deletions

View file

@ -549,7 +549,6 @@ protected:
SharedResourcePointer<Direct2DFactories> directWrite;
RectangleList<int> paintAreas;
DxgiAdapter::Ptr adapter;
std::optional<Direct2DDeviceResources> deviceResources;
std::vector<std::unique_ptr<Direct2DGraphicsContext::SavedState>> savedClientStates;
@ -557,7 +556,7 @@ protected:
virtual HRESULT prepare()
{
if (! deviceResources.has_value())
deviceResources = Direct2DDeviceResources::create (adapter);
deviceResources = Direct2DDeviceResources::create (directX->adapters.getDefaultAdapter());
return deviceResources.has_value() ? S_OK : E_FAIL;
}
@ -701,11 +700,6 @@ public:
popSavedState();
}
DxgiAdapter& getAdapter() const noexcept
{
return *adapter;
}
ComSmartPtr<ID2D1DeviceContext1> getDeviceContext() const noexcept
{
return deviceResources->deviceContext;
@ -860,24 +854,28 @@ private:
context->SetTransform (D2DUtilities::transformToMatrix (newTransform));
}
DxgiAdapter::Ptr findAdapter() const
{
if (! deviceResources.has_value())
return {};
return deviceResources->findAdapter (directX->adapters);
}
void adapterCreated (DxgiAdapter::Ptr newAdapter) override
{
if (! adapter || adapter->uniqueIDMatches (newAdapter))
{
teardown();
const auto adapter = findAdapter();
adapter = newAdapter;
}
if (adapter == nullptr || ! adapter->uniqueIDMatches (newAdapter))
teardown();
}
void adapterRemoved (DxgiAdapter::Ptr expiringAdapter) override
{
if (adapter && adapter->uniqueIDMatches (expiringAdapter))
{
teardown();
const auto adapter = findAdapter();
adapter = nullptr;
}
if (adapter != nullptr && adapter->uniqueIDMatches (expiringAdapter))
teardown();
}
HWND hwnd = nullptr;

View file

@ -324,13 +324,10 @@ private:
HRESULT prepare() override
{
if (! adapter || ! adapter->direct2DDevice)
{
adapter = directX->adapters.getAdapterForHwnd (hwnd);
const auto adapter = directX->adapters.getAdapterForHwnd (hwnd);
if (! adapter)
return E_FAIL;
}
if (adapter == nullptr)
return E_FAIL;
if (! deviceResources.has_value())
deviceResources = Direct2DDeviceResources::create (adapter);
@ -416,13 +413,10 @@ public:
: Pimpl (ownerIn, opaqueIn),
hwnd (hwndIn)
{
adapter = directX->adapters.getAdapterForHwnd (hwndIn);
}
~HwndPimpl() override = default;
HWND getHwnd() const { return hwnd; }
void handleShowWindow()
{
// One of the trickier problems was determining when Direct2D & DXGI resources can be safely created;
@ -687,11 +681,6 @@ Direct2DHwndContext::~Direct2DHwndContext()
#endif
}
void* Direct2DHwndContext::getHwnd() const noexcept
{
return pimpl->getHwnd();
}
Direct2DGraphicsContext::Pimpl* Direct2DHwndContext::getPimpl() const noexcept
{
return pimpl.get();

View file

@ -41,7 +41,6 @@ public:
Direct2DHwndContext (void* windowHandle, bool opaque);
~Direct2DHwndContext() override;
void* getHwnd() const noexcept;
void handleShowWindow();
void setWindowAlpha (float alpha);

View file

@ -44,10 +44,6 @@ public:
: Pimpl (ownerIn, opaque),
target (targetIn)
{
if (target != nullptr)
adapter = target->getAdapter();
else
jassertfalse;
}
Rectangle<int> getFrameSize() override

View file

@ -90,6 +90,9 @@ struct DxgiAdapter : public ReferenceCountedObject
bool uniqueIDMatches (ReferenceCountedObjectPtr<DxgiAdapter> other) const
{
if (other == nullptr)
return false;
auto luid = getAdapterUniqueID();
auto otherLuid = other->getAdapterUniqueID();
return (luid.HighPart == otherLuid.HighPart) && (luid.LowPart == otherLuid.LowPart);