Skip to content

Commit

Permalink
make hdc cache unconditional, check for null in sndplaysound, fix rle…
Browse files Browse the repository at this point in the history
… size in (stretch|set)dibits (#1069)
  • Loading branch information
cracyc authored Dec 12, 2021
1 parent 7ceaa99 commit 6bce5cc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 22 deletions.
34 changes: 31 additions & 3 deletions gdi/gdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3909,9 +3909,23 @@ INT16 WINAPI StretchDIBits16( HDC16 hdc, INT16 xDst, INT16 yDst, INT16 widthDst,
INT16 heightSrc, const VOID *bits,
const BITMAPINFO *info, UINT16 wUsage, DWORD dwRop )
{
return StretchDIBits( HDC_32(hdc), xDst, yDst, widthDst, heightDst,
BITMAPINFO *bmp = NULL;
HBITMAP16 ret;
if (((info->bmiHeader.biCompression == BI_RLE4) || (info->bmiHeader.biCompression == BI_RLE8)) && !info->bmiHeader.biSizeImage)
{
int hdrsize = info->bmiHeader.biSize + ((info->bmiHeader.biClrUsed ? info->bmiHeader.biClrUsed :
(info->bmiHeader.biBitCount == 4 ? 16 : 256)) * (wUsage == DIB_PAL_COLORS ? 2 : 4));

bmp = HeapAlloc(GetProcessHeap(), 0, hdrsize);
memcpy(bmp, info, hdrsize);
bmp->bmiHeader.biSizeImage = rle_size(info->bmiHeader.biCompression, bits);
}
ret = StretchDIBits( HDC_32(hdc), xDst, yDst, widthDst, heightDst,
xSrc, ySrc, widthSrc, heightSrc, bits,
info, wUsage, dwRop );
bmp ? bmp : info, wUsage, dwRop );
if (bmp)
HeapFree(GetProcessHeap(), 0, bmp);
return ret;
}


Expand Down Expand Up @@ -3954,8 +3968,22 @@ INT16 WINAPI SetDIBits16( HDC16 hdc, HBITMAP16 hbitmap, UINT16 startscan,
return lines;
}
}
BITMAPINFO *bmp = NULL;
HBITMAP16 ret;
if (((info->bmiHeader.biCompression == BI_RLE4) || (info->bmiHeader.biCompression == BI_RLE8)) && !info->bmiHeader.biSizeImage)
{
int hdrsize = info->bmiHeader.biSize + ((info->bmiHeader.biClrUsed ? info->bmiHeader.biClrUsed :
(info->bmiHeader.biBitCount == 4 ? 16 : 256)) * (coloruse == DIB_PAL_COLORS ? 2 : 4));

return SetDIBits( HDC_32(hdc), hbitmap32, startscan, lines, bits, info, coloruse );
bmp = HeapAlloc(GetProcessHeap(), 0, hdrsize);
memcpy(bmp, info, hdrsize);
bmp->bmiHeader.biSizeImage = rle_size(info->bmiHeader.biCompression, bits);
}

ret = SetDIBits( HDC_32(hdc), hbitmap32, startscan, lines, bits, bmp ? bmp : info, coloruse );
if (bmp)
HeapFree(GetProcessHeap(), 0, bmp);
return ret;
}


Expand Down
2 changes: 1 addition & 1 deletion mmsystem/mmsystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ BOOL16 WINAPI sndPlaySound16(LPCSTR lpszSoundName, UINT16 uFlags)
BOOL16 retv;
DWORD lc;
char buf[36];
if ((uFlags & SND_MEMORY) && (*(DWORD *)(lpszSoundName + 4) < 36))
if (lpszSoundName && (uFlags & SND_MEMORY) && (*(DWORD *)(lpszSoundName + 4) < 36))
{
memset(buf, 0, 36);
memcpy(buf, lpszSoundName, *(DWORD *)(lpszSoundName + 4));
Expand Down
27 changes: 9 additions & 18 deletions user/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1172,28 +1172,19 @@ INT16 WINAPI ReleaseDC16( HWND16 hwnd, HDC16 hdc )
hwnd = HWND_16(GetDesktopWindow());
if (WindowFromDC(HDC_32(hdc)) != HWND_32(hwnd))
return 0;
if (GetExpWinVer16(GetExePtr(GetCurrentTask())) < 0x30a)
if (dcc.dcs[dcc.next])
{
if (dcc.dcs[dcc.next])
HDC16 oldhdc = dcc.dcs[dcc.next];
HDC16 oldhwnd = dcc.wnds[dcc.next];
if(ReleaseDC( WIN_Handle32(oldhwnd), HDC_32(oldhdc) ) || !IsWindow(HWND_32(oldhwnd)))
{
HDC16 oldhdc = dcc.dcs[dcc.next];
HDC16 oldhwnd = dcc.wnds[dcc.next];
if(ReleaseDC( WIN_Handle32(oldhwnd), HDC_32(oldhdc) ) || !IsWindow(HWND_32(oldhwnd)))
{
K32WOWHandle16DestroyHint(HDC_32(oldhdc), WOW_TYPE_HDC);
}
K32WOWHandle16DestroyHint(HDC_32(oldhdc), WOW_TYPE_HDC);
}
dcc.dcs[dcc.next] = hdc;
dcc.wnds[dcc.next] = hwnd;
dcc.next = (dcc.next + 1) % 5;
return 1;
}
INT16 result = (INT16)ReleaseDC( WIN_Handle32(hwnd), HDC_32(hdc) );
if (result)
{
K32WOWHandle16DestroyHint(HDC_32(hdc), WOW_TYPE_HDC);
}
return result;
dcc.dcs[dcc.next] = hdc;
dcc.wnds[dcc.next] = hwnd;
dcc.next = (dcc.next + 1) % 5;
return 1;
}


Expand Down

0 comments on commit 6bce5cc

Please sign in to comment.