Skip to content

Commit

Permalink
Fixed AltTabFix=keepvidmem(1) not keeping back buffers
Browse files Browse the repository at this point in the history
See issue #316.
  • Loading branch information
narzoul committed Jul 1, 2024
1 parent 24bb721 commit 291e50a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions DDrawCompat/DDraw/DirectDraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ namespace
}
}

if (Config::Settings::AltTabFix::OFF == Config::altTabFix.get())
if (Config::Settings::AltTabFix::KEEPVIDMEM != Config::altTabFix.get())
{
return LOG_RESULT(g_origDDrawWindowProc(hwnd, WM_ACTIVATEAPP, wParam, lParam));
}
Expand All @@ -211,7 +211,7 @@ namespace
{
auto lcl = DDraw::DirectDrawSurface::getInt(*surface.getDDS()).lpLcl;
if (!(lcl->dwFlags & DDRAWISURF_INVALID) &&
(keepPrimary || !(surface.getOrigCaps() & DDSCAPS_PRIMARYSURFACE)))
(keepPrimary || !surface.isPrimary()))
{
lcl->dwFlags |= DDRAWISURF_INVALID;
surfacesToRestore.insert(lcl);
Expand All @@ -236,7 +236,7 @@ namespace
auto realPrimary(DDraw::RealPrimarySurface::getSurface());
if (realPrimary)
{
realPrimary->Restore(realPrimary);
DDraw::RealPrimarySurface::restore();
auto gdiResource = DDraw::PrimarySurface::getGdiResource();
if (gdiResource)
{
Expand Down
7 changes: 7 additions & 0 deletions DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,13 @@ namespace DDraw
{
resource->setAsPrimary();
}

auto surf = DDraw::Surface::getSurface(*surface);
if (surf)
{
surf->setAsPrimary();
}

CompatPtr<IDirectDrawSurface7> next;
result = surface->GetAttachedSurface(surface, &caps, &next.getRef());
next.swap(surface);
Expand Down
1 change: 1 addition & 0 deletions DDrawCompat/DDraw/Surfaces/Surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace DDraw
, m_refCount(0)
, m_sizeOverride{}
, m_sysMemBuffer(nullptr, &heapFree)
, m_isPrimary(false)
{
g_surfaces.insert(this);
}
Expand Down
3 changes: 3 additions & 0 deletions DDrawCompat/DDraw/Surfaces/Surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ namespace DDraw
template <typename TSurface>
SurfaceImpl<TSurface>* getImpl() const;

bool isPrimary() const { return m_isPrimary; }
virtual void restore();

void setAsPrimary() { m_isPrimary = true; }
void setSizeOverride(DWORD width, DWORD height);

protected:
Expand All @@ -71,5 +73,6 @@ namespace DDraw
DWORD m_refCount;
SIZE m_sizeOverride;
std::unique_ptr<void, void(*)(void*)> m_sysMemBuffer;
bool m_isPrimary;
};
}

0 comments on commit 291e50a

Please sign in to comment.