From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winemac.drv/macdrv.h | 11 ++++ dlls/winemac.drv/opengl.c | 72 ++++---------------------- dlls/winemac.drv/vulkan.c | 90 +++------------------------------ dlls/winemac.drv/window.c | 104 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 146 deletions(-)
diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h index 9c76fe78c38..522b8d95ee8 100644 --- a/dlls/winemac.drv/macdrv.h +++ b/dlls/winemac.drv/macdrv.h @@ -180,6 +180,7 @@ extern BOOL macdrv_SystemParametersInfo(UINT action, UINT int_param, void *ptr_p macdrv_window cocoa_window; macdrv_view cocoa_view; macdrv_view client_cocoa_view; + macdrv_view client_view; struct window_rects rects; /* window rects in monitor DPI, relative to parent client area */ int pixel_format; /* pixel format for GL */ HANDLE drag_event; /* event to signal that Cocoa-driven window dragging has ended */ @@ -191,6 +192,16 @@ extern BOOL macdrv_SystemParametersInfo(UINT action, UINT int_param, void *ptr_p unsigned int minimized : 1; /* is window minimized? */ };
+struct macdrv_client_surface +{ + struct client_surface client; + macdrv_view cocoa_view; + macdrv_metal_device metal_device; + macdrv_metal_view metal_view; +}; + +extern struct macdrv_client_surface *macdrv_client_surface_create(HWND hwnd); + extern struct macdrv_win_data *get_win_data(HWND hwnd); extern void release_win_data(struct macdrv_win_data *data); extern void init_win_context(void); diff --git a/dlls/winemac.drv/opengl.c b/dlls/winemac.drv/opengl.c index 172b0d60226..3675d49eeb5 100644 --- a/dlls/winemac.drv/opengl.c +++ b/dlls/winemac.drv/opengl.c @@ -43,7 +43,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(wgl);
- struct gl_info { char *glExtensions;
@@ -96,7 +95,6 @@ static pthread_mutex_t context_mutex = PTHREAD_MUTEX_INITIALIZER; static void *opengl_handle; static const struct opengl_funcs *funcs; static const struct opengl_driver_funcs macdrv_driver_funcs; -static const struct client_surface_funcs macdrv_client_surface_funcs; static const struct opengl_drawable_funcs macdrv_surface_funcs; static const struct opengl_drawable_funcs macdrv_pbuffer_funcs;
@@ -1471,7 +1469,7 @@ static BOOL create_context(struct macdrv_context *context, CGLContextObj share,
static BOOL macdrv_surface_create(HWND hwnd, HDC hdc, int format, struct opengl_drawable **drawable) { - struct client_surface *client; + struct macdrv_client_surface *client; struct macdrv_win_data *data; struct gl_drawable *gl;
@@ -1486,9 +1484,9 @@ static BOOL macdrv_surface_create(HWND hwnd, HDC hdc, int format, struct opengl_ data->pixel_format = format; release_win_data(data);
- if (!(client = client_surface_create(sizeof(*client), &macdrv_client_surface_funcs, hwnd))) return FALSE; - gl = opengl_drawable_create(sizeof(*gl), &macdrv_surface_funcs, format, client); - client_surface_release(client); + if (!(client = macdrv_client_surface_create(hwnd))) return FALSE; + gl = opengl_drawable_create(sizeof(*gl), &macdrv_surface_funcs, format, &client->client); + client_surface_release(&client->client); if (!gl) return FALSE;
*drawable = &gl->base; @@ -1500,22 +1498,6 @@ static void macdrv_surface_destroy(struct opengl_drawable *base) TRACE("drawable %s\n", debugstr_opengl_drawable(base)); }
-/********************************************************************** - * mark_contexts_for_moved_view - */ -static void mark_contexts_for_moved_view(macdrv_view view) -{ - struct macdrv_context *context; - - pthread_mutex_lock(&context_mutex); - LIST_FOR_EACH_ENTRY(context, &context_list, struct macdrv_context, entry) - { - if (context->draw_view == view) - InterlockedExchange(&context->view_moved, TRUE); - } - pthread_mutex_unlock(&context_mutex); -} - /********************************************************************** * sync_context_rect */ @@ -1525,7 +1507,7 @@ static BOOL sync_context_rect(struct macdrv_context *context) RECT rect; struct macdrv_win_data *data = get_win_data(context->draw_hwnd);
- if (data && data->client_cocoa_view == context->draw_view) + if (data && data->client_view == context->draw_view) { if (InterlockedCompareExchange(&context->view_moved, FALSE, TRUE)) { @@ -2391,7 +2373,7 @@ static BOOL macdrv_make_current(struct opengl_drawable *draw_base, struct opengl }
context->draw_hwnd = hwnd; - context->draw_view = data->client_cocoa_view; + context->draw_view = data->client_view; context->draw_rect = data->rects.client; OffsetRect(&context->draw_rect, -data->rects.visible.left, -data->rects.visible.top); NtUserGetClientRect(hwnd, &context->draw_rect_win_dpi, NtUserGetDpiForWindow(hwnd)); @@ -2414,9 +2396,9 @@ static BOOL macdrv_make_current(struct opengl_drawable *draw_base, struct opengl HWND hwnd = read->base.client->hwnd; if ((data = get_win_data(hwnd))) { - if (data->client_cocoa_view != context->draw_view) + if (data->client_view != context->draw_view) { - context->read_view = data->client_cocoa_view; + context->read_view = data->client_view; context->read_rect = data->rects.client; OffsetRect(&context->read_rect, -data->rects.visible.left, -data->rects.visible.top); } @@ -2904,7 +2886,7 @@ static BOOL macdrv_surface_swap(struct opengl_drawable *base) return FALSE; }
- if (context && context->draw_view == data->client_cocoa_view) + if (context && context->draw_view == data->client_view) match = TRUE;
release_win_data(data); @@ -2934,42 +2916,6 @@ static const struct opengl_driver_funcs macdrv_driver_funcs = .p_pbuffer_bind = macdrv_pbuffer_bind, };
-static void macdrv_client_surface_destroy(struct client_surface *client) -{ - TRACE("%s\n", debugstr_client_surface(client)); -} - -static void macdrv_client_surface_detach(struct client_surface *client) -{ -} - -static void macdrv_client_surface_update(struct client_surface *client) -{ - struct macdrv_win_data *data = get_win_data(client->hwnd); - - TRACE("%s\n", debugstr_client_surface(client)); - - if (data->client_cocoa_view && data->pixel_format) - { - TRACE("GL view %p changed position; marking contexts\n", data->client_cocoa_view); - mark_contexts_for_moved_view(data->client_cocoa_view); - } - - release_win_data(data); -} - -static void macdrv_client_surface_present(struct client_surface *client, HDC hdc) -{ -} - -static const struct client_surface_funcs macdrv_client_surface_funcs = -{ - .destroy = macdrv_client_surface_destroy, - .detach = macdrv_client_surface_detach, - .update = macdrv_client_surface_update, - .present = macdrv_client_surface_present, -}; - static const struct opengl_drawable_funcs macdrv_surface_funcs = { .destroy = macdrv_surface_destroy, diff --git a/dlls/winemac.drv/vulkan.c b/dlls/winemac.drv/vulkan.c index cfdac1acdde..c67b007705a 100644 --- a/dlls/winemac.drv/vulkan.c +++ b/dlls/winemac.drv/vulkan.c @@ -49,18 +49,6 @@ typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; typedef VkFlags VkMetalSurfaceCreateFlagsEXT; #define VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT 1000217000
-struct wine_vk_surface -{ - struct client_surface client; - macdrv_metal_device device; - macdrv_metal_view view; -}; - -static struct wine_vk_surface *impl_from_client_surface(struct client_surface *client) -{ - return CONTAINING_RECORD(client, struct wine_vk_surface, client); -} - typedef struct VkMacOSSurfaceCreateInfoMVK { VkStructureType sType; @@ -80,47 +68,19 @@ typedef struct VkMetalSurfaceCreateInfoEXT static VkResult (*pvkCreateMacOSSurfaceMVK)(VkInstance, const VkMacOSSurfaceCreateInfoMVK*, const VkAllocationCallbacks *, VkSurfaceKHR *); static VkResult (*pvkCreateMetalSurfaceEXT)(VkInstance, const VkMetalSurfaceCreateInfoEXT*, const VkAllocationCallbacks *, VkSurfaceKHR *);
-static const struct client_surface_funcs macdrv_vulkan_surface_funcs; static const struct vulkan_driver_funcs macdrv_vulkan_driver_funcs;
static VkResult macdrv_vulkan_surface_create(HWND hwnd, const struct vulkan_instance *instance, VkSurfaceKHR *handle, struct client_surface **client) { VkResult res; - struct wine_vk_surface *surface; - struct macdrv_win_data *data; + struct macdrv_client_surface *surface;
TRACE("%p %p %p %p\n", hwnd, instance, handle, client);
- if (!(data = get_win_data(hwnd))) - { - FIXME("DC for window %p of other process: not implemented\n", hwnd); - return VK_ERROR_INCOMPATIBLE_DRIVER; - } - - if (!(surface = client_surface_create(sizeof(*surface), &macdrv_vulkan_surface_funcs, hwnd))) - { - release_win_data(data); - return VK_ERROR_OUT_OF_HOST_MEMORY; - } - - surface->device = macdrv_create_metal_device(); - if (!surface->device) - { - ERR("Failed to allocate Metal device for hwnd=%p\n", hwnd); - res = VK_ERROR_OUT_OF_HOST_MEMORY; - goto err; - } - - surface->view = macdrv_view_create_metal_view(data->client_cocoa_view, surface->device); - if (!surface->view) - { - ERR("Failed to allocate Metal view for hwnd=%p\n", hwnd); - - /* VK_KHR_win32_surface only allows out of host and device memory as errors. */ - res = VK_ERROR_OUT_OF_HOST_MEMORY; - goto err; - } + if (!(surface = macdrv_client_surface_create(hwnd))) return VK_ERROR_OUT_OF_HOST_MEMORY; + if (!(surface->metal_device = macdrv_create_metal_device())) goto err; + if (!(surface->metal_view = macdrv_view_create_metal_view(surface->cocoa_view, surface->metal_device))) goto err;
if (pvkCreateMetalSurfaceEXT) { @@ -128,7 +88,7 @@ static VkResult macdrv_vulkan_surface_create(HWND hwnd, const struct vulkan_inst create_info_host.sType = VK_STRUCTURE_TYPE_METAL_SURFACE_CREATE_INFO_EXT; create_info_host.pNext = NULL; create_info_host.flags = 0; /* reserved */ - create_info_host.pLayer = macdrv_view_get_metal_layer(surface->view); + create_info_host.pLayer = macdrv_view_get_metal_layer(surface->metal_view);
res = pvkCreateMetalSurfaceEXT(instance->host.instance, &create_info_host, NULL /* allocator */, handle); } @@ -138,7 +98,7 @@ static VkResult macdrv_vulkan_surface_create(HWND hwnd, const struct vulkan_inst create_info_host.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; create_info_host.pNext = NULL; create_info_host.flags = 0; /* reserved */ - create_info_host.pView = macdrv_view_get_metal_layer(surface->view); + create_info_host.pView = macdrv_view_get_metal_layer(surface->metal_view);
res = pvkCreateMacOSSurfaceMVK(instance->host.instance, &create_info_host, NULL /* allocator */, handle); } @@ -148,41 +108,13 @@ static VkResult macdrv_vulkan_surface_create(HWND hwnd, const struct vulkan_inst goto err; }
- release_win_data(data); - *client = &surface->client; - TRACE("Created surface=0x%s, client=%p\n", wine_dbgstr_longlong(*handle), *client); return VK_SUCCESS;
err: client_surface_release(&surface->client); - release_win_data(data); - return res; -} - -static void macdrv_vulkan_surface_destroy(struct client_surface *client) -{ - struct wine_vk_surface *surface = impl_from_client_surface(client); - - TRACE("%s\n", debugstr_client_surface(client)); - - if (surface->view) - macdrv_view_release_metal_view(surface->view); - if (surface->device) - macdrv_release_metal_device(surface->device); -} - -static void macdrv_vulkan_surface_detach(struct client_surface *client) -{ -} - -static void macdrv_vulkan_surface_update(struct client_surface *client) -{ -} - -static void macdrv_vulkan_surface_present(struct client_surface *client, HDC hdc) -{ + return VK_ERROR_INCOMPATIBLE_DRIVER; }
static VkBool32 macdrv_vkGetPhysicalDeviceWin32PresentationSupportKHR(VkPhysicalDevice phys_dev, @@ -198,14 +130,6 @@ static const char *macdrv_get_host_surface_extension(void) return pvkCreateMetalSurfaceEXT ? "VK_EXT_metal_surface" : "VK_MVK_macos_surface"; }
-static const struct client_surface_funcs macdrv_vulkan_surface_funcs = -{ - .destroy = macdrv_vulkan_surface_destroy, - .detach = macdrv_vulkan_surface_detach, - .update = macdrv_vulkan_surface_update, - .present = macdrv_vulkan_surface_present, -}; - static const struct vulkan_driver_funcs macdrv_vulkan_driver_funcs = { .p_vulkan_surface_create = macdrv_vulkan_surface_create, diff --git a/dlls/winemac.drv/window.c b/dlls/winemac.drv/window.c index c9a4fcd5060..a0a97ac2f7a 100644 --- a/dlls/winemac.drv/window.c +++ b/dlls/winemac.drv/window.c @@ -1295,6 +1295,110 @@ static void perform_window_command(HWND hwnd, unsigned int style_any, unsigned i NtUserPostMessage(hwnd, WM_SYSCOMMAND, command, 0); }
+static struct macdrv_client_surface *impl_from_client_surface(struct client_surface *client) +{ + return CONTAINING_RECORD(client, struct macdrv_client_surface, client); +} + +static void macdrv_client_surface_destroy(struct client_surface *client) +{ + struct macdrv_client_surface *surface = impl_from_client_surface(client); + + TRACE("%s\n", debugstr_client_surface(client)); + + if (surface->metal_view) macdrv_view_release_metal_view(surface->metal_view); + if (surface->metal_device) macdrv_release_metal_device(surface->metal_device); +} + +static void macdrv_client_surface_detach(struct client_surface *client) +{ + struct macdrv_client_surface *surface = impl_from_client_surface(client); + + TRACE("%s\n", debugstr_client_surface(client)); + + if (surface->cocoa_view) + { + struct macdrv_win_data *data; + + if ((data = get_win_data(client->hwnd))) + { + if (data->client_view == surface->cocoa_view) + data->client_view = NULL; + release_win_data(data); + } + + macdrv_dispose_view(surface->cocoa_view); + } +} + +static void macdrv_client_surface_update(struct client_surface *client) +{ + struct macdrv_client_surface *surface = impl_from_client_surface(client); + HWND hwnd = client->hwnd, toplevel = NtUserGetAncestor(hwnd, GA_ROOT); + struct macdrv_win_data *data; + RECT rect; + + TRACE("%s\n", debugstr_client_surface(client)); + + NtUserGetClientRect(hwnd, &rect, NtUserGetWinMonitorDpi(hwnd, MDT_RAW_DPI)); + NtUserMapWindowPoints(hwnd, toplevel, (POINT *)&rect, 2, NtUserGetWinMonitorDpi(toplevel, MDT_RAW_DPI)); + + if (!(data = get_win_data(toplevel))) return; + OffsetRect(&rect, data->rects.client.left - data->rects.visible.left, data->rects.client.top - data->rects.visible.top); + macdrv_set_view_frame(surface->cocoa_view, cgrect_from_rect(rect)); + macdrv_set_view_superview(surface->cocoa_view, toplevel == hwnd ? NULL : data->client_view, data->cocoa_window, NULL, NULL); + release_win_data(data); +} + +static void macdrv_client_surface_present(struct client_surface *client, HDC hdc) +{ + struct macdrv_client_surface *surface = impl_from_client_surface(client); + struct macdrv_win_data *data; + + TRACE("%s\n", debugstr_client_surface(client)); + + if (!(data = get_win_data(surface->client.hwnd))) return; + if (data->client_view != surface->cocoa_view) + { + if (data->client_view) macdrv_set_view_hidden(data->client_view, TRUE); + macdrv_set_view_hidden(surface->cocoa_view, FALSE); + data->client_view = surface->cocoa_view; + } + release_win_data(data); +} + +static const struct client_surface_funcs macdrv_client_surface_funcs = +{ + .destroy = macdrv_client_surface_destroy, + .detach = macdrv_client_surface_detach, + .update = macdrv_client_surface_update, + .present = macdrv_client_surface_present, +}; + +struct macdrv_client_surface *macdrv_client_surface_create(HWND hwnd) +{ + HWND toplevel = NtUserGetAncestor(hwnd, GA_ROOT); + struct macdrv_client_surface *surface; + struct macdrv_win_data *data; + RECT rect; + + NtUserGetClientRect(hwnd, &rect, NtUserGetWinMonitorDpi(hwnd, MDT_RAW_DPI)); + NtUserMapWindowPoints(hwnd, toplevel, (POINT *)&rect, 2, NtUserGetWinMonitorDpi(toplevel, MDT_RAW_DPI)); + + if (!(data = get_win_data(toplevel))) return FALSE; + surface = client_surface_create(sizeof(*surface), &macdrv_client_surface_funcs, hwnd); + surface->cocoa_view = macdrv_create_view(cgrect_from_rect(rect)); + macdrv_set_view_hidden(surface->cocoa_view, TRUE); + release_win_data(data); + + if (surface) + { + macdrv_client_surface_update(&surface->client); + macdrv_client_surface_present(&surface->client, 0); + } + + return surface; +}
/********************************************************************** * SetDesktopWindow (MACDRV.@)