mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-07 13:18:02 +02:00
[win32] Make cairo as a win32 static library possible
This adds a win32 initialization function that is called from all surface creation and font creation functions to ensure that the win32 mutexes are initialized.
This commit is contained in:
parent
99360bd35d
commit
dbd0fa193c
3 changed files with 37 additions and 5 deletions
10
src/cairo-win32-font.c
Normal file → Executable file
10
src/cairo-win32-font.c
Normal file → Executable file
|
|
@ -237,6 +237,8 @@ _win32_scaled_font_create (LOGFONTW *logfont,
|
|||
cairo_matrix_t scale;
|
||||
cairo_status_t status;
|
||||
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
f = malloc (sizeof(cairo_win32_scaled_font_t));
|
||||
if (f == NULL)
|
||||
return NULL;
|
||||
|
|
@ -468,6 +470,8 @@ _cairo_win32_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
|
|||
int face_name_len;
|
||||
cairo_status_t status;
|
||||
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
status = _cairo_utf8_to_utf16 (toy_face->family, -1,
|
||||
&face_name, &face_name_len);
|
||||
if (status)
|
||||
|
|
@ -1489,6 +1493,8 @@ _cairo_win32_font_face_scaled_font_create (void *abstract_face,
|
|||
{
|
||||
cairo_win32_font_face_t *font_face = abstract_face;
|
||||
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
*font = _win32_scaled_font_create (&font_face->logfont,
|
||||
font_face->hfont,
|
||||
&font_face->base,
|
||||
|
|
@ -1526,6 +1532,8 @@ cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont)
|
|||
{
|
||||
cairo_win32_font_face_t *font_face;
|
||||
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
font_face = malloc (sizeof (cairo_win32_font_face_t));
|
||||
if (!font_face) {
|
||||
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
|
@ -1559,6 +1567,8 @@ cairo_win32_font_face_create_for_hfont (HFONT font)
|
|||
{
|
||||
cairo_win32_font_face_t *font_face;
|
||||
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
font_face = malloc (sizeof (cairo_win32_font_face_t));
|
||||
if (!font_face) {
|
||||
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
|
|
|||
3
src/cairo-win32-private.h
Normal file → Executable file
3
src/cairo-win32-private.h
Normal file → Executable file
|
|
@ -82,4 +82,7 @@ _cairo_win32_print_gdi_error (const char *context);
|
|||
cairo_bool_t
|
||||
_cairo_surface_is_win32 (cairo_surface_t *surface);
|
||||
|
||||
void
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
#endif /* CAIRO_WIN32_PRIVATE_H */
|
||||
|
|
|
|||
29
src/cairo-win32-surface.c
Normal file → Executable file
29
src/cairo-win32-surface.c
Normal file → Executable file
|
|
@ -266,6 +266,8 @@ _cairo_win32_surface_create_for_dc (HDC original_dc,
|
|||
char *bits;
|
||||
int rowstride;
|
||||
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
surface = malloc (sizeof (cairo_win32_surface_t));
|
||||
if (surface == NULL) {
|
||||
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
|
|
@ -1104,6 +1106,8 @@ cairo_win32_surface_create (HDC hdc)
|
|||
int depth;
|
||||
cairo_format_t format;
|
||||
|
||||
_cairo_win32_initialize ();
|
||||
|
||||
/* Try to figure out the drawing bounds for the Device context
|
||||
*/
|
||||
if (GetClipBox (hdc, &rect) == ERROR) {
|
||||
|
|
@ -1274,11 +1278,28 @@ static const cairo_surface_backend_t cairo_win32_surface_backend = {
|
|||
* threaded before any other function.
|
||||
* Initializing more than finally needed should not matter much.
|
||||
*/
|
||||
#ifndef HAVE_PTHREAD_H
|
||||
#if !defined(HAVE_PTHREAD_H)
|
||||
|
||||
CRITICAL_SECTION cairo_toy_font_face_hash_table_mutex;
|
||||
CRITICAL_SECTION cairo_scaled_font_map_mutex;
|
||||
CRITICAL_SECTION cairo_ft_unscaled_font_map_mutex;
|
||||
|
||||
static int _cairo_win32_initialized = 0;
|
||||
|
||||
void
|
||||
_cairo_win32_initialize () {
|
||||
if (_cairo_win32_initialized)
|
||||
return;
|
||||
|
||||
/* every 'mutex' from CAIRO_MUTEX_DECALRE needs to be initialized here */
|
||||
InitializeCriticalSection (&cairo_toy_font_face_hash_table_mutex);
|
||||
InitializeCriticalSection (&cairo_scaled_font_map_mutex);
|
||||
InitializeCriticalSection (&cairo_ft_unscaled_font_map_mutex);
|
||||
|
||||
_cairo_win32_initialized = 1;
|
||||
}
|
||||
|
||||
#if !defined(CAIRO_WIN32_STATIC_BUILD)
|
||||
BOOL WINAPI
|
||||
DllMain (HINSTANCE hinstDLL,
|
||||
DWORD fdwReason,
|
||||
|
|
@ -1287,10 +1308,7 @@ DllMain (HINSTANCE hinstDLL,
|
|||
switch (fdwReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
/* every 'mutex' from CAIRO_MUTEX_DECALRE needs to be initialized here */
|
||||
InitializeCriticalSection (&cairo_toy_font_face_hash_table_mutex);
|
||||
InitializeCriticalSection (&cairo_scaled_font_map_mutex);
|
||||
InitializeCriticalSection (&cairo_ft_unscaled_font_map_mutex);
|
||||
_cairo_win32_initialize();
|
||||
break;
|
||||
case DLL_PROCESS_DETACH:
|
||||
DeleteCriticalSection (&cairo_toy_font_face_hash_table_mutex);
|
||||
|
|
@ -1301,3 +1319,4 @@ DllMain (HINSTANCE hinstDLL,
|
|||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue