gdi32: Optimise StretchBlt for the case where no stretching is being done and the whole image is being set.
In this case, we can just call SetDIBits which is likely to be a lot faster.
This commit is contained in:
parent
42ad345852
commit
582de7ba0d
116
dlls/gdi32/dib.c
116
dlls/gdi32/dib.c
|
@ -205,13 +205,12 @@ INT WINAPI StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst,
|
||||||
}
|
}
|
||||||
else /* use StretchBlt */
|
else /* use StretchBlt */
|
||||||
{
|
{
|
||||||
HBITMAP hBitmap, hOldBitmap;
|
|
||||||
HPALETTE hpal = NULL;
|
|
||||||
HDC hdcMem;
|
|
||||||
LONG height;
|
LONG height;
|
||||||
LONG width;
|
LONG width;
|
||||||
WORD planes, bpp;
|
WORD planes, bpp;
|
||||||
DWORD compr, size;
|
DWORD compr, size;
|
||||||
|
HBITMAP hBitmap;
|
||||||
|
BOOL fastpath = FALSE;
|
||||||
|
|
||||||
release_dc_ptr( dc );
|
release_dc_ptr( dc );
|
||||||
|
|
||||||
|
@ -227,51 +226,84 @@ INT WINAPI StretchDIBits(HDC hdc, INT xDst, INT yDst, INT widthDst,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdcMem = CreateCompatibleDC( hdc );
|
hBitmap = GetCurrentObject(hdc, OBJ_BITMAP);
|
||||||
hBitmap = CreateCompatibleBitmap(hdc, width, height);
|
|
||||||
hOldBitmap = SelectObject( hdcMem, hBitmap );
|
if (xDst == 0 && yDst == 0 && xSrc == 0 && ySrc == 0 &&
|
||||||
if(wUsage == DIB_PAL_COLORS)
|
widthDst == widthSrc && heightDst == heightSrc &&
|
||||||
|
info->bmiHeader.biCompression == BI_RGB &&
|
||||||
|
dwRop == SRCCOPY)
|
||||||
{
|
{
|
||||||
hpal = GetCurrentObject(hdc, OBJ_PAL);
|
BITMAPOBJ *bmp;
|
||||||
hpal = SelectPalette(hdcMem, hpal, FALSE);
|
if ((bmp = (BITMAPOBJ *)GDI_GetObjPtr( hBitmap, BITMAP_MAGIC )))
|
||||||
|
{
|
||||||
|
if (bmp->bitmap.bmBitsPixel == bpp &&
|
||||||
|
bmp->bitmap.bmWidth == widthSrc &&
|
||||||
|
bmp->bitmap.bmHeight == heightSrc &&
|
||||||
|
bmp->bitmap.bmPlanes == planes)
|
||||||
|
fastpath = TRUE;
|
||||||
|
GDI_ReleaseObj( hBitmap );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->bmiHeader.biCompression == BI_RLE4 ||
|
if (fastpath)
|
||||||
info->bmiHeader.biCompression == BI_RLE8) {
|
{
|
||||||
|
/* fast path */
|
||||||
/* when RLE compression is used, there may be some gaps (ie the DIB doesn't
|
TRACE("using fast path\n");
|
||||||
* contain all the rectangle described in bmiHeader, but only part of it.
|
heightSrc = SetDIBits( hdc, hBitmap, 0, height, bits, info, wUsage);
|
||||||
* This mean that those undescribed pixels must be left untouched.
|
|
||||||
* So, we first copy on a memory bitmap the current content of the
|
|
||||||
* destination rectangle, blit the DIB bits on top of it - hence leaving
|
|
||||||
* the gaps untouched -, and blitting the rectangle back.
|
|
||||||
* This insure that gaps are untouched on the destination rectangle
|
|
||||||
* Not doing so leads to trashed images (the gaps contain what was on the
|
|
||||||
* memory bitmap => generally black or garbage)
|
|
||||||
* Unfortunately, RLE DIBs without gaps will be slowed down. But this is
|
|
||||||
* another speed vs correctness issue. Anyway, if speed is needed, then the
|
|
||||||
* pStretchDIBits function shall be implemented.
|
|
||||||
* ericP (2000/09/09)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* copy existing bitmap from destination dc */
|
|
||||||
StretchBlt( hdcMem, xSrc, abs(height) - heightSrc - ySrc,
|
|
||||||
widthSrc, heightSrc, hdc, xDst, yDst, widthDst, heightDst,
|
|
||||||
dwRop );
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* slow path - need to use StretchBlt */
|
||||||
|
HBITMAP hOldBitmap;
|
||||||
|
HPALETTE hpal = NULL;
|
||||||
|
HDC hdcMem;
|
||||||
|
|
||||||
SetDIBits(hdcMem, hBitmap, 0, height, bits, info, wUsage);
|
hdcMem = CreateCompatibleDC( hdc );
|
||||||
|
hBitmap = CreateCompatibleBitmap(hdc, width, height);
|
||||||
|
hOldBitmap = SelectObject( hdcMem, hBitmap );
|
||||||
|
if(wUsage == DIB_PAL_COLORS)
|
||||||
|
{
|
||||||
|
hpal = GetCurrentObject(hdc, OBJ_PAL);
|
||||||
|
hpal = SelectPalette(hdcMem, hpal, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Origin for DIBitmap may be bottom left (positive biHeight) or top
|
if (info->bmiHeader.biCompression == BI_RLE4 ||
|
||||||
left (negative biHeight) */
|
info->bmiHeader.biCompression == BI_RLE8) {
|
||||||
StretchBlt( hdc, xDst, yDst, widthDst, heightDst,
|
|
||||||
hdcMem, xSrc, abs(height) - heightSrc - ySrc,
|
/* when RLE compression is used, there may be some gaps (ie the DIB doesn't
|
||||||
widthSrc, heightSrc, dwRop );
|
* contain all the rectangle described in bmiHeader, but only part of it.
|
||||||
if(hpal)
|
* This mean that those undescribed pixels must be left untouched.
|
||||||
SelectPalette(hdcMem, hpal, FALSE);
|
* So, we first copy on a memory bitmap the current content of the
|
||||||
SelectObject( hdcMem, hOldBitmap );
|
* destination rectangle, blit the DIB bits on top of it - hence leaving
|
||||||
DeleteDC( hdcMem );
|
* the gaps untouched -, and blitting the rectangle back.
|
||||||
DeleteObject( hBitmap );
|
* This insure that gaps are untouched on the destination rectangle
|
||||||
|
* Not doing so leads to trashed images (the gaps contain what was on the
|
||||||
|
* memory bitmap => generally black or garbage)
|
||||||
|
* Unfortunately, RLE DIBs without gaps will be slowed down. But this is
|
||||||
|
* another speed vs correctness issue. Anyway, if speed is needed, then the
|
||||||
|
* pStretchDIBits function shall be implemented.
|
||||||
|
* ericP (2000/09/09)
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* copy existing bitmap from destination dc */
|
||||||
|
StretchBlt( hdcMem, xSrc, abs(height) - heightSrc - ySrc,
|
||||||
|
widthSrc, heightSrc, hdc, xDst, yDst, widthDst, heightDst,
|
||||||
|
dwRop );
|
||||||
|
}
|
||||||
|
|
||||||
|
SetDIBits(hdcMem, hBitmap, 0, height, bits, info, wUsage);
|
||||||
|
|
||||||
|
/* Origin for DIBitmap may be bottom left (positive biHeight) or top
|
||||||
|
left (negative biHeight) */
|
||||||
|
StretchBlt( hdc, xDst, yDst, widthDst, heightDst,
|
||||||
|
hdcMem, xSrc, abs(height) - heightSrc - ySrc,
|
||||||
|
widthSrc, heightSrc, dwRop );
|
||||||
|
if(hpal)
|
||||||
|
SelectPalette(hdcMem, hpal, FALSE);
|
||||||
|
SelectObject( hdcMem, hOldBitmap );
|
||||||
|
DeleteDC( hdcMem );
|
||||||
|
DeleteObject( hBitmap );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return heightSrc;
|
return heightSrc;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue