[PATCH 1/5] wined3d: Introduce a separate function for translating front buffer coordinates to GL coordinates.

Henri Verbeet hverbeet at codeweavers.com
Fri May 21 02:35:21 CDT 2010


---
 dlls/wined3d/arb_program_shader.c |   12 +--------
 dlls/wined3d/device.c             |   38 +++++++--------------------
 dlls/wined3d/surface.c            |   51 ++++++++++++------------------------
 dlls/wined3d/wined3d_private.h    |    1 +
 4 files changed, 29 insertions(+), 73 deletions(-)

diff --git a/dlls/wined3d/arb_program_shader.c b/dlls/wined3d/arb_program_shader.c
index f62ff56..c0b3924 100644
--- a/dlls/wined3d/arb_program_shader.c
+++ b/dlls/wined3d/arb_program_shader.c
@@ -7004,17 +7004,7 @@ HRESULT arbfp_blit_surface(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_
      * whereas the real gl drawable size is the size of the window. */
     dst_swapchain = (dst_surface->Flags & SFLAG_SWAPCHAIN) ? (IWineD3DSwapChainImpl *)dst_surface->container : NULL;
     if (dst_swapchain && dst_surface == dst_swapchain->front_buffer)
-    {
-        RECT windowsize;
-        POINT offset = {0,0};
-        UINT h;
-        ClientToScreen(context->win_handle, &offset);
-        GetClientRect(context->win_handle, &windowsize);
-        h = windowsize.bottom - windowsize.top;
-        dst_rect.left -= offset.x; dst_rect.right -=offset.x;
-        dst_rect.top -= offset.y; dst_rect.bottom -=offset.y;
-        dst_rect.top += dst_surface->currentDesc.Height - h; dst_rect.bottom += dst_surface->currentDesc.Height - h;
-    }
+        surface_translate_frontbuffer_coords(dst_surface, context->win_handle, &dst_rect);
 
     arbfp_blit_set((IWineD3DDevice *)device, src_surface);
 
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index feb3949..e73ecc9 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -5740,7 +5740,6 @@ void stretch_rect_fbo(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_surfa
     const struct wined3d_gl_info *gl_info;
     struct wined3d_context *context;
     GLenum gl_filter;
-    POINT offset = {0, 0};
     RECT src_rect, dst_rect;
 
     TRACE("device %p, src_surface %p, src_rect_in %s, dst_surface %p, dst_rect_in %s, filter %s (0x%08x).\n",
@@ -5788,19 +5787,11 @@ void stretch_rect_fbo(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_surfa
 
         TRACE("Source surface %p is onscreen\n", src_surface);
 
-        if(buffer == GL_FRONT) {
-            RECT windowsize;
-            UINT h;
-            ClientToScreen(context->win_handle, &offset);
-            GetClientRect(context->win_handle, &windowsize);
-            h = windowsize.bottom - windowsize.top;
-            src_rect.left -= offset.x; src_rect.right -=offset.x;
-            src_rect.top =  offset.y + h - src_rect.top;
-            src_rect.bottom =  offset.y + h - src_rect.bottom;
-        } else {
-            src_rect.top = src_surface->currentDesc.Height - src_rect.top;
-            src_rect.bottom = src_surface->currentDesc.Height - src_rect.bottom;
-        }
+        if (buffer == GL_FRONT)
+            surface_translate_frontbuffer_coords(src_surface, context->win_handle, &src_rect);
+
+        src_rect.top = src_surface->currentDesc.Height - src_rect.top;
+        src_rect.bottom = src_surface->currentDesc.Height - src_rect.bottom;
 
         ENTER_GL();
         context_bind_fbo(context, GL_READ_FRAMEBUFFER, NULL);
@@ -5822,20 +5813,11 @@ void stretch_rect_fbo(IWineD3DDeviceImpl *device, IWineD3DSurfaceImpl *src_surfa
 
         TRACE("Destination surface %p is onscreen\n", dst_surface);
 
-        if(buffer == GL_FRONT) {
-            RECT windowsize;
-            UINT h;
-            ClientToScreen(context->win_handle, &offset);
-            GetClientRect(context->win_handle, &windowsize);
-            h = windowsize.bottom - windowsize.top;
-            dst_rect.left -= offset.x; dst_rect.right -=offset.x;
-            dst_rect.top =  offset.y + h - dst_rect.top;
-            dst_rect.bottom =  offset.y + h - dst_rect.bottom;
-        } else {
-            /* Screen coords = window coords, surface height = window height */
-            dst_rect.top = dst_surface->currentDesc.Height - dst_rect.top;
-            dst_rect.bottom = dst_surface->currentDesc.Height - dst_rect.bottom;
-        }
+        if (buffer == GL_FRONT)
+            surface_translate_frontbuffer_coords(dst_surface, context->win_handle, &dst_rect);
+
+        dst_rect.top = dst_surface->currentDesc.Height - dst_rect.top;
+        dst_rect.bottom = dst_surface->currentDesc.Height - dst_rect.bottom;
 
         ENTER_GL();
         context_bind_fbo(context, GL_DRAW_FRAMEBUFFER, NULL);
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 9e1d434..ca796c5 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -3380,6 +3380,21 @@ static BOOL fbo_blit_supported(const struct wined3d_gl_info *gl_info, enum blit_
                                const RECT *dst_rect, DWORD dst_usage, WINED3DPOOL dst_pool,
                                const struct wined3d_format_desc *dst_format_desc);
 
+/* Front buffer coordinates are always full screen coordinates, but our GL
+ * drawable is limited to the window's client area. The sysmem and texture
+ * copies do have the full screen size. Note that GL has a bottom-left
+ * origin, while D3D has a top-left origin. */
+void surface_translate_frontbuffer_coords(IWineD3DSurfaceImpl *surface, HWND window, RECT *rect)
+{
+    POINT offset = {0, surface->currentDesc.Height};
+    RECT windowsize;
+
+    GetClientRect(window, &windowsize);
+    offset.y -= windowsize.bottom - windowsize.top;
+    ScreenToClient(window, &offset);
+    OffsetRect(rect, offset.x, offset.y);
+}
+
 /* Not called from the VTable */
 static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *dst_surface, const RECT *DestRect,
         IWineD3DSurfaceImpl *src_surface, const RECT *SrcRect, DWORD Flags, const WINEDDBLTFX *DDBltFx,
@@ -3674,25 +3689,8 @@ static HRESULT IWineD3DSurfaceImpl_BltOverride(IWineD3DSurfaceImpl *dst_surface,
         context = context_acquire(device, dst_surface);
         context_apply_blit_state(context, device);
 
-        /* The coordinates of the ddraw front buffer are always fullscreen ('screen coordinates',
-         * while OpenGL coordinates are window relative.
-         * Also beware of the origin difference(top left vs bottom left).
-         * Also beware that the front buffer's surface size is screen width x screen height,
-         * whereas the real gl drawable size is the size of the window.
-         */
         if (dstSwapchain && dst_surface == dstSwapchain->front_buffer)
-        {
-            RECT windowsize;
-            POINT offset = {0,0};
-            UINT h;
-            ClientToScreen(context->win_handle, &offset);
-            GetClientRect(context->win_handle, &windowsize);
-            h = windowsize.bottom - windowsize.top;
-            dst_rect.left -= offset.x; dst_rect.right -=offset.x;
-            dst_rect.top -= offset.y; dst_rect.bottom -=offset.y;
-            dst_rect.top += dst_surface->currentDesc.Height - h;
-            dst_rect.bottom += dst_surface->currentDesc.Height - h;
-        }
+            surface_translate_frontbuffer_coords(dst_surface, context->win_handle, &dst_rect);
 
         if (!device->blitter->blit_supported(&device->adapter->gl_info, BLIT_OP_BLIT,
                 &src_rect, src_surface->resource.usage, src_surface->resource.pool, src_surface->resource.format_desc,
@@ -4351,22 +4349,7 @@ static inline void surface_blt_to_drawable(IWineD3DSurfaceImpl *This, const RECT
     }
 
     if ((This->Flags & SFLAG_SWAPCHAIN) && This == ((IWineD3DSwapChainImpl *)This->container)->front_buffer)
-    {
-        RECT windowsize;
-        POINT offset = {0, 0};
-        UINT h;
-
-        ClientToScreen(context->win_handle, &offset);
-        GetClientRect(context->win_handle, &windowsize);
-        h = windowsize.bottom - windowsize.top;
-
-        dst_rect.left -= offset.x;
-        dst_rect.right -=offset.x;
-        dst_rect.top -= offset.y;
-        dst_rect.bottom -=offset.y;
-        dst_rect.top += This->currentDesc.Height - h;
-        dst_rect.bottom += This->currentDesc.Height - h;
-    }
+        surface_translate_frontbuffer_coords(This, context->win_handle, &dst_rect);
 
     device->blitter->set_shader((IWineD3DDevice *) device, This);
 
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 0147c2f..e1f4282 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2101,6 +2101,7 @@ HRESULT surface_init(IWineD3DSurfaceImpl *surface, WINED3DSURFTYPE surface_type,
         UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
         UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
         WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+void surface_translate_frontbuffer_coords(IWineD3DSurfaceImpl *surface, HWND window, RECT *rect) DECLSPEC_HIDDEN;
 
 /* Predeclare the shared Surface functions */
 HRESULT WINAPI IWineD3DBaseSurfaceImpl_QueryInterface(IWineD3DSurface *iface,
-- 
1.6.4.4




More information about the wine-patches mailing list