/*********************************************************************** * PEN_SelectObject */ static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc ) { PHYSDEV physdev; HGDIOBJ ret = 0; DC *dc = get_dc_ptr( hdc ); if (!dc) { SetLastError( ERROR_INVALID_HANDLE ); return 0; } if (!GDI_inc_ref_count( handle )) { release_dc_ptr( dc ); return 0; } physdev = GET_DC_PHYSDEV( dc, pSelectPen ); if (!physdev->funcs->pSelectPen( physdev, handle )) { GDI_dec_ref_count( handle ); } else { ret = dc->hPen; dc->hPen = handle; GDI_dec_ref_count( ret ); } release_dc_ptr( dc ); return ret; }
/****************************************************************************** * GdiAlphaBlend [GDI32.@] */ BOOL WINAPI GdiAlphaBlend(HDC hdcDst, int xDst, int yDst, int widthDst, int heightDst, HDC hdcSrc, int xSrc, int ySrc, int widthSrc, int heightSrc, BLENDFUNCTION blendFunction) { BOOL ret = FALSE; DC *dcDst, *dcSrc; TRACE( "%p %d,%d %dx%d -> %p %d,%d %dx%d op=%02x flags=%02x srcconstalpha=%02x alphafmt=%02x\n", hdcSrc, xSrc, ySrc, widthSrc, heightSrc, hdcDst, xDst, yDst, widthDst, heightDst, blendFunction.BlendOp, blendFunction.BlendFlags, blendFunction.SourceConstantAlpha, blendFunction.AlphaFormat ); dcSrc = get_dc_ptr( hdcSrc ); if (!dcSrc) return FALSE; if ((dcDst = get_dc_ptr( hdcDst ))) { PHYSDEV src_dev = GET_DC_PHYSDEV( dcSrc, pAlphaBlend ); PHYSDEV dst_dev = GET_DC_PHYSDEV( dcDst, pAlphaBlend ); update_dc( dcSrc ); update_dc( dcDst ); ret = dst_dev->funcs->pAlphaBlend( dst_dev, xDst, yDst, widthDst, heightDst, src_dev, xSrc, ySrc, widthSrc, heightSrc, blendFunction ); release_dc_ptr( dcDst ); } release_dc_ptr( dcSrc ); return ret; }
/*********************************************************************** * wglMakeContextCurrentARB */ static BOOL WINAPI wglMakeContextCurrentARB(HDC hDrawDC, HDC hReadDC, HGLRC hglrc) { BOOL ret = FALSE; PHYSDEV draw_physdev, read_physdev; DC *DrawDC; DC *ReadDC; TRACE("hDrawDC: (%p), hReadDC: (%p) hglrc: (%p)\n", hDrawDC, hReadDC, hglrc); /* Both hDrawDC and hReadDC need to be valid */ DrawDC = get_dc_ptr( hDrawDC ); if (!DrawDC) return FALSE; ReadDC = get_dc_ptr( hReadDC ); if (!ReadDC) { release_dc_ptr( DrawDC ); return FALSE; } update_dc( DrawDC ); update_dc( ReadDC ); draw_physdev = GET_DC_PHYSDEV( DrawDC, pwglMakeContextCurrentARB ); read_physdev = GET_DC_PHYSDEV( ReadDC, pwglMakeContextCurrentARB ); if (draw_physdev->funcs == read_physdev->funcs) ret = draw_physdev->funcs->pwglMakeContextCurrentARB(draw_physdev, read_physdev, hglrc); release_dc_ptr( DrawDC ); release_dc_ptr( ReadDC ); return ret; }
/*********************************************************************** * StretchBlt (GDI32.@) */ BOOL WINAPI StretchBlt( HDC hdcDst, INT xDst, INT yDst, INT widthDst, INT heightDst, HDC hdcSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop ) { BOOL ret = FALSE; DC *dcDst, *dcSrc; if (!rop_uses_src( rop )) return PatBlt( hdcDst, xDst, yDst, widthDst, heightDst, rop ); TRACE("%p %d,%d %dx%d -> %p %d,%d %dx%d rop=%06x\n", hdcSrc, xSrc, ySrc, widthSrc, heightSrc, hdcDst, xDst, yDst, widthDst, heightDst, rop ); if (!(dcDst = get_dc_ptr( hdcDst ))) return FALSE; if ((dcSrc = get_dc_ptr( hdcSrc ))) { PHYSDEV src_dev = GET_DC_PHYSDEV( dcSrc, pStretchBlt ); PHYSDEV dst_dev = GET_DC_PHYSDEV( dcDst, pStretchBlt ); update_dc( dcSrc ); update_dc( dcDst ); ret = dst_dev->funcs->pStretchBlt( dst_dev, xDst, yDst, widthDst, heightDst, src_dev, xSrc, ySrc, widthSrc, heightSrc, rop ); release_dc_ptr( dcSrc ); } release_dc_ptr( dcDst ); return ret; }
/*********************************************************************** * GetNearestColor [GDI32.@] * * Gets a system color to match. * * RETURNS * Success: Color from system palette that corresponds to given color * Failure: CLR_INVALID */ COLORREF WINAPI GetNearestColor( HDC hdc, /* [in] Handle of device context */ COLORREF color) /* [in] Color to be matched */ { unsigned char spec_type; COLORREF nearest; DC *dc; if (!(dc = get_dc_ptr( hdc ))) return CLR_INVALID; if (dc->funcs->pGetNearestColor) { nearest = dc->funcs->pGetNearestColor( dc->physDev, color ); release_dc_ptr( dc ); return nearest; } if (!(GetDeviceCaps(hdc, RASTERCAPS) & RC_PALETTE)) { release_dc_ptr( dc ); return color; } spec_type = color >> 24; if (spec_type == 1 || spec_type == 2) { /* we need logical palette for PALETTERGB and PALETTEINDEX colorrefs */ UINT index; PALETTEENTRY entry; HPALETTE hpal = dc->hPalette ? dc->hPalette : GetStockObject( DEFAULT_PALETTE ); if (spec_type == 2) /* PALETTERGB */ index = GetNearestPaletteIndex( hpal, color ); else /* PALETTEINDEX */ index = LOWORD(color); if (!GetPaletteEntries( hpal, index, 1, &entry )) { WARN("RGB(%x) : idx %d is out of bounds, assuming NULL\n", color, index ); if (!GetPaletteEntries( hpal, 0, 1, &entry )) { release_dc_ptr( dc ); return CLR_INVALID; } } color = RGB( entry.peRed, entry.peGreen, entry.peBlue ); } nearest = color & 0x00ffffff; release_dc_ptr( dc ); TRACE("(%06x): returning %06x\n", color, nearest ); return nearest; }
/*********************************************************************** * StretchBlt (GDI32.@) */ BOOL WINAPI StretchBlt( HDC hdcDst, INT xDst, INT yDst, INT widthDst, INT heightDst, HDC hdcSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop ) { BOOL ret = FALSE; DC *dcDst, *dcSrc; if (!rop_uses_src( rop )) return PatBlt( hdcDst, xDst, yDst, widthDst, heightDst, rop ); if (!(dcDst = get_dc_ptr( hdcDst ))) return FALSE; if ((dcSrc = get_dc_ptr( hdcSrc ))) { struct bitblt_coords src, dst; update_dc( dcSrc ); update_dc( dcDst ); src.log_x = xSrc; src.log_y = ySrc; src.log_width = widthSrc; src.log_height = heightSrc; src.layout = dcSrc->layout; dst.log_x = xDst; dst.log_y = yDst; dst.log_width = widthDst; dst.log_height = heightDst; dst.layout = dcDst->layout; if (rop & NOMIRRORBITMAP) { src.layout |= LAYOUT_BITMAPORIENTATIONPRESERVED; dst.layout |= LAYOUT_BITMAPORIENTATIONPRESERVED; rop &= ~NOMIRRORBITMAP; } ret = !get_vis_rectangles( dcDst, &dst, dcSrc, &src ); TRACE("src %p log=%d,%d %dx%d phys=%d,%d %dx%d vis=%s dst %p log=%d,%d %dx%d phys=%d,%d %dx%d vis=%s rop=%06x\n", hdcSrc, src.log_x, src.log_y, src.log_width, src.log_height, src.x, src.y, src.width, src.height, wine_dbgstr_rect(&src.visrect), hdcDst, dst.log_x, dst.log_y, dst.log_width, dst.log_height, dst.x, dst.y, dst.width, dst.height, wine_dbgstr_rect(&dst.visrect), rop ); if (!ret) { PHYSDEV src_dev = GET_DC_PHYSDEV( dcSrc, pStretchBlt ); PHYSDEV dst_dev = GET_DC_PHYSDEV( dcDst, pStretchBlt ); ret = dst_dev->funcs->pStretchBlt( dst_dev, &dst, src_dev, &src, rop ); } release_dc_ptr( dcSrc ); } release_dc_ptr( dcDst ); return ret; }
/*********************************************************************** * PEN_SelectObject */ static HGDIOBJ PEN_SelectObject( HGDIOBJ handle, HDC hdc ) { PENOBJ *pen; HGDIOBJ ret = 0; DC *dc = get_dc_ptr( hdc ); WORD type; if (!dc) { SetLastError( ERROR_INVALID_HANDLE ); return 0; } if ((pen = get_any_obj_ptr( handle, &type ))) { struct brush_pattern *pattern; PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSelectPen ); switch (type) { case OBJ_PEN: pattern = NULL; break; case OBJ_EXTPEN: pattern = &pen->pattern; if (!pattern->info) pattern = NULL; break; default: GDI_ReleaseObj( handle ); release_dc_ptr( dc ); return 0; } GDI_inc_ref_count( handle ); GDI_ReleaseObj( handle ); if (!physdev->funcs->pSelectPen( physdev, handle, pattern )) { GDI_dec_ref_count( handle ); } else { ret = dc->hPen; dc->hPen = handle; GDI_dec_ref_count( ret ); } } release_dc_ptr( dc ); return ret; }
/********************************************************************** * MFDRV_CloseMetaFile */ static DC *MFDRV_CloseMetaFile( HDC hdc ) { DC *dc; METAFILEDRV_PDEVICE *physDev; TRACE("(%p)\n", hdc ); if (!(dc = get_dc_ptr( hdc ))) return NULL; if (dc->header.type != OBJ_METADC) { release_dc_ptr( dc ); return NULL; } if (dc->refcount != 1) { FIXME( "not deleting busy DC %p refcount %u\n", hdc, dc->refcount ); release_dc_ptr( dc ); return NULL; } physDev = (METAFILEDRV_PDEVICE *)dc->physDev; /* Construct the end of metafile record - this is documented * in SDK Knowledgebase Q99334. */ if (!MFDRV_MetaParam0(dc->physDev, META_EOF)) { free_dc_ptr( dc ); return 0; } if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */ { if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) { free_dc_ptr( dc ); return 0; } physDev->mh->mtType = METAFILE_MEMORY; /* This is what windows does */ if (!WriteFile(physDev->hFile, physDev->mh, sizeof(*physDev->mh), NULL, NULL)) { free_dc_ptr( dc ); return 0; } CloseHandle(physDev->hFile); physDev->mh->mtType = METAFILE_DISK; } return dc; }
/*********************************************************************** * SetMetaRgn (GDI32.@) */ INT WINAPI SetMetaRgn( HDC hdc ) { INT ret; RECT dummy; DC *dc = get_dc_ptr( hdc ); if (!dc) return ERROR; if (dc->hClipRgn) { if (dc->hMetaRgn) { /* the intersection becomes the new meta region */ CombineRgn( dc->hMetaRgn, dc->hMetaRgn, dc->hClipRgn, RGN_AND ); DeleteObject( dc->hClipRgn ); dc->hClipRgn = 0; } else { dc->hMetaRgn = dc->hClipRgn; dc->hClipRgn = 0; } } /* else nothing to do */ /* Note: no need to call update_dc_clipping, the overall clip region hasn't changed */ ret = GetRgnBox( dc->hMetaRgn, &dummy ); release_dc_ptr( dc ); return ret; }
/*********************************************************************** * wglMakeCurrent (OPENGL32.@) */ BOOL WINAPI wglMakeCurrent(HDC hdc, HGLRC hglrc) { BOOL ret = FALSE; DC * dc = NULL; /* When the context hglrc is NULL, the HDC is ignored and can be NULL. * In that case use the global hDC to get access to the driver. */ if(hglrc == NULL) { if( hdc == NULL && !wglGetCurrentContext() ) { WARN( "Current context is NULL\n"); SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } dc = OPENGL_GetDefaultDC(); } else dc = get_dc_ptr( hdc ); TRACE("hdc: (%p), hglrc: (%p)\n", hdc, hglrc); if (dc) { PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglMakeCurrent ); update_dc( dc ); ret = physdev->funcs->pwglMakeCurrent( physdev, hglrc ); release_dc_ptr( dc ); } return ret; }
/*********************************************************************** * SetVirtualResolution (GDI32.@) * * Undocumented on msdn. * * Changes the values of screen size in pixels and millimeters used by * the mapping mode functions. * * PARAMS * hdc [I] Device context * horz_res [I] Width in pixels (equivalent to HORZRES device cap). * vert_res [I] Height in pixels (equivalent to VERTRES device cap). * horz_size [I] Width in mm (equivalent to HORZSIZE device cap). * vert_size [I] Height in mm (equivalent to VERTSIZE device cap). * * RETURNS * TRUE if successful. * FALSE if any (but not all) of the last four params are zero. * * NOTES * This doesn't change the values returned by GetDeviceCaps, just the * scaling of the mapping modes. * * Calling with the last four params equal to zero sets the values * back to their defaults obtained by calls to GetDeviceCaps. */ BOOL WINAPI SetVirtualResolution(HDC hdc, DWORD horz_res, DWORD vert_res, DWORD horz_size, DWORD vert_size) { DC * dc; TRACE("(%p %d %d %d %d)\n", hdc, horz_res, vert_res, horz_size, vert_size); if(horz_res == 0 && vert_res == 0 && horz_size == 0 && vert_size == 0) { horz_res = GetDeviceCaps(hdc, HORZRES); vert_res = GetDeviceCaps(hdc, VERTRES); horz_size = GetDeviceCaps(hdc, HORZSIZE); vert_size = GetDeviceCaps(hdc, VERTSIZE); } else if(horz_res == 0 || vert_res == 0 || horz_size == 0 || vert_size == 0) return FALSE; dc = get_dc_ptr( hdc ); if (!dc) return FALSE; dc->virtual_res.cx = horz_res; dc->virtual_res.cy = vert_res; dc->virtual_size.cx = horz_size; dc->virtual_size.cy = vert_size; release_dc_ptr( dc ); return TRUE; }
/*********************************************************************** * GDISelectPalette (Not a Windows API) */ HPALETTE WINAPI GDISelectPalette( HDC hdc, HPALETTE hpal, WORD wBkg) { HPALETTE ret = 0; DC *dc; TRACE("%p %p\n", hdc, hpal ); hpal = get_full_gdi_handle( hpal ); if (GetObjectType(hpal) != OBJ_PAL) { WARN("invalid selected palette %p\n",hpal); return 0; } if ((dc = get_dc_ptr( hdc ))) { PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSelectPalette ); ret = dc->hPalette; if (physdev->funcs->pSelectPalette( physdev, hpal, FALSE )) { dc->hPalette = hpal; if (!wBkg) hPrimaryPalette = hpal; } else ret = 0; release_dc_ptr( dc ); } return ret; }
/*********************************************************************** * Internal wglGetProcAddress for retrieving WGL extensions */ PROC WINAPI wglGetProcAddress(LPCSTR func) { PROC ret = NULL; DC *dc; if(!func) return NULL; TRACE("func: '%s'\n", func); /* Retrieve the global hDC to get access to the driver. */ dc = OPENGL_GetDefaultDC(); if (dc) { PHYSDEV physdev = GET_DC_PHYSDEV( dc, pwglGetProcAddress ); ret = physdev->funcs->pwglGetProcAddress(func); release_dc_ptr( dc ); } /* At the moment we implement one WGL extension which requires a HDC. When we * are looking up this call and when the Extension is available (that is the case * when a non-NULL value is returned by wglGetProcAddress), we return the address * of a wrapper function which will handle the HDC->PhysDev conversion. */ if(ret && strcmp(func, "wglCreateContextAttribsARB") == 0) return (PROC)wglCreateContextAttribsARB; else if(ret && strcmp(func, "wglMakeContextCurrentARB") == 0) return (PROC)wglMakeContextCurrentARB; else if(ret && strcmp(func, "wglGetPbufferDCARB") == 0) return (PROC)wglGetPbufferDCARB; else if(ret && strcmp(func, "wglSetPixelFormatWINE") == 0) return (PROC)wglSetPixelFormatWINE; return ret; }
/*********************************************************************** * IntersectVisRect (GDI.98) */ INT16 WINAPI IntersectVisRect16( HDC16 hdc16, INT16 left, INT16 top, INT16 right, INT16 bottom ) { HRGN tempRgn; INT16 ret; POINT pt[2]; HDC hdc = HDC_32( hdc16 ); DC * dc = get_dc_ptr( hdc ); if (!dc) return ERROR; pt[0].x = left; pt[0].y = top; pt[1].x = right; pt[1].y = bottom; LPtoDP( hdc, pt, 2 ); TRACE("%p %d,%d - %d,%d\n", hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y); if (!(tempRgn = CreateRectRgn( pt[0].x, pt[0].y, pt[1].x, pt[1].y ))) ret = ERROR; else { update_dc( dc ); ret = CombineRgn( dc->hVisRgn, dc->hVisRgn, tempRgn, RGN_AND ); DeleteObject( tempRgn ); } if (ret != ERROR) CLIPPING_UpdateGCRegion( dc ); release_dc_ptr( dc ); return ret; }
/*********************************************************************** * GetClipBox (GDI32.@) */ INT WINAPI GetClipBox( HDC hdc, LPRECT rect ) { RECT visrect; INT ret; DC *dc = get_dc_ptr( hdc ); if (!dc) return ERROR; update_dc( dc ); if (get_dc_region( dc )) { ret = GetRgnBox( get_dc_region( dc ), rect ); } else { ret = is_rect_empty( &dc->vis_rect ) ? ERROR : SIMPLEREGION; *rect = dc->vis_rect; } if (get_dc_device_rect( dc, &visrect ) && !intersect_rect( rect, rect, &visrect )) ret = NULLREGION; if (dc->layout & LAYOUT_RTL) { int tmp = rect->left; rect->left = rect->right - 1; rect->right = tmp - 1; } DPtoLP( hdc, (LPPOINT)rect, 2 ); release_dc_ptr( dc ); TRACE("%p => %d %s\n", hdc, ret, wine_dbgstr_rect( rect )); return ret; }
/***************************************************************************** * @ [GDI32.102] * * This should load the correct driver for lpszDevice and call this driver's * ExtDeviceMode proc. * * FIXME: convert ExtDeviceMode to unicode in the driver interface */ INT WINAPI GDI_CallExtDeviceMode16( HWND hwnd, LPDEVMODEA lpdmOutput, LPSTR lpszDevice, LPSTR lpszPort, LPDEVMODEA lpdmInput, LPSTR lpszProfile, DWORD fwMode ) { WCHAR deviceW[300]; WCHAR bufW[300]; char buf[300]; HDC hdc; DC *dc; INT ret = -1; TRACE("(%p, %p, %s, %s, %p, %s, %d)\n", hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode ); if (!lpszDevice) return -1; if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1; if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1; if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1; if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1; if ((dc = get_dc_ptr( hdc ))) { if (dc->funcs->pExtDeviceMode) ret = dc->funcs->pExtDeviceMode( buf, hwnd, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile, fwMode ); release_dc_ptr( dc ); } DeleteDC( hdc ); return ret; }
/***************************************************************************** * @ [GDI32.104] * * This should load the correct driver for lpszDevice and calls this driver's * DeviceCapabilities proc. * * FIXME: convert DeviceCapabilities to unicode in the driver interface */ DWORD WINAPI GDI_CallDeviceCapabilities16( LPCSTR lpszDevice, LPCSTR lpszPort, WORD fwCapability, LPSTR lpszOutput, LPDEVMODEA lpdm ) { WCHAR deviceW[300]; WCHAR bufW[300]; char buf[300]; HDC hdc; DC *dc; INT ret = -1; TRACE("(%s, %s, %d, %p, %p)\n", lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm ); if (!lpszDevice) return -1; if (!MultiByteToWideChar(CP_ACP, 0, lpszDevice, -1, deviceW, 300)) return -1; if(!DRIVER_GetDriverName( deviceW, bufW, 300 )) return -1; if (!WideCharToMultiByte(CP_ACP, 0, bufW, -1, buf, 300, NULL, NULL)) return -1; if (!(hdc = CreateICA( buf, lpszDevice, lpszPort, NULL ))) return -1; if ((dc = get_dc_ptr( hdc ))) { if (dc->funcs->pDeviceCapabilities) ret = dc->funcs->pDeviceCapabilities( buf, lpszDevice, lpszPort, fwCapability, lpszOutput, lpdm ); release_dc_ptr( dc ); } DeleteDC( hdc ); return ret; }
/*********************************************************************** * ArcTo (GDI32.@) */ BOOL WINAPI ArcTo( HDC hdc, INT left, INT top, INT right, INT bottom, INT xstart, INT ystart, INT xend, INT yend ) { double width = abs( right - left ), height = abs( bottom - top ), xradius = width/2, yradius = height/2, xcenter = right > left ? left+xradius : right+xradius, ycenter = bottom > top ? top+yradius : bottom+yradius, angle; PHYSDEV physdev; BOOL result; DC * dc = get_dc_ptr( hdc ); TRACE( "%p, (%d, %d)-(%d, %d), (%d, %d), (%d, %d)\n", hdc, left, top, right, bottom, xstart, ystart, xend, yend ); if(!dc) return FALSE; update_dc( dc ); physdev = GET_DC_PHYSDEV( dc, pArcTo ); result = physdev->funcs->pArcTo( physdev, left, top, right, bottom, xstart, ystart, xend, yend ); if (result) { angle = atan2(((yend-ycenter)/height), ((xend-xcenter)/width)); dc->cur_pos.x = GDI_ROUND( xcenter + (cos( angle ) * xradius) ); dc->cur_pos.y = GDI_ROUND( ycenter + (sin( angle ) * yradius) ); } release_dc_ptr( dc ); return result; }
/*********************************************************************** * AngleArc (GDI32.@) */ BOOL WINAPI AngleArc(HDC hdc, INT x, INT y, DWORD dwRadius, FLOAT eStartAngle, FLOAT eSweepAngle) { PHYSDEV physdev; BOOL result; DC *dc; TRACE( "%p, (%d, %d), %u, %f, %f\n", hdc, x, y, dwRadius, eStartAngle, eSweepAngle ); if( (signed int)dwRadius < 0 ) return FALSE; dc = get_dc_ptr( hdc ); if(!dc) return FALSE; update_dc( dc ); physdev = GET_DC_PHYSDEV( dc, pAngleArc ); result = physdev->funcs->pAngleArc( physdev, x, y, dwRadius, eStartAngle, eSweepAngle ); if (result) { dc->cur_pos.x = GDI_ROUND( x + cos( (eStartAngle + eSweepAngle) * M_PI / 180 ) * dwRadius ); dc->cur_pos.y = GDI_ROUND( y - sin( (eStartAngle + eSweepAngle) * M_PI / 180 ) * dwRadius ); } release_dc_ptr( dc ); return result; }
/*********************************************************************** * GDIRealizePalette (Not a Windows API) */ UINT WINAPI GDIRealizePalette( HDC hdc ) { UINT realized = 0; DC* dc = get_dc_ptr( hdc ); if (!dc) return 0; TRACE("%p...\n", hdc ); if( dc->hPalette == GetStockObject( DEFAULT_PALETTE )) { PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizeDefaultPalette ); realized = physdev->funcs->pRealizeDefaultPalette( physdev ); } else if (InterlockedExchangePointer( (void **)&hLastRealizedPalette, dc->hPalette ) != dc->hPalette) { PHYSDEV physdev = GET_DC_PHYSDEV( dc, pRealizePalette ); PALETTEOBJ *palPtr = GDI_GetObjPtr( dc->hPalette, OBJ_PAL ); if (palPtr) { realized = physdev->funcs->pRealizePalette( physdev, dc->hPalette, (dc->hPalette == hPrimaryPalette) ); palPtr->unrealize = physdev->funcs->pUnrealizePalette; GDI_ReleaseObj( dc->hPalette ); } } else TRACE(" skipping (hLastRealizedPalette = %p)\n", hLastRealizedPalette); release_dc_ptr( dc ); TRACE(" realized %i colors.\n", realized ); return realized; }
/****************************************************************************** * GdiGradientFill (GDI32.@) */ BOOL WINAPI GdiGradientFill( HDC hdc, TRIVERTEX *vert_array, ULONG nvert, void *grad_array, ULONG ngrad, ULONG mode ) { DC *dc; PHYSDEV physdev; BOOL ret; ULONG i; TRACE("%p vert_array:%p nvert:%d grad_array:%p ngrad:%d\n", hdc, vert_array, nvert, grad_array, ngrad); if (!vert_array || !nvert || !grad_array || !ngrad || mode > GRADIENT_FILL_TRIANGLE) { SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } for (i = 0; i < ngrad * (mode == GRADIENT_FILL_TRIANGLE ? 3 : 2); i++) if (((ULONG *)grad_array)[i] >= nvert) return FALSE; if (!(dc = get_dc_ptr( hdc ))) { SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } update_dc( dc ); physdev = GET_DC_PHYSDEV( dc, pGradientFill ); ret = physdev->funcs->pGradientFill( physdev, vert_array, nvert, grad_array, ngrad, mode ); release_dc_ptr( dc ); return ret; }
/*********************************************************************** * SetMetaRgn (GDI32.@) */ INT WINAPI SetMetaRgn( HDC hdc ) { INT ret; RECT dummy; DC *dc = get_dc_ptr( hdc ); if (!dc) return ERROR; if (dc->hMetaClipRgn) { /* the intersection becomes the new meta region */ DeleteObject( dc->hMetaRgn ); DeleteObject( dc->hClipRgn ); dc->hMetaRgn = dc->hMetaClipRgn; dc->hClipRgn = 0; dc->hMetaClipRgn = 0; } else if (dc->hClipRgn) { dc->hMetaRgn = dc->hClipRgn; dc->hClipRgn = 0; } /* else nothing to do */ /* Note: no need to call CLIPPING_UpdateGCRegion, the overall clip region hasn't changed */ ret = GetRgnBox( dc->hMetaRgn, &dummy ); release_dc_ptr( dc ); return ret; }
/****************************************************************************** * ExtSelectClipRgn [GDI32.@] */ INT WINAPI ExtSelectClipRgn( HDC hdc, HRGN hrgn, INT fnMode ) { INT retval; RECT rect; DC * dc = get_dc_ptr( hdc ); if (!dc) return ERROR; TRACE("%p %p %d\n", hdc, hrgn, fnMode ); update_dc( dc ); if (dc->funcs->pExtSelectClipRgn) { retval = dc->funcs->pExtSelectClipRgn( dc->physDev, hrgn, fnMode ); release_dc_ptr( dc ); return retval; } if (!hrgn) { if (fnMode == RGN_COPY) { if (dc->hClipRgn) DeleteObject( dc->hClipRgn ); dc->hClipRgn = 0; } else { FIXME("Unimplemented: hrgn NULL in mode: %d\n", fnMode); release_dc_ptr( dc ); return ERROR; } } else { if (!dc->hClipRgn) create_default_clip_region( dc ); if(fnMode == RGN_COPY) CombineRgn( dc->hClipRgn, hrgn, 0, fnMode ); else CombineRgn( dc->hClipRgn, dc->hClipRgn, hrgn, fnMode); } CLIPPING_UpdateGCRegion( dc ); release_dc_ptr( dc ); return GetClipBox(hdc, &rect); }
/*********************************************************************** * BITMAP_SelectObject */ static HGDIOBJ BITMAP_SelectObject( HGDIOBJ handle, HDC hdc ) { HGDIOBJ ret; BITMAPOBJ *bitmap; DC *dc; if (!(dc = get_dc_ptr( hdc ))) return 0; if (GetObjectType( hdc ) != OBJ_MEMDC) { ret = 0; goto done; } ret = dc->hBitmap; if (handle == dc->hBitmap) goto done; /* nothing to do */ if (!(bitmap = GDI_GetObjPtr( handle, BITMAP_MAGIC ))) { ret = 0; goto done; } if (bitmap->header.dwCount && (handle != GetStockObject(DEFAULT_BITMAP))) { WARN( "Bitmap already selected in another DC\n" ); GDI_ReleaseObj( handle ); ret = 0; goto done; } if (!bitmap->funcs && !BITMAP_SetOwnerDC( handle, dc )) { GDI_ReleaseObj( handle ); ret = 0; goto done; } if (dc->funcs->pSelectBitmap && !dc->funcs->pSelectBitmap( dc->physDev, handle )) { GDI_ReleaseObj( handle ); ret = 0; } else { dc->hBitmap = handle; GDI_inc_ref_count( handle ); dc->dirty = 0; SetRectRgn( dc->hVisRgn, 0, 0, bitmap->bitmap.bmWidth, bitmap->bitmap.bmHeight); GDI_ReleaseObj( handle ); DC_InitDC( dc ); GDI_dec_ref_count( ret ); } done: release_dc_ptr( dc ); return ret; }
/****************************************************************************** * AbortDoc [GDI32.@] */ INT WINAPI AbortDoc(HDC hdc) { INT ret = 0; DC *dc = get_dc_ptr( hdc ); if(!dc) return SP_ERROR; if (dc->funcs->pAbortDoc) ret = dc->funcs->pAbortDoc( dc->physDev ); release_dc_ptr( dc ); return ret; }
/*********************************************************************** * GetRandomRgn [GDI32.@] * * NOTES * This function is documented in MSDN online for the case of * iCode == SYSRGN (4). * * For iCode == 1 it should return the clip region * 2 " " " the meta region * 3 " " " the intersection of the clip with * the meta region (== 'Rao' region). * * See http://www.codeproject.com/gdi/cliprgnguide.asp */ INT WINAPI GetRandomRgn(HDC hDC, HRGN hRgn, INT iCode) { HRGN rgn; DC *dc = get_dc_ptr( hDC ); if (!dc) return -1; switch (iCode) { case 1: rgn = dc->hClipRgn; break; case 2: rgn = dc->hMetaRgn; break; case 3: rgn = dc->hMetaClipRgn; if(!rgn) rgn = dc->hClipRgn; if(!rgn) rgn = dc->hMetaRgn; break; case SYSRGN: /* == 4 */ update_dc( dc ); rgn = dc->hVisRgn; break; default: WARN("Unknown code %d\n", iCode); release_dc_ptr( dc ); return -1; } if (rgn) CombineRgn( hRgn, rgn, 0, RGN_COPY ); release_dc_ptr( dc ); /* On Windows NT/2000, the SYSRGN returned is in screen coordinates */ if (iCode == SYSRGN && !(GetVersion() & 0x80000000)) { POINT org; GetDCOrgEx( hDC, &org ); OffsetRgn( hRgn, org.x, org.y ); } return (rgn != 0); }
/*********************************************************************** * dibdrv_wglGetPixelFormat */ static int dibdrv_wglGetPixelFormat( HDC hdc ) { DC *dc = get_dc_ptr( hdc ); int ret = 0; if (dc) { ret = dc->pixel_format; release_dc_ptr( dc ); } return ret; }
/*********************************************************************** * SetPixelV (GDI32.@) */ BOOL WINAPI SetPixelV( HDC hdc, INT x, INT y, COLORREF color ) { PHYSDEV physdev; DC * dc = get_dc_ptr( hdc ); if (!dc) return FALSE; update_dc( dc ); physdev = GET_DC_PHYSDEV( dc, pSetPixel ); physdev->funcs->pSetPixel( physdev, x, y, color ); release_dc_ptr( dc ); return TRUE; }
/*********************************************************************** * GetPixel (GDI32.@) */ COLORREF WINAPI GetPixel( HDC hdc, INT x, INT y ) { PHYSDEV physdev; COLORREF ret; DC * dc = get_dc_ptr( hdc ); if (!dc) return CLR_INVALID; update_dc( dc ); physdev = GET_DC_PHYSDEV( dc, pGetPixel ); ret = physdev->funcs->pGetPixel( physdev, x, y ); release_dc_ptr( dc ); return ret; }
/*********************************************************************** * SetPixel (GDI32.@) */ COLORREF WINAPI SetPixel( HDC hdc, INT x, INT y, COLORREF color ) { PHYSDEV physdev; COLORREF ret; DC * dc = get_dc_ptr( hdc ); if (!dc) return 0; update_dc( dc ); physdev = GET_DC_PHYSDEV( dc, pSetPixel ); ret = physdev->funcs->pSetPixel( physdev, x, y, color ); release_dc_ptr( dc ); return ret; }