Jacek Caban : win32u: Move NtUserCountClipboardFormats implementation from user32.

Alexandre Julliard julliard at winehq.org
Thu Nov 11 16:01:29 CST 2021


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Thu Nov 11 14:13:45 2021 +0100

win32u: Move NtUserCountClipboardFormats implementation from user32.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/clipboard.c      | 23 +-----------------
 dlls/user32/user32.spec      |  2 +-
 dlls/win32u/Makefile.in      |  1 +
 dlls/win32u/clipboard.c      | 55 ++++++++++++++++++++++++++++++++++++++++++++
 dlls/win32u/driver.c         | 34 +++++++++++++++++++++++----
 dlls/win32u/gdiobj.c         |  1 +
 dlls/win32u/win32u.spec      |  2 +-
 dlls/win32u/win32u_private.h |  3 +++
 dlls/win32u/wrappers.c       |  5 ++++
 include/ntuser.h             |  1 +
 10 files changed, 99 insertions(+), 28 deletions(-)

diff --git a/dlls/user32/clipboard.c b/dlls/user32/clipboard.c
index a13085719a9..b9bcc184ca1 100644
--- a/dlls/user32/clipboard.c
+++ b/dlls/user32/clipboard.c
@@ -926,27 +926,6 @@ done:
 }
 
 
-/**************************************************************************
- *		CountClipboardFormats (USER32.@)
- */
-INT WINAPI CountClipboardFormats(void)
-{
-    INT count = 0;
-
-    USER_Driver->pUpdateClipboard();
-
-    SERVER_START_REQ( get_clipboard_formats )
-    {
-        wine_server_call( req );
-        count = reply->count;
-    }
-    SERVER_END_REQ;
-
-    TRACE("returning %d\n", count);
-    return count;
-}
-
-
 /**************************************************************************
  *		EnumClipboardFormats (USER32.@)
  */
@@ -1107,7 +1086,7 @@ INT WINAPI GetPriorityClipboardFormat(UINT *list, INT nCount)
 
     TRACE( "%p %u\n", list, nCount );
 
-    if(CountClipboardFormats() == 0)
+    if (NtUserCountClipboardFormats() == 0)
         return 0;
 
     for (i = 0; i < nCount; i++)
diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index e6906f025b7..87f4dc468bf 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -83,7 +83,7 @@
 @ stdcall CopyIcon(long)
 @ stdcall CopyImage(long long long long long)
 @ stdcall CopyRect(ptr ptr)
-@ stdcall CountClipboardFormats()
+@ stdcall CountClipboardFormats() NtUserCountClipboardFormats
 @ stdcall CreateAcceleratorTableA(ptr long)
 @ stdcall CreateAcceleratorTableW(ptr long)
 @ stdcall CreateCaret(long long long long)
diff --git a/dlls/win32u/Makefile.in b/dlls/win32u/Makefile.in
index 92e1858b9bc..306a3302260 100644
--- a/dlls/win32u/Makefile.in
+++ b/dlls/win32u/Makefile.in
@@ -11,6 +11,7 @@ C_SRCS = \
 	bitblt.c \
 	bitmap.c \
 	brush.c \
+	clipboard.c \
 	clipping.c \
 	dc.c \
 	dib.c \
diff --git a/dlls/win32u/clipboard.c b/dlls/win32u/clipboard.c
new file mode 100644
index 00000000000..8d0e09fdb55
--- /dev/null
+++ b/dlls/win32u/clipboard.c
@@ -0,0 +1,55 @@
+/*
+ * WIN32 clipboard implementation
+ *
+ * Copyright 1994 Martin Ayotte
+ * Copyright 1996 Alex Korobka
+ * Copyright 1999 Noel Borthwick
+ * Copyright 2003 Ulrich Czekalla for CodeWeavers
+ * Copyright 2016 Alexandre Julliard
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ *
+ */
+
+#if 0
+#pragma makedep unix
+#endif
+
+#include "win32u_private.h"
+#include "wine/server.h"
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(clipboard);
+
+
+/**************************************************************************
+ *           NtUserCountClipboardFormats    (win32u.@)
+ */
+INT WINAPI NtUserCountClipboardFormats(void)
+{
+    INT count = 0;
+
+    user_driver->pUpdateClipboard();
+
+    SERVER_START_REQ( get_clipboard_formats )
+    {
+        wine_server_call( req );
+        count = reply->count;
+    }
+    SERVER_END_REQ;
+
+    TRACE( "returning %d\n", count );
+    return count;
+}
diff --git a/dlls/win32u/driver.c b/dlls/win32u/driver.c
index ae83749d10f..15e7d3701f7 100644
--- a/dlls/win32u/driver.c
+++ b/dlls/win32u/driver.c
@@ -56,7 +56,7 @@ struct d3dkmt_device
     struct list entry;                  /* List entry */
 };
 
-static const struct user_driver_funcs *user_driver;
+static const struct user_driver_funcs lazy_load_driver;
 
 static struct list d3dkmt_adapters = LIST_INIT( d3dkmt_adapters );
 static struct list d3dkmt_devices = LIST_INIT( d3dkmt_devices );
