2 * GDI Device Context functions
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "gdi_private.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dc
);
37 static BOOL
DC_DeleteObject( HGDIOBJ handle
);
39 static const struct gdi_obj_funcs dc_funcs
=
41 NULL
, /* pSelectObject */
42 NULL
, /* pGetObjectA */
43 NULL
, /* pGetObjectW */
44 NULL
, /* pUnrealizeObject */
45 DC_DeleteObject
/* pDeleteObject */
49 static inline DC
*get_dc_obj( HDC hdc
)
52 DC
*dc
= get_any_obj_ptr( hdc
, &type
);
63 GDI_ReleaseObj( hdc
);
64 SetLastError( ERROR_INVALID_HANDLE
);
70 /***********************************************************************
71 * set_initial_dc_state
73 static void set_initial_dc_state( DC
*dc
)
83 dc
->miterLimit
= 10.0f
; /* 10.0 is the default, from MSDN */
85 dc
->font_code_page
= CP_ACP
;
86 dc
->ROPmode
= R2_COPYPEN
;
87 dc
->polyFillMode
= ALTERNATE
;
88 dc
->stretchBltMode
= BLACKONWHITE
;
89 dc
->relAbsMode
= ABSOLUTE
;
90 dc
->backgroundMode
= OPAQUE
;
91 dc
->backgroundColor
= RGB( 255, 255, 255 );
92 dc
->dcBrushColor
= RGB( 255, 255, 255 );
93 dc
->dcPenColor
= RGB( 0, 0, 0 );
94 dc
->textColor
= RGB( 0, 0, 0 );
98 dc
->textAlign
= TA_LEFT
| TA_TOP
| TA_NOUPDATECP
;
102 dc
->MapMode
= MM_TEXT
;
103 dc
->GraphicsMode
= GM_COMPATIBLE
;
106 dc
->ArcDirection
= AD_COUNTERCLOCKWISE
;
107 dc
->xformWorld2Wnd
.eM11
= 1.0f
;
108 dc
->xformWorld2Wnd
.eM12
= 0.0f
;
109 dc
->xformWorld2Wnd
.eM21
= 0.0f
;
110 dc
->xformWorld2Wnd
.eM22
= 1.0f
;
111 dc
->xformWorld2Wnd
.eDx
= 0.0f
;
112 dc
->xformWorld2Wnd
.eDy
= 0.0f
;
113 dc
->xformWorld2Vport
= dc
->xformWorld2Wnd
;
114 dc
->xformVport2World
= dc
->xformWorld2Wnd
;
115 dc
->vport2WorldValid
= TRUE
;
117 reset_bounds( &dc
->bounds
);
120 /***********************************************************************
123 DC
*alloc_dc_ptr( WORD magic
)
127 if (!(dc
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*dc
) ))) return NULL
;
129 dc
->nulldrv
.funcs
= &null_driver
;
130 dc
->physDev
= &dc
->nulldrv
;
131 dc
->thread
= GetCurrentThreadId();
133 dc
->hPen
= GDI_inc_ref_count( GetStockObject( BLACK_PEN
));
134 dc
->hBrush
= GDI_inc_ref_count( GetStockObject( WHITE_BRUSH
));
135 dc
->hFont
= GDI_inc_ref_count( GetStockObject( SYSTEM_FONT
));
136 dc
->hPalette
= GetStockObject( DEFAULT_PALETTE
);
138 set_initial_dc_state( dc
);
140 if (!(dc
->hSelf
= alloc_gdi_handle( dc
, magic
, &dc_funcs
)))
142 HeapFree( GetProcessHeap(), 0, dc
);
145 dc
->nulldrv
.hdc
= dc
->hSelf
;
147 if (!font_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
157 /***********************************************************************
160 static void free_dc_state( DC
*dc
)
162 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
163 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
164 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
165 if (dc
->region
) DeleteObject( dc
->region
);
166 if (dc
->path
) free_gdi_path( dc
->path
);
167 HeapFree( GetProcessHeap(), 0, dc
);
171 /***********************************************************************
174 void free_dc_ptr( DC
*dc
)
176 assert( dc
->refcount
== 1 );
178 while (dc
->physDev
!= &dc
->nulldrv
)
180 PHYSDEV physdev
= dc
->physDev
;
181 dc
->physDev
= physdev
->next
;
182 physdev
->funcs
->pDeleteDC( physdev
);
184 GDI_dec_ref_count( dc
->hPen
);
185 GDI_dec_ref_count( dc
->hBrush
);
186 GDI_dec_ref_count( dc
->hFont
);
187 if (dc
->hBitmap
) GDI_dec_ref_count( dc
->hBitmap
);
188 free_gdi_handle( dc
->hSelf
);
193 /***********************************************************************
196 * Retrieve a DC pointer but release the GDI lock.
198 DC
*get_dc_ptr( HDC hdc
)
200 DC
*dc
= get_dc_obj( hdc
);
201 if (!dc
) return NULL
;
204 GDI_ReleaseObj( hdc
);
208 if (!InterlockedCompareExchange( &dc
->refcount
, 1, 0 ))
210 dc
->thread
= GetCurrentThreadId();
212 else if (dc
->thread
!= GetCurrentThreadId())
214 WARN( "dc %p belongs to thread %04x\n", hdc
, dc
->thread
);
215 GDI_ReleaseObj( hdc
);
218 else InterlockedIncrement( &dc
->refcount
);
220 GDI_ReleaseObj( hdc
);
225 /***********************************************************************
228 void release_dc_ptr( DC
*dc
)
233 ref
= InterlockedDecrement( &dc
->refcount
);
235 if (ref
) dc
->thread
= GetCurrentThreadId(); /* we still own it */
239 /***********************************************************************
242 * Make sure the DC vis region is up to date.
243 * This function may call up to USER so the GDI lock should _not_
244 * be held when calling it.
246 void update_dc( DC
*dc
)
248 if (InterlockedExchange( &dc
->dirty
, 0 ) && dc
->hookProc
)
249 dc
->hookProc( dc
->hSelf
, DCHC_INVALIDVISRGN
, dc
->dwHookData
, 0 );
253 /***********************************************************************
256 static BOOL
DC_DeleteObject( HGDIOBJ handle
)
258 return DeleteDC( handle
);
262 /***********************************************************************
265 * Setup device-specific DC values for a newly created DC.
267 void DC_InitDC( DC
* dc
)
269 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pRealizeDefaultPalette
);
270 physdev
->funcs
->pRealizeDefaultPalette( physdev
);
271 SetTextColor( dc
->hSelf
, dc
->textColor
);
272 SetBkColor( dc
->hSelf
, dc
->backgroundColor
);
273 SelectObject( dc
->hSelf
, dc
->hPen
);
274 SelectObject( dc
->hSelf
, dc
->hBrush
);
275 SelectObject( dc
->hSelf
, dc
->hFont
);
276 update_dc_clipping( dc
);
277 SetVirtualResolution( dc
->hSelf
, 0, 0, 0, 0 );
278 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
279 physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
);
283 /***********************************************************************
286 * Computes the inverse of the transformation xformSrc and stores it to
287 * xformDest. Returns TRUE if successful or FALSE if the xformSrc matrix
290 static BOOL
DC_InvertXform( const XFORM
*xformSrc
, XFORM
*xformDest
)
294 determinant
= xformSrc
->eM11
*xformSrc
->eM22
-
295 xformSrc
->eM12
*xformSrc
->eM21
;
296 if (determinant
> -1e-12 && determinant
< 1e-12)
299 xformDest
->eM11
= xformSrc
->eM22
/ determinant
;
300 xformDest
->eM12
= -xformSrc
->eM12
/ determinant
;
301 xformDest
->eM21
= -xformSrc
->eM21
/ determinant
;
302 xformDest
->eM22
= xformSrc
->eM11
/ determinant
;
303 xformDest
->eDx
= -xformSrc
->eDx
* xformDest
->eM11
-
304 xformSrc
->eDy
* xformDest
->eM21
;
305 xformDest
->eDy
= -xformSrc
->eDx
* xformDest
->eM12
-
306 xformSrc
->eDy
* xformDest
->eM22
;
311 /* Construct a transformation to do the window-to-viewport conversion */
312 static void construct_window_to_viewport(DC
*dc
, XFORM
*xform
)
314 double scaleX
, scaleY
;
315 scaleX
= (double)dc
->vport_ext
.cx
/ (double)dc
->wnd_ext
.cx
;
316 scaleY
= (double)dc
->vport_ext
.cy
/ (double)dc
->wnd_ext
.cy
;
318 if (dc
->layout
& LAYOUT_RTL
) scaleX
= -scaleX
;
319 xform
->eM11
= scaleX
;
322 xform
->eM22
= scaleY
;
323 xform
->eDx
= (double)dc
->vport_org
.x
- scaleX
* (double)dc
->wnd_org
.x
;
324 xform
->eDy
= (double)dc
->vport_org
.y
- scaleY
* (double)dc
->wnd_org
.y
;
325 if (dc
->layout
& LAYOUT_RTL
) xform
->eDx
= dc
->vis_rect
.right
- dc
->vis_rect
.left
- 1 - xform
->eDx
;
328 /***********************************************************************
331 * Compares the linear transform portion of two XFORMs (i.e. the 2x2 submatrix).
332 * Returns 0 if they match.
334 static inline int linear_xform_cmp( const XFORM
*a
, const XFORM
*b
)
336 return memcmp( a
, b
, FIELD_OFFSET( XFORM
, eDx
) );
339 /***********************************************************************
342 * Updates the xformWorld2Vport, xformVport2World and vport2WorldValid
343 * fields of the specified DC by creating a transformation that
344 * represents the current mapping mode and combining it with the DC's
345 * world transform. This function should be called whenever the
346 * parameters associated with the mapping mode (window and viewport
347 * extents and origins) or the world transform change.
349 void DC_UpdateXforms( DC
*dc
)
351 XFORM xformWnd2Vport
, oldworld2vport
;
353 construct_window_to_viewport(dc
, &xformWnd2Vport
);
355 oldworld2vport
= dc
->xformWorld2Vport
;
356 /* Combine with the world transformation */
357 CombineTransform( &dc
->xformWorld2Vport
, &dc
->xformWorld2Wnd
,
360 /* Create inverse of world-to-viewport transformation */
361 dc
->vport2WorldValid
= DC_InvertXform( &dc
->xformWorld2Vport
,
362 &dc
->xformVport2World
);
364 /* Reselect the font and pen back into the dc so that the size
366 if (linear_xform_cmp( &oldworld2vport
, &dc
->xformWorld2Vport
) &&
367 !GdiIsMetaFileDC(dc
->hSelf
))
369 SelectObject(dc
->hSelf
, dc
->hFont
);
370 SelectObject(dc
->hSelf
, dc
->hPen
);
375 /***********************************************************************
378 INT CDECL
nulldrv_SaveDC( PHYSDEV dev
)
380 DC
*newdc
, *dc
= get_nulldrv_dc( dev
);
382 if (!(newdc
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*newdc
)))) return 0;
383 newdc
->layout
= dc
->layout
;
384 newdc
->hPen
= dc
->hPen
;
385 newdc
->hBrush
= dc
->hBrush
;
386 newdc
->hFont
= dc
->hFont
;
387 newdc
->hBitmap
= dc
->hBitmap
;
388 newdc
->hPalette
= dc
->hPalette
;
389 newdc
->ROPmode
= dc
->ROPmode
;
390 newdc
->polyFillMode
= dc
->polyFillMode
;
391 newdc
->stretchBltMode
= dc
->stretchBltMode
;
392 newdc
->relAbsMode
= dc
->relAbsMode
;
393 newdc
->backgroundMode
= dc
->backgroundMode
;
394 newdc
->backgroundColor
= dc
->backgroundColor
;
395 newdc
->textColor
= dc
->textColor
;
396 newdc
->dcBrushColor
= dc
->dcBrushColor
;
397 newdc
->dcPenColor
= dc
->dcPenColor
;
398 newdc
->brush_org
= dc
->brush_org
;
399 newdc
->mapperFlags
= dc
->mapperFlags
;
400 newdc
->textAlign
= dc
->textAlign
;
401 newdc
->charExtra
= dc
->charExtra
;
402 newdc
->breakExtra
= dc
->breakExtra
;
403 newdc
->breakRem
= dc
->breakRem
;
404 newdc
->MapMode
= dc
->MapMode
;
405 newdc
->GraphicsMode
= dc
->GraphicsMode
;
406 newdc
->cur_pos
= dc
->cur_pos
;
407 newdc
->ArcDirection
= dc
->ArcDirection
;
408 newdc
->xformWorld2Wnd
= dc
->xformWorld2Wnd
;
409 newdc
->xformWorld2Vport
= dc
->xformWorld2Vport
;
410 newdc
->xformVport2World
= dc
->xformVport2World
;
411 newdc
->vport2WorldValid
= dc
->vport2WorldValid
;
412 newdc
->wnd_org
= dc
->wnd_org
;
413 newdc
->wnd_ext
= dc
->wnd_ext
;
414 newdc
->vport_org
= dc
->vport_org
;
415 newdc
->vport_ext
= dc
->vport_ext
;
416 newdc
->virtual_res
= dc
->virtual_res
;
417 newdc
->virtual_size
= dc
->virtual_size
;
419 /* Get/SetDCState() don't change hVisRgn field ("Undoc. Windows" p.559). */
423 newdc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
424 CombineRgn( newdc
->hClipRgn
, dc
->hClipRgn
, 0, RGN_COPY
);
428 newdc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
429 CombineRgn( newdc
->hMetaRgn
, dc
->hMetaRgn
, 0, RGN_COPY
);
432 if (!PATH_SavePath( newdc
, dc
))
434 release_dc_ptr( dc
);
435 free_dc_state( newdc
);
439 newdc
->saved_dc
= dc
->saved_dc
;
440 dc
->saved_dc
= newdc
;
441 return ++dc
->saveLevel
;
445 /***********************************************************************
448 BOOL CDECL
nulldrv_RestoreDC( PHYSDEV dev
, INT level
)
450 DC
*dcs
, *first_dcs
, *dc
= get_nulldrv_dc( dev
);
453 /* find the state level to restore */
455 if (abs(level
) > dc
->saveLevel
|| level
== 0) return FALSE
;
456 if (level
< 0) level
= dc
->saveLevel
+ level
+ 1;
457 first_dcs
= dc
->saved_dc
;
458 for (dcs
= first_dcs
, save_level
= dc
->saveLevel
; save_level
> level
; save_level
--)
461 /* restore the state */
463 if (!PATH_RestorePath( dc
, dcs
)) return FALSE
;
465 dc
->layout
= dcs
->layout
;
466 dc
->ROPmode
= dcs
->ROPmode
;
467 dc
->polyFillMode
= dcs
->polyFillMode
;
468 dc
->stretchBltMode
= dcs
->stretchBltMode
;
469 dc
->relAbsMode
= dcs
->relAbsMode
;
470 dc
->backgroundMode
= dcs
->backgroundMode
;
471 dc
->backgroundColor
= dcs
->backgroundColor
;
472 dc
->textColor
= dcs
->textColor
;
473 dc
->dcBrushColor
= dcs
->dcBrushColor
;
474 dc
->dcPenColor
= dcs
->dcPenColor
;
475 dc
->brush_org
= dcs
->brush_org
;
476 dc
->mapperFlags
= dcs
->mapperFlags
;
477 dc
->textAlign
= dcs
->textAlign
;
478 dc
->charExtra
= dcs
->charExtra
;
479 dc
->breakExtra
= dcs
->breakExtra
;
480 dc
->breakRem
= dcs
->breakRem
;
481 dc
->MapMode
= dcs
->MapMode
;
482 dc
->GraphicsMode
= dcs
->GraphicsMode
;
483 dc
->cur_pos
= dcs
->cur_pos
;
484 dc
->ArcDirection
= dcs
->ArcDirection
;
485 dc
->xformWorld2Wnd
= dcs
->xformWorld2Wnd
;
486 dc
->xformWorld2Vport
= dcs
->xformWorld2Vport
;
487 dc
->xformVport2World
= dcs
->xformVport2World
;
488 dc
->vport2WorldValid
= dcs
->vport2WorldValid
;
489 dc
->wnd_org
= dcs
->wnd_org
;
490 dc
->wnd_ext
= dcs
->wnd_ext
;
491 dc
->vport_org
= dcs
->vport_org
;
492 dc
->vport_ext
= dcs
->vport_ext
;
493 dc
->virtual_res
= dcs
->virtual_res
;
494 dc
->virtual_size
= dcs
->virtual_size
;
498 if (!dc
->hClipRgn
) dc
->hClipRgn
= CreateRectRgn( 0, 0, 0, 0 );
499 CombineRgn( dc
->hClipRgn
, dcs
->hClipRgn
, 0, RGN_COPY
);
503 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
508 if (!dc
->hMetaRgn
) dc
->hMetaRgn
= CreateRectRgn( 0, 0, 0, 0 );
509 CombineRgn( dc
->hMetaRgn
, dcs
->hMetaRgn
, 0, RGN_COPY
);
513 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
516 DC_UpdateXforms( dc
);
517 update_dc_clipping( dc
);
519 SelectObject( dev
->hdc
, dcs
->hBitmap
);
520 SelectObject( dev
->hdc
, dcs
->hBrush
);
521 SelectObject( dev
->hdc
, dcs
->hFont
);
522 SelectObject( dev
->hdc
, dcs
->hPen
);
523 SetBkColor( dev
->hdc
, dcs
->backgroundColor
);
524 SetTextColor( dev
->hdc
, dcs
->textColor
);
525 GDISelectPalette( dev
->hdc
, dcs
->hPalette
, FALSE
);
527 dc
->saved_dc
= dcs
->saved_dc
;
529 dc
->saveLevel
= save_level
- 1;
531 /* now destroy all the saved DCs */
535 DC
*next
= first_dcs
->saved_dc
;
536 free_dc_state( first_dcs
);
543 /***********************************************************************
546 static BOOL
reset_dc_state( HDC hdc
)
550 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
552 set_initial_dc_state( dc
);
553 SetBkColor( hdc
, RGB( 255, 255, 255 ));
554 SetTextColor( hdc
, RGB( 0, 0, 0 ));
555 SelectObject( hdc
, GetStockObject( WHITE_BRUSH
));
556 SelectObject( hdc
, GetStockObject( SYSTEM_FONT
));
557 SelectObject( hdc
, GetStockObject( BLACK_PEN
));
558 SetVirtualResolution( hdc
, 0, 0, 0, 0 );
559 GDISelectPalette( hdc
, GetStockObject( DEFAULT_PALETTE
), FALSE
);
560 SetBoundsRect( hdc
, NULL
, DCB_DISABLE
);
563 if (dc
->hClipRgn
) DeleteObject( dc
->hClipRgn
);
564 if (dc
->hMetaRgn
) DeleteObject( dc
->hMetaRgn
);
567 update_dc_clipping( dc
);
569 for (dcs
= dc
->saved_dc
; dcs
; dcs
= next
)
571 next
= dcs
->saved_dc
;
572 free_dc_state( dcs
);
576 release_dc_ptr( dc
);
581 /***********************************************************************
584 INT WINAPI
SaveDC( HDC hdc
)
589 if ((dc
= get_dc_ptr( hdc
)))
591 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSaveDC
);
592 ret
= physdev
->funcs
->pSaveDC( physdev
);
593 release_dc_ptr( dc
);
599 /***********************************************************************
600 * RestoreDC (GDI32.@)
602 BOOL WINAPI
RestoreDC( HDC hdc
, INT level
)
606 BOOL success
= FALSE
;
608 TRACE("%p %d\n", hdc
, level
);
609 if ((dc
= get_dc_ptr( hdc
)))
612 physdev
= GET_DC_PHYSDEV( dc
, pRestoreDC
);
613 success
= physdev
->funcs
->pRestoreDC( physdev
, level
);
614 release_dc_ptr( dc
);
620 /***********************************************************************
621 * CreateDCW (GDI32.@)
623 HDC WINAPI
CreateDCW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
624 const DEVMODEW
*initData
)
626 const WCHAR
*display
, *p
;
629 const struct gdi_dc_funcs
*funcs
;
634 if (!device
|| !DRIVER_GetDriverName( device
, buf
, 300 ))
638 ERR( "no device found for %s\n", debugstr_w(device
) );
641 lstrcpyW(buf
, driver
);
644 if (!(funcs
= DRIVER_load_driver( buf
)))
646 ERR( "no driver found for %s\n", debugstr_w(buf
) );
649 if (!(dc
= alloc_dc_ptr( OBJ_DC
))) return 0;
652 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
654 TRACE("(driver=%s, device=%s, output=%s): returning %p\n",
655 debugstr_w(driver
), debugstr_w(device
), debugstr_w(output
), dc
->hSelf
);
657 if (funcs
->pCreateDC
)
659 if (!funcs
->pCreateDC( &dc
->physDev
, buf
, device
, output
, initData
))
661 WARN("creation aborted by device\n" );
667 if (is_display_device( driver
))
669 else if (is_display_device( device
))
676 /* Copy only the display name. For example, \\.\DISPLAY1 in \\.\DISPLAY1\Monitor0 */
678 while (iswdigit( *p
))
680 lstrcpynW( dc
->display
, display
, p
- display
+ 1 );
681 dc
->display
[p
- display
] = '\0';
684 dc
->vis_rect
.left
= 0;
685 dc
->vis_rect
.top
= 0;
686 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
687 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
690 release_dc_ptr( dc
);
695 /***********************************************************************
696 * CreateDCA (GDI32.@)
698 HDC WINAPI
CreateDCA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
699 const DEVMODEA
*initData
)
701 UNICODE_STRING driverW
, deviceW
, outputW
;
705 if (driver
) RtlCreateUnicodeStringFromAsciiz(&driverW
, driver
);
706 else driverW
.Buffer
= NULL
;
708 if (device
) RtlCreateUnicodeStringFromAsciiz(&deviceW
, device
);
709 else deviceW
.Buffer
= NULL
;
711 if (output
) RtlCreateUnicodeStringFromAsciiz(&outputW
, output
);
712 else outputW
.Buffer
= NULL
;
717 /* don't convert initData for DISPLAY driver, it's not used */
718 if (!driverW
.Buffer
|| wcsicmp( driverW
.Buffer
, L
"display" ))
719 initDataW
= GdiConvertToDevmodeW(initData
);
722 ret
= CreateDCW( driverW
.Buffer
, deviceW
.Buffer
, outputW
.Buffer
, initDataW
);
724 RtlFreeUnicodeString(&driverW
);
725 RtlFreeUnicodeString(&deviceW
);
726 RtlFreeUnicodeString(&outputW
);
727 HeapFree(GetProcessHeap(), 0, initDataW
);
732 /***********************************************************************
733 * CreateICA (GDI32.@)
735 HDC WINAPI
CreateICA( LPCSTR driver
, LPCSTR device
, LPCSTR output
,
736 const DEVMODEA
* initData
)
738 /* Nothing special yet for ICs */
739 return CreateDCA( driver
, device
, output
, initData
);
743 /***********************************************************************
744 * CreateICW (GDI32.@)
746 HDC WINAPI
CreateICW( LPCWSTR driver
, LPCWSTR device
, LPCWSTR output
,
747 const DEVMODEW
* initData
)
749 /* Nothing special yet for ICs */
750 return CreateDCW( driver
, device
, output
, initData
);
754 /***********************************************************************
755 * CreateCompatibleDC (GDI32.@)
757 HDC WINAPI
CreateCompatibleDC( HDC hdc
)
761 const struct gdi_dc_funcs
*funcs
;
762 PHYSDEV physDev
= NULL
;
768 if (!(origDC
= get_dc_ptr( hdc
))) return 0;
769 physDev
= GET_DC_PHYSDEV( origDC
, pCreateCompatibleDC
);
770 funcs
= physDev
->funcs
;
771 release_dc_ptr( origDC
);
773 else funcs
= DRIVER_load_driver( L
"display" );
775 if (!(dc
= alloc_dc_ptr( OBJ_MEMDC
))) return 0;
777 TRACE("(%p): returning %p\n", hdc
, dc
->hSelf
);
779 dc
->hBitmap
= GDI_inc_ref_count( GetStockObject( DEFAULT_BITMAP
));
780 dc
->vis_rect
.left
= 0;
781 dc
->vis_rect
.top
= 0;
782 dc
->vis_rect
.right
= 1;
783 dc
->vis_rect
.bottom
= 1;
784 dc
->device_rect
= dc
->vis_rect
;
788 if (funcs
->pCreateCompatibleDC
&& !funcs
->pCreateCompatibleDC( physDev
, &dc
->physDev
))
790 WARN("creation aborted by device\n");
795 if (!dib_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
))
800 physDev
= GET_DC_PHYSDEV( dc
, pSelectBitmap
);
801 physDev
->funcs
->pSelectBitmap( physDev
, dc
->hBitmap
);
804 release_dc_ptr( dc
);
809 /***********************************************************************
812 BOOL WINAPI
DeleteDC( HDC hdc
)
820 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
821 if (dc
->refcount
!= 1)
823 FIXME( "not deleting busy DC %p refcount %u\n", dc
->hSelf
, dc
->refcount
);
824 release_dc_ptr( dc
);
828 /* Call hook procedure to check whether is it OK to delete this DC */
829 if (dc
->hookProc
&& !dc
->hookProc( dc
->hSelf
, DCHC_DELETEDC
, dc
->dwHookData
, 0 ))
831 release_dc_ptr( dc
);
834 reset_dc_state( hdc
);
840 /***********************************************************************
843 HDC WINAPI
ResetDCW( HDC hdc
, const DEVMODEW
*devmode
)
848 if ((dc
= get_dc_ptr( hdc
)))
850 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pResetDC
);
851 ret
= physdev
->funcs
->pResetDC( physdev
, devmode
);
852 if (ret
) /* reset the visible region */
855 dc
->vis_rect
.left
= 0;
856 dc
->vis_rect
.top
= 0;
857 dc
->vis_rect
.right
= GetDeviceCaps( hdc
, DESKTOPHORZRES
);
858 dc
->vis_rect
.bottom
= GetDeviceCaps( hdc
, DESKTOPVERTRES
);
859 if (dc
->hVisRgn
) DeleteObject( dc
->hVisRgn
);
861 update_dc_clipping( dc
);
863 release_dc_ptr( dc
);
869 /***********************************************************************
872 HDC WINAPI
ResetDCA( HDC hdc
, const DEVMODEA
*devmode
)
877 if (devmode
) devmodeW
= GdiConvertToDevmodeW(devmode
);
878 else devmodeW
= NULL
;
880 ret
= ResetDCW(hdc
, devmodeW
);
882 HeapFree(GetProcessHeap(), 0, devmodeW
);
887 /***********************************************************************
888 * GetDeviceCaps (GDI32.@)
890 INT WINAPI
GetDeviceCaps( HDC hdc
, INT cap
)
895 if ((dc
= get_dc_ptr( hdc
)))
897 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceCaps
);
898 ret
= physdev
->funcs
->pGetDeviceCaps( physdev
, cap
);
899 release_dc_ptr( dc
);
905 /***********************************************************************
906 * GetBkColor (GDI32.@)
908 COLORREF WINAPI
GetBkColor( HDC hdc
)
911 DC
* dc
= get_dc_ptr( hdc
);
914 ret
= dc
->backgroundColor
;
915 release_dc_ptr( dc
);
921 /***********************************************************************
922 * SetBkColor (GDI32.@)
924 COLORREF WINAPI
SetBkColor( HDC hdc
, COLORREF color
)
926 COLORREF ret
= CLR_INVALID
;
927 DC
* dc
= get_dc_ptr( hdc
);
929 TRACE("hdc=%p color=0x%08x\n", hdc
, color
);
933 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkColor
);
934 ret
= dc
->backgroundColor
;
935 dc
->backgroundColor
= physdev
->funcs
->pSetBkColor( physdev
, color
);
936 release_dc_ptr( dc
);
942 /***********************************************************************
943 * GetTextColor (GDI32.@)
945 COLORREF WINAPI
GetTextColor( HDC hdc
)
948 DC
* dc
= get_dc_ptr( hdc
);
952 release_dc_ptr( dc
);
958 /***********************************************************************
959 * SetTextColor (GDI32.@)
961 COLORREF WINAPI
SetTextColor( HDC hdc
, COLORREF color
)
963 COLORREF ret
= CLR_INVALID
;
964 DC
* dc
= get_dc_ptr( hdc
);
966 TRACE(" hdc=%p color=0x%08x\n", hdc
, color
);
970 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextColor
);
972 dc
->textColor
= physdev
->funcs
->pSetTextColor( physdev
, color
);
973 release_dc_ptr( dc
);
979 /***********************************************************************
980 * GetTextAlign (GDI32.@)
982 UINT WINAPI
GetTextAlign( HDC hdc
)
985 DC
* dc
= get_dc_ptr( hdc
);
989 release_dc_ptr( dc
);
995 /***********************************************************************
996 * SetTextAlign (GDI32.@)
998 UINT WINAPI
SetTextAlign( HDC hdc
, UINT align
)
1000 UINT ret
= GDI_ERROR
;
1001 DC
*dc
= get_dc_ptr( hdc
);
1003 TRACE("hdc=%p align=%d\n", hdc
, align
);
1007 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetTextAlign
);
1008 align
= physdev
->funcs
->pSetTextAlign( physdev
, align
);
1009 if (align
!= GDI_ERROR
)
1011 ret
= dc
->textAlign
;
1012 dc
->textAlign
= align
;
1014 release_dc_ptr( dc
);
1019 /***********************************************************************
1020 * GetDCOrgEx (GDI32.@)
1022 BOOL WINAPI
GetDCOrgEx( HDC hDC
, LPPOINT lpp
)
1026 if (!lpp
) return FALSE
;
1027 if (!(dc
= get_dc_ptr( hDC
))) return FALSE
;
1028 lpp
->x
= dc
->vis_rect
.left
;
1029 lpp
->y
= dc
->vis_rect
.top
;
1030 release_dc_ptr( dc
);
1035 /***********************************************************************
1036 * GetGraphicsMode (GDI32.@)
1038 INT WINAPI
GetGraphicsMode( HDC hdc
)
1041 DC
* dc
= get_dc_ptr( hdc
);
1044 ret
= dc
->GraphicsMode
;
1045 release_dc_ptr( dc
);
1051 /***********************************************************************
1052 * SetGraphicsMode (GDI32.@)
1054 INT WINAPI
SetGraphicsMode( HDC hdc
, INT mode
)
1057 DC
*dc
= get_dc_ptr( hdc
);
1059 /* One would think that setting the graphics mode to GM_COMPATIBLE
1060 * would also reset the world transformation matrix to the unity
1061 * matrix. However, in Windows, this is not the case. This doesn't
1062 * make a lot of sense to me, but that's the way it is.
1065 if ((mode
> 0) && (mode
<= GM_LAST
))
1067 ret
= dc
->GraphicsMode
;
1068 dc
->GraphicsMode
= mode
;
1070 /* font metrics depend on the graphics mode */
1071 if (ret
!= mode
) SelectObject(dc
->hSelf
, dc
->hFont
);
1072 release_dc_ptr( dc
);
1077 /***********************************************************************
1078 * GetArcDirection (GDI32.@)
1080 INT WINAPI
GetArcDirection( HDC hdc
)
1083 DC
* dc
= get_dc_ptr( hdc
);
1086 ret
= dc
->ArcDirection
;
1087 release_dc_ptr( dc
);
1093 /***********************************************************************
1094 * SetArcDirection (GDI32.@)
1096 INT WINAPI
SetArcDirection( HDC hdc
, INT dir
)
1101 if (dir
!= AD_COUNTERCLOCKWISE
&& dir
!= AD_CLOCKWISE
)
1103 SetLastError(ERROR_INVALID_PARAMETER
);
1107 if ((dc
= get_dc_ptr( hdc
)))
1109 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetArcDirection
);
1110 dir
= physdev
->funcs
->pSetArcDirection( physdev
, dir
);
1113 ret
= dc
->ArcDirection
;
1114 dc
->ArcDirection
= dir
;
1116 release_dc_ptr( dc
);
1122 /***********************************************************************
1123 * GetWorldTransform (GDI32.@)
1125 BOOL WINAPI
GetWorldTransform( HDC hdc
, LPXFORM xform
)
1128 if (!xform
) return FALSE
;
1129 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1130 *xform
= dc
->xformWorld2Wnd
;
1131 release_dc_ptr( dc
);
1136 /***********************************************************************
1137 * GetTransform (GDI32.@)
1141 * Returns one of the co-ordinate space transforms
1144 * hdc [I] Device context.
1145 * which [I] Which xform to return:
1146 * 0x203 World -> Page transform (that set by SetWorldTransform).
1147 * 0x304 Page -> Device transform (the mapping mode transform).
1148 * 0x204 World -> Device transform (the combination of the above two).
1149 * 0x402 Device -> World transform (the inversion of the above).
1150 * xform [O] The xform.
1153 BOOL WINAPI
GetTransform( HDC hdc
, DWORD which
, XFORM
*xform
)
1156 DC
*dc
= get_dc_ptr( hdc
);
1157 if (!dc
) return FALSE
;
1162 *xform
= dc
->xformWorld2Wnd
;
1166 construct_window_to_viewport(dc
, xform
);
1170 *xform
= dc
->xformWorld2Vport
;
1174 *xform
= dc
->xformVport2World
;
1178 FIXME("Unknown code %x\n", which
);
1182 release_dc_ptr( dc
);
1187 /****************************************************************************
1188 * CombineTransform [GDI32.@]
1189 * Combines two transformation matrices.
1192 * xformResult [O] Stores the result of combining the two matrices
1193 * xform1 [I] Specifies the first matrix to apply
1194 * xform2 [I] Specifies the second matrix to apply
1197 * The same matrix can be passed in for more than one of the parameters.
1201 * Failure: FALSE. Use GetLastError() to determine the cause.
1203 BOOL WINAPI
CombineTransform( LPXFORM xformResult
, const XFORM
*xform1
,
1204 const XFORM
*xform2
)
1208 /* Check for illegal parameters */
1209 if (!xformResult
|| !xform1
|| !xform2
)
1212 /* Create the result in a temporary XFORM, since xformResult may be
1213 * equal to xform1 or xform2 */
1214 xformTemp
.eM11
= xform1
->eM11
* xform2
->eM11
+
1215 xform1
->eM12
* xform2
->eM21
;
1216 xformTemp
.eM12
= xform1
->eM11
* xform2
->eM12
+
1217 xform1
->eM12
* xform2
->eM22
;
1218 xformTemp
.eM21
= xform1
->eM21
* xform2
->eM11
+
1219 xform1
->eM22
* xform2
->eM21
;
1220 xformTemp
.eM22
= xform1
->eM21
* xform2
->eM12
+
1221 xform1
->eM22
* xform2
->eM22
;
1222 xformTemp
.eDx
= xform1
->eDx
* xform2
->eM11
+
1223 xform1
->eDy
* xform2
->eM21
+
1225 xformTemp
.eDy
= xform1
->eDx
* xform2
->eM12
+
1226 xform1
->eDy
* xform2
->eM22
+
1229 /* Copy the result to xformResult */
1230 *xformResult
= xformTemp
;
1236 /***********************************************************************
1237 * SetDCHook (GDI32.@)
1239 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1241 BOOL WINAPI
SetDCHook( HDC hdc
, DCHOOKPROC hookProc
, DWORD_PTR dwHookData
)
1243 DC
*dc
= get_dc_ptr( hdc
);
1245 if (!dc
) return FALSE
;
1247 dc
->dwHookData
= dwHookData
;
1248 dc
->hookProc
= hookProc
;
1249 release_dc_ptr( dc
);
1254 /***********************************************************************
1255 * GetDCHook (GDI32.@)
1257 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1259 DWORD_PTR WINAPI
GetDCHook( HDC hdc
, DCHOOKPROC
*proc
)
1261 DC
*dc
= get_dc_ptr( hdc
);
1265 if (proc
) *proc
= dc
->hookProc
;
1266 ret
= dc
->dwHookData
;
1267 release_dc_ptr( dc
);
1272 /***********************************************************************
1273 * SetHookFlags (GDI32.@)
1275 * Note: this doesn't exist in Win32, we add it here because user32 needs it.
1277 WORD WINAPI
SetHookFlags( HDC hdc
, WORD flags
)
1279 DC
*dc
= get_dc_obj( hdc
); /* not get_dc_ptr, this needs to work from any thread */
1284 TRACE("hDC %p, flags %04x\n",hdc
,flags
);
1286 if (flags
& DCHF_INVALIDATEVISRGN
)
1287 ret
= InterlockedExchange( &dc
->dirty
, 1 );
1288 else if (flags
& DCHF_VALIDATEVISRGN
|| !flags
)
1289 ret
= InterlockedExchange( &dc
->dirty
, 0 );
1291 if (flags
& DCHF_DISABLEDC
)
1292 ret
= InterlockedExchange( &dc
->disabled
, 1 );
1293 else if (flags
& DCHF_ENABLEDC
)
1294 ret
= InterlockedExchange( &dc
->disabled
, 0 );
1296 GDI_ReleaseObj( hdc
);
1298 if (flags
& DCHF_RESETDC
) ret
= reset_dc_state( hdc
);
1302 /***********************************************************************
1303 * SetICMMode (GDI32.@)
1305 INT WINAPI
SetICMMode(HDC hdc
, INT iEnableICM
)
1307 /*FIXME: Assume that ICM is always off, and cannot be turned on */
1308 if (iEnableICM
== ICM_OFF
) return ICM_OFF
;
1309 if (iEnableICM
== ICM_ON
) return 0;
1310 if (iEnableICM
== ICM_QUERY
) return ICM_OFF
;
1314 /***********************************************************************
1315 * GetDeviceGammaRamp (GDI32.@)
1317 BOOL WINAPI
GetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1320 DC
*dc
= get_dc_ptr( hDC
);
1322 TRACE("%p, %p\n", hDC
, ptr
);
1325 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1327 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGetDeviceGammaRamp
);
1328 ret
= physdev
->funcs
->pGetDeviceGammaRamp( physdev
, ptr
);
1330 else SetLastError( ERROR_INVALID_PARAMETER
);
1331 release_dc_ptr( dc
);
1336 static BOOL
check_gamma_ramps(void *ptr
)
1340 while (ramp
< (WORD
*)ptr
+ 3 * 256)
1342 float r_x
, r_y
, r_lx
, r_ly
, r_d
, r_v
, r_e
, g_avg
, g_min
, g_max
;
1343 unsigned i
, f
, l
, g_n
, c
;
1349 TRACE("inverted or flat gamma ramp (%d->%d), rejected\n", f
, l
);
1353 g_min
= g_max
= g_avg
= 0.0;
1355 /* check gamma ramp entries to estimate the gamma */
1356 TRACE("analyzing gamma ramp (%d->%d)\n", f
, l
);
1357 for (i
=1, g_n
=0; i
<255; i
++)
1359 if (ramp
[i
] < f
|| ramp
[i
] > l
)
1361 TRACE("strange gamma ramp ([%d]=%d for %d->%d), rejected\n", i
, ramp
[i
], f
, l
);
1365 if (!c
) continue; /* avoid log(0) */
1367 /* normalize entry values into 0..1 range */
1368 r_x
= i
/255.0; r_y
= c
/ r_d
;
1369 /* compute logarithms of values */
1370 r_lx
= log(r_x
); r_ly
= log(r_y
);
1371 /* compute gamma for this entry */
1373 /* compute differential (error estimate) for this entry */
1374 /* some games use table-based logarithms that magnifies the error by 128 */
1375 r_e
= -r_lx
* 128 / (c
* r_lx
* r_lx
);
1377 /* compute min & max while compensating for estimated error */
1378 if (!g_n
|| g_min
> (r_v
+ r_e
)) g_min
= r_v
+ r_e
;
1379 if (!g_n
|| g_max
< (r_v
- r_e
)) g_max
= r_v
- r_e
;
1381 /* add to average */
1388 TRACE("no gamma data, shouldn't happen\n");
1392 TRACE("low bias is %d, high is %d, gamma is %5.3f\n", f
, 65535-l
, g_avg
);
1394 /* check that the gamma is reasonably uniform across the ramp */
1395 if (g_max
- g_min
> 12.8)
1397 TRACE("ramp not uniform (max=%f, min=%f, avg=%f), rejected\n", g_max
, g_min
, g_avg
);
1401 /* check that the gamma is not too bright */
1404 TRACE("too bright gamma ( %5.3f), rejected\n", g_avg
);
1414 /***********************************************************************
1415 * SetDeviceGammaRamp (GDI32.@)
1417 BOOL WINAPI
SetDeviceGammaRamp(HDC hDC
, LPVOID ptr
)
1420 DC
*dc
= get_dc_ptr( hDC
);
1422 TRACE("%p, %p\n", hDC
, ptr
);
1425 if (GetObjectType( hDC
) != OBJ_MEMDC
)
1427 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDeviceGammaRamp
);
1429 if (check_gamma_ramps(ptr
))
1430 ret
= physdev
->funcs
->pSetDeviceGammaRamp( physdev
, ptr
);
1432 else SetLastError( ERROR_INVALID_PARAMETER
);
1433 release_dc_ptr( dc
);
1438 /***********************************************************************
1439 * GetColorSpace (GDI32.@)
1441 HCOLORSPACE WINAPI
GetColorSpace(HDC hdc
)
1443 /*FIXME Need to do whatever GetColorSpace actually does */
1447 /***********************************************************************
1448 * CreateColorSpaceA (GDI32.@)
1450 HCOLORSPACE WINAPI
CreateColorSpaceA( LPLOGCOLORSPACEA lpLogColorSpace
)
1456 /***********************************************************************
1457 * CreateColorSpaceW (GDI32.@)
1459 HCOLORSPACE WINAPI
CreateColorSpaceW( LPLOGCOLORSPACEW lpLogColorSpace
)
1465 /***********************************************************************
1466 * DeleteColorSpace (GDI32.@)
1468 BOOL WINAPI
DeleteColorSpace( HCOLORSPACE hColorSpace
)
1475 /***********************************************************************
1476 * SetColorSpace (GDI32.@)
1478 HCOLORSPACE WINAPI
SetColorSpace( HDC hDC
, HCOLORSPACE hColorSpace
)
1485 /***********************************************************************
1486 * GetBoundsRect (GDI32.@)
1488 UINT WINAPI
GetBoundsRect(HDC hdc
, LPRECT rect
, UINT flags
)
1493 DC
*dc
= get_dc_ptr( hdc
);
1495 if ( !dc
) return 0;
1497 physdev
= GET_DC_PHYSDEV( dc
, pGetBoundsRect
);
1498 ret
= physdev
->funcs
->pGetBoundsRect( physdev
, &device_rect
, DCB_RESET
);
1501 release_dc_ptr( dc
);
1504 if (dc
->bounds_enabled
&& ret
== DCB_SET
) add_bounds_rect( &dc
->bounds
, &device_rect
);
1508 if (is_rect_empty( &dc
->bounds
))
1510 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
1516 rect
->left
= max( rect
->left
, 0 );
1517 rect
->top
= max( rect
->top
, 0 );
1518 rect
->right
= min( rect
->right
, dc
->vis_rect
.right
- dc
->vis_rect
.left
);
1519 rect
->bottom
= min( rect
->bottom
, dc
->vis_rect
.bottom
- dc
->vis_rect
.top
);
1522 dp_to_lp( dc
, (POINT
*)rect
, 2 );
1526 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1527 release_dc_ptr( dc
);
1532 /***********************************************************************
1533 * SetBoundsRect (GDI32.@)
1535 UINT WINAPI
SetBoundsRect(HDC hdc
, const RECT
* rect
, UINT flags
)
1541 if ((flags
& DCB_ENABLE
) && (flags
& DCB_DISABLE
)) return 0;
1542 if (!(dc
= get_dc_ptr( hdc
))) return 0;
1544 physdev
= GET_DC_PHYSDEV( dc
, pSetBoundsRect
);
1545 ret
= physdev
->funcs
->pSetBoundsRect( physdev
, &dc
->bounds
, flags
);
1548 release_dc_ptr( dc
);
1552 ret
= (dc
->bounds_enabled
? DCB_ENABLE
: DCB_DISABLE
) |
1553 (is_rect_empty( &dc
->bounds
) ? ret
& DCB_SET
: DCB_SET
);
1555 if (flags
& DCB_RESET
) reset_bounds( &dc
->bounds
);
1557 if ((flags
& DCB_ACCUMULATE
) && rect
)
1561 lp_to_dp( dc
, (POINT
*)&rc
, 2 );
1562 add_bounds_rect( &dc
->bounds
, &rc
);
1565 if (flags
& DCB_ENABLE
) dc
->bounds_enabled
= TRUE
;
1566 if (flags
& DCB_DISABLE
) dc
->bounds_enabled
= FALSE
;
1568 release_dc_ptr( dc
);
1573 /***********************************************************************
1574 * GetRelAbs (GDI32.@)
1576 INT WINAPI
GetRelAbs( HDC hdc
, DWORD dwIgnore
)
1579 DC
*dc
= get_dc_ptr( hdc
);
1582 ret
= dc
->relAbsMode
;
1583 release_dc_ptr( dc
);
1591 /***********************************************************************
1592 * GetBkMode (GDI32.@)
1594 INT WINAPI
GetBkMode( HDC hdc
)
1597 DC
* dc
= get_dc_ptr( hdc
);
1600 ret
= dc
->backgroundMode
;
1601 release_dc_ptr( dc
);
1607 /***********************************************************************
1608 * SetBkMode (GDI32.@)
1610 INT WINAPI
SetBkMode( HDC hdc
, INT mode
)
1615 if ((mode
<= 0) || (mode
> BKMODE_LAST
))
1617 SetLastError(ERROR_INVALID_PARAMETER
);
1620 if ((dc
= get_dc_ptr( hdc
)))
1622 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetBkMode
);
1623 mode
= physdev
->funcs
->pSetBkMode( physdev
, mode
);
1626 ret
= dc
->backgroundMode
;
1627 dc
->backgroundMode
= mode
;
1629 release_dc_ptr( dc
);
1635 /***********************************************************************
1638 INT WINAPI
GetROP2( HDC hdc
)
1641 DC
* dc
= get_dc_ptr( hdc
);
1645 release_dc_ptr( dc
);
1651 /***********************************************************************
1654 INT WINAPI
SetROP2( HDC hdc
, INT mode
)
1659 if ((mode
< R2_BLACK
) || (mode
> R2_WHITE
))
1661 SetLastError(ERROR_INVALID_PARAMETER
);
1664 if ((dc
= get_dc_ptr( hdc
)))
1666 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetROP2
);
1667 mode
= physdev
->funcs
->pSetROP2( physdev
, mode
);
1673 release_dc_ptr( dc
);
1679 /***********************************************************************
1680 * SetRelAbs (GDI32.@)
1682 INT WINAPI
SetRelAbs( HDC hdc
, INT mode
)
1687 if ((mode
!= ABSOLUTE
) && (mode
!= RELATIVE
))
1689 SetLastError(ERROR_INVALID_PARAMETER
);
1692 if ((dc
= get_dc_ptr( hdc
)))
1694 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetRelAbs
);
1695 mode
= physdev
->funcs
->pSetRelAbs( physdev
, mode
);
1698 ret
= dc
->relAbsMode
;
1699 dc
->relAbsMode
= mode
;
1701 release_dc_ptr( dc
);
1707 /***********************************************************************
1708 * GetPolyFillMode (GDI32.@)
1710 INT WINAPI
GetPolyFillMode( HDC hdc
)
1713 DC
* dc
= get_dc_ptr( hdc
);
1716 ret
= dc
->polyFillMode
;
1717 release_dc_ptr( dc
);
1723 /***********************************************************************
1724 * SetPolyFillMode (GDI32.@)
1726 INT WINAPI
SetPolyFillMode( HDC hdc
, INT mode
)
1731 if ((mode
<= 0) || (mode
> POLYFILL_LAST
))
1733 SetLastError(ERROR_INVALID_PARAMETER
);
1736 if ((dc
= get_dc_ptr( hdc
)))
1738 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetPolyFillMode
);
1739 mode
= physdev
->funcs
->pSetPolyFillMode( physdev
, mode
);
1742 ret
= dc
->polyFillMode
;
1743 dc
->polyFillMode
= mode
;
1745 release_dc_ptr( dc
);
1751 /***********************************************************************
1752 * GetStretchBltMode (GDI32.@)
1754 INT WINAPI
GetStretchBltMode( HDC hdc
)
1757 DC
* dc
= get_dc_ptr( hdc
);
1760 ret
= dc
->stretchBltMode
;
1761 release_dc_ptr( dc
);
1767 /***********************************************************************
1768 * SetStretchBltMode (GDI32.@)
1770 INT WINAPI
SetStretchBltMode( HDC hdc
, INT mode
)
1775 if ((mode
<= 0) || (mode
> MAXSTRETCHBLTMODE
))
1777 SetLastError(ERROR_INVALID_PARAMETER
);
1780 if ((dc
= get_dc_ptr( hdc
)))
1782 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetStretchBltMode
);
1783 mode
= physdev
->funcs
->pSetStretchBltMode( physdev
, mode
);
1786 ret
= dc
->stretchBltMode
;
1787 dc
->stretchBltMode
= mode
;
1789 release_dc_ptr( dc
);
1795 /***********************************************************************
1796 * GetMapMode (GDI32.@)
1798 INT WINAPI
GetMapMode( HDC hdc
)
1801 DC
* dc
= get_dc_ptr( hdc
);
1805 release_dc_ptr( dc
);
1811 /***********************************************************************
1812 * GetBrushOrgEx (GDI32.@)
1814 BOOL WINAPI
GetBrushOrgEx( HDC hdc
, LPPOINT pt
)
1816 DC
* dc
= get_dc_ptr( hdc
);
1817 if (!dc
) return FALSE
;
1818 *pt
= dc
->brush_org
;
1819 release_dc_ptr( dc
);
1824 /***********************************************************************
1825 * GetCurrentPositionEx (GDI32.@)
1827 BOOL WINAPI
GetCurrentPositionEx( HDC hdc
, LPPOINT pt
)
1829 DC
* dc
= get_dc_ptr( hdc
);
1830 if (!dc
) return FALSE
;
1832 release_dc_ptr( dc
);
1837 /***********************************************************************
1838 * GetViewportExtEx (GDI32.@)
1840 BOOL WINAPI
GetViewportExtEx( HDC hdc
, LPSIZE size
)
1842 DC
* dc
= get_dc_ptr( hdc
);
1843 if (!dc
) return FALSE
;
1844 *size
= dc
->vport_ext
;
1845 release_dc_ptr( dc
);
1850 /***********************************************************************
1851 * GetViewportOrgEx (GDI32.@)
1853 BOOL WINAPI
GetViewportOrgEx( HDC hdc
, LPPOINT pt
)
1855 DC
* dc
= get_dc_ptr( hdc
);
1856 if (!dc
) return FALSE
;
1857 *pt
= dc
->vport_org
;
1858 release_dc_ptr( dc
);
1863 /***********************************************************************
1864 * GetWindowExtEx (GDI32.@)
1866 BOOL WINAPI
GetWindowExtEx( HDC hdc
, LPSIZE size
)
1868 DC
* dc
= get_dc_ptr( hdc
);
1869 if (!dc
) return FALSE
;
1870 *size
= dc
->wnd_ext
;
1871 release_dc_ptr( dc
);
1876 /***********************************************************************
1877 * GetWindowOrgEx (GDI32.@)
1879 BOOL WINAPI
GetWindowOrgEx( HDC hdc
, LPPOINT pt
)
1881 DC
* dc
= get_dc_ptr( hdc
);
1882 if (!dc
) return FALSE
;
1884 release_dc_ptr( dc
);
1889 /***********************************************************************
1890 * GetLayout (GDI32.@)
1892 * Gets left->right or right->left text layout flags of a dc.
1895 DWORD WINAPI
GetLayout(HDC hdc
)
1897 DWORD layout
= GDI_ERROR
;
1899 DC
* dc
= get_dc_ptr( hdc
);
1902 layout
= dc
->layout
;
1903 release_dc_ptr( dc
);
1906 TRACE("hdc : %p, layout : %08x\n", hdc
, layout
);
1911 /***********************************************************************
1912 * SetLayout (GDI32.@)
1914 * Sets left->right or right->left text layout flags of a dc.
1917 DWORD WINAPI
SetLayout(HDC hdc
, DWORD layout
)
1919 DWORD oldlayout
= GDI_ERROR
;
1921 DC
* dc
= get_dc_ptr( hdc
);
1924 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetLayout
);
1925 layout
= physdev
->funcs
->pSetLayout( physdev
, layout
);
1926 if (layout
!= GDI_ERROR
)
1928 oldlayout
= dc
->layout
;
1929 dc
->layout
= layout
;
1930 if (layout
!= oldlayout
)
1932 if (layout
& LAYOUT_RTL
) dc
->MapMode
= MM_ANISOTROPIC
;
1933 DC_UpdateXforms( dc
);
1936 release_dc_ptr( dc
);
1939 TRACE("hdc : %p, old layout : %08x, new layout : %08x\n", hdc
, oldlayout
, layout
);
1944 /***********************************************************************
1945 * GetDCBrushColor (GDI32.@)
1947 COLORREF WINAPI
GetDCBrushColor(HDC hdc
)
1950 COLORREF dcBrushColor
= CLR_INVALID
;
1952 TRACE("hdc(%p)\n", hdc
);
1954 dc
= get_dc_ptr( hdc
);
1957 dcBrushColor
= dc
->dcBrushColor
;
1958 release_dc_ptr( dc
);
1961 return dcBrushColor
;
1964 /***********************************************************************
1965 * SetDCBrushColor (GDI32.@)
1967 COLORREF WINAPI
SetDCBrushColor(HDC hdc
, COLORREF crColor
)
1970 COLORREF oldClr
= CLR_INVALID
;
1972 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
1974 dc
= get_dc_ptr( hdc
);
1977 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCBrushColor
);
1978 crColor
= physdev
->funcs
->pSetDCBrushColor( physdev
, crColor
);
1979 if (crColor
!= CLR_INVALID
)
1981 oldClr
= dc
->dcBrushColor
;
1982 dc
->dcBrushColor
= crColor
;
1984 release_dc_ptr( dc
);
1990 /***********************************************************************
1991 * GetDCPenColor (GDI32.@)
1993 COLORREF WINAPI
GetDCPenColor(HDC hdc
)
1996 COLORREF dcPenColor
= CLR_INVALID
;
1998 TRACE("hdc(%p)\n", hdc
);
2000 dc
= get_dc_ptr( hdc
);
2003 dcPenColor
= dc
->dcPenColor
;
2004 release_dc_ptr( dc
);
2010 /***********************************************************************
2011 * SetDCPenColor (GDI32.@)
2013 COLORREF WINAPI
SetDCPenColor(HDC hdc
, COLORREF crColor
)
2016 COLORREF oldClr
= CLR_INVALID
;
2018 TRACE("hdc(%p) crColor(%08x)\n", hdc
, crColor
);
2020 dc
= get_dc_ptr( hdc
);
2023 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSetDCPenColor
);
2024 crColor
= physdev
->funcs
->pSetDCPenColor( physdev
, crColor
);
2025 if (crColor
!= CLR_INVALID
)
2027 oldClr
= dc
->dcPenColor
;
2028 dc
->dcPenColor
= crColor
;
2030 release_dc_ptr( dc
);
2036 /***********************************************************************
2037 * CancelDC (GDI32.@)
2039 BOOL WINAPI
CancelDC(HDC hdc
)
2045 /*******************************************************************
2046 * GetMiterLimit [GDI32.@]
2050 BOOL WINAPI
GetMiterLimit(HDC hdc
, PFLOAT peLimit
)
2055 TRACE("(%p,%p)\n", hdc
, peLimit
);
2057 dc
= get_dc_ptr( hdc
);
2061 *peLimit
= dc
->miterLimit
;
2063 release_dc_ptr( dc
);
2069 /*******************************************************************
2070 * SetMiterLimit [GDI32.@]
2074 BOOL WINAPI
SetMiterLimit(HDC hdc
, FLOAT eNewLimit
, PFLOAT peOldLimit
)
2079 TRACE("(%p,%f,%p)\n", hdc
, eNewLimit
, peOldLimit
);
2081 dc
= get_dc_ptr( hdc
);
2085 *peOldLimit
= dc
->miterLimit
;
2086 dc
->miterLimit
= eNewLimit
;
2087 release_dc_ptr( dc
);
2093 /*******************************************************************
2094 * GdiIsMetaPrintDC [GDI32.@]
2096 BOOL WINAPI
GdiIsMetaPrintDC(HDC hdc
)
2102 /*******************************************************************
2103 * GdiIsMetaFileDC [GDI32.@]
2105 BOOL WINAPI
GdiIsMetaFileDC(HDC hdc
)
2109 switch( GetObjectType( hdc
) )
2118 /*******************************************************************
2119 * GdiIsPlayMetafileDC [GDI32.@]
2121 BOOL WINAPI
GdiIsPlayMetafileDC(HDC hdc
)