From: Toni Wilen Date: Thu, 16 Jun 2022 17:39:14 +0000 (+0300) Subject: DirectDraw removed. Replaced with basic GDI mode. WIP. X-Git-Tag: 41000~218 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=ab850a4014a90f502451bfe03704ac190a9bd14b;p=francis%2Fwinuae.git DirectDraw removed. Replaced with basic GDI mode. WIP. --- diff --git a/od-win32/ahidsound_dsonly.cpp b/od-win32/ahidsound_dsonly.cpp index 55bc7ca1..92c16ebd 100644 --- a/od-win32/ahidsound_dsonly.cpp +++ b/od-win32/ahidsound_dsonly.cpp @@ -33,7 +33,7 @@ #include "newcpu.h" #include "traps.h" #include "sounddep/sound.h" -#include "dxwrap.h" +#include "render.h" #include "win32.h" #include "parser.h" #include "enforcer.h" diff --git a/od-win32/ahidsound_new.cpp b/od-win32/ahidsound_new.cpp index 521850f2..f9bf6c77 100644 --- a/od-win32/ahidsound_new.cpp +++ b/od-win32/ahidsound_new.cpp @@ -34,7 +34,7 @@ #include "win32.h" #include "sounddep/sound.h" #include "ahidsound_new.h" -#include "dxwrap.h" +#include "render.h" #include #include diff --git a/od-win32/avioutput.cpp b/od-win32/avioutput.cpp index 49aa2104..119ec16d 100644 --- a/od-win32/avioutput.cpp +++ b/od-win32/avioutput.cpp @@ -10,8 +10,6 @@ Copyright(c) 2001 - 2002; #include -#include - #include #include #include @@ -29,7 +27,7 @@ Copyright(c) 2001 - 2002; #include "memory.h" #include "newcpu.h" #include "picasso96.h" -#include "dxwrap.h" +#include "render.h" #include "win32.h" #include "win32gfx.h" #include "direct3d.h" diff --git a/od-win32/bsdsock.cpp b/od-win32/bsdsock.cpp index a5d74b4c..97c670ad 100644 --- a/od-win32/bsdsock.cpp +++ b/od-win32/bsdsock.cpp @@ -40,7 +40,6 @@ #include "wininet.h" #include "mmsystem.h" #include "win32.h" -#include "dxwrap.h" int rawsockets = 0; static int hWndSelector = 0; /* Set this to zero to get hSockWnd */ @@ -2419,29 +2418,6 @@ uae_u32 host_inet_addr(TrapContext *ctx, uae_u32 cp) return addr; } -int isfullscreen (void); -static BOOL CheckOnline(SB) -{ - struct AmigaMonitor *mon = &AMonitors[0]; - DWORD dwFlags; - BOOL bReturn = TRUE; - - hAmigaSockWnd = mon->hAmigaWnd; - if (InternetGetConnectedState(&dwFlags,0) == FALSE) { // Internet is offline - if (InternetAttemptConnect(0) != ERROR_SUCCESS) { // Show Dialer window - sb->sb_errno = 10001; - sb->sb_herrno = 1; - bReturn = FALSE; - // No success or aborted - } - if (isfullscreen() > 0) { - ShowWindow(mon->hAmigaWnd, SW_RESTORE); - SetActiveWindow(mon->hAmigaWnd); - } - } - return bReturn; -} - #define GET_STATE_FREE 0 #define GET_STATE_ACTIVE 1 #define GET_STATE_CANCEL 2 @@ -2489,25 +2465,22 @@ static unsigned int thread_get2 (void *indexp) else name_rp = ""; - if (strchr (name_rp, '.') == 0 || CheckOnline(sb) == TRUE) { - // Local Address or Internet Online ? - BSDTRACE((_T("tg2_0a %d:%d -> "),addrtype,wscnt)); - if (addrtype == -1) { - host = gethostbyname (name_rp); + BSDTRACE((_T("tg2_0a %d:%d -> "),addrtype,wscnt)); + if (addrtype == -1) { + host = gethostbyname (name_rp); + } else { + host = gethostbyaddr (name_rp, namelen, addrtype); + } + BSDTRACE((_T("tg2_0b %d -> "), wscnt)); + if (bsd->threadGetargs_inuse[index] != GET_STATE_CANCEL) { + // No CTRL-C Signal + if (host == 0) { + // Error occurred + SETERRNO; + BSDTRACE((_T("tg2_0 failed %d:%d -> "), sb->sb_errno,wscnt)); } else { - host = gethostbyaddr (name_rp, namelen, addrtype); - } - BSDTRACE((_T("tg2_0b %d -> "), wscnt)); - if (bsd->threadGetargs_inuse[index] != GET_STATE_CANCEL) { - // No CTRL-C Signal - if (host == 0) { - // Error occurred - SETERRNO; - BSDTRACE((_T("tg2_0 failed %d:%d -> "), sb->sb_errno,wscnt)); - } else { - bsdsocklib_seterrno(ctx, sb, 0); - memcpy((void*)args->buf, host, sizeof(HOSTENT)); - } + bsdsocklib_seterrno(ctx, sb, 0); + memcpy((void*)args->buf, host, sizeof(HOSTENT)); } } diff --git a/od-win32/cda_play.cpp b/od-win32/cda_play.cpp index d681fedf..e4aee403 100644 --- a/od-win32/cda_play.cpp +++ b/od-win32/cda_play.cpp @@ -14,7 +14,7 @@ #include "sysdeps.h" #include "options.h" -#include "dxwrap.h" +#include "render.h" #include "audio.h" #include "blkdev.h" #include "threaddep/thread.h" diff --git a/od-win32/dinput.cpp b/od-win32/dinput.cpp index 7263c7a7..d3ad75b3 100644 --- a/od-win32/dinput.cpp +++ b/od-win32/dinput.cpp @@ -48,7 +48,7 @@ int no_windowsmouse = 0; #include "catweasel.h" #include "keyboard.h" #include "custom.h" -#include "dxwrap.h" +#include "render.h" #include "akiko.h" #include "clipboard.h" #include "tabletlibrary.h" diff --git a/od-win32/direct3d.cpp b/od-win32/direct3d.cpp index c5da8e20..b5a67b8a 100644 --- a/od-win32/direct3d.cpp +++ b/od-win32/direct3d.cpp @@ -23,7 +23,7 @@ #include "xwin.h" #include "custom.h" #include "drawing.h" -#include "dxwrap.h" +#include "render.h" #include "win32.h" #include "win32gfx.h" #include "gfxfilter.h" @@ -221,10 +221,6 @@ struct d3dstruct float m_scale; LPCSTR m_strName; - - int ddraw_fs; - int ddraw_fs_attempt; - LPDIRECTDRAW7 ddraw; }; static struct d3dstruct d3ddata[MAX_AMIGAMONITORS]; @@ -237,64 +233,6 @@ struct TLVERTEX { D3DXVECTOR2 texcoord; // texture coords }; - -static void ddraw_fs_hack_free (struct d3dstruct *d3d) -{ - HRESULT hr; - - if (!d3d->ddraw_fs) - return; - if (d3d->ddraw_fs == 2) - d3d->ddraw->RestoreDisplayMode (); - hr = d3d->ddraw->SetCooperativeLevel (d3d->d3dhwnd, DDSCL_NORMAL); - if (FAILED (hr)) { - write_log (_T("IDirectDraw7_SetCooperativeLevel CLEAR: %s\n"), DXError (hr)); - } - d3d->ddraw->Release (); - d3d->ddraw = NULL; - d3d->ddraw_fs = 0; -} - -static int ddraw_fs_hack_init (struct d3dstruct *d3d) -{ - HRESULT hr; - struct MultiDisplay *md; - - ddraw_fs_hack_free(d3d); - DirectDraw_get_GUIDs(); - md = getdisplay(&currprefs, 0); - if (!md) - return 0; - hr = DirectDrawCreateEx(md->primary ? NULL : &md->ddguid, (LPVOID*)&d3d->ddraw, IID_IDirectDraw7, NULL); - if (FAILED (hr)) { - write_log (_T("DirectDrawCreateEx failed, %s\n"), DXError (hr)); - return 0; - } - d3d->ddraw_fs = 1; - hr = d3d->ddraw->SetCooperativeLevel(d3d->d3dhwnd, DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); - if (FAILED (hr)) { - write_log (_T("IDirectDraw7_SetCooperativeLevel SET: %s\n"), DXError (hr)); - ddraw_fs_hack_free (d3d); - return 0; - } - hr = d3d->ddraw->SetDisplayMode(d3d->dpp.BackBufferWidth, d3d->dpp.BackBufferHeight, d3d->t_depth, d3d->dpp.FullScreen_RefreshRateInHz, 0); - if (FAILED (hr)) { - write_log (_T("1:IDirectDraw7_SetDisplayMode: %s\n"), DXError (hr)); - if (d3d->dpp.FullScreen_RefreshRateInHz && isvsync_chipset () < 0) { - hr = d3d->ddraw->SetDisplayMode(d3d->dpp.BackBufferWidth, d3d->dpp.BackBufferHeight, d3d->t_depth, 0, 0); - if (FAILED (hr)) - write_log (_T("2:IDirectDraw7_SetDisplayMode: %s\n"), DXError (hr)); - } - if (FAILED (hr)) { - write_log (_T("IDirectDraw7_SetDisplayMode: %s\n"), DXError (hr)); - ddraw_fs_hack_free(d3d); - return 0; - } - } - d3d->ddraw_fs = 2; - return 1; -} - static const TCHAR *D3D_ErrorText (HRESULT error) { return _T(""); @@ -2623,7 +2561,6 @@ void xD3D_free (int monid, bool immediate) if (!fakemodewaitms || immediate) { waitfakemode (d3d); D3D_free2 (d3d); - ddraw_fs_hack_free (d3d); return; } } @@ -2912,16 +2849,6 @@ static const TCHAR *D3D_init2 (struct d3dstruct *d3d, HWND ahwnd, int w_w, int w if (FAILED (ret)) { _stprintf (errmsg, _T("%s failed, %s\n"), d3d->d3d_ex && D3DEX ? _T("CreateDeviceEx") : _T("CreateDevice"), D3D_ErrorString (ret)); - if (ret == D3DERR_INVALIDCALL && d3d->dpp.Windowed == 0 && d3d->dpp.FullScreen_RefreshRateInHz && !d3d->ddraw_fs) { - write_log (_T("%s\n"), errmsg); - write_log (_T("%s: Retrying fullscreen with DirectDraw\n"), D3DHEAD); - if (ddraw_fs_hack_init (d3d)) { - const TCHAR *err2 = D3D_init (ahwnd, monid, w_w, w_h, depth, freq, mmulth, mmultv); - if (err2) - ddraw_fs_hack_free (d3d); - return err2; - } - } if (d3d->d3d_ex && D3DEX) { write_log (_T("%s\n"), errmsg); D3DEX = 0; @@ -3180,7 +3107,6 @@ static HRESULT reset (void) static int D3D_needreset (struct d3dstruct *d3d) { HRESULT hr; - bool do_dd = false; if (!d3d->devicelost) return -1; @@ -3220,23 +3146,11 @@ static int D3D_needreset (struct d3dstruct *d3d) alloctextures (d3d); return -1; } else if (hr == S_PRESENT_MODE_CHANGED) { - write_log (_T("%s: S_PRESENT_MODE_CHANGED (%d,%d)\n"), D3DHEAD, d3d->ddraw_fs, d3d->ddraw_fs_attempt); -#if 0 - if (!d3d->ddraw_fs) { - d3d->ddraw_fs_attempt++; - if (d3d->ddraw_fs_attempt >= 5) { - do_dd = true; - } - } -#endif + write_log (_T("%s: S_PRESENT_MODE_CHANGED\n"), D3DHEAD); } if (SUCCEEDED (hr)) { d3d->devicelost = 0; invalidatedeviceobjects (d3d); - if (do_dd) { - write_log (_T("%s: S_PRESENT_MODE_CHANGED, Retrying fullscreen with DirectDraw\n"), D3DHEAD); - ddraw_fs_hack_init (d3d); - } hr = reset (); if (FAILED (hr)) write_log (_T("%s: Reset failed %s\n"), D3DHEAD, D3D_ErrorString (hr)); @@ -3280,8 +3194,6 @@ static void D3D_showframe2 (struct d3dstruct *d3d, bool dowait) d3d->renderdisabled = true; write_log (_T("%s: mode changed or fullscreen focus lost\n"), D3DHEAD); } - } else { - d3d->ddraw_fs_attempt = 0; } return; } diff --git a/od-win32/direct3d.h b/od-win32/direct3d.h index e7c9d483..b54b20f3 100644 --- a/od-win32/direct3d.h +++ b/od-win32/direct3d.h @@ -43,6 +43,7 @@ void D3D_getpixelformat(int depth, int *rb, int *gb, int *bb, int *rs, int *gs, void d3d9_select(void); void d3d11_select(void); +void gdi_select(void); void d3d_select(struct uae_prefs *p); int can_D3D11(bool checkdevice); diff --git a/od-win32/direct3d11.cpp b/od-win32/direct3d11.cpp index ddce625a..0275a3e1 100644 --- a/od-win32/direct3d11.cpp +++ b/od-win32/direct3d11.cpp @@ -15,7 +15,7 @@ using Microsoft::WRL::ComPtr; #include "options.h" #include "xwin.h" -#include "dxwrap.h" +#include "render.h" #include "win32.h" #include "win32gfx.h" #include "direct3d.h" @@ -5415,7 +5415,9 @@ void d3d_select(struct uae_prefs *p) for (int i = 0; i < MAX_AMIGAMONITORS; i++) { d3d11data[i].num = i; } - if (p->gfx_api >= 2) + if (p->gfx_api == 0) + gdi_select(); + else if (p->gfx_api >= 2) d3d11_select(); else d3d9_select(); diff --git a/od-win32/dxwrap.cpp b/od-win32/dxwrap.cpp deleted file mode 100644 index 0678ad28..00000000 --- a/od-win32/dxwrap.cpp +++ /dev/null @@ -1,1341 +0,0 @@ -#include "sysconfig.h" - -#include "sysdeps.h" -#include "options.h" - -#include "dxwrap.h" -#include "win32gfx.h" -#include "statusline.h" -#include "xwin.h" - -#include - - -struct ddstuff dxdata; -struct ddcaps dxcaps; -static int flipinterval_supported = 1; -int ddforceram = DDFORCED_DEFAULT; -static int statuswidth = 800; -static int statusheight = TD_TOTAL_HEIGHT; - -HRESULT DirectDraw_GetDisplayMode (void) -{ - HRESULT ddrval; - - dxdata.native.dwSize = sizeof (DDSURFACEDESC2); - ddrval = IDirectDraw7_GetDisplayMode (dxdata.maindd, &dxdata.native); - if (FAILED (ddrval)) - write_log (_T("IDirectDraw7_GetDisplayMode: %s\n"), DXError (ddrval)); - return ddrval; -} - -#define releaser(x, y) if (x) { y (x); x = NULL; } - -static LPDIRECTDRAWSURFACE7 getlocksurface (void) -{ - struct AmigaMonitor *mon = &AMonitors[0]; - if (dxdata.backbuffers > 0 && currprefs.gfx_apmode[APMODE_NATIVE].gfx_fullscreen > 0 && !WIN32GFX_IsPicassoScreen(mon)) - return dxdata.flipping[0]; - return dxdata.secondary; -} - -static void freemainsurface (void) -{ - if (dxdata.dclip) { - DirectDraw_SetClipper (NULL); - releaser (dxdata.dclip, IDirectDrawClipper_Release); - } - releaser (dxdata.flipping[1], IDirectDrawSurface7_Release); - releaser (dxdata.flipping[0], IDirectDrawSurface7_Release); - releaser (dxdata.primary, IDirectDrawSurface7_Release); - releaser (dxdata.secondary, IDirectDrawSurface7_Release); - releaser (dxdata.statussurface, IDirectDrawSurface7_Release); - dxdata.backbuffers = 0; -} - -static HRESULT restoresurface_2 (LPDIRECTDRAWSURFACE7 surf) -{ - HRESULT ddrval; - - if (surf == dxdata.flipping[0] || surf == dxdata.flipping[1]) - surf = dxdata.primary; - ddrval = IDirectDrawSurface7_IsLost (surf); - if (SUCCEEDED (ddrval)) - return ddrval; - ddrval = IDirectDrawSurface7_Restore (surf); - return ddrval; -} - -HRESULT restoresurface (LPDIRECTDRAWSURFACE7 surf) -{ - HRESULT ddrval; - - if (surf == NULL) - return E_FAIL; - if (surf == dxdata.flipping[0] || surf == dxdata.flipping[1]) - surf = dxdata.primary; - ddrval = IDirectDrawSurface7_IsLost (surf); - if (SUCCEEDED (ddrval)) - return ddrval; - ddrval = IDirectDrawSurface7_Restore (surf); - if (FAILED (ddrval)) { - write_log (_T("IDirectDrawSurface7_Restore: %s\n"), DXError (ddrval)); - } - return ddrval; -} - -static HRESULT restoresurfacex (LPDIRECTDRAWSURFACE7 surf1, LPDIRECTDRAWSURFACE7 surf2) -{ - HRESULT r1, r2; - - r1 = restoresurface (surf1); - r2 = restoresurface (surf2); - if (SUCCEEDED (r1) && SUCCEEDED (r2)) - return r1; - if (SUCCEEDED (r1)) - return r2; - return r1; -} - -static void clearsurf (LPDIRECTDRAWSURFACE7 surf, DWORD color) -{ - HRESULT ddrval; - DDBLTFX ddbltfx; - - if (surf == NULL) - return; - memset(&ddbltfx, 0, sizeof (ddbltfx)); - ddbltfx.dwFillColor = color; - ddbltfx.dwSize = sizeof (ddbltfx); - while (FAILED (ddrval = IDirectDrawSurface7_Blt (surf, NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface (surf); - if (FAILED (ddrval)) - break; - } - break; - } -} - -void DirectDraw_ClearSurface (LPDIRECTDRAWSURFACE7 surf) -{ - if (surf == NULL) - surf = getlocksurface (); - clearsurf (surf, 0); -} - - -int DirectDraw_LockSurface (LPDIRECTDRAWSURFACE7 surf, LPDDSURFACEDESC2 desc) -{ - static int cnt = 50; - HRESULT ddrval; - desc->dwSize = sizeof (*desc); - while (FAILED (ddrval = IDirectDrawSurface7_Lock (surf, NULL, desc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface_2 (surf); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - if (cnt > 0) { - cnt--; - write_log (_T("locksurface %d: %s\n"), cnt, DXError (ddrval)); - } - return 0; - } - } - return 1; -} -void DirectDraw_UnlockSurface (LPDIRECTDRAWSURFACE7 surf) -{ - HRESULT ddrval; - - ddrval = IDirectDrawSurface7_Unlock (surf, NULL); - if (FAILED (ddrval)) - write_log (_T("IDirectDrawSurface7_Unlock: %s\n"), DXError (ddrval)); -} - -static void setsurfacecap (DDSURFACEDESC2 *desc, int w, int h, int mode) -{ - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_NONLOCALVIDMEM | DDSCAPS_VIDEOMEMORY; - if (mode >= DDFORCED_DEFAULT) - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - if (mode == DDFORCED_VIDMEM) - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_VIDEOMEMORY; - if (w > dxcaps.maxwidth || h > dxcaps.maxheight || mode == DDFORCED_SYSMEM) - desc->ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - desc->dwWidth = w; - desc->dwHeight = h; -} - -STATIC_INLINE uae_u16 rgb32torgb16pc (uae_u32 rgb) -{ - return (((rgb >> (16 + 3)) & 0x1f) << 11) | (((rgb >> (8 + 2)) & 0x3f) << 5) | (((rgb >> (0 + 3)) & 0x1f) << 0); -} - -static TCHAR *alloctexts[] = { _T("NonLocalVRAM"), _T("DefaultRAM"), _T("VRAM"), _T("RAM") }; -static LPDIRECTDRAWSURFACE7 allocsurface_3 (int width, int height, uae_u8 *ptr, int pitch, int ck, int forcemode) -{ - HRESULT ddrval; - DDSURFACEDESC2 desc; - LPDIRECTDRAWSURFACE7 surf = NULL; - - memset (&desc, 0, sizeof desc); - desc.dwSize = sizeof (desc); - desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT; - setsurfacecap (&desc, width, height, forcemode); - memcpy (&desc.ddpfPixelFormat, &dxdata.native.ddpfPixelFormat, sizeof (DDPIXELFORMAT)); - - if (ck) { - DWORD mask = 0xff00fe; - if (desc.ddpfPixelFormat.dwRGBBitCount == 16) - mask = rgb32torgb16pc (mask); - else if (desc.ddpfPixelFormat.dwRGBBitCount == 8) - mask = 16; - dxdata.colorkey = mask; - if (dxcaps.cancolorkey) { - desc.dwFlags |= DDSD_CKSRCBLT; - desc.ddckCKSrcBlt.dwColorSpaceLowValue = mask; - desc.ddckCKSrcBlt.dwColorSpaceHighValue = mask; - } - } - - if (ptr) { - desc.dwFlags |= DDSD_LPSURFACE | DDSD_PITCH; - desc.lPitch = pitch; - desc.lpSurface = ptr; - } - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &surf, NULL); - if (FAILED (ddrval)) { - write_log (_T("IDirectDraw7_CreateSurface (%dx%d,%s): %s\n"), width, height, alloctexts[forcemode], DXError (ddrval)); - } else { - write_log (_T("Created %dx%dx%d (%p) surface in %s (%d)%s\n"), width, height, desc.ddpfPixelFormat.dwRGBBitCount, surf, - alloctexts[forcemode], forcemode, ck ? (dxcaps.cancolorkey ? _T(" hardware colorkey") : _T(" software colorkey")) : _T("")); - } - return surf; -} - -static LPDIRECTDRAWSURFACE7 allocsurface_2 (int width, int height, int ck) -{ - LPDIRECTDRAWSURFACE7 s; - int mode = ddforceram; - static int failednonlocal; - - if (failednonlocal && mode == DDFORCED_NONLOCAL) - mode = DDFORCED_DEFAULT; - for (;;) { - s = allocsurface_3 (width, height, NULL, 0, ck, mode); - if (s) { - clearsurf (s, 0); - return s; - } - if (mode == DDFORCED_NONLOCAL) - failednonlocal = 1; - mode++; - if (mode >= 4) - mode = 0; - if (mode == ddforceram) - return NULL; - } -} - -LPDIRECTDRAWSURFACE7 allocsurface (int width, int height) -{ - return allocsurface_2 (width, height, FALSE); -} -LPDIRECTDRAWSURFACE7 allocsystemsurface (int width, int height) -{ - return allocsurface_3 (width, height, NULL, 0, FALSE, DDFORCED_SYSMEM); -} - -LPDIRECTDRAWSURFACE7 createsurface (uae_u8 *ptr, int pitch, int width, int height) -{ - return allocsurface_3 (width, height, ptr, pitch, FALSE, DDFORCED_SYSMEM); -} - -void freesurface (LPDIRECTDRAWSURFACE7 surf) -{ - if (surf) - IDirectDrawSurface7_Release (surf); -} - -void DirectDraw_FreeMainSurface (void) -{ - freemainsurface (); -} - -#if 0 -static int testck2 (LPDIRECTDRAWSURFACE7 tmp, RECT *r) -{ - DDSURFACEDESC2 desc; - if (locksurface (tmp, &desc)) { - uae_u8 *p = (uae_u8*)desc.lpSurface + r->top * desc.lPitch + r->left * desc.ddpfPixelFormat.dwRGBBitCount / 8; - DWORD v1 = ((uae_u32*)p)[0]; - DWORD v2 = ((uae_u32*)p)[1]; - unlocksurface (tmp); - // no more black = failure - if (v1 != 0 || v2 != 0) - return 0; - } - return 1; -} - -int dx_testck (void) -{ - int failed = 0; - LPDIRECTDRAWSURFACE7 cksurf; - LPDIRECTDRAWSURFACE7 tmp; - RECT r1; - int x; - - cksurf = dxdata.cursorsurface1; - tmp = dxdata.secondary; - if (!dxcaps.cancolorkey || !cksurf || !tmp) - return 1; - r1.left = 0; - r1.top = 0; - r1.right = dxcaps.cursorwidth; - r1.bottom = dxcaps.cursorheight; - failed = 0; - // test by blitting surface filled with color key color to destination filled with black - clearsurf (cksurf, dxdata.colorkey); - clearsurf (tmp, 0); - for (x = 0; x < 16; x++) { - DirectDraw_BlitRectCK (tmp, &r1, cksurf, NULL); - if (!testck2 (tmp, &r1)) // non-black = failed - failed = 1; - r1.left++; - r1.right++; - if (x & 1) { - r1.top++; - r1.bottom++; - } - } - clearsurface (cksurf); - clearsurface (tmp); - if (failed) { - write_log (_T("Color key test failure, display driver bug, falling back to software emulation.\n")); - dxcaps.cancolorkey = 0; - releaser (dxdata.cursorsurface1, IDirectDrawSurface7_Release); - dxdata.cursorsurface1 = allocsurface_2 (dxcaps.cursorwidth, dxcaps.cursorheight, TRUE); - return 0; - } - return 1; -} -#endif - -static void createstatussurface (void) -{ - releaser (dxdata.statussurface, IDirectDrawSurface7_Release); - dxdata.statussurface = allocsurface_2 (statuswidth, statusheight, FALSE); - if (dxdata.statussurface) - clearsurf (dxdata.statussurface, 0); -} - -HRESULT DirectDraw_CreateMainSurface (int width, int height) -{ - struct AmigaMonitor *mon = &AMonitors[0]; - HRESULT ddrval; - DDSURFACEDESC2 desc = { 0 }; - LPDIRECTDRAWSURFACE7 surf; - struct apmode *ap = WIN32GFX_IsPicassoScreen(mon) ? &currprefs.gfx_apmode[1] : &currprefs.gfx_apmode[0]; - - width = (width + 7) & ~7; - desc.dwSize = sizeof (desc); - desc.dwFlags = DDSD_CAPS; - desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - if (dxdata.fsmodeset) { - int ok = 0; - DWORD oldcaps = desc.ddsCaps.dwCaps; - DWORD oldflags = desc.dwFlags; - desc.dwFlags |= DDSD_BACKBUFFERCOUNT; - desc.ddsCaps.dwCaps |= DDSCAPS_COMPLEX | DDSCAPS_FLIP; - //desc.dwBackBufferCount = ap->gfx_backbuffers == 0 ? 1 : ap->gfx_backbuffers; - desc.dwBackBufferCount = ap->gfx_backbuffers; - if (desc.dwBackBufferCount > 0) { - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); - if (SUCCEEDED (ddrval)) { - DDSCAPS2 ddscaps; - memset (&ddscaps, 0, sizeof ddscaps); - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - ddrval = IDirectDrawSurface7_GetAttachedSurface (dxdata.primary, &ddscaps, &dxdata.flipping[0]); - if(SUCCEEDED (ddrval)) { - if (desc.dwBackBufferCount > 1) { - memset (&ddscaps, 0, sizeof ddscaps); - ddscaps.dwCaps = DDSCAPS_FLIP; - ddrval = IDirectDrawSurface7_GetAttachedSurface (dxdata.flipping[0], &ddscaps, &dxdata.flipping[1]); - } - } - if (FAILED (ddrval)) - write_log (_T("IDirectDrawSurface7_GetAttachedSurface: %s\n"), DXError (ddrval)); - ok = 1; - } - } - if (!ok) { - desc.dwBackBufferCount = 0; - desc.ddsCaps.dwCaps = oldcaps; - desc.dwFlags = oldflags; - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); - } - } else { - ddrval = IDirectDraw7_CreateSurface (dxdata.maindd, &desc, &dxdata.primary, NULL); - } - if (FAILED (ddrval)) { - write_log (_T("IDirectDraw7_CreateSurface: %s\n"), DXError (ddrval)); - return ddrval; - } - dxdata.native.dwSize = sizeof (DDSURFACEDESC2); - ddrval = IDirectDrawSurface7_GetSurfaceDesc (dxdata.primary, &dxdata.native); - if (FAILED (ddrval)) - write_log (_T("IDirectDrawSurface7_GetSurfaceDesc: %s\n"), DXError (ddrval)); - if (dxdata.fsmodeset) { - clearsurf (dxdata.primary, 0); - dxdata.fsmodeset = 1; - } - dxdata.backbuffers = desc.dwBackBufferCount; - clearsurf (dxdata.flipping[0], 0); - clearsurf (dxdata.flipping[1], 0); - surf = allocsurface (width, height); - if (surf) { - dxdata.secondary = surf; - dxdata.swidth = width; - dxdata.sheight = height; - dxdata.pitch = 0; - if (DirectDraw_LockSurface (surf, &desc)) { - dxdata.pitch = desc.lPitch; - DirectDraw_UnlockSurface (surf); - } else { - write_log (_T("Couldn't get surface pitch!\n")); - } - createstatussurface (); - } else { - ddrval = DD_FALSE; - } - write_log (_T("DDRAW: %dx%d B=%d%s %d-bit\n"), - width, height, - ap->gfx_backbuffers, ap->gfx_vflip < 0 ? _T("WE") : (ap->gfx_vflip > 0 ? _T("WS") : _T("I")), - dxdata.native.ddpfPixelFormat.dwRGBBitCount - ); - return ddrval; -} - -HRESULT DirectDraw_SetDisplayMode (int width, int height, int bits, int freq) -{ - HRESULT ddrval; - - if (dxdata.fsmodeset && dxdata.width == width && dxdata.height == height && - dxdata.depth == bits && dxdata.freq == freq) - return DD_OK; - - getvsyncrate(0, (float)freq, &dxdata.vblank_skip); - dxdata.vblank_skip_cnt = 0; - ddrval = IDirectDraw7_SetDisplayMode (dxdata.maindd, width, height, bits, freq, 0); - if (FAILED (ddrval)) { - write_log (_T("IDirectDraw7_SetDisplayMode(%d,%d,%d,%d): %s\n"), width, height, bits, freq, DXError (ddrval)); - IDirectDraw7_RestoreDisplayMode (dxdata.maindd); - dxdata.fsmodeset = 0; - } else { - dxdata.fsmodeset = -1; - dxdata.width = width; - dxdata.height = height; - dxdata.depth = bits; - dxdata.freq = freq; - } - return ddrval; -} - -HRESULT DirectDraw_SetCooperativeLevel (HWND window, int fullscreen, int doset) -{ - HRESULT ddrval; - - if (doset) { - dxdata.hwnd = window; - ddrval = IDirectDraw7_SetCooperativeLevel (dxdata.maindd, window, fullscreen ? - DDSCL_ALLOWREBOOT | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN : DDSCL_NORMAL); - if (FAILED (ddrval)) - write_log (_T("IDirectDraw7_SetCooperativeLevel: SET %s\n"), DXError (ddrval)); - } else { - ddrval = IDirectDraw7_SetCooperativeLevel (dxdata.maindd, dxdata.hwnd, DDSCL_NORMAL); - if (FAILED (ddrval)) - write_log (_T("IDirectDraw7_SetCooperativeLevel: RESET %s\n"), DXError (ddrval)); - } - return ddrval; -} - -HRESULT DirectDraw_CreateClipper (void) -{ - HRESULT ddrval; - - ddrval = IDirectDraw7_CreateClipper (dxdata.maindd, 0, &dxdata.dclip, NULL); - if (FAILED (ddrval)) - write_log (_T("IDirectDraw7_CreateClipper: %s\n"), DXError (ddrval)); - return ddrval; -} - -HRESULT DirectDraw_SetClipper (HWND hWnd) -{ - HRESULT ddrval; - - if (dxdata.primary == NULL) - return DD_FALSE; - ddrval = IDirectDrawSurface7_SetClipper (dxdata.primary, hWnd ? dxdata.dclip : NULL); - if (FAILED (ddrval)) - write_log (_T("IDirectDrawSurface7_SetClipper: %s\n"), DXError (ddrval)); - if(hWnd && SUCCEEDED (ddrval)) { - ddrval = IDirectDrawClipper_SetHWnd (dxdata.dclip, 0, hWnd); - if (FAILED (ddrval)) - write_log (_T("IDirectDrawClipper_SetHWnd: %s\n"), DXError (ddrval)); - } - return ddrval; -} - - -TCHAR *outGUID (const GUID *guid) -{ - static TCHAR gb[64]; - if (guid == NULL) - return _T("NULL"); - _stprintf (gb, _T("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"), - guid->Data1, guid->Data2, guid->Data3, - guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], - guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); - return gb; -} - -const TCHAR *DXError (HRESULT ddrval) -{ - static TCHAR dderr[1000]; - _stprintf(dderr, _T("%08X S=%d F=%04X C=%04X (%d)"), - ddrval, (ddrval & 0x80000000) ? 1 : 0, - HRESULT_FACILITY(ddrval), - HRESULT_CODE(ddrval), - HRESULT_CODE(ddrval)); - return dderr; -} - -RGBFTYPE DirectDraw_GetSurfacePixelFormat (LPDDSURFACEDESC2 surface) -{ - int surface_is = 0; - DDPIXELFORMAT *pfp = NULL; - DWORD r, g, b; - DWORD surf_flags; - - if (surface == NULL) - surface = &dxdata.native; - surf_flags = surface->dwFlags; - pfp = &surface->ddpfPixelFormat; - - if ((surf_flags & DDSD_PIXELFORMAT) == 0x0) - return RGBFB_NONE; - - if ((pfp->dwFlags & DDPF_RGB) == 0) - return RGBFB_NONE; - - r = pfp->dwRBitMask; - g = pfp->dwGBitMask; - b = pfp->dwBBitMask; - switch (pfp->dwRGBBitCount) - { - case 8: - break; - - case 16: - if (r == 0xF800 && g == 0x07E0 && b == 0x001F) - return RGBFB_R5G6B5PC; - if (r == 0x7C00 && g == 0x03E0 && b == 0x001F) - return RGBFB_R5G5B5PC; - if (b == 0xF800 && g == 0x07E0 && r == 0x001F) - return RGBFB_B5G6R5PC; - if (b == 0x7C00 && g == 0x03E0 && r == 0x001F) - return RGBFB_B5G5R5PC; - break; - - case 24: - if (r == 0xFF0000 && g == 0x00FF00 && b == 0x0000FF) - return RGBFB_B8G8R8; - if (r == 0x0000FF && g == 0x00FF00 && b == 0xFF0000) - return RGBFB_R8G8B8; - break; - - case 32: - if (r == 0x00FF0000 && g == 0x0000FF00 && b == 0x000000FF) - return RGBFB_B8G8R8A8; - if (r == 0x000000FF && g == 0x0000FF00 && b == 0x00FF0000) - return RGBFB_R8G8B8A8; - if (r == 0xFF000000 && g == 0x00FF0000 && b == 0x0000FF00) - return RGBFB_A8B8G8R8; - if (r == 0x0000FF00 && g == 0x00FF0000 && b == 0xFF000000) - return RGBFB_A8R8G8B8; - break; - - default: - write_log (_T("Unknown %d bit format %d %d %d\n"), pfp->dwRGBBitCount, r, g, b); - break; - } - return RGBFB_NONE; -} - -HRESULT DirectDraw_EnumDisplayModes (DWORD flags, LPDDENUMMODESCALLBACK2 callback, void *context) -{ - HRESULT result; - result = IDirectDraw7_EnumDisplayModes (dxdata.maindd, flags, NULL, context, callback); - return result; -} - -HRESULT DirectDraw_EnumDisplays (LPDDENUMCALLBACKEXA callback) -{ - HRESULT result; - result = DirectDrawEnumerateExA (callback, 0, DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_ATTACHEDSECONDARYDEVICES); - return result; -} - -DWORD DirectDraw_CurrentWidth (void) -{ - return dxdata.native.dwWidth; -} -DWORD DirectDraw_CurrentHeight (void) -{ - return dxdata.native.dwHeight; -} -DWORD DirectDraw_GetCurrentDepth (void) -{ - return dxdata.native.ddpfPixelFormat.dwRGBBitCount; -} - -int DirectDraw_SurfaceLock (void) -{ - int ok; - LPDIRECTDRAWSURFACE7 surf; - - surf = getlocksurface (); - if (surf == NULL) - return 0; - if (FAILED (IDirectDrawSurface7_IsLost (surf))) { - restoresurface (surf); - return 0; - } - if (dxdata.lockcnt > 0) - return 1; - ok = DirectDraw_LockSurface (getlocksurface (), &dxdata.locksurface); - if (ok) - dxdata.lockcnt++; - return ok; -} -void DirectDraw_SurfaceUnlock (void) -{ - if (dxdata.lockcnt < 0) - write_log (_T("DirectDraw_SurfaceUnlock negative lock count %d!\n"), dxdata.lockcnt); - if (dxdata.lockcnt == 0) - return; - dxdata.lockcnt--; - DirectDraw_UnlockSurface (getlocksurface ()); -} - -uae_u8 *DirectDraw_GetSurfacePointer (void) -{ - return (uae_u8*)dxdata.locksurface.lpSurface; -} -DWORD DirectDraw_GetSurfacePitch (void) -{ - return dxdata.locksurface.lPitch; -} -int DirectDraw_IsLocked (void) -{ - return dxdata.lockcnt; -} -DWORD DirectDraw_GetPixelFormatBitMask (DirectDraw_Mask_e mask) -{ - DWORD result = 0; - switch(mask) - { - case red_mask: - result = dxdata.native.ddpfPixelFormat.dwRBitMask; - break; - case green_mask: - result = dxdata.native.ddpfPixelFormat.dwGBitMask; - break; - case blue_mask: - result = dxdata.native.ddpfPixelFormat.dwBBitMask; - break; - } - return result; -} -RGBFTYPE DirectDraw_GetPixelFormat (void) -{ - return (RGBFTYPE)DirectDraw_GetSurfacePixelFormat (&dxdata.native); -} -DWORD DirectDraw_GetBytesPerPixel (void) -{ - return (dxdata.native.ddpfPixelFormat.dwRGBBitCount + 7) >> 3; -} - -HRESULT DirectDraw_GetDC (HDC *hdc) -{ - if (getlocksurface () == NULL) - return E_FAIL; - return IDirectDrawSurface7_GetDC (getlocksurface (), hdc); -} -HRESULT DirectDraw_ReleaseDC (HDC hdc) -{ - if (getlocksurface () == NULL) - return E_FAIL; - return IDirectDrawSurface7_ReleaseDC (getlocksurface (), hdc); -} -int DirectDraw_GetVerticalBlankStatus (void) -{ - BOOL status; - if (!dxdata.ddinit) - return -1; - if (FAILED (IDirectDraw7_GetVerticalBlankStatus (dxdata.maindd, &status))) - return -1; - return status ? 1 : 0; -} -void DirectDraw_GetPrimaryPixelFormat (DDSURFACEDESC2 *desc) -{ - memcpy (&desc->ddpfPixelFormat, &dxdata.native.ddpfPixelFormat, sizeof (DDPIXELFORMAT)); - desc->dwFlags |= DDSD_PIXELFORMAT; -} -DWORD DirectDraw_CurrentRefreshRate (void) -{ - if (!dxdata.ddinit) - return -1; - DirectDraw_GetDisplayMode (); - return dxdata.native.dwRefreshRate; -} - -HRESULT DirectDraw_FlipToGDISurface (void) -{ - if (!dxdata.ddinit || !dxdata.fsmodeset) - return DD_OK; - return IDirectDraw7_FlipToGDISurface (dxdata.maindd); -} - -int DirectDraw_BlitToPrimaryScale (RECT *dstrect, RECT *srcrect) -{ - struct AmigaMonitor *mon = &AMonitors[0]; - LPDIRECTDRAWSURFACE7 dst; - int result = 0; - HRESULT ddrval; - RECT dstrect2; - int x = 0, y = 0, w = dxdata.swidth, h = dxdata.sheight; - - dst = dxdata.primary; - if (dstrect == NULL) { - dstrect = &dstrect2; - SetRect (dstrect, x, y, x + w, y + h); - } - centerdstrect(mon, dstrect); - while (FAILED (ddrval = IDirectDrawSurface7_Blt (dst, dstrect, dxdata.secondary, srcrect, DDBLT_WAIT, NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurfacex (dst, dxdata.secondary); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (_T("DirectDraw_BlitToPrimary: %s\n"), DXError (ddrval)); - if (srcrect) - write_log (_T("SRC=%dx%d %dx%d\n"), srcrect->left, srcrect->top, srcrect->right, srcrect->bottom); - if (srcrect) - write_log (_T("DST=%dx%d %dx%d\n"), dstrect->left, dstrect->top, dstrect->right, dstrect->bottom); - break; - } - } - if (SUCCEEDED(ddrval)) - result = 1; - return result; -} - -static int DirectDraw_BlitToPrimary2 (RECT *rect, int dooffset) -{ - struct AmigaMonitor *mon = &AMonitors[0]; - LPDIRECTDRAWSURFACE7 dst; - int result = 0; - HRESULT ddrval; - RECT srcrect, dstrect; - int x = 0, y = 0, w = dxdata.swidth, h = dxdata.sheight; - - dst = dxdata.primary; - if (dst == NULL) - return DD_FALSE; - if (rect) { - x = rect->left; - y = rect->top; - w = rect->right - rect->left; - h = rect->bottom - rect->top; - } - if (w > dxdata.swidth - x) - w = dxdata.swidth - x; - if (h > dxdata.sheight - y) - h = dxdata.sheight - y; - SetRect (&srcrect, x, y, x + w, y + h); - SetRect (&dstrect, x, y, x + w, y + h); - if (rect || dooffset) - centerdstrect(mon, &dstrect); - while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, &dstrect, dxdata.secondary, &srcrect, DDBLT_WAIT, NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurfacex (dst, dxdata.secondary); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (_T("DirectDraw_BlitToPrimary: %s\n"), DXError (ddrval)); - break; - } - } - if (SUCCEEDED(ddrval)) - result = 1; - return result; -} - -int DirectDraw_BlitToPrimary (RECT *rect) -{ - return DirectDraw_BlitToPrimary2 (rect, FALSE); -} - -static int DirectDraw_Blt_EmuCK (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *srcrect) -{ - DDSURFACEDESC2 dstd, srcd; - int x, y, w, h, bpp; - int sx, sy, dx, dy; - int ok; - DWORD ck; - - ok = 0; - ck = dxdata.colorkey; - sx = sy = dx = dy = 0; - if (srcrect) { - sx = srcrect->left; - sy = srcrect->top; - } - if (dstrect) { - dx = dstrect->left; - dy = dstrect->top; - } - if (DirectDraw_LockSurface (dst, &dstd)) { - if (DirectDraw_LockSurface (src, &srcd)) { - bpp = srcd.ddpfPixelFormat.dwRGBBitCount / 8; - h = srcd.dwHeight; - w = srcd.dwWidth; - if (srcrect) - w = srcrect->right - srcrect->left; - if (srcrect) - h = srcrect->bottom - srcrect->top; - for (y = 0; y < h; y++) { - for (x = 0; x < w; x++) { - uae_u8 *sp = (uae_u8*)srcd.lpSurface + srcd.lPitch * (y + sy) + (x + sx) * bpp; - uae_u8 *dp = (uae_u8*)dstd.lpSurface + dstd.lPitch * (y + dy) + (x + dx) * bpp; - if (bpp == 1) { - if (*sp != ck) - *dp = *sp; - } else if (bpp == 2) { - if (((uae_u16*)sp)[0] != ck) - ((uae_u16*)dp)[0] = ((uae_u16*)sp)[0]; - } else if (bpp == 4) { - if (((uae_u32*)sp)[0] != ck) - ((uae_u32*)dp)[0] = ((uae_u32*)sp)[0]; - } - } - } - ok = 1; - DirectDraw_UnlockSurface (src); - } - DirectDraw_UnlockSurface (dst); - } - return ok; -} - -static int DirectDraw_Blt (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *srcrect, int ck) -{ - HRESULT ddrval; - - if (dst == NULL) - dst = getlocksurface (); - if (src == NULL) - src = getlocksurface (); - if (dst == src) - return 1; - if (ck && dxcaps.cancolorkey == 0) - return DirectDraw_Blt_EmuCK (dst, dstrect, src, srcrect); - while (FAILED(ddrval = IDirectDrawSurface7_Blt (dst, dstrect, src, srcrect, DDBLT_WAIT | (ck ? DDBLT_KEYSRC : 0), NULL))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurfacex (dst, src); - if (FAILED (ddrval)) - return 0; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (_T("DirectDraw_Blit: %s\n"), DXError (ddrval)); - return 0; - } - } - return 1; -} -int DirectDraw_Blit (LPDIRECTDRAWSURFACE7 dst, LPDIRECTDRAWSURFACE7 src) -{ - return DirectDraw_Blt (dst, NULL, src, NULL, FALSE); -} -int DirectDraw_BlitRect (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *scrrect) -{ - return DirectDraw_Blt (dst, dstrect, src, scrrect, FALSE); -} -static int DirectDraw_BlitRectCK (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *scrrect) -{ - return DirectDraw_Blt (dst, dstrect, src, scrrect, TRUE); -} - -static void DirectDraw_FillSurface (LPDIRECTDRAWSURFACE7 dst, RECT *rect, uae_u32 color) -{ - HRESULT ddrval; - DDBLTFX ddbltfx; - - if (!dst) - return; - memset (&ddbltfx, 0, sizeof (ddbltfx)); - ddbltfx.dwFillColor = color; - ddbltfx.dwSize = sizeof (ddbltfx); - while (FAILED (ddrval = IDirectDrawSurface7_Blt (dst, rect, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx))) { - if (ddrval == DDERR_SURFACELOST) { - ddrval = restoresurface (dst); - if (FAILED (ddrval)) - break; - } else if (ddrval != DDERR_SURFACEBUSY) { - write_log (_T("DirectDraw_Fill: %s\n"), DXError (ddrval)); - break; - } - } - -} - -void DirectDraw_Fill (RECT *rect, uae_u32 color) -{ - DirectDraw_FillSurface (getlocksurface (), rect, color); -} - -void DirectDraw_FillPrimary (void) -{ - DirectDraw_FillSurface (dxdata.primary, NULL, 0); -} - -static void flip (void) -{ - struct AmigaMonitor *mon = &AMonitors[0]; - int result = 0; - HRESULT ddrval = DD_OK; - DWORD flags = 0; // Why did I put DDFLIP_DONOTWAIT here? - int vsync = isvsync (); - bool novsync = false; - struct apmode *ap = WIN32GFX_IsPicassoScreen(mon) ? &currprefs.gfx_apmode[1] : &currprefs.gfx_apmode[0]; - - if (currprefs.turbo_emulation || !ap->gfx_vflip) { - novsync = true; - flags |= DDFLIP_NOVSYNC; - } - if (dxdata.backbuffers == 2) { - DirectDraw_Blit (dxdata.flipping[1], dxdata.flipping[0]); - if (vsync) { - if (ap->gfx_strobo) { - if (currprefs.turbo_emulation) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - DirectDraw_FillSurface (dxdata.flipping[0], NULL, 0); - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } - } else { - if (currprefs.turbo_emulation || dxdata.vblank_skip == 0) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else if (dxdata.vblank_skip > 0) { - dxdata.vblank_skip_cnt ^= 1; - if (dxdata.vblank_skip_cnt == 0) - return; - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else if (flipinterval_supported && !novsync) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_INTERVAL2); - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - DirectDraw_Blit (dxdata.flipping[1], dxdata.primary); - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } - } - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } - } else if(dxdata.backbuffers == 1) { - if (vsync) { - if (ap->gfx_strobo) { - if (currprefs.turbo_emulation) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - DirectDraw_FillSurface (dxdata.flipping[0], NULL, 0); - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } - } else { - if (currprefs.turbo_emulation || dxdata.vblank_skip == 0) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else if (dxdata.vblank_skip > 0) { - dxdata.vblank_skip_cnt ^= 1; - if (dxdata.vblank_skip_cnt == 0) - return; - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - } else if (flipinterval_supported && !novsync) { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags | DDFLIP_INTERVAL2); - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - DirectDraw_Blit (dxdata.flipping[0], dxdata.primary); - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - DirectDraw_Blit (dxdata.flipping[0], dxdata.primary); - } - } - } else { - ddrval = IDirectDrawSurface7_Flip (dxdata.primary, NULL, flags); - DirectDraw_Blit (dxdata.flipping[0], dxdata.primary); - } - } - if (ddrval == DDERR_SURFACELOST) { - static int recurse; - restoresurface (dxdata.primary); - if (!recurse) { - recurse++; - flip (); - recurse--; - } - } else if (FAILED (ddrval)) { - write_log (_T("IDirectDrawSurface7_Flip: %s\n"), DXError (ddrval)); - } -} - -int DirectDraw_Flip (int doflip) -{ - if (dxdata.primary == NULL) - return 0; - if (getlocksurface () != dxdata.secondary) { - if (doflip) { - flip (); - return 1; - } else { - DirectDraw_Blit (dxdata.primary, getlocksurface ()); - } - } else { - DirectDraw_BlitToPrimary2 (NULL, TRUE); - } - return 1; -} - -void DirectDraw_Release (void) -{ - if (!dxdata.ddinit) - return; - dxdata.isoverlay = 0; - dxdata.islost = 0; - dxdata.ddinit = 0; - freemainsurface (); - if (dxdata.fsmodeset) - IDirectDraw7_RestoreDisplayMode (dxdata.maindd); - dxdata.fsmodeset = 0; - IDirectDraw7_SetCooperativeLevel (dxdata.maindd, dxdata.hwnd, DDSCL_NORMAL); - releaser (dxdata.dclip, IDirectDrawClipper_Release); - releaser (dxdata.maindd, IDirectDraw7_Release); - memset (&dxdata, 0, sizeof (dxdata)); -} - -struct dxcap { - int num; - TCHAR *name; - DWORD mask; -}; -static struct dxcap dxcapsinfo[] = -{ - { 1, _T("DDCAPS_BLT"), DDCAPS_BLT }, - { 1, _T("DDCAPS_BLTQUEUE"), DDCAPS_BLTQUEUE }, - { 1, _T("DDCAPS_BLTFOURCC"), DDCAPS_BLTFOURCC }, - { 1, _T("DDCAPS_BLTCOLORFILL"), DDCAPS_BLTSTRETCH }, - { 1, _T("DDCAPS_BLTSTRETCH"), DDCAPS_BLTSTRETCH }, - { 1, _T("DDCAPS_CANBLTSYSMEM"), DDCAPS_CANBLTSYSMEM }, - { 1, _T("DDCAPS_CANCLIP"), DDCAPS_CANCLIP }, - { 1, _T("DDCAPS_CANCLIPSTRETCHED"), DDCAPS_CANCLIPSTRETCHED }, - { 1, _T("DDCAPS_COLORKEY"), DDCAPS_COLORKEY }, - { 1, _T("DDCAPS_COLORKEYHWASSIST"), DDCAPS_COLORKEYHWASSIST }, - { 1, _T("DDCAPS_GDI"), DDCAPS_GDI }, - { 1, _T("DDCAPS_NOHARDWARE"), DDCAPS_NOHARDWARE }, - { 1, _T("DDCAPS_OVERLAY"), DDCAPS_OVERLAY }, - { 1, _T("DDCAPS_VBI"), DDCAPS_VBI }, - { 1, _T("DDCAPS_3D"), DDCAPS_3D }, - { 1, _T("DDCAPS_BANKSWITCHED"), DDCAPS_BANKSWITCHED }, - { 1, _T("DDCAPS_PALETTE"), DDCAPS_PALETTE }, - { 1, _T("DDCAPS_PALETTEVSYNC"), DDCAPS_PALETTEVSYNC }, - { 1, _T("DDCAPS_READSCANLINE"), DDCAPS_READSCANLINE }, - { 2, _T("DDCAPS2_CERTIFIED"), DDCAPS2_CERTIFIED }, - { 2, _T("DDCAPS2_CANRENDERWINDOWED"), DDCAPS2_CANRENDERWINDOWED }, - { 2, _T("DDCAPS2_NOPAGELOCKREQUIRED"), DDCAPS2_NOPAGELOCKREQUIRED }, - { 2, _T("DDCAPS2_FLIPNOVSYNC"), DDCAPS2_FLIPNOVSYNC }, - { 2, _T("DDCAPS2_FLIPINTERVAL"), DDCAPS2_FLIPINTERVAL }, - { 2, _T("DDCAPS2_NO2DDURING3DSCENE"), DDCAPS2_NO2DDURING3DSCENE }, - { 2, _T("DDCAPS2_NONLOCALVIDMEM"), DDCAPS2_NONLOCALVIDMEM }, - { 2, _T("DDCAPS2_NONLOCALVIDMEMCAPS"), DDCAPS2_NONLOCALVIDMEMCAPS }, - { 2, _T("DDCAPS2_WIDESURFACES"), DDCAPS2_WIDESURFACES }, - { 3, _T("DDCKEYCAPS_DESTBLT"), DDCKEYCAPS_DESTBLT }, - { 3, _T("DDCKEYCAPS_DESTBLTCLRSPACE"), DDCKEYCAPS_DESTBLTCLRSPACE }, - { 3, _T("DDCKEYCAPS_SRCBLT"), DDCKEYCAPS_SRCBLT }, - { 3, _T("DDCKEYCAPS_SRCBLTCLRSPACE"), DDCKEYCAPS_SRCBLTCLRSPACE }, - { 0, NULL } -}; - -static void showcaps (DDCAPS_DX7 *dc) -{ - int i, out; - write_log (_T("%08x %08x %08x %08x %08x %08x\n"), - dc->dwCaps, dc->dwCaps2, dc->dwCKeyCaps, dc->dwFXCaps, dc->dwFXAlphaCaps, dc->dwPalCaps, dc->ddsCaps); - out = 0; - for (i = 0; dxcapsinfo[i].name; i++) { - DWORD caps = 0; - switch (dxcapsinfo[i].num) - { - case 1: - caps = dc->dwCaps; - break; - case 2: - caps = dc->dwCaps2; - break; - case 3: - caps = dc->dwCKeyCaps; - break; - } - if (caps & dxcapsinfo[i].mask) { - if (out > 0) - write_log (_T(",")); - write_log (_T("%s"), dxcapsinfo[i].name); - out++; - } - } - if (out > 0) - write_log (_T("\n")); - if ((dc->dwCaps & DDCAPS_COLORKEY) && (dc->dwCKeyCaps & DDCKEYCAPS_SRCBLT)) - dxcaps.cancolorkey = TRUE; - if (dc->dwCaps2 & DDCAPS2_NONLOCALVIDMEM) - dxcaps.cannonlocalvidmem = TRUE; -} - - -static void getcaps (void) -{ - HRESULT hr; - DDCAPS_DX7 dc, hc; - - memset (&dc, 0, sizeof dc); - memset (&hc, 0, sizeof hc); - dc.dwSize = sizeof dc; - hc.dwSize = sizeof hc; - hr = IDirectDraw7_GetCaps (dxdata.maindd, &dc, &hc); - if (FAILED (hr)) { - write_log (_T("IDirectDraw7_GetCaps() failed %s\n"), DXError (hr)); - return; - } - write_log (_T("DriverCaps: ")); - showcaps (&dc); - write_log (_T("HELCaps : ")); - showcaps (&hc); -} - -static GUID monitorguids[MAX_DISPLAYS]; - -static BOOL CALLBACK displaysCallback (GUID *guid, char *adesc, char *aname, LPVOID ctx, HMONITOR hm) -{ - HMONITOR winmon; - POINT pt; - int i; - - if (guid == NULL) - return TRUE; - for (i = 0; Displays[i].monitorname; i++) { - struct MultiDisplay *md = &Displays[i]; - pt.x = (md->rect.right - md->rect.left) / 2 + md->rect.left; - pt.y = (md->rect.bottom - md->rect.top) / 2 + md->rect.top; - winmon = MonitorFromPoint (pt, MONITOR_DEFAULTTONEAREST); - if (hm == winmon) { - write_log(_T("%s = %s\n"), md->fullname, outGUID (guid)); - memcpy (&monitorguids[i], guid, sizeof GUID); - memcpy (&md->ddguid, guid, sizeof GUID); - return TRUE; - } - } - return TRUE; -} - -void DirectDraw_get_GUIDs (void) -{ - static bool guidsenumerated; - if (guidsenumerated) - return; - guidsenumerated = true; - write_log (_T("DirectDraw displays:\n")); - DirectDrawEnumerateExA (displaysCallback, 0, DDENUM_DETACHEDSECONDARYDEVICES | DDENUM_ATTACHEDSECONDARYDEVICES); - write_log (_T("End\n")); -} - -int DirectDraw_Start (void) -{ - static int first, firstdd; - HRESULT ddrval; - LPDIRECT3D9 d3d; - D3DCAPS9 d3dCaps; - HINSTANCE d3dDLL; - GUID *guid; - - if (!first) { - d3dDLL = LoadLibrary (_T("D3D9.DLL")); - if (d3dDLL) { - d3d = Direct3DCreate9 (D3D9b_SDK_VERSION); - if (d3d) { - if (SUCCEEDED (IDirect3D9_GetDeviceCaps (d3d, 0, D3DDEVTYPE_HAL, &d3dCaps))) { - dxcaps.maxwidth = d3dCaps.MaxTextureWidth; - dxcaps.maxheight = d3dCaps.MaxTextureHeight; - write_log (_T("Max hardware surface size: %dx%d\n"), dxcaps.maxwidth, dxcaps.maxheight); - } - IDirect3D9_Release (d3d); - } - FreeLibrary (d3dDLL); - } - if (dxcaps.maxwidth < 2048) - dxcaps.maxwidth = 2048; - if (dxcaps.maxheight < 2048) - dxcaps.maxheight = 2048; - - first = 1; - } - - if (currprefs.gfx_api) { - return 1; - } - - DirectDraw_get_GUIDs (); - - guid = NULL; - if (isfullscreen ()) { - MultiDisplay *md = getdisplay(&currprefs, 0); - int disp = (int)(md - Displays); - if (disp < 0) - disp = 0; - if (disp >= MAX_DISPLAYS) - disp = 0; - guid = &monitorguids[disp]; - } - dxdata.islost = 0; - if (dxdata.ddinit) { - if (guid == NULL && dxdata.ddzeroguid) - return -1; - if (guid && !memcmp (guid, &dxdata.ddguid, sizeof (GUID))) - return -1; - DirectDraw_Release (); - } -#if 0 - LPDIRECTDRAW dd; - ddrval = DirectDrawCreate (guid, &dd, NULL); - if (FAILED (ddrval)) { - write_log (_T("DirectDrawCreate() failed, %s\n"), DXError (ddrval)); - if (guid != NULL) - return 0; - goto oops; - } - ddrval = IDirectDraw_QueryInterface (dd, &IID_IDirectDraw7, &dxdata.maindd); - IDirectDraw_Release (dd); - if (FAILED (ddrval)) { - write_log (_T("IDirectDraw_QueryInterface() failed, %s\n"), DXError (ddrval)); - goto oops; - } -#else - ddrval = DirectDrawCreateEx (guid, (void**)&dxdata.maindd, IID_IDirectDraw7, NULL); - if (FAILED (ddrval)) { - write_log (_T("DirectDrawCreateEx() failed, %s\n"), DXError (ddrval)); - if (guid != NULL) - return 0; - goto oops; - } -#endif - - if (!firstdd) - getcaps (); - firstdd = 1; - - if (SUCCEEDED (DirectDraw_GetDisplayMode ())) { - dxdata.ddinit = 1; - dxdata.ddzeroguid = 1; - if (guid) { - dxdata.ddzeroguid = 0; - memcpy (&dxdata.ddguid, guid, sizeof (GUID)); - } - write_log (_T("DirectDraw Display GUID = %s\n"), outGUID (guid)); - return 1; - } -oops: - write_log (_T("DirectDraw_Start: %s\n"), DXError (ddrval)); - DirectDraw_Release (); - return 0; -} - -int dx_islost (void) -{ - return dxdata.islost; -} - -void dx_check (void) -{ - dxdata.islost = 0; - if (dxdata.fsmodeset <= 0 || dxdata.primary == NULL) - return; - if (IDirectDrawSurface7_IsLost (dxdata.primary) != DDERR_SURFACELOST) - return; - if (IDirectDrawSurface7_Restore (dxdata.primary) != DDERR_WRONGMODE) - return; - dxdata.islost = 1; -} - -bool DD_getvblankpos (int *vpos) -{ - HRESULT hr; - DWORD sl, slstate; - BOOL vbs; - - *vpos = -10; - if ((dxdata.primary == NULL && dxdata.fsmodeset > 0) || dxdata.islost || !dxdata.maindd) - return false; - hr = IDirectDraw7_GetVerticalBlankStatus (dxdata.maindd, &vbs); - if (FAILED (hr)) { - write_log (_T("IDirectDraw7_GetVerticalBlankStatus() failed, %s\n"), DXError (hr)); - return false; - } - slstate = 4; - sl = -1; - if (!vbs) { - slstate = 3; - hr = IDirectDraw7_GetScanLine (dxdata.maindd, &sl); - if (hr == 0x88760219) { // "vertical blank is in progress" - vbs = TRUE; - slstate = 2; - sl = -1; - } else if (FAILED (hr) ) { - write_log (_T("IDirectDraw7_GetScanLine() failed, %s\n"), DXError (hr)); - return false; - } - } - if (vbs) - *vpos = -1; - else - *vpos = sl; - -#if 0 - static DWORD oldsl, oldslstate; - if (oldsl != sl || oldslstate != slstate) { - write_log (_T("%d:%d "), sl, slstate); - oldsl = sl; - oldslstate = slstate; - } -#endif - - return true; -} - -void DD_vblank_reset(float freq) -{ - getvsyncrate(0, freq, &dxdata.vblank_skip); - dxdata.vblank_skip_cnt = 0; - dx_check (); - if ((dxdata.primary == NULL && dxdata.fsmodeset > 0) || dxdata.islost || !dxdata.maindd) - return; - IDirectDraw7_WaitForVerticalBlank (dxdata.maindd, DDWAITVB_BLOCKBEGIN, NULL); -} diff --git a/od-win32/gdirender.cpp b/od-win32/gdirender.cpp new file mode 100644 index 00000000..2bf4d650 --- /dev/null +++ b/od-win32/gdirender.cpp @@ -0,0 +1,315 @@ + +#include +#include "resource.h" + +#include "sysconfig.h" +#include "sysdeps.h" + +#include "options.h" +#include "xwin.h" +#include "custom.h" +#include "drawing.h" +#include "render.h" +#include "win32.h" +#include "win32gfx.h" +#include "statusline.h" +#include "uae.h" +#include "direct3d.h" + +struct gdibm +{ + bool active; + int x, y; + int width, height, depth; + HDC thdc; + HBITMAP hbm; + HGDIOBJ oldbm; + void *bits; + int pitch; +}; + +struct gdistruct +{ + int num; + int width, height, depth; + int wwidth, wheight; + HWND hwnd; + HDC hdc; + HDC thdc; + HBITMAP hbm; + HGDIOBJ oldbm; + void *bits; + int pitch; + int statusbar_hx, statusbar_vx; + int ledwidth, ledheight; + struct gdibm osd; +}; + +static struct gdistruct gdidata[MAX_AMIGAMONITORS]; + +static void gdi_refresh(int monid) +{ + struct gdistruct *gdi = &gdidata[monid]; +} + +static void gdi_restore(int monid, bool checkonly) +{ + struct gdistruct *gdi = &gdidata[monid]; +} + +static void freetexture(int monid) +{ + struct gdistruct *gdi = &gdidata[monid]; + if (gdi->hdc) { + if (gdi->thdc) { + if (gdi->hbm) { + if (gdi->oldbm) { + SelectObject(gdi->thdc, gdi->oldbm); + } + DeleteObject(gdi->hbm); + } + gdi->oldbm = NULL; + gdi->hbm = NULL; + gdi->bits = NULL; + DeleteDC(gdi->thdc); + gdi->thdc = NULL; + } + ReleaseDC(gdi->hwnd, gdi->hdc); + gdi->hdc = NULL; + } +} + +static void freesprite(struct gdistruct *gdi, struct gdibm *bm) +{ + if (bm->thdc) { + if (bm->hbm) { + if (bm->oldbm) { + SelectObject(bm->thdc, bm->oldbm); + } + DeleteObject(bm->hbm); + } + bm->oldbm = NULL; + bm->hbm = NULL; + bm->bits = NULL; + DeleteDC(bm->thdc); + bm->thdc = NULL; + } +} + +static bool allocsprite(struct gdistruct *gdi, struct gdibm *bm, int w, int h) +{ + bm->thdc = CreateCompatibleDC(gdi->hdc); + if (bm->thdc) { + BITMAPV4HEADER bmi = { 0 }; + + bmi.bV4Size = sizeof(BITMAPINFOHEADER); + bmi.bV4Width = w; + bmi.bV4Height = -h; + bmi.bV4Planes = 1; + bmi.bV4V4Compression = BI_RGB; + bmi.bV4BitCount = gdi->depth; + bm->width = w; + bm->height = h; + bm->depth = gdi->depth; + bm->pitch = ((w * bmi.bV4BitCount + 31) / 32) * 4; + bmi.bV4SizeImage = gdi->pitch * h; + bm->hbm = CreateDIBSection(gdi->hdc, (const BITMAPINFO*)&bmi, DIB_RGB_COLORS, &bm->bits, NULL, 0); + if (bm->hbm) { + bm->oldbm = SelectObject(bm->thdc, bm->hbm); + return true; + } + } + return false; +} + +static bool gdi_alloctexture(int monid, int w, int h) +{ + struct gdistruct *gdi = &gdidata[monid]; + + freetexture(monid); + + gdi->hdc = GetDC(gdi->hwnd); + if (gdi->hdc) { + gdi->thdc = CreateCompatibleDC(gdi->hdc); + if (gdi->thdc) { + BITMAPV4HEADER bmi = { 0 }; + + bmi.bV4Size = sizeof(BITMAPINFOHEADER); + bmi.bV4Width = w; + bmi.bV4Height = -h; + bmi.bV4Planes = 1; + bmi.bV4V4Compression = BI_RGB; + bmi.bV4BitCount = gdi->depth; + gdi->width = w; + gdi->height = h; + gdi->pitch = ((w * bmi.bV4BitCount + 31) / 32) * 4; + bmi.bV4SizeImage = gdi->pitch * h; + gdi->hbm = CreateDIBSection(gdi->hdc, (const BITMAPINFO*)&bmi, DIB_RGB_COLORS, &gdi->bits, NULL, 0); + if (gdi->hbm) { + gdi->oldbm = SelectObject(gdi->thdc, gdi->hbm); + return true; + } + } + } + freetexture(monid); + return false; +} + +static void updateleds(struct gdistruct *gdi) +{ + static uae_u32 rc[256], gc[256], bc[256], a[256]; + static int done; + int osdx, osdy; + + if (!done) { + for (int i = 0; i < 256; i++) { + rc[i] = i << 16; + gc[i] = i << 8; + bc[i] = i << 0; + a[i] = i << 24; + } + done = 1; + } + + + if (gdi->osd.bits == NULL || gdi != gdidata) + return; + + statusline_getpos(gdi->num, &osdx, &osdy, gdi->wwidth, gdi->wheight); + gdi->osd.x = osdx; + gdi->osd.y = osdy; + + for (int y = 0; y < gdi->osd.height; y++) { + uae_u8 *buf = (uae_u8*)gdi->osd.bits + y * gdi->osd.pitch; + statusline_single_erase(gdi->num, buf, gdi->osd.depth / 8, y, gdi->ledwidth); + } + statusline_render(gdi->num, (uae_u8*)gdi->osd.bits, gdi->osd.depth / 8, gdi->osd.pitch, gdi->ledwidth, gdi->ledheight, rc, gc, bc, a); + + for (int y = 0; y < gdi->osd.height; y++) { + uae_u8 *buf = (uae_u8*)gdi->osd.bits + y * gdi->osd.pitch; + draw_status_line_single(gdi->num, buf, gdi->osd.depth / 8, y, gdi->ledwidth, rc, gc, bc, a); + } +} + +static void gdi_guimode(int monid, int guion) +{ +} + +static uae_u8 *gdi_locktexture(int monid, int *pitch, int *height, int fullupdate) +{ + struct gdistruct *gdi = &gdidata[monid]; + if (gdi->bits) { + *pitch = gdi->pitch; + *height = gdi->height; + return (uae_u8*)gdi->bits; + } + return NULL; +} + +static void gdi_unlocktexture(int monid, int y_start, int y_end) +{ + struct gdistruct *gdi = &gdidata[monid]; + + struct AmigaMonitor *mon = &AMonitors[monid]; + bool rtg = WIN32GFX_IsPicassoScreen(mon); + if (((currprefs.leds_on_screen & STATUSLINE_CHIPSET) && !rtg) || ((currprefs.leds_on_screen & STATUSLINE_RTG) && rtg)) { + updateleds(gdi); + gdi->osd.active = true; + } else { + gdi->osd.active = false; + } +} + +static void gdi_flushtexture(int monid, int miny, int maxy) +{ +} + +static bool gdi_renderframe(int monid, int mode, bool immediate) +{ + struct gdistruct *gdi = &gdidata[monid]; + + return gdi->hbm != NULL; +} + +static void gdi_showframe(int monid) +{ + struct gdistruct *gdi = &gdidata[monid]; + + if (gdi->hbm) { + StretchBlt(gdi->hdc, 0, 0, gdi->wwidth, gdi->wheight, gdi->thdc, 0, 0, gdi->width, gdi->height, SRCCOPY); + } + if (gdi->osd.active && gdi->osd.hbm) { + BLENDFUNCTION bf = { 0 }; + bf.BlendOp = AC_SRC_OVER; + bf.SourceConstantAlpha = 255; + bf.AlphaFormat = AC_SRC_ALPHA; + AlphaBlend(gdi->hdc, gdi->osd.x, gdi->osd.y, gdi->ledwidth, gdi->ledheight, gdi->osd.thdc, 0, 0, gdi->ledwidth, gdi->ledheight, bf); + } +} + +void gdi_free(int monid, bool immediate) +{ + struct gdistruct *gdi = &gdidata[monid]; + freetexture(monid); +} + +static const TCHAR *gdi_init(HWND ahwnd, int monid, int w_w, int w_h, int depth, int *freq, int mmulth, int mmultv) +{ + struct gdistruct *gdi = &gdidata[monid]; + + if (isfullscreen() > 0) { + return _T("GDI fullscreen not supported"); + } + + gdi->hwnd = ahwnd; + gdi->depth = depth; + gdi->wwidth = w_w; + gdi->wheight = w_h; + + gdi->statusbar_hx = gdi->statusbar_vx = statusline_set_multiplier(monid, gdi->wwidth, gdi->wheight) / 100; + gdi->ledwidth = gdi->wwidth; + gdi->ledheight = TD_TOTAL_HEIGHT * gdi->statusbar_vx; + allocsprite(gdi, &gdi->osd, gdi->ledwidth, gdi->ledheight); + + return NULL; +} + + +void gdi_select(void) +{ + for (int i = 0; i < MAX_AMIGAMONITORS; i++) { + gdidata[i].num = i; + } + + D3D_free = gdi_free; + D3D_init = gdi_init; + + D3D_renderframe = gdi_renderframe; + D3D_alloctexture = gdi_alloctexture; + D3D_refresh = gdi_refresh; + D3D_restore = gdi_restore; + + D3D_locktexture = gdi_locktexture; + D3D_unlocktexture = gdi_unlocktexture; + D3D_flushtexture = gdi_flushtexture; + + D3D_showframe = gdi_showframe; + D3D_showframe_special = NULL; + D3D_guimode = gdi_guimode; + D3D_getDC = NULL; + D3D_isenabled = NULL; + D3D_clear = NULL; + D3D_canshaders = NULL; + D3D_goodenough = NULL; + D3D_setcursor = NULL; + D3D_setcursorsurface = NULL; + D3D_getrefreshrate = NULL; + D3D_resize = NULL; + D3D_change = NULL; + D3D_getscalerect = NULL; + D3D_run = NULL; + D3D_debug = NULL; + D3D_led = NULL; + D3D_getscanline = NULL; + D3D_extoverlay = NULL; +} diff --git a/od-win32/keyboard_win32.cpp b/od-win32/keyboard_win32.cpp index f73c3794..c21b331b 100644 --- a/od-win32/keyboard_win32.cpp +++ b/od-win32/keyboard_win32.cpp @@ -401,8 +401,8 @@ bool my_kbd_handler (int keyboard, int scancode, int newstate, bool alwaysreleas return; } #endif -#if 0 - if (scancode == DIK_F8) { +#if 1 + if (scancode == DIK_F8 && specialpressed()) { if (newstate) { extern int blop2; blop2++; diff --git a/od-win32/midi.cpp b/od-win32/midi.cpp index 103b354c..249326d5 100644 --- a/od-win32/midi.cpp +++ b/od-win32/midi.cpp @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include diff --git a/od-win32/parser.cpp b/od-win32/parser.cpp index 5d653611..d13568a2 100644 --- a/od-win32/parser.cpp +++ b/od-win32/parser.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include diff --git a/od-win32/picasso96_win.cpp b/od-win32/picasso96_win.cpp index 6b03dead..09f164df 100644 --- a/od-win32/picasso96_win.cpp +++ b/od-win32/picasso96_win.cpp @@ -67,7 +67,7 @@ #include "inputdevice.h" #include "debug.h" #include "registry.h" -#include "dxwrap.h" +#include "render.h" #ifdef RETROPLATFORM #include "rp.h" #endif @@ -77,7 +77,6 @@ #include "clipboard.h" #include "gfxboard.h" #include "gfxfilter.h" -#include "dxwrap.h" #include "devices.h" int debug_rtg_blitter = 3; @@ -1063,11 +1062,7 @@ static void setconvert(int monid) } else { vidinfo->picasso_convert[0] = vidinfo->picasso_convert[1] = getconvert(state->RGBFormat, picasso_vidinfo[monid].pixbytes); } - if (currprefs.gfx_api) { - vidinfo->host_mode = picasso_vidinfo[monid].pixbytes == 4 ? RGBFB_B8G8R8A8 : RGBFB_B5G6R5PC; - } else { - vidinfo->host_mode = DirectDraw_GetSurfacePixelFormat(NULL); - } + vidinfo->host_mode = picasso_vidinfo[monid].pixbytes == 4 ? RGBFB_B8G8R8A8 : RGBFB_B5G6R5PC; if (picasso_vidinfo[monid].pixbytes == 4) alloc_colors_rgb(8, 8, 8, 16, 8, 0, 0, 0, 0, 0, p96rc, p96gc, p96bc); else @@ -1134,11 +1129,6 @@ void picasso_refresh(int monid) state->VirtualWidth : state->Width; height = (state->VirtualHeight < state->Height) ? state->VirtualHeight : state->Height; - // Let's put a black-border around the case where we've got a sub-screen... - if (!state->BigAssBitmap) { - if (state->XOffset || state->YOffset) - DX_Fill(mon, 0, 0, state->Width, state->Height, 0); - } } else { width = state->Width; height = state->Height; diff --git a/od-win32/picasso96_win.h b/od-win32/picasso96_win.h index 9b3e9780..d7fd3d19 100644 --- a/od-win32/picasso96_win.h +++ b/od-win32/picasso96_win.h @@ -10,7 +10,7 @@ #ifdef PICASSO96 -#include "dxwrap.h" +#include "render.h" #define NOSIGNAL 0xFFFFFFFF diff --git a/od-win32/posixemu.cpp b/od-win32/posixemu.cpp index 7b02209b..aef1182e 100644 --- a/od-win32/posixemu.cpp +++ b/od-win32/posixemu.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/od-win32/dxwrap.h b/od-win32/render.h similarity index 57% rename from od-win32/dxwrap.h rename to od-win32/render.h index 038ec2ba..e77b819f 100644 --- a/od-win32/dxwrap.h +++ b/od-win32/render.h @@ -149,60 +149,7 @@ typedef enum blue_mask } DirectDraw_Mask_e; -extern const TCHAR *DXError (HRESULT hr); +extern const TCHAR *DXError(HRESULT hr); extern TCHAR *outGUID (const GUID *guid); -HRESULT DirectDraw_GetDisplayMode (void); -void DirectDraw_Release(void); -int DirectDraw_Start(void); -void DirectDraw_get_GUIDs (void); -void DirectDraw_ClearSurface (LPDIRECTDRAWSURFACE7 surf); -int DirectDraw_LockSurface (LPDIRECTDRAWSURFACE7 surf, LPDDSURFACEDESC2 desc); -void DirectDraw_UnlockSurface (LPDIRECTDRAWSURFACE7 surf); -LPDIRECTDRAWSURFACE7 allocsurface (int width, int height); -LPDIRECTDRAWSURFACE7 allocsystemsurface (int width, int height); -LPDIRECTDRAWSURFACE7 createsurface (uae_u8 *ptr, int pitch, int width, int height); -void freesurface (LPDIRECTDRAWSURFACE7 surf); -void DirectDraw_FreeMainSurface (void); -HRESULT DirectDraw_CreateMainSurface (int width, int height); -HRESULT DirectDraw_SetDisplayMode(int width, int height, int bits, int freq); -HRESULT DirectDraw_SetCooperativeLevel (HWND window, int fullscreen, int doset); -HRESULT DirectDraw_CreateClipper (void); -HRESULT DirectDraw_SetClipper(HWND hWnd); -RGBFTYPE DirectDraw_GetSurfacePixelFormat(LPDDSURFACEDESC2 surface); -DWORD DirectDraw_CurrentWidth (void); -DWORD DirectDraw_CurrentHeight (void); -DWORD DirectDraw_GetCurrentDepth (void); -int DirectDraw_SurfaceLock (void); -void DirectDraw_SurfaceUnlock (void); -uae_u8 *DirectDraw_GetSurfacePointer (void); -DWORD DirectDraw_GetSurfacePitch (void); -int DirectDraw_IsLocked (void); -DWORD DirectDraw_GetPixelFormatBitMask (DirectDraw_Mask_e mask); -RGBFTYPE DirectDraw_GetPixelFormat (void); -DWORD DirectDraw_GetBytesPerPixel (void); -HRESULT DirectDraw_GetDC (HDC *hdc); -HRESULT DirectDraw_ReleaseDC (HDC hdc); -int DirectDraw_GetVerticalBlankStatus (void); -DWORD DirectDraw_CurrentRefreshRate (void); -void DirectDraw_GetPrimaryPixelFormat (DDSURFACEDESC2 *desc); -HRESULT DirectDraw_FlipToGDISurface (void); -int DirectDraw_Flip (int doflip); -int DirectDraw_BlitToPrimary (RECT *rect); -int DirectDraw_BlitToPrimaryScale (RECT *dstrect, RECT *srcrect); -int DirectDraw_Blit (LPDIRECTDRAWSURFACE7 dst, LPDIRECTDRAWSURFACE7 src); -int DirectDraw_BlitRect (LPDIRECTDRAWSURFACE7 dst, RECT *dstrect, LPDIRECTDRAWSURFACE7 src, RECT *scrrect); -void DirectDraw_Fill (RECT *rect, uae_u32 color); -void DirectDraw_FillPrimary (void); -bool DD_getvblankpos (int *vpos); -void DD_vblank_reset (float freq); - -void dx_check (void); -int dx_islost (void); - -#define DDFORCED_NONLOCAL 0 -#define DDFORCED_DEFAULT 1 -#define DDFORCED_VIDMEM 2 -#define DDFORCED_SYSMEM 3 - #endif diff --git a/od-win32/screenshot.cpp b/od-win32/screenshot.cpp index 47b044e5..ab26762e 100644 --- a/od-win32/screenshot.cpp +++ b/od-win32/screenshot.cpp @@ -10,7 +10,7 @@ #include "sysdeps.h" #include "options.h" #include "custom.h" -#include "dxwrap.h" +#include "render.h" #include "win32.h" #include "win32gfx.h" #include "direct3d.h" @@ -786,7 +786,7 @@ static int filenumber = 0; static int dirnumber = 1; /* -Captures the Amiga display (DirectDraw, D3D or OpenGL) surface and saves it to file as a 24bit bitmap. +Captures the Amiga display (GDI, D3D or OpenGL) surface and saves it to file as a 24bit bitmap. */ int screenshotf(int monid, const TCHAR *spath, int mode, int doprepare, int imagemode, struct vidbuffer *vb) { diff --git a/od-win32/sounddep/sound.cpp b/od-win32/sounddep/sound.cpp index e764b294..17052805 100644 --- a/od-win32/sounddep/sound.cpp +++ b/od-win32/sounddep/sound.cpp @@ -22,7 +22,7 @@ #include "threaddep/thread.h" #include "avioutput.h" #include "gui.h" -#include "dxwrap.h" +#include "render.h" #include "win32.h" #include "savestate.h" #include "driveclick.h" diff --git a/od-win32/win32.cpp b/od-win32/win32.cpp index efe071f7..d04d6a1f 100644 --- a/od-win32/win32.cpp +++ b/od-win32/win32.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -64,7 +63,7 @@ #include "inputdevice.h" #include "keybuf.h" #include "drawing.h" -#include "dxwrap.h" +#include "render.h" #include "picasso96_win.h" #include "bsdsocket.h" #include "win32.h" @@ -1914,7 +1913,6 @@ static LRESULT CALLBACK AmigaWindowProc(HWND hWnd, UINT message, WPARAM wParam, //write_log(_T("WM_SETFOCUS\n")); winuae_active(mon, hWnd, minimized); unsetminimized(mon->monitor_id); - dx_check(); return 0; case WM_EXITSIZEMOVE: if (wParam == SC_MOVE) { @@ -1950,7 +1948,6 @@ static LRESULT CALLBACK AmigaWindowProc(HWND hWnd, UINT message, WPARAM wParam, unsetminimized(mon->monitor_id); winuae_inactive(mon, hWnd, minimized); } - dx_check(); return 0; case WM_MOUSEACTIVATE: if (isfocus() == 0) @@ -1972,7 +1969,6 @@ static LRESULT CALLBACK AmigaWindowProc(HWND hWnd, UINT message, WPARAM wParam, #ifdef RETROPLATFORM rp_activate(wParam, lParam); #endif - dx_check(); return 0; case WM_KEYDOWN: @@ -4188,7 +4184,7 @@ void target_fixup_options (struct uae_prefs *p) } if (p->rtg_hardwaresprite && !p->gfx_api) { - error_log(_T("DirectDraw is not RTG hardware sprite compatible.")); + error_log(_T("GDI is not RTG hardware sprite compatible.")); p->rtg_hardwaresprite = false; } if (p->rtgboards[0].rtgmem_type >= GFXBOARD_HARDWARE) { @@ -5627,8 +5623,8 @@ static void WIN32_HandleRegistryStuff (void) int x = GetSystemMetrics (SM_CXSCREEN); int y = GetSystemMetrics (SM_CYSCREEN); int dpi = getdpiformonitor(NULL); - x = (x - (800 * dpi / 96)) / 2; - y = (y - (600 * dpi / 96)) / 2; + x = (x - (GUI_INTERNAL_WIDTH_NEW * dpi / 96)) / 2; + y = (y - (GUI_INTERNAL_HEIGHT_NEW * dpi / 96)) / 2; if (x < 10) x = 10; if (y < 10) @@ -5650,7 +5646,6 @@ static void WIN32_HandleRegistryStuff (void) forceroms = 1; } - regqueryint (NULL, _T("DirectDraw_Secondary"), &ddforceram); if (regexists (NULL, _T("SoundDriverMask"))) { regqueryint (NULL, _T("SoundDriverMask"), &sounddrivermask); } else { @@ -6749,10 +6744,6 @@ static int parseargs(const TCHAR *argx, const TCHAR *np, const TCHAR *np2) return 2; } if (!_tcscmp (arg, _T("ddforcemode"))) { - extern int ddforceram; - ddforceram = getval (np); - if (ddforceram < 0 || ddforceram > 3) - ddforceram = 0; return 2; } if (!_tcscmp (arg, _T("affinity"))) { @@ -7161,7 +7152,6 @@ static int PASCAL WinMain2 (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR #endif WIN32_InitLang (); WIN32_InitHtmlHelp (); - DirectDraw_Release (); unicode_init (); can_D3D11(false); if (betamessage ()) { diff --git a/od-win32/win32_scaler.cpp b/od-win32/win32_scaler.cpp index 734f8e89..595eb17e 100644 --- a/od-win32/win32_scaler.cpp +++ b/od-win32/win32_scaler.cpp @@ -7,11 +7,10 @@ #include "options.h" #include "custom.h" #include "xwin.h" -#include "dxwrap.h" #include "win32.h" #include "win32gfx.h" #include "gfxfilter.h" -#include "dxwrap.h" +#include "render.h" #include "statusline.h" #include "drawing.h" #include "direct3d.h" @@ -48,12 +47,10 @@ static int dst_width, dst_height, amiga_width, amiga_height, amiga_depth, dst_de static int dst_width2, dst_height2, amiga_width2, amiga_height2, amiga_depth2, dst_depth2; static int temp_width, temp_height; uae_u8 *bufmem_ptr; -static LPDIRECTDRAWSURFACE7 tempsurf; static uae_u8 *tempsurf2, *tempsurf3; static int cleartemp; static uae_u32 rc[256], gc[256], bc[256]; static int deskw, deskh; -static int d3d; static bool inited; void getfilteroffset(int monid, float *dx, float *dy, float *mx, float *my) @@ -881,34 +878,6 @@ uae_u8 *getfilterbuffer(int monid, int *widthp, int *heightp, int *pitch, int *d #endif } -static void statusline(int monid) -{ - DDSURFACEDESC2 desc; - RECT sr, dr; - int y; - int lx, ly; - int slx, sly; - - if (!(currprefs.leds_on_screen & STATUSLINE_CHIPSET) || !tempsurf) - return; - statusline_getpos(monid, &slx, &sly, dst_width, dst_height); - int m = statusline_get_multiplier(monid) / 100; - lx = dst_width; - ly = dst_height; - SetRect(&sr, slx, 0, slx + lx, TD_TOTAL_HEIGHT * m); - SetRect(&dr, slx, sly, slx + lx, sly + TD_TOTAL_HEIGHT * m); - DirectDraw_BlitRect(tempsurf, &sr, NULL, &dr); - if (DirectDraw_LockSurface(tempsurf, &desc)) { - statusline_render(0, (uae_u8*)desc.lpSurface, dst_depth / 8, desc.lPitch, lx, ly, rc, gc, bc, NULL); - for (y = 0; y < TD_TOTAL_HEIGHT * m; y++) { - uae_u8 *buf = (uae_u8*)desc.lpSurface + y * desc.lPitch; - draw_status_line_single(monid, buf, dst_depth / 8, y, lx, rc, gc, bc, NULL); - } - DirectDraw_UnlockSurface(tempsurf); - DirectDraw_BlitRect(NULL, &dr, tempsurf, &sr); - } -} - void S2X_configure(int monid, int rb, int gb, int bb, int rs, int gs, int bs) { if (monid) @@ -936,8 +905,6 @@ void S2X_free(int monid) changed_prefs.leds_on_screen &= ~STATUSLINE_TARGET; currprefs.leds_on_screen &= ~STATUSLINE_TARGET; - freesurface (tempsurf); - tempsurf = 0; xfree (tempsurf2); tempsurf2 = 0; xfree (tempsurf3); @@ -970,13 +937,11 @@ bool S2X_init(int monid, int dw, int dh, int dd) amiga_depth2 = vb->pixbytes * 8; S2X_free(monid); - d3d = currprefs.gfx_api; changed_prefs.leds_on_screen |= STATUSLINE_TARGET; currprefs.leds_on_screen |= STATUSLINE_TARGET; statusline_set_multiplier(monid, dw, dh); - if (d3d) - dd = amiga_depth2; + dd = amiga_depth2; if (dd == 32) alloc_colors_rgb (8, 8, 8, 16, 8, 0, 0, 0, 0, 0, rc, gc, bc); @@ -1014,19 +979,14 @@ bool S2X_init(int monid, int dw, int dh, int dd) amiga_height = vb->outheight; amiga_depth = vb->pixbytes * 8; - if (d3d) { - int mh = currprefs.gf[ad->picasso_on].gfx_filter_filtermodeh + 1; - if (mh < scale) - mh = scale; - temp_width = dst_width * mh; - int mv = currprefs.gf[ad->picasso_on].gfx_filter_filtermodev + 1; - if (mv < scale) - mv = scale; - temp_height = dst_height * mv; - } else { - temp_width = dst_width * 2; - temp_height = dst_height * 2; - } + int mh = currprefs.gf[ad->picasso_on].gfx_filter_filtermodeh + 1; + if (mh < scale) + mh = scale; + temp_width = dst_width * mh; + int mv = currprefs.gf[ad->picasso_on].gfx_filter_filtermodev + 1; + if (mv < scale) + mv = scale; + temp_height = dst_height * mv; if (usedfilter->type == UAE_FILTER_HQ2X || usedfilter->type == UAE_FILTER_HQ3X || usedfilter->type == UAE_FILTER_HQ4X) { int w = amiga_width > dst_width ? amiga_width : dst_width; @@ -1034,41 +994,6 @@ bool S2X_init(int monid, int dw, int dh, int dd) tempsurf2 = xmalloc (uae_u8, w * h * (amiga_depth / 8) * ((scale + 1) / 2)); tempsurf3 = xmalloc (uae_u8, w * h *(dst_depth / 8) * 4 * scale); } - if (!d3d) { - for (;;) { - if (temp_width > dxcaps.maxwidth) - temp_width = dxcaps.maxwidth; - if (temp_height > dxcaps.maxheight) - temp_height = dxcaps.maxheight; - if (temp_width < dst_width) - temp_width = dst_width; - if (temp_height < dst_height) - temp_height = dst_height; - tempsurf = allocsurface(temp_width, temp_height); - if (tempsurf) - break; - if (temp_width >= 2 * dst_width || temp_height >= 2 * dst_height) { - temp_width = dst_width * 3 / 2; - temp_height = dst_height * 3 / 2; - continue; - } - if (temp_width == dst_width * 3 / 2 || temp_height == dst_height * 2) { - temp_width = dst_width * 4 / 3; - temp_height = dst_height * 4 / 3; - continue; - } - if (temp_width > dst_width || temp_height > dst_height) { - temp_width = dst_width; - temp_height = dst_height; - continue; - } - break; - } - } - if (!tempsurf && !d3d) { - write_log (_T("DDRAW: failed to create temp surface (%dx%d)\n"), temp_width, temp_height); - return false; - } inited = true; return true; } @@ -1083,8 +1008,6 @@ void S2X_render(int monid, int y_start, int y_end) int aw, ah, aws, ahs; uae_u8 *dptr, *enddptr, *sptr, *endsptr; int ok = 0; - RECT sr, dr, zr; - DDSURFACEDESC2 desc; int pitch, surf_height; uae_u8 *surfstart; @@ -1104,30 +1027,14 @@ void S2X_render(int monid, int y_start, int y_end) endsptr = vb->bufmemend; bufmem_ptr = sptr; - if (d3d) { - if (D3D_restore) - D3D_restore(monid, true); - surfstart = D3D_locktexture(monid, &pitch, &surf_height, y_start < -1 ? -1 : (y_start < 0 ? 1 : 0)); - if (surfstart == NULL) - return; - } else { - if (tempsurf == NULL) - return; - if (cleartemp) { - DirectDraw_ClearSurface (tempsurf); - cleartemp = 0; - } - if (!DirectDraw_LockSurface (tempsurf, &desc)) - return; - pitch = desc.lPitch; - surfstart = (uae_u8*)desc.lpSurface; - surf_height = desc.dwHeight; + if (D3D_restore) + D3D_restore(monid, true); + surfstart = D3D_locktexture(monid, &pitch, &surf_height, y_start < -1 ? -1 : (y_start < 0 ? 1 : 0)); + if (surfstart == NULL) { + return; } dptr = surfstart; enddptr = dptr + pitch * surf_height; - if (!d3d) { - dptr = getfilterrect1 (&sr, &dr, dst_width, dst_height, dst_depth, aw, ah, scale, temp_width, temp_height, dptr, pitch); - } if (!dptr) /* weird things can happen */ goto end; @@ -1275,33 +1182,13 @@ void S2X_render(int monid, int y_start, int y_end) usedfilter = &uaefilters[0]; changed_prefs.gf[ad->picasso_on].gfx_filter = usedfilter->type; } - -end: - if (d3d) { - ;//D3D_unlocktexture (); unlock in win32gfx.c - } else { - DirectDraw_UnlockSurface (tempsurf); - - getfilterrect2(monid, &dr, &sr, &zr, dst_width, dst_height, aw, ah, scale, temp_width, temp_height); - //write_log (_T("(%d %d %d %d) - (%d %d %d %d) (%d %d)\n"), dr.left, dr.top, dr.right, dr.bottom, sr.left, sr.top, sr.right, sr.bottom, zr.left, zr.top); - OffsetRect (&sr, zr.left, zr.top); - if (sr.left < 0) - sr.left = 0; - if (sr.top < 0) - sr.top = 0; - if (sr.right <= temp_width && sr.bottom <= temp_height) { - if (sr.left < sr.right && sr.top < sr.bottom) - DirectDraw_BlitRect (NULL, &dr, tempsurf, &sr); - } - statusline(monid); - } +end:; } void S2X_refresh(int monid) { if (monid) return; - DirectDraw_ClearSurface(NULL); S2X_render(monid, -1, -1); } diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index 09d84c9e..e2b22b10 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -1,4 +1,5 @@ /* +/* * UAE - The Un*x Amiga Emulator * * Win32 Drawing and DirectX interface @@ -16,7 +17,6 @@ #include #include -#include #include #include #include @@ -37,7 +37,7 @@ #include "xwin.h" #include "keyboard.h" #include "drawing.h" -#include "dxwrap.h" +#include "render.h" #include "picasso96_win.h" #include "registry.h" #include "win32.h" @@ -67,8 +67,6 @@ #define DM_W_FULLSCREEN 2 #define DM_D3D_FULLSCREEN 16 #define DM_PICASSO96 32 -#define DM_DDRAW 64 -#define DM_DC 128 #define DM_D3D 256 #define DM_SWSCALE 1024 @@ -130,11 +128,6 @@ static int isscreen(struct AmigaMonitor *mon) return mon->hMainWnd ? 1 : 0; } -static void clearscreen (void) -{ - DirectDraw_FillPrimary (); -} - static int isfullscreen_2(struct uae_prefs *p) { struct AmigaMonitor *mon = &AMonitors[0]; @@ -634,17 +627,6 @@ void getgfxoffset(int monid, float *dxp, float *dyp, float *mxp, float *myp) *myp = 1.0f / my; } -void DX_Fill(struct AmigaMonitor *mon, int dstx, int dsty, int width, int height, uae_u32 color) -{ - RECT dstrect; - if (width < 0) - width = mon->currentmode.current_width; - if (height < 0) - height = mon->currentmode.current_height; - SetRect (&dstrect, dstx, dsty, dstx + width, dsty + height); - DirectDraw_Fill (&dstrect, color); -} - static int rgbformat_bits (RGBFTYPE t) { unsigned long f = 1 << t; @@ -681,86 +663,6 @@ int getrefreshrate(int monid, int width, int height) return freq; } -static int set_ddraw_2(struct AmigaMonitor *mon) -{ - struct amigadisplay *ad = &adisplays[mon->monitor_id]; - struct picasso96_state_struct *state = &picasso96_state[mon->monitor_id]; - - HRESULT ddrval; - int bits = (mon->currentmode.current_depth + 7) & ~7; - int width = mon->currentmode.native_width; - int height = mon->currentmode.native_height; - int dxfullscreen, wfullscreen, dd; - struct apmode *ap = ad->picasso_on ? &currprefs.gfx_apmode[APMODE_RTG] : &currprefs.gfx_apmode[APMODE_NATIVE]; - int freq = ap->gfx_refreshrate; - - dxfullscreen = (mon->currentmode.flags & DM_DX_FULLSCREEN) ? TRUE : FALSE; - wfullscreen = (mon->currentmode.flags & DM_W_FULLSCREEN) ? TRUE : FALSE; - dd = (mon->currentmode.flags & DM_DDRAW) ? TRUE : FALSE; - - if (WIN32GFX_IsPicassoScreen(mon) && (state->Width > width || state->Height > height)) { - width = state->Width; - height = state->Height; - } - - DirectDraw_FreeMainSurface (); - - if (!dd && !dxfullscreen) - return 1; - - ddrval = DirectDraw_SetCooperativeLevel (mon->hAmigaWnd, dxfullscreen, TRUE); - if (FAILED (ddrval)) - goto oops; - - if (dxfullscreen) { - for (;;) { - HRESULT olderr; - freq = getrefreshrate(mon->monitor_id, width, height); - write_log (_T("set_ddraw: trying %dx%d, bits=%d, refreshrate=%d\n"), width, height, bits, freq); - ddrval = DirectDraw_SetDisplayMode (width, height, bits, freq); - if (SUCCEEDED (ddrval)) - break; - olderr = ddrval; - if (freq) { - write_log (_T("set_ddraw: failed, trying without forced refresh rate\n")); - freq = 0; - DirectDraw_SetCooperativeLevel (mon->hAmigaWnd, dxfullscreen, TRUE); - ddrval = DirectDraw_SetDisplayMode (width, height, bits, freq); - if (SUCCEEDED (ddrval)) - break; - } - if (olderr != DDERR_INVALIDMODE && olderr != 0x80004001 && olderr != DDERR_UNSUPPORTEDMODE) - goto oops; - return -1; - } - mon->currentmode.freq = freq; - updatewinrect(mon, true); - } - - if (dd) { - ddrval = DirectDraw_CreateClipper (); - if (FAILED (ddrval)) - goto oops; - ddrval = DirectDraw_CreateMainSurface (width, height); - if (FAILED(ddrval)) { - write_log (_T("set_ddraw: couldn't CreateSurface() for primary because %s.\n"), DXError (ddrval)); - goto oops; - } - ddrval = DirectDraw_SetClipper(mon->hAmigaWnd); - if (FAILED (ddrval)) - goto oops; - if (DirectDraw_SurfaceLock ()) { - mon->currentmode.pitch = DirectDraw_GetSurfacePitch (); - DirectDraw_SurfaceUnlock (); - } - } - - write_log (_T("set_ddraw: %dx%d@%d-bytes\n"), width, height, bits); - return 1; -oops: - return 0; -} - static void addmode (struct MultiDisplay *md, DEVMODE *dm, int rawmode) { int ct; @@ -1363,7 +1265,7 @@ bool render_screen(int monid, int mode, bool immediate) int cnt; mon->render_ok = false; - if (minimized || ad->picasso_on || monitor_off || dx_islost ()) { + if (minimized || ad->picasso_on || monitor_off) { return mon->render_ok; } cnt = 0; @@ -1382,8 +1284,6 @@ bool render_screen(int monid, int mode, bool immediate) } else if (mon->currentmode.flags & DM_SWSCALE) { S2X_render(monid, -1, -1); v = true; - } else if (mon->currentmode.flags & DM_DDRAW) { - v = true; } mon->render_ok = v; gfx_unlock(); @@ -1552,33 +1452,11 @@ void show_screen(int monid, int mode) D3D_showframe_special(0, 2); } } -#ifdef GFXFILTER - } else if (mon->currentmode.flags & DM_SWSCALE) { - if (!dx_islost () && !ad->picasso_on) - DirectDraw_Flip(1); -#endif - } else if (mon->currentmode.flags & DM_DDRAW) { - if (!dx_islost () && !ad->picasso_on) - DirectDraw_Flip(1); } gfx_unlock(); mon->render_ok = false; } -static uae_u8 *ddraw_dolock (void) -{ - struct vidbuf_description *avidinfo = &adisplays[0].gfxvidinfo; - if (!DirectDraw_SurfaceLock ()) { - dx_check (); - return 0; - } - avidinfo->outbuffer->bufmem = DirectDraw_GetSurfacePointer (); - avidinfo->outbuffer->rowbytes = DirectDraw_GetSurfacePitch (); - init_row_map (); - clear_inhibit_frame(0, IHF_WINDOWHIDDEN); - return avidinfo->outbuffer->bufmem; -} - bool lockscr3d(struct vidbuffer *vb) { struct AmigaMonitor *mon = &AMonitors[vb->monitor_id]; @@ -1631,8 +1509,6 @@ int lockscr(struct vidbuffer *vb, bool fullupdate, bool first, bool skip) #endif } else if (mon->currentmode.flags & DM_SWSCALE) { ret = 1; - } else if (mon->currentmode.flags & DM_DDRAW) { - ret = ddraw_dolock() != 0; } gfx_unlock(); return ret; @@ -1649,11 +1525,6 @@ void unlockscr(struct vidbuffer *vb, int y_start, int y_end) vb->bufmem = NULL; } D3D_unlocktexture(vb->monitor_id, y_start, y_end); - } else if (mon->currentmode.flags & DM_SWSCALE) { - return; - } else if (mon->currentmode.flags & DM_DDRAW) { - DirectDraw_SurfaceUnlock(); - vb->bufmem = NULL; } gfx_unlock(); } @@ -1718,10 +1589,8 @@ static void DX_Blit96(struct AmigaMonitor *mon, int x, int y, int w, int h) } picasso_offset_mx = (float)state->Width / (dr.right - dr.left); picasso_offset_my = (float)state->Height / (dr.bottom - dr.top); - DirectDraw_BlitToPrimaryScale (&dr, &sr); } else { SetRect (&sr, x, y, x + w, y + h); - DirectDraw_BlitToPrimary (&sr); } } @@ -1810,19 +1679,10 @@ void getrtgfilterrect2(int monid, RECT *sr, RECT *dr, RECT *zr, int dst_width, i static uae_u8 *gfx_lock_picasso2(int monid, bool fullupdate) { struct picasso_vidbuf_description *vidinfo = &picasso_vidinfo[monid]; - if (currprefs.gfx_api) { - int pitch; - uae_u8 *p = D3D_locktexture(monid, &pitch, NULL, fullupdate); - vidinfo->rowbytes = pitch; - return p; - } else { - if (!DirectDraw_SurfaceLock ()) { - dx_check (); - return 0; - } - vidinfo->rowbytes = DirectDraw_GetSurfacePitch (); - return DirectDraw_GetSurfacePointer (); - } + int pitch; + uae_u8 *p = D3D_locktexture(monid, &pitch, NULL, fullupdate); + vidinfo->rowbytes = pitch; + return p; } uae_u8 *gfx_lock_picasso(int monid, bool fullupdate) { @@ -1848,35 +1708,22 @@ void gfx_unlock_picasso(int monid, bool dorender) if (!mon->rtg_locked) gfx_lock(); mon->rtg_locked = false; - if (currprefs.gfx_api) { - if (dorender) { - if (mon->p96_double_buffer_needs_flushing) { - D3D_flushtexture(monid, mon->p96_double_buffer_first, mon->p96_double_buffer_last); - mon->p96_double_buffer_needs_flushing = 0; - } + if (dorender) { + if (mon->p96_double_buffer_needs_flushing) { + D3D_flushtexture(monid, mon->p96_double_buffer_first, mon->p96_double_buffer_last); + mon->p96_double_buffer_needs_flushing = 0; } - D3D_unlocktexture(monid, -1, -1); - if (dorender) { - if (D3D_renderframe(monid, true, false)) { - gfx_unlock(); - mon->render_ok = true; - show_screen_maybe(monid, true); - } else { - gfx_unlock(); - } + } + D3D_unlocktexture(monid, -1, -1); + if (dorender) { + if (D3D_renderframe(monid, true, false)) { + gfx_unlock(); + mon->render_ok = true; + show_screen_maybe(monid, true); } else { gfx_unlock(); } } else { - DirectDraw_SurfaceUnlock (); - if (dorender) { - if (mon->p96_double_buffer_needs_flushing) { - DX_Blit96(mon, mon->p96_double_buffer_firstx, mon->p96_double_buffer_first, - mon->p96_double_buffer_lastx - mon->p96_double_buffer_firstx + 1, - mon->p96_double_buffer_last - mon->p96_double_buffer_first + 1); - mon->p96_double_buffer_needs_flushing = 0; - } - } gfx_unlock(); } } @@ -1975,10 +1822,9 @@ static bool canmatchdepth(void) static void updatemodes(struct AmigaMonitor *mon) { struct uae_filter *usedfilter = mon->usedfilter; - DWORD flags; + DWORD flags = 0; mon->currentmode.fullfill = 0; - flags = DM_DDRAW; if (isfullscreen () > 0) flags |= DM_DX_FULLSCREEN; else if (isfullscreen () < 0) @@ -1990,13 +1836,10 @@ static void updatemodes(struct AmigaMonitor *mon) mon->currentmode.current_depth = 16; } #endif - if (currprefs.gfx_api) { - flags |= DM_D3D; - if (flags & DM_DX_FULLSCREEN) { - flags &= ~DM_DX_FULLSCREEN; - flags |= DM_D3D_FULLSCREEN; - } - flags &= ~DM_DDRAW; + flags |= DM_D3D; + if (flags & DM_DX_FULLSCREEN) { + flags &= ~DM_DX_FULLSCREEN; + flags |= DM_D3D_FULLSCREEN; } mon->currentmode.flags = flags; if (flags & DM_SWSCALE) @@ -2157,8 +2000,6 @@ static int open_windows(struct AmigaMonitor *mon, bool mousecapture, bool starte D3D_free(mon->monitor_id, false); gfx_unlock(); #endif - if (!DirectDraw_Start()) - return 0; int init_round = 0; ret = -2; @@ -2170,14 +2011,11 @@ static int open_windows(struct AmigaMonitor *mon, bool mousecapture, bool starte ret = doInit(mon); init_round++; if (ret < -9) { - DirectDraw_Release(); - if (!DirectDraw_Start()) - return 0; + return 0; } } while (ret < 0); if (!ret) { - DirectDraw_Release(); return ret; } @@ -2233,8 +2071,6 @@ static int open_windows(struct AmigaMonitor *mon, bool mousecapture, bool starte static void reopen_gfx(struct AmigaMonitor *mon) { open_windows(mon, false, true); - if (isfullscreen () <= 0) - DirectDraw_FillPrimary (); render_screen(mon->monitor_id, 1, true); } @@ -2528,8 +2364,6 @@ int check_prefs_changed_gfx (void) inputdevice_unacquire(); unacquired = true; } - DirectDraw_Fill(NULL, 0); - DirectDraw_BlitToPrimary(NULL); } if (c & 256) { init_colors(mon->monitor_id); @@ -2772,19 +2606,8 @@ void init_colors(int monid) { struct AmigaMonitor *mon = &AMonitors[monid]; /* init colors */ - if (mon->currentmode.flags & DM_D3D) { - D3D_getpixelformat (mon->currentmode.current_depth, - &red_bits, &green_bits, &blue_bits, &red_shift, &green_shift, &blue_shift, &alpha_bits, &alpha_shift, &alpha); - } else { - red_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (red_mask)); - green_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (green_mask)); - blue_bits = bits_in_mask (DirectDraw_GetPixelFormatBitMask (blue_mask)); - red_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (red_mask)); - green_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (green_mask)); - blue_shift = mask_shift (DirectDraw_GetPixelFormatBitMask (blue_mask)); - alpha_bits = 0; - alpha_shift = 0; - } + D3D_getpixelformat (mon->currentmode.current_depth, + &red_bits, &green_bits, &blue_bits, &red_shift, &green_shift, &blue_shift, &alpha_bits, &alpha_shift, &alpha); if (!(mon->currentmode.flags & (DM_D3D))) { if (mon->currentmode.current_depth != mon->currentmode.native_depth) { @@ -3085,8 +2908,6 @@ static int modeswitchneeded(struct AmigaMonitor *mon, struct winuae_currentmode return -1; } else { /* fullwindow to fullwindow */ - DirectDraw_Fill (NULL, 0); - DirectDraw_BlitToPrimary (NULL); if (mon->screen_is_picasso) { if (currprefs.gf[1].gfx_filter_autoscale && ((wc->native_width > state->Width && wc->native_height >= state->Height) || (wc->native_height > state->Height && wc->native_width >= state->Width))) return -1; @@ -3124,7 +2945,6 @@ void gfx_set_picasso_state(int monid, int on) updatemodes(mon); update_gfxparams(mon); - clearscreen(); // if filter changes, need to reset mode = 0; @@ -3189,7 +3009,6 @@ void gfx_set_picasso_modeinfo(int monid, RGBFTYPE rgbfmt) int need; if (!mon->screen_is_picasso) return; - clearscreen(); gfx_set_picasso_colors(monid, rgbfmt); updatemodes(mon); need = modeswitchneeded(mon, &mon->currentmode); @@ -3326,7 +3145,6 @@ void close_windows(struct AmigaMonitor *mon) #endif freevidbuffer(mon->monitor_id, &avidinfo->drawbuffer); freevidbuffer(mon->monitor_id, &avidinfo->tempbuffer); - DirectDraw_Release(); close_hwnds(mon); } @@ -3552,10 +3370,8 @@ float target_getcurrentvblankrate(int monid) return (float)mon->currentmode.freq; if (get_display_vblank_params(-1, NULL, NULL, &vb, NULL)) { return vb; - } else if (currprefs.gfx_api) { - return D3D_getrefreshrate(0); } else { - return (float)DirectDraw_CurrentRefreshRate(); + return D3D_getrefreshrate(0); } } @@ -3627,7 +3443,7 @@ static void getextramonitorpos(struct AmigaMonitor *mon, RECT *r) r->right = r->left + width; } -static int create_windows_2(struct AmigaMonitor *mon) +static int create_windows(struct AmigaMonitor *mon) { static bool firstwindow = true; int dxfs = mon->currentmode.flags & (DM_DX_FULLSCREEN); @@ -3985,26 +3801,6 @@ static int create_windows_2(struct AmigaMonitor *mon) return 1; } -static int set_ddraw(struct AmigaMonitor *mon) -{ - int cnt, ret; - - cnt = 3; - for (;;) { - ret = set_ddraw_2(mon); - if (cnt-- <= 0) - return 0; - if (ret < 0) { - getbestmode(mon, 1); - continue; - } - if (ret == 0) - return 0; - break; - } - return 1; -} - static void allocsoftbuffer(int monid, const TCHAR *name, struct vidbuffer *buf, int flags, int width, int height, int depth) { struct vidbuf_description *vidinfo = &adisplays[monid].gfxvidinfo; @@ -4042,14 +3838,6 @@ static void allocsoftbuffer(int monid, const TCHAR *name, struct vidbuffer *buf, } } -static int create_windows(struct AmigaMonitor *mon) -{ - if (!create_windows_2(mon)) - return 0; - - return set_ddraw(mon); -} - static int oldtex_w[MAX_AMIGAMONITORS], oldtex_h[MAX_AMIGAMONITORS], oldtex_rtg[MAX_AMIGAMONITORS]; static BOOL doInit(struct AmigaMonitor *mon) @@ -4079,43 +3867,6 @@ retry: mon->currentmode.native_width = rc.right - rc.left; mon->currentmode.native_height = rc.bottom - rc.top; } - - if (isfullscreen() <= 0 && !(mon->currentmode.flags & (DM_D3D))) { - mon->currentmode.current_depth = DirectDraw_GetCurrentDepth (); - updatemodes(mon); - } - if (!(mon->currentmode.flags & (DM_D3D)) && DirectDraw_GetCurrentDepth () == mon->currentmode.current_depth) { - updatemodes(mon); - } -#if 0 - TCHAR tmpstr[300]; - int fs_warning = -1; - if (!rp_isactive () && (mon->currentmode.current_width > GetSystemMetrics(SM_CXVIRTUALSCREEN) || - mon->currentmode.current_height > GetSystemMetrics(SM_CYVIRTUALSCREEN))) { - if (!console_logging) - fs_warning = IDS_UNSUPPORTEDSCREENMODE_3; - } - if (fs_warning >= 0 && isfullscreen () <= 0) { - TCHAR szMessage[MAX_DPATH], szMessage2[MAX_DPATH]; - WIN32GUI_LoadUIString(IDS_UNSUPPORTEDSCREENMODE, szMessage, MAX_DPATH); - WIN32GUI_LoadUIString(fs_warning, szMessage2, MAX_DPATH); - // Temporarily drop the DirectDraw stuff - DirectDraw_Release (); - _stprintf (tmpstr, szMessage, szMessage2); - gui_message (tmpstr); - DirectDraw_Start (); - if (mon->screen_is_picasso) - changed_prefs.gfx_apmode[1].gfx_fullscreen = currprefs.gfx_apmode[1].gfx_fullscreen = GFX_FULLSCREEN; - else - changed_prefs.gfx_apmode[0].gfx_fullscreen = currprefs.gfx_apmode[0].gfx_fullscreen = GFX_FULLSCREEN; - updatewinfsmode(mon->monitor_id, &currprefs); - updatewinfsmode(mon->monitor_id, &changed_prefs); - mon->currentmode.current_depth = tmp_depth; - updatemodes(mon); - ret = -2; - goto oops; - } -#endif if (!create_windows(mon)) goto oops; #ifdef PICASSO96 @@ -4238,12 +3989,16 @@ retry: } if (err) { D3D_free(0, true); - error_log(_T("Direct3D9 failed to initialize ('%s'), falling back to DirectDraw."), err); - changed_prefs.gfx_api = currprefs.gfx_api = 0; - changed_prefs.gf[ad->picasso_on].gfx_filter = currprefs.gf[ad->picasso_on].gfx_filter = 1; + if (isfullscreen() > 0) { + int idx = mon->screen_is_picasso ? 1 : 0; + changed_prefs.gfx_apmode[idx].gfx_fullscreen = currprefs.gfx_apmode[idx].gfx_fullscreen = GFX_FULLWINDOW; + } else if (currprefs.gfx_api > 0) { + error_log(_T("Direct3D9 failed to initialize ('%s'), falling back to GDI."), err); + changed_prefs.gfx_api = currprefs.gfx_api = 0; + changed_prefs.gf[ad->picasso_on].gfx_filter = currprefs.gf[ad->picasso_on].gfx_filter = 1; + } mon->currentmode.current_depth = mon->currentmode.native_depth; gfxmode_reset(mon->monitor_id); - DirectDraw_Start(); ret = -1; goto oops; } @@ -4305,13 +4060,9 @@ bool target_graphics_buffer_update(int monid) } S2X_free(mon->monitor_id); - if (mon->currentmode.flags & DM_D3D) { - if (!D3D_alloctexture(mon->monitor_id, w, h)) { - graphicsbuffer_retry = true; - return false; - } - } else { - DirectDraw_ClearSurface (NULL); + if (!D3D_alloctexture(mon->monitor_id, w, h)) { + graphicsbuffer_retry = true; + return false; } oldtex_w[monid] = w; @@ -4333,24 +4084,7 @@ static void updatedisplayarea2(int monid) struct amigadisplay *ad = &adisplays[monid]; if (!mon->screen_is_initialized) return; - if (dx_islost()) - return; -#if defined (GFXFILTER) - if (mon->currentmode.flags & DM_D3D) { -#if defined (D3D) - D3D_refresh(monid); -#endif - } else -#endif - if (mon->currentmode.flags & DM_DDRAW) { -#if defined (GFXFILTER) - if (!ad->picasso_on) { - if (mon->currentmode.flags & DM_SWSCALE) - S2X_refresh(monid); - } -#endif - DirectDraw_Flip(0); - } + D3D_refresh(monid); } void updatedisplayarea(int monid) @@ -4553,22 +4287,38 @@ HDC gethdc(int monid) { HDC hdc = 0; -#ifdef D3D if (D3D_isenabled(0)) return D3D_getDC(monid, 0); -#endif - if(FAILED(DirectDraw_GetDC(&hdc))) - hdc = 0; return hdc; } void releasehdc(int monid, HDC hdc) { -#ifdef D3D if (D3D_isenabled(0)) { D3D_getDC(monid, hdc); return; } -#endif - DirectDraw_ReleaseDC(hdc); +} + +TCHAR *outGUID(const GUID *guid) +{ + static TCHAR gb[64]; + if (guid == NULL) + return _T("NULL"); + _stprintf(gb, _T("{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}"), + guid->Data1, guid->Data2, guid->Data3, + guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3], + guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7]); + return gb; +} + +const TCHAR *DXError(HRESULT ddrval) +{ + static TCHAR dderr[1000]; + _stprintf(dderr, _T("%08X S=%d F=%04X C=%04X (%d)"), + ddrval, (ddrval & 0x80000000) ? 1 : 0, + HRESULT_FACILITY(ddrval), + HRESULT_CODE(ddrval), + HRESULT_CODE(ddrval)); + return dderr; } diff --git a/od-win32/win32gui.cpp b/od-win32/win32gui.cpp index 59daa8a2..fb0d5aad 100644 --- a/od-win32/win32gui.cpp +++ b/od-win32/win32gui.cpp @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -59,7 +58,7 @@ #include "drawing.h" #include "fsdb.h" #include "blkdev.h" -#include "dxwrap.h" +#include "render.h" #include "win32.h" #include "registry.h" #include "picasso96_win.h" @@ -2313,7 +2312,7 @@ static void flipgui(int opengui) if (full_property_sheet) return; if (opengui) { - DirectDraw_FlipToGDISurface(); + ; } else { if (quit_program) return; @@ -12480,13 +12479,7 @@ static void misc_gui_font (HWND hDlg, int fonttype) static void values_to_miscdlg_dx(HWND hDlg) { xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_RESETCONTENT, 0, 0); - if (workprefs.gfx_api == 0) { - xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("NonLocalVRAM")); - xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("DefaultRAM *")); - xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("LocalVRAM")); - xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("SystemRAM")); - xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_SETCURSEL, ddforceram, 0); - } else if (workprefs.gfx_api >= 2) { + if (workprefs.gfx_api >= 2) { xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("Hardware D3D11")); xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_ADDSTRING, 0, (LPARAM)_T("Software D3D11")); xSendDlgItemMessage(hDlg, IDC_DXMODE_OPTIONS, CB_SETCURSEL, workprefs.gfx_api_options, 0); @@ -12511,7 +12504,7 @@ static void values_to_miscdlg (HWND hDlg) misc_lang (hDlg); xSendDlgItemMessage(hDlg, IDC_DXMODE, CB_RESETCONTENT, 0, 0); - xSendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("DirectDraw")); + xSendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("GDI")); xSendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("Direct3D 9")); xSendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("Direct3D 11")); xSendDlgItemMessage(hDlg, IDC_DXMODE, CB_ADDSTRING, 0, (LPARAM)_T("Direct3D 11 HDR (experimental)")); @@ -12585,12 +12578,15 @@ static void setdefaultguisize(int skipdpi) int dpi = skipdpi ? 96 : getdpiformonitor(NULL); int w, h; + int dw = GetSystemMetrics(SM_CXVIRTUALSCREEN); + int dh = GetSystemMetrics(SM_CYVIRTUALSCREEN); + getguidefaultsize(&w, &h); gui_width = MulDiv(w, dpi, 96); gui_height = MulDiv(h, dpi, 96); - if ((dpi > 96) && (gui_width > w || gui_height > h)) { + if ((dpi > 96) && (gui_width >= dw * 9 / 10 || gui_height > dh * 9 / 10)) { gui_width = w; gui_height = h; } @@ -12788,9 +12784,6 @@ static INT_PTR MiscDlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) if (v != CB_ERR) { if (workprefs.gfx_api >= 2) { workprefs.gfx_api_options = v; - } else if (!workprefs.gfx_api) { - ddforceram = v; - regsetint(NULL, _T("DirectDraw_Secondary"), ddforceram); } } break; @@ -22375,7 +22368,6 @@ static int GetSettings (int all_options, HWND hwnd) regexists = regqueryint (NULL, _T("GUIResize"), &v); gui_fullscreen = 0; gui_resize_allowed = true; - gui_resize_enabled = v != 0; v = 0; regqueryint(NULL, _T("GUIFullscreen"), &v); if (v) { @@ -22395,7 +22387,7 @@ static int GetSettings (int all_options, HWND hwnd) regsetint (NULL, _T("GUIResize"), 0); regsetint (NULL, _T("GUIFullscreen"), 0); } else { - if (gui_width < MIN_GUI_INTERNAL_WIDTH || gui_width > 4096 || gui_height < MIN_GUI_INTERNAL_HEIGHT || gui_height > 4096) { + if (gui_width < MIN_GUI_INTERNAL_WIDTH || gui_width > 8192 || gui_height < MIN_GUI_INTERNAL_HEIGHT || gui_height > 8192) { scaleresource_setdefaults(hwnd); setdefaultguisize(resetcount > 0); resetcount++; @@ -22421,7 +22413,7 @@ static int GetSettings (int all_options, HWND hwnd) int w = md->rect.right - md->rect.left; int h = md->rect.bottom - md->rect.top; write_log(_T("GUI Fullscreen, screen size %dx%d (%dx%d)\n"), w, h, start_gui_width, start_gui_height); - if (w < (start_gui_width / 10 * 9) || h < (start_gui_height / 10 * 9)) { + if (w < (start_gui_width * 9 / 10) || h < (start_gui_height * 9 / 10)) { gui_width = start_gui_width; gui_height = start_gui_height; write_log(_T("GUI Fullscreen %dx%d, closing fullscreen.\n"), gui_width, gui_height); @@ -22986,16 +22978,6 @@ static int fsdialog (HWND *hwnd, DWORD *flags) *flags |= MB_SETFOREGROUND; *flags |= MB_TOPMOST; return 0; - /* - HRESULT hr; - hr = DirectDraw_FlipToGDISurface(); - if (FAILED(hr)) { - write_log (_T("FlipToGDISurface failed, %s\n"), DXError (hr)); - return 0; - } - *hwnd = NULL; - return 1; - */ } int gui_message_multibutton (int flags, const TCHAR *format,...) diff --git a/od-win32/win32gui_extra.cpp b/od-win32/win32gui_extra.cpp index 3262d354..209481e7 100644 --- a/od-win32/win32gui_extra.cpp +++ b/od-win32/win32gui_extra.cpp @@ -1556,7 +1556,7 @@ static void boxartpaint(HDC hdc, HWND hwnd) Gdiplus::Rect d(x1, y1, x2, y2); graphics.DrawImage(img, d); - Gdiplus::Rect d2(x1 - 1, y1 - 1, x2 + 1, y2 + 1); + Gdiplus::Rect d2(x1 - 1, y1 - 1, x2 + 2, y2 + 2); if (im->metafile) { graphics.DrawRectangle(&pen2, d2); } else { diff --git a/od-win32/winuae_msvc15/winuae_msvc.vcxproj b/od-win32/winuae_msvc15/winuae_msvc.vcxproj index ab3ba589..5d086033 100644 --- a/od-win32/winuae_msvc15/winuae_msvc.vcxproj +++ b/od-win32/winuae_msvc15/winuae_msvc.vcxproj @@ -99,7 +99,7 @@ Unicode v143 false - false + true @@ -270,13 +270,13 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName)$(TargetExt) true %(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\ %(AdditionalManifestDependencies) %(IgnoreSpecificDefaultLibraries) - d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;ddraw.dll;Iphlpapi.dll;gdiplus.dll;%(DelayLoadDLLs) + d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;Iphlpapi.dll;gdiplus.dll;%(DelayLoadDLLs) true .\Release/winuae.pdb Windows @@ -351,13 +351,13 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName)$(TargetExt) true %(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\ %(AdditionalManifestDependencies) %(IgnoreSpecificDefaultLibraries) - d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;ddraw.dll;Iphlpapi.dll;gdiplus.dll;%(DelayLoadDLLs) + d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;Iphlpapi.dll;gdiplus.dll;%(DelayLoadDLLs) true .\Release/winuae.pdb Windows @@ -433,13 +433,13 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName)$(TargetExt) true %(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\ %(AdditionalManifestDependencies) %(IgnoreSpecificDefaultLibraries) - d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;ddraw.dll;Iphlpapi.dll;gdiplus.dll;%(DelayLoadDLLs) + d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;Iphlpapi.dll;gdiplus.dll;Msimg32.dll;%(DelayLoadDLLs) true .\Test/winuae.pdb Windows @@ -514,7 +514,7 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) NotSet $(OutDir)$(TargetName)$(TargetExt) true @@ -590,7 +590,7 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) NotSet $(OutDir)$(TargetName)$(TargetExt) true @@ -668,7 +668,7 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) NotSet $(OutDir)$(TargetName)$(TargetExt) true @@ -746,13 +746,13 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;winio.lib;setupapi.lib;wininet.lib;shlwapi.lib;libpng16.lib;lglcd.lib;openal32.lib;portaudio_x86.lib;vfw32.lib;wtsapi32.lib;enet.lib;lzmalib.lib;prowizard.lib;libFLAC_static.lib;hid.lib;zlibstat.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) $(OutDir)$(TargetName)$(TargetExt) true %(AdditionalLibraryDirectories);$(SolutionDir)\..\lib\ %(AdditionalManifestDependencies) %(IgnoreSpecificDefaultLibraries) - d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;ddraw.dll;Iphlpapi.dll;gdiplus.dll;%(DelayLoadDLLs) + d3dx9_43.dll;openal32.dll;portaudio_x86.dll;ws2_32.dll;msacm32.dll;wtsapi32.dll;dsound.dll;wininet.dll;Iphlpapi.dll;gdiplus.dll;%(DelayLoadDLLs) true .\FullRelease/winuae.pdb Windows @@ -827,7 +827,7 @@ 0x0409 - ws2_32.lib;ddraw.lib;dxguid.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;dxerr.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;%(AdditionalDependencies) + ws2_32.lib;winmm.lib;comctl32.lib;version.lib;vfw32.lib;msacm32.lib;dsound.lib;dinput8.lib;d3d9.lib;d3dx9.lib;setupapi.lib;wininet.lib;shlwapi.lib;zlibstat.lib;portaudio_x64.lib;openal32.lib;libpng16.lib;lglcd.lib;wtsapi32.lib;enet_x64.lib;prowizard_x64.lib;lzmalib.lib;libFLAC_static.lib;hid.lib;Iphlpapi.lib;luastatic.lib;libmpeg2_ff.lib;softfloat.lib;gdiplus.lib;effects11.lib;Msimg32.lib;%(AdditionalDependencies) NotSet $(OutDir)$(TargetName)$(TargetExt) true @@ -1052,10 +1052,10 @@ - + diff --git a/od-win32/winuae_msvc15/winuae_msvc.vcxproj.filters b/od-win32/winuae_msvc15/winuae_msvc.vcxproj.filters index f4fa914c..1606b48b 100644 --- a/od-win32/winuae_msvc15/winuae_msvc.vcxproj.filters +++ b/od-win32/winuae_msvc15/winuae_msvc.vcxproj.filters @@ -112,9 +112,6 @@ win32 - - win32 - win32 @@ -985,6 +982,9 @@ common + + win32 + diff --git a/sampler.cpp b/sampler.cpp index 0de6bfb9..22e2fb04 100644 --- a/sampler.cpp +++ b/sampler.cpp @@ -12,7 +12,7 @@ #include "custom.h" #include "sampler.h" -#include "dxwrap.h" +#include "render.h" #include