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
34 #include "ntgdi_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
39 #define FIRST_GDI_HANDLE 32
41 static GDI_SHARED_MEMORY gdi_shared
;
42 static GDI_HANDLE_ENTRY
*next_free
;
43 static GDI_HANDLE_ENTRY
*next_unused
= gdi_shared
.Handles
+ FIRST_GDI_HANDLE
;
44 static LONG debug_count
;
45 HMODULE gdi32_module
= 0;
47 static inline HGDIOBJ
entry_to_handle( GDI_HANDLE_ENTRY
*entry
)
49 unsigned int idx
= entry
- gdi_shared
.Handles
;
50 return LongToHandle( idx
| (entry
->Unique
<< 16) );
53 static inline GDI_HANDLE_ENTRY
*handle_entry( HGDIOBJ handle
)
55 unsigned int idx
= LOWORD(handle
);
57 if (idx
< GDI_MAX_HANDLE_COUNT
&& gdi_shared
.Handles
[idx
].Type
)
59 if (!HIWORD( handle
) || HIWORD( handle
) == gdi_shared
.Handles
[idx
].Unique
)
60 return &gdi_shared
.Handles
[idx
];
62 if (handle
) WARN( "invalid handle %p\n", handle
);
66 static inline struct gdi_obj_header
*entry_obj( GDI_HANDLE_ENTRY
*entry
)
68 return (struct gdi_obj_header
*)(ULONG_PTR
)entry
->Object
;
71 /***********************************************************************
75 static const LOGBRUSH WhiteBrush
= { BS_SOLID
, RGB(255,255,255), 0 };
76 static const LOGBRUSH BlackBrush
= { BS_SOLID
, RGB(0,0,0), 0 };
77 static const LOGBRUSH NullBrush
= { BS_NULL
, 0, 0 };
79 static const LOGBRUSH LtGrayBrush
= { BS_SOLID
, RGB(192,192,192), 0 };
80 static const LOGBRUSH GrayBrush
= { BS_SOLID
, RGB(128,128,128), 0 };
81 static const LOGBRUSH DkGrayBrush
= { BS_SOLID
, RGB(64,64,64), 0 };
83 static const LOGPEN WhitePen
= { PS_SOLID
, { 0, 0 }, RGB(255,255,255) };
84 static const LOGPEN BlackPen
= { PS_SOLID
, { 0, 0 }, RGB(0,0,0) };
85 static const LOGPEN NullPen
= { PS_NULL
, { 0, 0 }, 0 };
87 static const LOGBRUSH DCBrush
= { BS_SOLID
, RGB(255,255,255), 0 };
88 static const LOGPEN DCPen
= { PS_SOLID
, { 0, 0 }, RGB(0,0,0) };
90 /* reserve one extra entry for the stock default bitmap */
91 /* this is what Windows does too */
92 #define NB_STOCK_OBJECTS (STOCK_LAST+2)
94 static HGDIOBJ stock_objects
[NB_STOCK_OBJECTS
];
95 static HGDIOBJ scaled_stock_objects
[NB_STOCK_OBJECTS
];
97 static CRITICAL_SECTION gdi_section
;
98 static CRITICAL_SECTION_DEBUG critsect_debug
=
101 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
102 0, 0, { (DWORD_PTR
)(__FILE__
": gdi_section") }
104 static CRITICAL_SECTION gdi_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
107 /****************************************************************************
109 * language-independent stock fonts
113 static const LOGFONTW OEMFixedFont
=
114 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, OEM_CHARSET
,
115 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"" };
117 static const LOGFONTW AnsiFixedFont
=
118 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
119 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier" };
121 static const LOGFONTW AnsiVarFont
=
122 { 12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
123 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Sans Serif" };
125 /******************************************************************************
127 * language-dependent stock fonts
129 * 'ANSI' charset and 'DEFAULT' charset is not same.
130 * The chars in CP_ACP should be drawn with 'DEFAULT' charset.
131 * 'ANSI' charset seems to be identical with ISO-8859-1.
132 * 'DEFAULT' charset is a language-dependent charset.
134 * 'System' font seems to be an alias for language-dependent font.
138 * language-dependent stock fonts for all known charsets
139 * please see TranslateCharsetInfo (dlls/gdi/font.c) and
140 * CharsetBindingInfo (dlls/x11drv/xfont.c),
141 * and modify entries for your language if needed.
143 struct DefaultFontInfo
147 LOGFONTW DeviceDefaultFont
;
148 LOGFONTW SystemFixedFont
;
149 LOGFONTW DefaultGuiFont
;
152 static const struct DefaultFontInfo default_fonts
[] =
156 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
157 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
159 { /* Device Default */
160 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
161 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
164 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
165 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
167 { /* DefaultGuiFont */
168 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ANSI_CHARSET
,
169 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
172 { EASTEUROPE_CHARSET
,
174 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
175 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
177 { /* Device Default */
178 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
179 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
182 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
183 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
185 { /* DefaultGuiFont */
186 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, EASTEUROPE_CHARSET
,
187 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
192 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
193 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
195 { /* Device Default */
196 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
197 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
200 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
201 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
203 { /* DefaultGuiFont */
204 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, RUSSIAN_CHARSET
,
205 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
210 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
211 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
213 { /* Device Default */
214 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
215 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
218 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
219 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
221 { /* DefaultGuiFont */
222 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GREEK_CHARSET
,
223 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
228 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
229 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
231 { /* Device Default */
232 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
233 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
236 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
237 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
239 { /* DefaultGuiFont */
240 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, TURKISH_CHARSET
,
241 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
246 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
247 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
249 { /* Device Default */
250 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
251 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
254 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
255 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
257 { /* DefaultGuiFont */
258 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HEBREW_CHARSET
,
259 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
264 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
265 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
267 { /* Device Default */
268 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
269 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
272 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
273 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
275 { /* DefaultGuiFont */
276 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, ARABIC_CHARSET
,
277 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
282 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
283 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
285 { /* Device Default */
286 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
287 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
290 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
291 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
293 { /* DefaultGuiFont */
294 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, BALTIC_CHARSET
,
295 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
300 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
301 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
303 { /* Device Default */
304 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
305 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
308 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
309 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
311 { /* DefaultGuiFont */
312 -11, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, THAI_CHARSET
,
313 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
318 18, 8, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
319 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
321 { /* Device Default */
322 18, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
323 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
326 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
327 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
329 { /* DefaultGuiFont */
330 -12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, SHIFTJIS_CHARSET
,
331 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
336 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
337 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
339 { /* Device Default */
340 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
341 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
344 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
345 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
347 { /* DefaultGuiFont */
348 -12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, GB2312_CHARSET
,
349 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
354 16, 8, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
355 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
357 { /* Device Default */
358 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
359 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
362 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
363 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
365 { /* DefaultGuiFont */
366 -12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, HANGEUL_CHARSET
,
367 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
370 { CHINESEBIG5_CHARSET
,
372 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
373 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
375 { /* Device Default */
376 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
377 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
380 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
381 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
383 { /* DefaultGuiFont */
384 -12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, CHINESEBIG5_CHARSET
,
385 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
390 16, 7, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
391 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
393 { /* Device Default */
394 16, 0, 0, 0, FW_BOLD
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
395 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"System"
398 16, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
399 0, 0, DEFAULT_QUALITY
, FIXED_PITCH
| FF_MODERN
, L
"Courier"
401 { /* DefaultGuiFont */
402 -12, 0, 0, 0, FW_NORMAL
, FALSE
, FALSE
, FALSE
, JOHAB_CHARSET
,
403 0, 0, DEFAULT_QUALITY
, VARIABLE_PITCH
| FF_SWISS
, L
"MS Shell Dlg"
409 /*************************************************************************
410 * __wine_make_gdi_object_system (GDI32.@)
412 * USER has to tell GDI that its system brushes and pens are non-deletable.
413 * For a description of the GDI object magics and their flags,
414 * see "Undocumented Windows" (wrong about the OBJECT_NOSYSTEM flag, though).
416 void CDECL
__wine_make_gdi_object_system( HGDIOBJ handle
, BOOL set
)
418 GDI_HANDLE_ENTRY
*entry
;
420 EnterCriticalSection( &gdi_section
);
421 if ((entry
= handle_entry( handle
))) entry_obj( entry
)->system
= !!set
;
422 LeaveCriticalSection( &gdi_section
);
425 /******************************************************************************
428 static const struct DefaultFontInfo
* get_default_fonts(UINT charset
)
432 for(n
= 0; n
< ARRAY_SIZE( default_fonts
); n
++)
434 if ( default_fonts
[n
].charset
== charset
)
435 return &default_fonts
[n
];
438 FIXME( "unhandled charset 0x%08x - use ANSI_CHARSET for default stock objects\n", charset
);
439 return &default_fonts
[0];
443 /******************************************************************************
444 * get_default_charset (internal)
446 * get the language-dependent charset that can handle CP_ACP correctly.
448 static UINT
get_default_charset( void )
454 csi
.ciCharset
= ANSI_CHARSET
;
455 if ( !TranslateCharsetInfo( ULongToPtr(uACP
), &csi
, TCI_SRCCODEPAGE
) )
457 FIXME( "unhandled codepage %u - use ANSI_CHARSET for default stock objects\n", uACP
);
461 return csi
.ciCharset
;
465 /***********************************************************************
468 * Retrieve the reference count of a GDI object.
469 * Note: the object must be locked otherwise the count is meaningless.
471 UINT
GDI_get_ref_count( HGDIOBJ handle
)
473 GDI_HANDLE_ENTRY
*entry
;
476 EnterCriticalSection( &gdi_section
);
477 if ((entry
= handle_entry( handle
))) ret
= entry_obj( entry
)->selcount
;
478 LeaveCriticalSection( &gdi_section
);
483 /***********************************************************************
486 * Increment the reference count of a GDI object.
488 HGDIOBJ
GDI_inc_ref_count( HGDIOBJ handle
)
490 GDI_HANDLE_ENTRY
*entry
;
492 EnterCriticalSection( &gdi_section
);
493 if ((entry
= handle_entry( handle
))) entry_obj( entry
)->selcount
++;
495 LeaveCriticalSection( &gdi_section
);
500 /***********************************************************************
503 * Decrement the reference count of a GDI object.
505 BOOL
GDI_dec_ref_count( HGDIOBJ handle
)
507 GDI_HANDLE_ENTRY
*entry
;
509 EnterCriticalSection( &gdi_section
);
510 if ((entry
= handle_entry( handle
)))
512 assert( entry_obj( entry
)->selcount
);
513 if (!--entry_obj( entry
)->selcount
&& entry_obj( entry
)->deleted
)
515 /* handle delayed DeleteObject*/
516 entry_obj( entry
)->deleted
= 0;
517 LeaveCriticalSection( &gdi_section
);
518 TRACE( "executing delayed DeleteObject for %p\n", handle
);
519 DeleteObject( handle
);
523 LeaveCriticalSection( &gdi_section
);
524 return entry
!= NULL
;
528 /******************************************************************************
531 * Read a DWORD value from the registry
533 static BOOL
get_reg_dword(HKEY base
, const WCHAR
*key_name
, const WCHAR
*value_name
, DWORD
*value
)
536 DWORD type
, data
, size
= sizeof(data
);
539 if (RegOpenKeyW(base
, key_name
, &key
) == ERROR_SUCCESS
)
541 if (RegQueryValueExW(key
, value_name
, NULL
, &type
, (void *)&data
, &size
) == ERROR_SUCCESS
&&
552 /******************************************************************************
555 * get the dpi from the registry
561 if (get_reg_dword(HKEY_CURRENT_USER
, L
"Control Panel\\Desktop", L
"LogPixels", &dpi
))
563 if (get_reg_dword(HKEY_CURRENT_CONFIG
, L
"Software\\Fonts", L
"LogPixels", &dpi
))
568 /******************************************************************************
571 * Get the system DPI, based on the DPI awareness mode.
573 DWORD
get_system_dpi(void)
575 static UINT (WINAPI
*pGetDpiForSystem
)(void);
577 if (!pGetDpiForSystem
)
579 HMODULE user
= GetModuleHandleW( L
"user32.dll" );
580 if (user
) pGetDpiForSystem
= (void *)GetProcAddress( user
, "GetDpiForSystem" );
582 return pGetDpiForSystem
? pGetDpiForSystem() : 96;
585 static HFONT
create_scaled_font( const LOGFONTW
*deffont
)
597 lf
.lfHeight
= MulDiv( lf
.lfHeight
, dpi
, 96 );
598 return CreateFontIndirectW( &lf
);
601 static void set_gdi_shared(void)
604 if (NtCurrentTeb()->GdiBatchCount
)
606 TEB64
*teb64
= (TEB64
*)(UINT_PTR
)NtCurrentTeb()->GdiBatchCount
;
607 PEB64
*peb64
= (PEB64
*)(UINT_PTR
)teb64
->Peb
;
608 peb64
->GdiSharedHandleTable
= (UINT_PTR
)&gdi_shared
;
612 /* NOTE: Windows uses 32-bit for 32-bit kernel */
613 NtCurrentTeb()->Peb
->GdiSharedHandleTable
= &gdi_shared
;
616 static HGDIOBJ
make_stock_object( HGDIOBJ obj
)
618 GDI_HANDLE_ENTRY
*entry
;
620 if (!(entry
= handle_entry( obj
))) return 0;
621 entry_obj( entry
)->system
= TRUE
;
622 entry
->StockFlag
= 1;
623 return entry_to_handle( entry
);
626 /***********************************************************************
629 * GDI initialization.
631 BOOL WINAPI
DllMain( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
633 const struct DefaultFontInfo
* deffonts
;
636 if (reason
!= DLL_PROCESS_ATTACH
) return TRUE
;
639 DisableThreadLibraryCalls( inst
);
643 /* create stock objects */
644 stock_objects
[WHITE_BRUSH
] = CreateBrushIndirect( &WhiteBrush
);
645 stock_objects
[LTGRAY_BRUSH
] = CreateBrushIndirect( &LtGrayBrush
);
646 stock_objects
[GRAY_BRUSH
] = CreateBrushIndirect( &GrayBrush
);
647 stock_objects
[DKGRAY_BRUSH
] = CreateBrushIndirect( &DkGrayBrush
);
648 stock_objects
[BLACK_BRUSH
] = CreateBrushIndirect( &BlackBrush
);
649 stock_objects
[NULL_BRUSH
] = CreateBrushIndirect( &NullBrush
);
651 stock_objects
[WHITE_PEN
] = CreatePenIndirect( &WhitePen
);
652 stock_objects
[BLACK_PEN
] = CreatePenIndirect( &BlackPen
);
653 stock_objects
[NULL_PEN
] = CreatePenIndirect( &NullPen
);
655 stock_objects
[DEFAULT_PALETTE
] = PALETTE_Init();
656 stock_objects
[DEFAULT_BITMAP
] = CreateBitmap( 1, 1, 1, 1, NULL
);
658 /* language-independent stock fonts */
659 stock_objects
[OEM_FIXED_FONT
] = CreateFontIndirectW( &OEMFixedFont
);
660 stock_objects
[ANSI_FIXED_FONT
] = CreateFontIndirectW( &AnsiFixedFont
);
661 stock_objects
[ANSI_VAR_FONT
] = CreateFontIndirectW( &AnsiVarFont
);
663 /* language-dependent stock fonts */
664 deffonts
= get_default_fonts(get_default_charset());
665 stock_objects
[SYSTEM_FONT
] = CreateFontIndirectW( &deffonts
->SystemFont
);
666 stock_objects
[DEVICE_DEFAULT_FONT
] = CreateFontIndirectW( &deffonts
->DeviceDefaultFont
);
667 stock_objects
[SYSTEM_FIXED_FONT
] = CreateFontIndirectW( &deffonts
->SystemFixedFont
);
668 stock_objects
[DEFAULT_GUI_FONT
] = CreateFontIndirectW( &deffonts
->DefaultGuiFont
);
670 scaled_stock_objects
[OEM_FIXED_FONT
] = create_scaled_font( &OEMFixedFont
);
671 scaled_stock_objects
[SYSTEM_FONT
] = create_scaled_font( &deffonts
->SystemFont
);
672 scaled_stock_objects
[SYSTEM_FIXED_FONT
] = create_scaled_font( &deffonts
->SystemFixedFont
);
673 scaled_stock_objects
[DEFAULT_GUI_FONT
] = create_scaled_font( &deffonts
->DefaultGuiFont
);
675 stock_objects
[DC_BRUSH
] = CreateBrushIndirect( &DCBrush
);
676 stock_objects
[DC_PEN
] = CreatePenIndirect( &DCPen
);
678 /* clear the NOSYSTEM bit on all stock objects*/
679 for (i
= 0; i
< NB_STOCK_OBJECTS
; i
++)
681 stock_objects
[i
] = make_stock_object( stock_objects
[i
] );
682 scaled_stock_objects
[i
] = make_stock_object( scaled_stock_objects
[i
] );
688 /***********************************************************************
691 * Stub entry point, some games (CoD: Black Ops 3) call it directly.
693 BOOL WINAPI
GdiDllInitialize( HINSTANCE inst
, DWORD reason
, LPVOID reserved
)
700 static const char *gdi_obj_type( unsigned type
)
704 case NTGDI_OBJ_PEN
: return "NTGDI_OBJ_PEN";
705 case NTGDI_OBJ_BRUSH
: return "NTGDI_OBJ_BRUSH";
706 case NTGDI_OBJ_DC
: return "NTGDI_OBJ_DC";
707 case NTGDI_OBJ_METADC
: return "NTGDI_OBJ_METADC";
708 case NTGDI_OBJ_PAL
: return "NTGDI_OBJ_PAL";
709 case NTGDI_OBJ_FONT
: return "NTGDI_OBJ_FONT";
710 case NTGDI_OBJ_BITMAP
: return "NTGDI_OBJ_BITMAP";
711 case NTGDI_OBJ_REGION
: return "NTGDI_OBJ_REGION";
712 case NTGDI_OBJ_METAFILE
: return "NTGDI_OBJ_METAFILE";
713 case NTGDI_OBJ_MEMDC
: return "NTGDI_OBJ_MEMDC";
714 case NTGDI_OBJ_EXTPEN
: return "NTGDI_OBJ_EXTPEN";
715 case NTGDI_OBJ_ENHMETADC
: return "NTGDI_OBJ_ENHMETADC";
716 case NTGDI_OBJ_ENHMETAFILE
: return "NTGDI_OBJ_ENHMETAFILE";
717 default: return "UNKNOWN";
721 static void dump_gdi_objects( void )
723 GDI_HANDLE_ENTRY
*entry
;
725 TRACE( "%u objects:\n", GDI_MAX_HANDLE_COUNT
);
727 EnterCriticalSection( &gdi_section
);
728 for (entry
= gdi_shared
.Handles
; entry
< next_unused
; entry
++)
731 TRACE( "handle %p FREE\n", entry_to_handle( entry
));
733 TRACE( "handle %p obj %s type %s selcount %u deleted %u\n",
734 entry_to_handle( entry
), wine_dbgstr_longlong( entry
->Object
),
735 gdi_obj_type( entry
->ExtType
), entry_obj( entry
)->selcount
,
736 entry_obj( entry
)->deleted
);
738 LeaveCriticalSection( &gdi_section
);
741 /***********************************************************************
744 * Allocate a GDI handle for an object, which must have been allocated on the process heap.
746 HGDIOBJ
alloc_gdi_handle( struct gdi_obj_header
*obj
, WORD type
, const struct gdi_obj_funcs
*funcs
)
748 GDI_HANDLE_ENTRY
*entry
;
751 assert( type
); /* type 0 is reserved to mark free entries */
753 EnterCriticalSection( &gdi_section
);
757 next_free
= (GDI_HANDLE_ENTRY
*)(UINT_PTR
)entry
->Object
;
758 else if (next_unused
< gdi_shared
.Handles
+ GDI_MAX_HANDLE_COUNT
)
759 entry
= next_unused
++;
762 LeaveCriticalSection( &gdi_section
);
763 ERR( "out of GDI object handles, expect a crash\n" );
764 if (TRACE_ON(gdi
)) dump_gdi_objects();
771 entry
->Object
= (UINT_PTR
)obj
;
772 entry
->Type
= type
& 0x1f;
773 entry
->ExtType
= type
;
774 if (++entry
->Generation
== 0xff) entry
->Generation
= 1;
775 ret
= entry_to_handle( entry
);
776 LeaveCriticalSection( &gdi_section
);
777 TRACE( "allocated %s %p %u/%u\n", gdi_obj_type(type
), ret
,
778 InterlockedIncrement( &debug_count
), GDI_MAX_HANDLE_COUNT
);
783 /***********************************************************************
786 * Free a GDI handle and return a pointer to the object.
788 void *free_gdi_handle( HGDIOBJ handle
)
791 GDI_HANDLE_ENTRY
*entry
;
793 EnterCriticalSection( &gdi_section
);
794 if ((entry
= handle_entry( handle
)))
796 TRACE( "freed %s %p %u/%u\n", gdi_obj_type( entry
->ExtType
), handle
,
797 InterlockedDecrement( &debug_count
) + 1, GDI_MAX_HANDLE_COUNT
);
798 object
= entry_obj( entry
);
800 entry
->Object
= (UINT_PTR
)next_free
;
803 LeaveCriticalSection( &gdi_section
);
808 /***********************************************************************
809 * get_full_gdi_handle
811 * Return the full GDI handle from a possibly truncated value.
813 HGDIOBJ
get_full_gdi_handle( HGDIOBJ handle
)
815 GDI_HANDLE_ENTRY
*entry
;
817 if (!HIWORD( handle
))
819 EnterCriticalSection( &gdi_section
);
820 if ((entry
= handle_entry( handle
))) handle
= entry_to_handle( entry
);
821 LeaveCriticalSection( &gdi_section
);
826 /***********************************************************************
829 * Return a pointer to, and the type of, the GDI object
830 * associated with the handle.
831 * The object must be released with GDI_ReleaseObj.
833 void *get_any_obj_ptr( HGDIOBJ handle
, WORD
*type
)
836 GDI_HANDLE_ENTRY
*entry
;
838 EnterCriticalSection( &gdi_section
);
840 if ((entry
= handle_entry( handle
)))
842 ptr
= entry_obj( entry
);
843 *type
= entry
->ExtType
;
846 if (!ptr
) LeaveCriticalSection( &gdi_section
);
850 /***********************************************************************
853 * Return a pointer to the GDI object associated with the handle.
854 * Return NULL if the object has the wrong type.
855 * The object must be released with GDI_ReleaseObj.
857 void *GDI_GetObjPtr( HGDIOBJ handle
, WORD type
)
860 void *ptr
= get_any_obj_ptr( handle
, &ret_type
);
861 if (ptr
&& ret_type
!= type
)
863 GDI_ReleaseObj( handle
);
869 /***********************************************************************
873 void GDI_ReleaseObj( HGDIOBJ handle
)
875 LeaveCriticalSection( &gdi_section
);
879 /***********************************************************************
882 void GDI_CheckNotLock(void)
884 if (RtlIsCriticalSectionLockedByThread(&gdi_section
))
886 ERR( "BUG: holding GDI lock\n" );
892 /***********************************************************************
893 * NtGdiDeleteObjectApp (win32u.@)
895 * Delete a Gdi object.
898 * obj [I] Gdi object to delete
901 * Success: TRUE. If obj was not returned from GetStockObject(), any resources
902 * it consumed are released.
903 * Failure: FALSE, if obj is not a valid Gdi object, or is currently selected
906 BOOL WINAPI
NtGdiDeleteObjectApp( HGDIOBJ obj
)
908 GDI_HANDLE_ENTRY
*entry
;
909 const struct gdi_obj_funcs
*funcs
= NULL
;
910 struct gdi_obj_header
*header
;
912 EnterCriticalSection( &gdi_section
);
913 if (!(entry
= handle_entry( obj
)))
915 LeaveCriticalSection( &gdi_section
);
919 header
= entry_obj( entry
);
922 TRACE("Preserving system object %p\n", obj
);
923 LeaveCriticalSection( &gdi_section
);
927 obj
= entry_to_handle( entry
); /* make it a full handle */
929 if (header
->selcount
)
931 TRACE("delayed for %p because object in use, count %u\n", obj
, header
->selcount
);
932 header
->deleted
= 1; /* mark for delete */
934 else funcs
= header
->funcs
;
936 LeaveCriticalSection( &gdi_section
);
940 if (funcs
&& funcs
->pDeleteObject
) return funcs
->pDeleteObject( obj
);
944 /***********************************************************************
945 * NtGdiCreateClientObj (win32u.@)
947 HANDLE WINAPI
NtGdiCreateClientObj( ULONG type
)
949 struct gdi_obj_header
*obj
;
952 if (!(obj
= HeapAlloc( GetProcessHeap(), 0, sizeof(*obj
) )))
955 handle
= alloc_gdi_handle( obj
, type
, NULL
);
956 if (!handle
) HeapFree( GetProcessHeap(), 0, obj
);
960 /***********************************************************************
961 * NtGdiDeleteClientObj (win32u.@)
963 BOOL WINAPI
NtGdiDeleteClientObj( HGDIOBJ handle
)
966 if (!(obj
= free_gdi_handle( handle
))) return FALSE
;
967 HeapFree( GetProcessHeap(), 0, obj
);
971 /***********************************************************************
972 * GetStockObject (GDI32.@)
974 HGDIOBJ WINAPI
GetStockObject( INT obj
)
976 if ((obj
< 0) || (obj
>= NB_STOCK_OBJECTS
)) return 0;
981 case SYSTEM_FIXED_FONT
:
982 case DEFAULT_GUI_FONT
:
983 if (get_system_dpi() != 96) return scaled_stock_objects
[obj
];
986 return stock_objects
[obj
];
990 /***********************************************************************
991 * NtGdiExtGetObjectW (win32u.@)
993 INT WINAPI
NtGdiExtGetObjectW( HGDIOBJ handle
, INT count
, void *buffer
)
995 GDI_HANDLE_ENTRY
*entry
;
996 const struct gdi_obj_funcs
*funcs
= NULL
;
999 TRACE("%p %d %p\n", handle
, count
, buffer
);
1001 EnterCriticalSection( &gdi_section
);
1002 if ((entry
= handle_entry( handle
)))
1004 funcs
= entry_obj( entry
)->funcs
;
1005 handle
= entry_to_handle( entry
); /* make it a full handle */
1007 LeaveCriticalSection( &gdi_section
);
1009 if (funcs
&& funcs
->pGetObjectW
)
1011 if (buffer
&& ((ULONG_PTR
)buffer
>> 16) == 0) /* catch apps getting argument order wrong */
1012 SetLastError( ERROR_NOACCESS
);
1014 result
= funcs
->pGetObjectW( handle
, count
, buffer
);
1019 /***********************************************************************
1020 * GetCurrentObject (GDI32.@)
1022 * Get the currently selected object of a given type in a device context.
1025 * hdc [I] Device context to get the current object from
1026 * type [I] Type of current object to get (OBJ_* defines from "wingdi.h")
1029 * Success: The current object of the given type selected in hdc.
1030 * Failure: A NULL handle.
1033 * - only the following object types are supported:
1040 HGDIOBJ WINAPI
GetCurrentObject(HDC hdc
,UINT type
)
1043 DC
* dc
= get_dc_ptr( hdc
);
1048 case OBJ_EXTPEN
: /* fall through */
1049 case OBJ_PEN
: ret
= dc
->hPen
; break;
1050 case OBJ_BRUSH
: ret
= dc
->hBrush
; break;
1051 case OBJ_PAL
: ret
= dc
->hPalette
; break;
1052 case OBJ_FONT
: ret
= dc
->hFont
; break;
1053 case OBJ_BITMAP
: ret
= dc
->hBitmap
; break;
1055 /* tests show that OBJ_REGION is explicitly ignored */
1056 case OBJ_REGION
: break;
1058 /* the SDK only mentions those above */
1059 FIXME("(%p,%d): unknown type.\n",hdc
,type
);
1062 release_dc_ptr( dc
);
1067 /***********************************************************************
1068 * UnrealizeObject (GDI32.@)
1070 BOOL WINAPI
UnrealizeObject( HGDIOBJ obj
)
1072 const struct gdi_obj_funcs
*funcs
= NULL
;
1073 GDI_HANDLE_ENTRY
*entry
;
1075 EnterCriticalSection( &gdi_section
);
1076 if ((entry
= handle_entry( obj
)))
1078 funcs
= entry_obj( entry
)->funcs
;
1079 obj
= entry_to_handle( entry
); /* make it a full handle */
1081 LeaveCriticalSection( &gdi_section
);
1083 if (funcs
&& funcs
->pUnrealizeObject
) return funcs
->pUnrealizeObject( obj
);
1084 return funcs
!= NULL
;
1088 /* Solid colors to enumerate */
1089 static const COLORREF solid_colors
[] =
1090 { RGB(0x00,0x00,0x00), RGB(0xff,0xff,0xff),
1091 RGB(0xff,0x00,0x00), RGB(0x00,0xff,0x00),
1092 RGB(0x00,0x00,0xff), RGB(0xff,0xff,0x00),
1093 RGB(0xff,0x00,0xff), RGB(0x00,0xff,0xff),
1094 RGB(0x80,0x00,0x00), RGB(0x00,0x80,0x00),
1095 RGB(0x80,0x80,0x00), RGB(0x00,0x00,0x80),
1096 RGB(0x80,0x00,0x80), RGB(0x00,0x80,0x80),
1097 RGB(0x80,0x80,0x80), RGB(0xc0,0xc0,0xc0)
1101 /***********************************************************************
1102 * EnumObjects (GDI32.@)
1104 INT WINAPI
EnumObjects( HDC hdc
, INT nObjType
,
1105 GOBJENUMPROC lpEnumFunc
, LPARAM lParam
)
1112 TRACE("%p %d %p %08lx\n", hdc
, nObjType
, lpEnumFunc
, lParam
);
1116 /* Enumerate solid pens */
1117 for (i
= 0; i
< ARRAY_SIZE( solid_colors
); i
++)
1119 pen
.lopnStyle
= PS_SOLID
;
1120 pen
.lopnWidth
.x
= 1;
1121 pen
.lopnWidth
.y
= 0;
1122 pen
.lopnColor
= solid_colors
[i
];
1123 retval
= lpEnumFunc( &pen
, lParam
);
1124 TRACE("solid pen %08x, ret=%d\n",
1125 solid_colors
[i
], retval
);
1131 /* Enumerate solid brushes */
1132 for (i
= 0; i
< ARRAY_SIZE( solid_colors
); i
++)
1134 brush
.lbStyle
= BS_SOLID
;
1135 brush
.lbColor
= solid_colors
[i
];
1137 retval
= lpEnumFunc( &brush
, lParam
);
1138 TRACE("solid brush %08x, ret=%d\n",
1139 solid_colors
[i
], retval
);
1143 /* Now enumerate hatched brushes */
1144 if (retval
) for (i
= HS_HORIZONTAL
; i
<= HS_DIAGCROSS
; i
++)
1146 brush
.lbStyle
= BS_HATCHED
;
1147 brush
.lbColor
= RGB(0,0,0);
1149 retval
= lpEnumFunc( &brush
, lParam
);
1150 TRACE("hatched brush %d, ret=%d\n",
1157 /* FIXME: implement Win32 types */
1158 WARN("(%d): Invalid type\n", nObjType
);
1165 /***********************************************************************
1166 * SetObjectOwner (GDI32.@)
1168 void WINAPI
SetObjectOwner( HGDIOBJ handle
, HANDLE owner
)
1173 /***********************************************************************
1174 * GdiInitializeLanguagePack (GDI32.@)
1176 DWORD WINAPI
GdiInitializeLanguagePack( DWORD arg
)
1182 /***********************************************************************
1183 * GdiFlush (GDI32.@)
1185 BOOL WINAPI
GdiFlush(void)
1187 return TRUE
; /* FIXME */
1191 /***********************************************************************
1192 * GdiGetBatchLimit (GDI32.@)
1194 DWORD WINAPI
GdiGetBatchLimit(void)
1196 return 1; /* FIXME */
1200 /***********************************************************************
1201 * GdiSetBatchLimit (GDI32.@)
1203 DWORD WINAPI
GdiSetBatchLimit( DWORD limit
)
1205 return 1; /* FIXME */
1209 /*******************************************************************
1210 * GetColorAdjustment [GDI32.@]
1214 BOOL WINAPI
GetColorAdjustment(HDC hdc
, LPCOLORADJUSTMENT lpca
)
1220 /*******************************************************************
1221 * GdiComment [GDI32.@]
1225 BOOL WINAPI
GdiComment(HDC hdc
, UINT cbSize
, const BYTE
*lpData
)
1227 DC
*dc
= get_dc_ptr(hdc
);
1232 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pGdiComment
);
1233 ret
= physdev
->funcs
->pGdiComment( physdev
, cbSize
, lpData
);
1234 release_dc_ptr( dc
);
1239 /*******************************************************************
1240 * SetColorAdjustment [GDI32.@]
1244 BOOL WINAPI
SetColorAdjustment(HDC hdc
, const COLORADJUSTMENT
* lpca
)