Alexandre Julliard : user32: Try to load libpng only once.

Alexandre Julliard julliard at winehq.org
Tue Apr 3 15:39:06 CDT 2018


Module: wine
Branch: master
Commit: b1631d69da38a2820db6b500e1c0cb9a9b7d0263
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=b1631d69da38a2820db6b500e1c0cb9a9b7d0263

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Apr  3 20:41:37 2018 +0200

user32: Try to load libpng only once.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/cursoricon.c | 65 ++++++++++++++++++++++++++----------------------
 1 file changed, 35 insertions(+), 30 deletions(-)

diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index 6304192..7730736 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -144,42 +144,42 @@ MAKE_FUNCPTR(png_set_gray_to_rgb);
 MAKE_FUNCPTR(png_set_read_fn);
 #undef MAKE_FUNCPTR
 
-static BOOL load_libpng(void)
-{
-    USER_Lock();
+static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
 
-    if (!libpng_handle && (libpng_handle = wine_dlopen(SONAME_LIBPNG, RTLD_NOW, NULL, 0)) != NULL)
+static BOOL WINAPI load_libpng( INIT_ONCE *once, void *param, void **context )
+{
+    if (!(libpng_handle = wine_dlopen(SONAME_LIBPNG, RTLD_NOW, NULL, 0)))
     {
+        WARN( "failed to load %s\n", SONAME_LIBPNG );
+        return TRUE;
+    }
 #define LOAD_FUNCPTR(f) \
     if ((p##f = wine_dlsym(libpng_handle, #f, NULL, 0)) == NULL) \
     { \
+        WARN( "%s not found in %s\n", #f, SONAME_LIBPNG ); \
         libpng_handle = NULL; \
-        USER_Unlock(); \
-        return FALSE; \
-    }
-        LOAD_FUNCPTR(png_create_read_struct);
-        LOAD_FUNCPTR(png_create_info_struct);
-        LOAD_FUNCPTR(png_destroy_read_struct);
-        LOAD_FUNCPTR(png_error);
-        LOAD_FUNCPTR(png_get_bit_depth);
-        LOAD_FUNCPTR(png_get_color_type);
-        LOAD_FUNCPTR(png_get_error_ptr);
-        LOAD_FUNCPTR(png_get_image_height);
-        LOAD_FUNCPTR(png_get_image_width);
-        LOAD_FUNCPTR(png_get_io_ptr);
-        LOAD_FUNCPTR(png_read_image);
-        LOAD_FUNCPTR(png_read_info);
-        LOAD_FUNCPTR(png_read_update_info);
-        LOAD_FUNCPTR(png_set_bgr);
-        LOAD_FUNCPTR(png_set_crc_action);
-        LOAD_FUNCPTR(png_set_error_fn);
-        LOAD_FUNCPTR(png_set_expand);
-        LOAD_FUNCPTR(png_set_gray_to_rgb);
-        LOAD_FUNCPTR(png_set_read_fn);
+        return TRUE; \
+    }
+    LOAD_FUNCPTR(png_create_read_struct);
+    LOAD_FUNCPTR(png_create_info_struct);
+    LOAD_FUNCPTR(png_destroy_read_struct);
+    LOAD_FUNCPTR(png_error);
+    LOAD_FUNCPTR(png_get_bit_depth);
+    LOAD_FUNCPTR(png_get_color_type);
+    LOAD_FUNCPTR(png_get_error_ptr);
+    LOAD_FUNCPTR(png_get_image_height);
+    LOAD_FUNCPTR(png_get_image_width);
+    LOAD_FUNCPTR(png_get_io_ptr);
+    LOAD_FUNCPTR(png_read_image);
+    LOAD_FUNCPTR(png_read_info);
+    LOAD_FUNCPTR(png_read_update_info);
+    LOAD_FUNCPTR(png_set_bgr);
+    LOAD_FUNCPTR(png_set_crc_action);
+    LOAD_FUNCPTR(png_set_error_fn);
+    LOAD_FUNCPTR(png_set_expand);
+    LOAD_FUNCPTR(png_set_gray_to_rgb);
+    LOAD_FUNCPTR(png_set_read_fn);
 #undef LOAD_FUNCPTR
-    }
-
-    USER_Unlock();
     return TRUE;
 }
 
@@ -233,6 +233,11 @@ static unsigned be_uint(unsigned val)
     return (u.c[0] << 24) | (u.c[1] << 16) | (u.c[2] << 8) | u.c[3];
 }
 
+static BOOL have_libpng(void)
+{
+    return InitOnceExecuteOnce( &init_once, load_libpng, NULL, NULL ) && libpng_handle;
+}
+
 static BOOL get_png_info(const void *png_data, DWORD size, int *width, int *height, int *bpp)
 {
     static const char png_sig[8] = { 0x89,'P','N','G',0x0d,0x0a,0x1a,0x0a };
@@ -271,7 +276,7 @@ static BITMAPINFO *load_png(const char *png_data, DWORD *size)
     if (!get_png_info(png_data, *size, &width, &height, &bpp))
         return NULL;
 
-    if (!load_libpng()) return NULL;
+    if (!have_libpng()) return NULL;
 
     png.buffer = png_data;
     png.size = *size;




More information about the wine-cvs mailing list