mirror of
https://github.com/narzoul/DDrawCompat
synced 2024-12-30 08:55:36 +01:00
Fixed GDI display issues in Titanic: Adventure Out of Time
This commit is contained in:
parent
f13d842c24
commit
2099c80095
@ -48,8 +48,9 @@ namespace D3dDdi
|
||||
|
||||
HRESULT Device::createPrivateResource(D3DDDIARG_CREATERESOURCE2& data)
|
||||
{
|
||||
const bool isPalettizedOffScreen = D3DDDIFMT_P8 == data.Format && !data.Flags.Texture;
|
||||
if (isPalettizedOffScreen)
|
||||
const bool isPalettized = D3DDDIFMT_P8 == data.Format;
|
||||
const bool isTexture = data.Flags.Texture;
|
||||
if (isPalettized)
|
||||
{
|
||||
data.Format = D3DDDIFMT_L8;
|
||||
data.Flags.Texture = 1;
|
||||
@ -59,10 +60,10 @@ namespace D3dDdi
|
||||
? m_origVtable.pfnCreateResource2(m_device, &data)
|
||||
: m_origVtable.pfnCreateResource(m_device, reinterpret_cast<D3DDDIARG_CREATERESOURCE*>(&data));
|
||||
|
||||
if (isPalettizedOffScreen)
|
||||
if (isPalettized)
|
||||
{
|
||||
data.Format = D3DDDIFMT_P8;
|
||||
data.Flags.Texture = 0;
|
||||
data.Flags.Texture = isTexture;
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -114,6 +115,7 @@ namespace D3dDdi
|
||||
|
||||
void Device::setGdiResourceHandle(HANDLE resource)
|
||||
{
|
||||
LOG_FUNC("Device::setGdiResourceHandle", resource);
|
||||
ScopedCriticalSection lock;
|
||||
if ((!resource && !g_gdiResource) ||
|
||||
(g_gdiResource && resource == *g_gdiResource))
|
||||
|
@ -478,6 +478,11 @@ namespace D3dDdi
|
||||
}
|
||||
}
|
||||
|
||||
if (D3DDDIFMT_P8 == m_fixedData.Format)
|
||||
{
|
||||
data.Color <<= 16;
|
||||
}
|
||||
|
||||
prepareForBltDst(data.hResource, data.SubResourceIndex, data.DstRect);
|
||||
return LOG_RESULT(m_device.getOrigVtable().pfnColorFill(m_device, &data));
|
||||
}
|
||||
@ -924,7 +929,7 @@ namespace D3dDdi
|
||||
return prepareForBltDst(data.hDstResource, data.DstSubResourceIndex, data.DstRect);
|
||||
}
|
||||
|
||||
Resource& Resource::prepareForBltDst(HANDLE& resource, UINT& subResourceIndex, RECT& rect)
|
||||
Resource& Resource::prepareForBltDst(HANDLE& resource, UINT subResourceIndex, RECT& rect)
|
||||
{
|
||||
if (m_lockResource)
|
||||
{
|
||||
@ -1241,6 +1246,8 @@ namespace D3dDdi
|
||||
return;
|
||||
}
|
||||
|
||||
DDraw::PrimarySurface::updatePalette();
|
||||
|
||||
if (isFullscreen)
|
||||
{
|
||||
g_presentationRect = calculatePresentationRect();
|
||||
|
@ -40,7 +40,7 @@ namespace D3dDdi
|
||||
void onDestroyResource(HANDLE resource);
|
||||
Resource& prepareForBltSrc(const D3DDDIARG_BLT& data);
|
||||
Resource& prepareForBltDst(D3DDDIARG_BLT& data);
|
||||
Resource& prepareForBltDst(HANDLE& resource, UINT& subResourceIndex, RECT& rect);
|
||||
Resource& prepareForBltDst(HANDLE& resource, UINT subResourceIndex, RECT& rect);
|
||||
void prepareForCpuRead(UINT subResourceIndex);
|
||||
void prepareForCpuWrite(UINT subResourceIndex);
|
||||
Resource& prepareForGpuRead(UINT subResourceIndex);
|
||||
|
@ -79,18 +79,21 @@ namespace
|
||||
HRESULT STDMETHODCALLTYPE SetCooperativeLevel(TDirectDraw* This, HWND hWnd, DWORD dwFlags)
|
||||
{
|
||||
HRESULT result = getOrigVtable(This).SetCooperativeLevel(This, hWnd, dwFlags);
|
||||
if (SUCCEEDED(result))
|
||||
if (SUCCEEDED(result) && (dwFlags & (DDSCL_FULLSCREEN | DDSCL_NORMAL)))
|
||||
{
|
||||
auto tagSurface = DDraw::TagSurface::get(*CompatPtr<IDirectDraw>::from(This));
|
||||
if (tagSurface)
|
||||
{
|
||||
if (dwFlags & DDSCL_FULLSCREEN)
|
||||
const bool wasFullscreen = tagSurface->isFullscreen();
|
||||
const bool isFullscreen = dwFlags & DDSCL_FULLSCREEN;
|
||||
if (wasFullscreen != isFullscreen)
|
||||
{
|
||||
tagSurface->setFullscreenWindow(hWnd);
|
||||
}
|
||||
else if (dwFlags & DDSCL_NORMAL)
|
||||
{
|
||||
tagSurface->setFullscreenWindow(nullptr);
|
||||
tagSurface->setFullscreenWindow(isFullscreen ? hWnd : nullptr);
|
||||
if (DDraw::RealPrimarySurface::getSurface())
|
||||
{
|
||||
DDraw::RealPrimarySurface::release();
|
||||
DDraw::RealPrimarySurface::create(CompatRef<TDirectDraw>(*This));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -293,12 +293,9 @@ namespace
|
||||
g_clipper.release();
|
||||
CALL_ORIG_PROC(DirectDrawCreateClipper)(0, &g_clipper.getRef(), nullptr);
|
||||
g_frontBuffer->SetClipper(g_frontBuffer, g_clipper);
|
||||
|
||||
const bool isFlippable = 0 != (desc.ddsCaps.dwCaps & DDSCAPS_FLIP);
|
||||
g_surfaceDesc = desc;
|
||||
g_isFullscreen = isFlippable;
|
||||
|
||||
if (isFlippable)
|
||||
if (0 != (desc.ddsCaps.dwCaps & DDSCAPS_FLIP))
|
||||
{
|
||||
g_frontBuffer->Flip(g_frontBuffer, getLastSurface(), DDFLIP_WAIT);
|
||||
D3dDdi::KernelModeThunks::waitForVsyncCounter(D3dDdi::KernelModeThunks::getVsyncCounter() + 1);
|
||||
@ -341,7 +338,7 @@ namespace
|
||||
Input::updateCursor();
|
||||
});
|
||||
|
||||
if (!g_frontBuffer || !src || DDraw::RealPrimarySurface::isLost())
|
||||
if (!g_frontBuffer || !src || DDraw::RealPrimarySurface::isLost() || FAILED(src->IsLost(src)))
|
||||
{
|
||||
Gdi::Window::present(nullptr);
|
||||
return;
|
||||
@ -381,12 +378,16 @@ namespace
|
||||
bool isFullscreen = false;
|
||||
if (SUCCEEDED(g_frontBuffer->IsLost(g_frontBuffer)))
|
||||
{
|
||||
HWND foregroundWindow = GetForegroundWindow();
|
||||
if (foregroundWindow)
|
||||
auto primary(DDraw::PrimarySurface::getPrimary());
|
||||
if (primary && SUCCEEDED(primary->IsLost(primary)))
|
||||
{
|
||||
DWORD pid = 0;
|
||||
GetWindowThreadProcessId(foregroundWindow, &pid);
|
||||
isFullscreen = GetCurrentProcessId() == pid && Gdi::Window::hasFullscreenWindow();
|
||||
HWND foregroundWindow = GetForegroundWindow();
|
||||
if (foregroundWindow)
|
||||
{
|
||||
DWORD pid = 0;
|
||||
GetWindowThreadProcessId(foregroundWindow, &pid);
|
||||
isFullscreen = GetCurrentProcessId() == pid && Gdi::Window::hasFullscreenWindow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -446,11 +447,13 @@ namespace DDraw
|
||||
desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
|
||||
desc.dwBackBufferCount = 2;
|
||||
|
||||
g_isFullscreen = true;
|
||||
CompatPtr<typename Types<DirectDraw>::TCreatedSurface> surface;
|
||||
HRESULT result = dd->CreateSurface(&dd, &desc, &surface.getRef(), nullptr);
|
||||
|
||||
if (DDERR_NOEXCLUSIVEMODE == result)
|
||||
{
|
||||
g_isFullscreen = false;
|
||||
desc.dwFlags = DDSD_CAPS;
|
||||
desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
|
||||
desc.dwBackBufferCount = 0;
|
||||
|
@ -255,6 +255,10 @@ namespace DDraw
|
||||
{
|
||||
if (!s_palette)
|
||||
{
|
||||
if (DDraw::RealPrimarySurface::isFullscreen())
|
||||
{
|
||||
Gdi::Palette::setHardwarePalette(Gdi::Palette::getSystemPalette().data());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ namespace DDraw
|
||||
|
||||
static bool doesFullscreenDirectDrawExist();
|
||||
|
||||
bool isFullscreen() const { return m_fullscreenWindow; }
|
||||
void setFullscreenWindow(HWND hwnd);
|
||||
LONG setWindowStyle(LONG style);
|
||||
LONG setWindowExStyle(LONG exStyle);
|
||||
|
@ -21,6 +21,7 @@ namespace Gdi
|
||||
{
|
||||
HWND create(HWND owner)
|
||||
{
|
||||
LOG_FUNC("PresentationWindow::create", owner);
|
||||
HWND presentationWindow = nullptr;
|
||||
GuiThread::execute([&]()
|
||||
{
|
||||
@ -40,7 +41,7 @@ namespace Gdi
|
||||
CALL_ORIG_FUNC(SetLayeredWindowAttributes)(presentationWindow, 0, 255, LWA_ALPHA);
|
||||
}
|
||||
});
|
||||
return presentationWindow;
|
||||
return LOG_RESULT(presentationWindow);
|
||||
}
|
||||
|
||||
void installHooks()
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <Config/Config.h>
|
||||
#include <Common/ScopedCriticalSection.h>
|
||||
#include <D3dDdi/Device.h>
|
||||
#include <D3dDdi/Resource.h>
|
||||
#include <D3dDdi/ScopedCriticalSection.h>
|
||||
#include <DDraw/DirectDraw.h>
|
||||
#include <DDraw/RealPrimarySurface.h>
|
||||
@ -270,6 +271,8 @@ namespace Gdi
|
||||
|
||||
prevDisplaySettingsUniqueness = Win32::DisplayMode::queryDisplaySettingsUniqueness();
|
||||
prevIsFullscreen = g_isFullscreen;
|
||||
|
||||
auto gdiResource = D3dDdi::Device::getGdiResource();
|
||||
D3dDdi::Device::setGdiResourceHandle(nullptr);
|
||||
|
||||
if (g_isFullscreen)
|
||||
@ -307,6 +310,11 @@ namespace Gdi
|
||||
{
|
||||
SelectObject(dc.first, createDib(dc.second.useDefaultPalette));
|
||||
}
|
||||
|
||||
if (gdiResource && DDraw::PrimarySurface::getPrimary())
|
||||
{
|
||||
D3dDdi::Device::setGdiResourceHandle(*gdiResource);
|
||||
}
|
||||
}
|
||||
|
||||
Gdi::Window::updateAll();
|
||||
|
Loading…
x
Reference in New Issue
Block a user