@@ -70,9 +70,10 @@ static pthread_mutex_t driver_lock = PTHREAD_MUTEX_INITIALIZER;
  */
 const struct gdi_dc_funcs *get_display_driver(void)
 {
-    if (!user_driver)
+    if (user_driver == &lazy_load_driver)
     {
-        if (!user_callbacks || !user_callbacks->pGetDesktopWindow() || !user_driver)
+        if (!user_callbacks || !user_callbacks->pGetDesktopWindow() ||
+            user_driver == &lazy_load_driver)
         {
             static struct user_driver_funcs empty_funcs;
             WARN( "failed to load the display driver, falling back to null driver\n" );
@@ -123,7 +124,7 @@ static BOOL CDECL nulldrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT
 
 static BOOL CDECL nulldrv_CreateCompatibleDC( PHYSDEV orig, PHYSDEV *pdev )
 {
-    if (!user_driver || !user_driver->dc_funcs.pCreateCompatibleDC) return TRUE;
+    if (!user_driver->dc_funcs.pCreateCompatibleDC) return TRUE;
     return user_driver->dc_funcs.pCreateCompatibleDC( NULL, pdev );
 }
 
@@ -989,6 +990,31 @@ static void CDECL nulldrv_ThreadDetach( void )
 {
 }
 
+/**********************************************************************
+ * Lazy loading user driver
+ *
+ * Initial driver used before another driver is loaded.
+ * Each entry point simply loads the real driver and chains to it.
+ */
+
+static const struct user_driver_funcs *load_driver(void)
+{
+    get_display_driver();
+    return user_driver;
+}
+
+static void CDECL loaderdrv_UpdateClipboard(void)
+{
+    load_driver()->pUpdateClipboard();
+}
+
+static const struct user_driver_funcs lazy_load_driver =
+{
+    .pUpdateClipboard = loaderdrv_UpdateClipboard,
+};
+
+const struct user_driver_funcs *user_driver = &lazy_load_driver;
+
 /******************************************************************************
  *	     __wine_set_display_driver   (win32u.@)
  */
diff --git a/dlls/win32u/gdiobj.c b/dlls/win32u/gdiobj.c
index c8dae928340..4737aa30cd2 100644
--- a/dlls/win32u/gdiobj.c
+++ b/dlls/win32u/gdiobj.c
@@ -1167,6 +1167,7 @@ static struct unix_funcs unix_funcs =
     NtGdiUnrealizeObject,
     NtGdiUpdateColors,
     NtGdiWidenPath,
+    NtUserCountClipboardFormats,
 
     GDIRealizePalette,
     GDISelectPalette,
diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec
index 8327e588b77..daea9cfe21a 100644
--- a/dlls/win32u/win32u.spec
+++ b/dlls/win32u/win32u.spec
@@ -803,7 +803,7 @@
 @ stub NtUserConsoleControl
 @ stub NtUserConvertMemHandle
 @ stub NtUserCopyAcceleratorTable
-@ stub NtUserCountClipboardFormats
+@ stdcall NtUserCountClipboardFormats()
 @ stub NtUserCreateAcceleratorTable
 @ stub NtUserCreateActivationGroup
 @ stub NtUserCreateActivationObject
diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h
index de3c69b9ed4..a78c7bb906b 100644
--- a/dlls/win32u/win32u_private.h
+++ b/dlls/win32u/win32u_private.h
@@ -194,6 +194,7 @@ struct unix_funcs
     BOOL     (WINAPI *pNtGdiUnrealizeObject)( HGDIOBJ obj );
     BOOL     (WINAPI *pNtGdiUpdateColors)( HDC hdc );
     BOOL     (WINAPI *pNtGdiWidenPath)( HDC hdc );
+    INT      (WINAPI *pNtUserCountClipboardFormats)(void);
 
     /* Wine-specific functions */
     UINT (WINAPI *pGDIRealizePalette)( HDC hdc );
@@ -229,6 +230,8 @@ extern HKEY reg_open_key( HKEY root, const WCHAR *name, ULONG name_len ) DECLSPE
 extern ULONG query_reg_ascii_value( HKEY hkey, const char *name,
                                     KEY_VALUE_PARTIAL_INFORMATION *info, ULONG size ) DECLSPEC_HIDDEN;
 
+extern const struct user_driver_funcs *user_driver DECLSPEC_HIDDEN;
+
 static inline WCHAR *win32u_wcsrchr( const WCHAR *str, WCHAR ch )
 {
     WCHAR *ret = NULL;
diff --git a/dlls/win32u/wrappers.c b/dlls/win32u/wrappers.c
index 922723903b9..d236fb6b2db 100644
--- a/dlls/win32u/wrappers.c
+++ b/dlls/win32u/wrappers.c
@@ -596,6 +596,11 @@ NTSTATUS WINAPI NtGdiDdDDISetVidPnSourceOwner( const D3DKMT_SETVIDPNSOURCEOWNER
     return unix_funcs->pNtGdiDdDDISetVidPnSourceOwner( desc );
 }
 
+INT WINAPI NtUserCountClipboardFormats(void)
+{
+    return unix_funcs->pNtUserCountClipboardFormats();
+}
+
 UINT WINAPI GDIRealizePalette( HDC hdc )
 {
     return unix_funcs->pGDIRealizePalette( hdc );
diff --git a/include/ntuser.h b/include/ntuser.h
index c05c743b553..de493b7a6d7 100644
--- a/include/ntuser.h
+++ b/include/ntuser.h
@@ -25,6 +25,7 @@
 
 BOOL    WINAPI NtUserCloseDesktop( HDESK handle );
 BOOL    WINAPI NtUserCloseWindowStation( HWINSTA handle );
+INT     WINAPI NtUserCountClipboardFormats(void);
 HDESK   WINAPI NtUserCreateDesktopEx( OBJECT_ATTRIBUTES *attr, UNICODE_STRING *device,
                                       DEVMODEW *devmode, DWORD flags, ACCESS_MASK access,
                                       ULONG heap_size );




More information about the wine-cvs mailing list