1313#include <d2d1.h>
1414#include <dxgi.h>
1515#include <stdlib.h>
16+ #include "VersionHelpers.h"
1617
1718/* Defining DEBUG or D2D_DEBUG will turn on debugging for Direct2D & Direct3D
1819// (if it's used). To see any output from them you'll need to install
@@ -193,6 +194,7 @@ typedef struct D2DGlobalState
193194 ID2D1HwndRenderTarget * pHwndTarget ; /* The guy that lets us render to a window */
194195 } NonLayered ;
195196 } RenderParams ;
197+ BOOL isWin10 ;
196198} D2DGlobalState ;
197199
198200/* We could statically allocate the state as a global, but that would
@@ -234,6 +236,7 @@ static D2DGlobalState* CreateGlobalState(HWND hwnd, HMODULE hD2D, ID2D1Factory*
234236 }
235237 ++ i ;
236238 }
239+ pState -> isWin10 = IsWindows10OrGreater ();
237240 if (!SetProp (hwnd , MAKEINTRESOURCE (D2D_PROP_ID ), (HANDLE )pState )) {
238241 free (pState );
239242 pState = NULL ;
@@ -622,8 +625,20 @@ static void D2DCommonPaintInternal(D2DGlobalState* pGlobalState)
622625 dirtyRect .bottom = ((pLastDirtyRow - pDirtyStart ) + 1 ) * scanlineSize ;
623626 drawRect .left = dirtyRect .left ;
624627 drawRect .right = dirtyRect .right ;
625- drawRect .top = dirtyRect .top ;
626- drawRect .bottom = dirtyRect .bottom ;
628+
629+ if ( pGlobalState -> isWin10 ) {
630+ drawRect .top = dirtyRect .top ;
631+ drawRect .bottom = dirtyRect .bottom ;
632+ }
633+ else {
634+ /* on win7 the update / scaling doesn't work correctly.
635+ // Only thing that seems to work at this point is if
636+ // we update the entire window. (jeffm)
637+ */
638+ drawRect .top = 0 ;
639+ drawRect .bottom = winHeight ;
640+ }
641+
627642
628643 DBG_TEXT ("%s - dirty rect L-%lu, T-%lu, R-%lu, B-%lu" , dirtyRect .left , dirtyRect .top , dirtyRect .right , dirtyRect .bottom );
629644
@@ -640,6 +655,14 @@ static void D2DCommonPaintInternal(D2DGlobalState* pGlobalState)
640655
641656 ID2D1Bitmap_CopyFromMemory (pBackBuffer , & dirtyRect , pBitmapDataSrc , stride );
642657
658+ if ( !pGlobalState -> isWin10 )
659+ {
660+ /* win7 seems to handle ID2D1RenderTarget_DrawBitmap() differently
661+ // than on win10. Force the DPI for the render target otherwise
662+ // we get weird scaling when system is in a high-dpi mode (jeffm).
663+ */
664+ ID2D1RenderTarget_SetDpi ( pRT , 96 , 96 );
665+ }
643666 ID2D1RenderTarget_BeginDraw (pRT );
644667 ID2D1RenderTarget_DrawBitmap (pRT , pBackBuffer , & drawRect , 1.0f , D2D1_BITMAP_INTERPOLATION_MODE_LINEAR , & drawRect );
645668 if (pGlobalState -> Paint )
0 commit comments