2011-04-01 16:27:48 +02:00
|
|
|
/*
|
|
|
|
* DIB driver initialization and DC functions.
|
|
|
|
*
|
|
|
|
* Copyright 2011 Huw Davies
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "gdi_private.h"
|
|
|
|
#include "dibdrv.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dib);
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* dibdrv_DeleteDC
|
|
|
|
*/
|
|
|
|
static BOOL CDECL dibdrv_DeleteDC( PHYSDEV dev )
|
|
|
|
{
|
2011-04-13 15:57:44 +02:00
|
|
|
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
|
2011-04-01 16:27:48 +02:00
|
|
|
TRACE("(%p)\n", dev);
|
2011-04-13 15:57:44 +02:00
|
|
|
DeleteObject(pdev->clip);
|
2011-04-01 16:27:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-04-05 14:26:08 +02:00
|
|
|
static void calc_shift_and_len(DWORD mask, int *shift, int *len)
|
|
|
|
{
|
|
|
|
int s, l;
|
|
|
|
|
2011-04-12 13:49:08 +02:00
|
|
|
if(!mask)
|
|
|
|
{
|
|
|
|
*shift = *len = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-05 14:26:08 +02:00
|
|
|
s = 0;
|
|
|
|
while ((mask & 1) == 0)
|
|
|
|
{
|
|
|
|
mask >>= 1;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
l = 0;
|
|
|
|
while ((mask & 1) == 1)
|
|
|
|
{
|
|
|
|
mask >>= 1;
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
*shift = s;
|
|
|
|
*len = l;
|
|
|
|
}
|
|
|
|
|
2011-04-05 14:23:20 +02:00
|
|
|
static void init_bit_fields(dib_info *dib, const DWORD *bit_fields)
|
|
|
|
{
|
|
|
|
dib->red_mask = bit_fields[0];
|
|
|
|
dib->green_mask = bit_fields[1];
|
|
|
|
dib->blue_mask = bit_fields[2];
|
2011-04-05 14:26:08 +02:00
|
|
|
calc_shift_and_len(dib->red_mask, &dib->red_shift, &dib->red_len);
|
|
|
|
calc_shift_and_len(dib->green_mask, &dib->green_shift, &dib->green_len);
|
|
|
|
calc_shift_and_len(dib->blue_mask, &dib->blue_shift, &dib->blue_len);
|
2011-04-05 14:23:20 +02:00
|
|
|
}
|
|
|
|
|
2011-04-01 16:27:48 +02:00
|
|
|
static BOOL init_dib(dib_info *dib, const BITMAPINFOHEADER *bi, const DWORD *bit_fields, void *bits)
|
|
|
|
{
|
2011-05-11 16:13:40 +02:00
|
|
|
static const DWORD bit_fields_888[3] = {0xff0000, 0x00ff00, 0x0000ff};
|
|
|
|
|
2011-04-01 16:27:48 +02:00
|
|
|
dib->bit_count = bi->biBitCount;
|
|
|
|
dib->width = bi->biWidth;
|
|
|
|
dib->height = bi->biHeight;
|
|
|
|
dib->stride = ((dib->width * dib->bit_count + 31) >> 3) & ~3;
|
|
|
|
dib->bits = bits;
|
|
|
|
|
|
|
|
if(dib->height < 0) /* top-down */
|
|
|
|
{
|
|
|
|
dib->height = -dib->height;
|
|
|
|
}
|
|
|
|
else /* bottom-up */
|
|
|
|
{
|
|
|
|
/* bits always points to the top-left corner and the stride is -ve */
|
|
|
|
dib->bits = (BYTE*)dib->bits + (dib->height - 1) * dib->stride;
|
|
|
|
dib->stride = -dib->stride;
|
|
|
|
}
|
|
|
|
|
2011-04-05 14:23:20 +02:00
|
|
|
dib->funcs = &funcs_null;
|
|
|
|
|
2011-04-01 16:27:48 +02:00
|
|
|
switch(dib->bit_count)
|
|
|
|
{
|
2011-04-05 14:23:20 +02:00
|
|
|
case 32:
|
2011-04-12 13:49:08 +02:00
|
|
|
if(bi->biCompression == BI_RGB)
|
2011-05-11 16:13:40 +02:00
|
|
|
bit_fields = bit_fields_888;
|
|
|
|
|
|
|
|
init_bit_fields(dib, bit_fields);
|
|
|
|
|
|
|
|
if(dib->red_mask == 0xff0000 && dib->green_mask == 0x00ff00 && dib->blue_mask == 0x0000ff)
|
2011-04-07 14:47:18 +02:00
|
|
|
dib->funcs = &funcs_8888;
|
|
|
|
else
|
2011-05-11 16:13:40 +02:00
|
|
|
dib->funcs = &funcs_32;
|
2011-04-07 14:47:18 +02:00
|
|
|
break;
|
2011-04-05 14:23:20 +02:00
|
|
|
|
2011-04-01 16:27:48 +02:00
|
|
|
default:
|
|
|
|
TRACE("bpp %d not supported, will forward to graphics driver.\n", dib->bit_count);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* dibdrv_SelectBitmap
|
|
|
|
*/
|
|
|
|
static HBITMAP CDECL dibdrv_SelectBitmap( PHYSDEV dev, HBITMAP bitmap )
|
|
|
|
{
|
|
|
|
PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSelectBitmap );
|
|
|
|
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
|
|
|
|
BITMAPOBJ *bmp = GDI_GetObjPtr( bitmap, OBJ_BITMAP );
|
|
|
|
TRACE("(%p, %p)\n", dev, bitmap);
|
|
|
|
|
|
|
|
if (!bmp) return 0;
|
|
|
|
assert(bmp->dib);
|
|
|
|
|
2011-04-13 15:57:44 +02:00
|
|
|
pdev->clip = CreateRectRgn(0, 0, 0, 0);
|
2011-04-07 14:47:18 +02:00
|
|
|
pdev->defer = 0;
|
|
|
|
|
|
|
|
if(!init_dib(&pdev->dib, &bmp->dib->dsBmih, bmp->dib->dsBitfields, bmp->dib->dsBm.bmBits))
|
|
|
|
pdev->defer |= DEFER_FORMAT;
|
2011-04-01 16:27:48 +02:00
|
|
|
|
|
|
|
GDI_ReleaseObj( bitmap );
|
|
|
|
|
|
|
|
return next->funcs->pSelectBitmap( next, bitmap );
|
|
|
|
}
|
|
|
|
|
2011-05-06 12:21:13 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* dibdrv_SetBkColor
|
|
|
|
*/
|
|
|
|
static COLORREF CDECL dibdrv_SetBkColor( PHYSDEV dev, COLORREF color )
|
|
|
|
{
|
|
|
|
PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetBkColor );
|
|
|
|
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
|
|
|
|
|
|
|
|
pdev->bkgnd_color = pdev->dib.funcs->colorref_to_pixel( &pdev->dib, color );
|
|
|
|
|
|
|
|
if( GetBkMode(dev->hdc) == OPAQUE )
|
|
|
|
calc_and_xor_masks( GetROP2(dev->hdc), pdev->bkgnd_color, &pdev->bkgnd_and, &pdev->bkgnd_xor );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pdev->bkgnd_and = ~0u;
|
|
|
|
pdev->bkgnd_xor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next->funcs->pSetBkColor( next, color );
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* dibdrv_SetBkMode
|
|
|
|
*/
|
|
|
|
static INT CDECL dibdrv_SetBkMode( PHYSDEV dev, INT mode )
|
|
|
|
{
|
|
|
|
PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetBkMode );
|
|
|
|
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
|
|
|
|
|
|
|
|
if( mode == OPAQUE )
|
|
|
|
calc_and_xor_masks( GetROP2(dev->hdc), pdev->bkgnd_color, &pdev->bkgnd_and, &pdev->bkgnd_xor );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pdev->bkgnd_and = ~0u;
|
|
|
|
pdev->bkgnd_xor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return next->funcs->pSetBkMode( next, mode );
|
|
|
|
}
|
|
|
|
|
2011-04-13 15:57:44 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* dibdrv_SetDeviceClipping
|
|
|
|
*/
|
|
|
|
static void CDECL dibdrv_SetDeviceClipping( PHYSDEV dev, HRGN vis_rgn, HRGN clip_rgn )
|
|
|
|
{
|
|
|
|
PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetDeviceClipping );
|
|
|
|
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
|
|
|
|
TRACE("(%p, %p, %p)\n", dev, vis_rgn, clip_rgn);
|
|
|
|
|
|
|
|
CombineRgn( pdev->clip, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
|
|
|
|
return next->funcs->pSetDeviceClipping( next, vis_rgn, clip_rgn);
|
|
|
|
}
|
|
|
|
|
2011-04-07 14:48:39 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* dibdrv_SetROP2
|
|
|
|
*/
|
|
|
|
static INT CDECL dibdrv_SetROP2( PHYSDEV dev, INT rop )
|
|
|
|
{
|
|
|
|
PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSetROP2 );
|
|
|
|
dibdrv_physdev *pdev = get_dibdrv_pdev(dev);
|
|
|
|
|
|
|
|
calc_and_xor_masks(rop, pdev->pen_color, &pdev->pen_and, &pdev->pen_xor);
|
2011-04-11 11:00:28 +02:00
|
|
|
update_brush_rop(pdev, rop);
|
2011-05-06 12:21:13 +02:00
|
|
|
if( GetBkMode(dev->hdc) == OPAQUE )
|
|
|
|
calc_and_xor_masks(rop, pdev->bkgnd_color, &pdev->bkgnd_and, &pdev->bkgnd_xor);
|
2011-04-07 14:48:39 +02:00
|
|
|
|
|
|
|
return next->funcs->pSetROP2( next, rop );
|
|
|
|
}
|
|
|
|
|
2011-04-01 16:27:48 +02:00
|
|
|
const DC_FUNCTIONS dib_driver =
|
|
|
|
{
|
|
|
|
NULL, /* pAbortDoc */
|
|
|
|
NULL, /* pAbortPath */
|
|
|
|
NULL, /* pAlphaBlend */
|
|
|
|
NULL, /* pAngleArc */
|
|
|
|
NULL, /* pArc */
|
|
|
|
NULL, /* pArcTo */
|
|
|
|
NULL, /* pBeginPath */
|
|
|
|
NULL, /* pChoosePixelFormat */
|
|
|
|
NULL, /* pChord */
|
|
|
|
NULL, /* pCloseFigure */
|
|
|
|
NULL, /* pCreateBitmap */
|
|
|
|
NULL, /* pCreateDC */
|
|
|
|
NULL, /* pCreateDIBSection */
|
|
|
|
NULL, /* pDeleteBitmap */
|
|
|
|
dibdrv_DeleteDC, /* pDeleteDC */
|
|
|
|
NULL, /* pDeleteObject */
|
|
|
|
NULL, /* pDescribePixelFormat */
|
|
|
|
NULL, /* pDeviceCapabilities */
|
|
|
|
NULL, /* pEllipse */
|
|
|
|
NULL, /* pEndDoc */
|
|
|
|
NULL, /* pEndPage */
|
|
|
|
NULL, /* pEndPath */
|
|
|
|
NULL, /* pEnumDeviceFonts */
|
|
|
|
NULL, /* pEnumICMProfiles */
|
|
|
|
NULL, /* pExcludeClipRect */
|
|
|
|
NULL, /* pExtDeviceMode */
|
|
|
|
NULL, /* pExtEscape */
|
|
|
|
NULL, /* pExtFloodFill */
|
|
|
|
NULL, /* pExtSelectClipRgn */
|
|
|
|
NULL, /* pExtTextOut */
|
|
|
|
NULL, /* pFillPath */
|
|
|
|
NULL, /* pFillRgn */
|
|
|
|
NULL, /* pFlattenPath */
|
|
|
|
NULL, /* pFrameRgn */
|
|
|
|
NULL, /* pGdiComment */
|
|
|
|
NULL, /* pGetBitmapBits */
|
|
|
|
NULL, /* pGetCharWidth */
|
|
|
|
NULL, /* pGetDIBits */
|
|
|
|
NULL, /* pGetDeviceCaps */
|
|
|
|
NULL, /* pGetDeviceGammaRamp */
|
|
|
|
NULL, /* pGetICMProfile */
|
|
|
|
NULL, /* pGetNearestColor */
|
|
|
|
NULL, /* pGetPixel */
|
|
|
|
NULL, /* pGetPixelFormat */
|
|
|
|
NULL, /* pGetSystemPaletteEntries */
|
|
|
|
NULL, /* pGetTextExtentExPoint */
|
|
|
|
NULL, /* pGetTextMetrics */
|
|
|
|
NULL, /* pIntersectClipRect */
|
|
|
|
NULL, /* pInvertRgn */
|
2011-04-07 14:49:33 +02:00
|
|
|
dibdrv_LineTo, /* pLineTo */
|
2011-04-01 16:27:48 +02:00
|
|
|
NULL, /* pModifyWorldTransform */
|
|
|
|
NULL, /* pMoveTo */
|
|
|
|
NULL, /* pOffsetClipRgn */
|
|
|
|
NULL, /* pOffsetViewportOrg */
|
|
|
|
NULL, /* pOffsetWindowOrg */
|
|
|
|
NULL, /* pPaintRgn */
|
2011-04-11 11:07:12 +02:00
|
|
|
dibdrv_PatBlt, /* pPatBlt */
|
2011-04-01 16:27:48 +02:00
|
|
|
NULL, /* pPie */
|
|
|
|
NULL, /* pPolyBezier */
|
|
|
|
NULL, /* pPolyBezierTo */
|
|
|
|
NULL, /* pPolyDraw */
|
|
|
|
NULL, /* pPolyPolygon */
|
|
|
|
NULL, /* pPolyPolyline */
|
|
|
|
NULL, /* pPolygon */
|
|
|
|
NULL, /* pPolyline */
|
|
|
|
NULL, /* pPolylineTo */
|
|
|
|
NULL, /* pRealizeDefaultPalette */
|
|
|
|
NULL, /* pRealizePalette */
|
|
|
|
NULL, /* pRectangle */
|
|
|
|
NULL, /* pResetDC */
|
|
|
|
NULL, /* pRestoreDC */
|
|
|
|
NULL, /* pRoundRect */
|
|
|
|
NULL, /* pSaveDC */
|
|
|
|
NULL, /* pScaleViewportExt */
|
|
|
|
NULL, /* pScaleWindowExt */
|
|
|
|
dibdrv_SelectBitmap, /* pSelectBitmap */
|
2011-04-11 11:00:28 +02:00
|
|
|
dibdrv_SelectBrush, /* pSelectBrush */
|
2011-04-01 16:27:48 +02:00
|
|
|
NULL, /* pSelectClipPath */
|
|
|
|
NULL, /* pSelectFont */
|
|
|
|
NULL, /* pSelectPalette */
|
2011-04-07 14:46:33 +02:00
|
|
|
dibdrv_SelectPen, /* pSelectPen */
|
2011-04-01 16:27:48 +02:00
|
|
|
NULL, /* pSetArcDirection */
|
|
|
|
NULL, /* pSetBitmapBits */
|
2011-05-06 12:21:13 +02:00
|
|
|
dibdrv_SetBkColor, /* pSetBkColor */
|
|
|
|
dibdrv_SetBkMode, /* pSetBkMode */
|
2011-04-11 11:00:28 +02:00
|
|
|
dibdrv_SetDCBrushColor, /* pSetDCBrushColor */
|
2011-04-07 14:47:59 +02:00
|
|
|
dibdrv_SetDCPenColor, /* pSetDCPenColor */
|
2011-04-01 16:27:48 +02:00
|
|
|
NULL, /* pSetDIBColorTable */
|
|
|
|
NULL, /* pSetDIBits */
|
|
|
|
NULL, /* pSetDIBitsToDevice */
|
2011-04-13 15:57:44 +02:00
|
|
|
dibdrv_SetDeviceClipping, /* pSetDeviceClipping */
|
2011-04-01 16:27:48 +02:00
|
|
|
NULL, /* pSetDeviceGammaRamp */
|
|
|
|
NULL, /* pSetLayout */
|
|
|
|
NULL, /* pSetMapMode */
|
|
|
|
NULL, /* pSetMapperFlags */
|
|
|
|
NULL, /* pSetPixel */
|
|
|
|
NULL, /* pSetPixelFormat */
|
|
|
|
NULL, /* pSetPolyFillMode */
|
2011-04-07 14:48:39 +02:00
|
|
|
dibdrv_SetROP2, /* pSetROP2 */
|
2011-04-01 16:27:48 +02:00
|
|
|
NULL, /* pSetRelAbs */
|
|
|
|
NULL, /* pSetStretchBltMode */
|
|
|
|
NULL, /* pSetTextAlign */
|
|
|
|
NULL, /* pSetTextCharacterExtra */
|
|
|
|
NULL, /* pSetTextColor */
|
|
|
|
NULL, /* pSetTextJustification */
|
|
|
|
NULL, /* pSetViewportExt */
|
|
|
|
NULL, /* pSetViewportOrg */
|
|
|
|
NULL, /* pSetWindowExt */
|
|
|
|
NULL, /* pSetWindowOrg */
|
|
|
|
NULL, /* pSetWorldTransform */
|
|
|
|
NULL, /* pStartDoc */
|
|
|
|
NULL, /* pStartPage */
|
|
|
|
NULL, /* pStretchBlt */
|
|
|
|
NULL, /* pStretchDIBits */
|
|
|
|
NULL, /* pStrokeAndFillPath */
|
|
|
|
NULL, /* pStrokePath */
|
|
|
|
NULL, /* pSwapBuffers */
|
|
|
|
NULL, /* pUnrealizePalette */
|
|
|
|
NULL, /* pWidenPath */
|
|
|
|
NULL, /* pwglCopyContext */
|
|
|
|
NULL, /* pwglCreateContext */
|
|
|
|
NULL, /* pwglCreateContextAttribsARB */
|
|
|
|
NULL, /* pwglDeleteContext */
|
|
|
|
NULL, /* pwglGetProcAddress */
|
|
|
|
NULL, /* pwglGetPbufferDCARB */
|
|
|
|
NULL, /* pwglMakeCurrent */
|
|
|
|
NULL, /* pwglMakeContextCurrentARB */
|
|
|
|
NULL, /* pwglSetPixelFormatWINE */
|
|
|
|
NULL, /* pwglShareLists */
|
|
|
|
NULL, /* pwglUseFontBitmapsA */
|
|
|
|
NULL /* pwglUseFontBitmapsW */
|
|
|
|
};
|