[6/11] WineD3D: Use the context manager to prepare contexts for drawing

Stefan Dösinger stefan at codeweavers.com
Fri Jan 26 15:44:14 CST 2007


This patch adds a new file context.c, which will deal with all sorts of 
context related work. One of them is selecting a context for drawing and 
blitting depending on the current thread and render target.
-------------- next part --------------
From 03dc54ae8827f7b0b8c30dfe0dde7f048e25c213 Mon Sep 17 00:00:00 2001
From: Stefan Doesinger <stefan at codeweavers.com>
Date: Fri, 19 Jan 2007 22:01:16 +0100
Subject: [PATCH] WineD3D: Use the context manager to prepare for drawing

---
 dlls/wined3d/Makefile.in       |    1 +
 dlls/wined3d/context.c         |   82 ++++++++++++++++++++++++++++++++++++++++
 dlls/wined3d/drawprim.c        |   18 +--------
 dlls/wined3d/wined3d_private.h |   13 +++++-
 4 files changed, 96 insertions(+), 18 deletions(-)

diff --git a/dlls/wined3d/Makefile.in b/dlls/wined3d/Makefile.in
index 0cdd967..4700483 100644
--- a/dlls/wined3d/Makefile.in
+++ b/dlls/wined3d/Makefile.in
@@ -12,6 +12,7 @@ C_SRCS = \
 	arb_program_shader.c \
 	baseshader.c \
 	basetexture.c \
+	context.c \
 	cubetexture.c \
 	device.c \
 	directx.c \
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
new file mode 100644
index 0000000..3090538
--- /dev/null
+++ b/dlls/wined3d/context.c
@@ -0,0 +1,82 @@
+/*
+ * Context and render target management in wined3d
+ *
+ * Copyright 2007 Stefan Dösinger for CodeWeavers
+ *
+ * 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
+ */
+
+#include "config.h"
+#include <stdio.h>
+#ifdef HAVE_FLOAT_H
+# include <float.h>
+#endif
+#include "wined3d_private.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(d3d);
+
+/*****************************************************************************
+ * ActivateContext
+ *
+ * Finds a rendering context and drawable matching the device and render
+ * target for the current thread, activates them and puts them into the
+ * requested state.
+ *
+ * Params:
+ *  This: Device to activate the context for
+ *  target: Requested render target
+ *  usage: Prepares the context for blitting, drawing or other actions
+ *
+ *****************************************************************************/
+void ActivateContext(IWineD3DDeviceImpl *This, IWineD3DSurface *target, ContextUsage usage) {
+    DWORD tid = This->createParms.BehaviorFlags & D3DCREATE_MULTITHREADED ? GetCurrentThreadId() : 0;
+    int                           i;
+    DWORD                         dirtyState, idx;
+    BYTE                          shift;
+    WineD3DContext                *context;
+
+    TRACE("(%p): Selecting context for render target %p, thread %d\n", This, target, tid);
+    /* TODO: Render target selection */
+
+    /* TODO: Thread selection */
+
+    /* TODO: Activate the opengl context */
+    context = &This->contexts[This->activeContext];
+
+    switch(usage) {
+        case CTXUSAGE_RESOURCELOAD:
+            /* This does not require any special states to be set up */
+            break;
+
+        case CTXUSAGE_DRAWPRIM:
+            /* This needs all dirty states applied */
+            for(i=0; i < context->numDirtyEntries; i++) {
+                dirtyState = context->dirtyArray[i];
+                idx = dirtyState >> 5;
+                shift = dirtyState & 0x1f;
+                context->isStateDirty[idx] &= ~(1 << shift);
+                StateTable[dirtyState].apply(dirtyState, This->stateBlock, context);
+            }
+            context->numDirtyEntries = 0; /* This makes the whole list clean */
+            break;
+
+        case CTXUSAGE_BLIT:
+            FIXME("Setting up for blitting not supported yet\n");
+            break;
+
+        default:
+            FIXME("Unexpected context usage requested\n");
+    }
+}
diff --git a/dlls/wined3d/drawprim.c b/dlls/wined3d/drawprim.c
index 0d6adf0..dcf6d26 100644
--- a/dlls/wined3d/drawprim.c
+++ b/dlls/wined3d/drawprim.c
@@ -1178,10 +1178,7 @@ void drawPrimitive(IWineD3DDevice *iface,
 
     IWineD3DDeviceImpl           *This = (IWineD3DDeviceImpl *)iface;
     IWineD3DSwapChainImpl         *swapchain;
-    int                           i;
-    DWORD                         dirtyState, idx;
-    BYTE                          shift;
-    WineD3DContext                *context;
+    int i;
 
     /* Signals other modules that a drawing is in progress and the stateblock finalized */
     This->isInDraw = TRUE;
@@ -1198,18 +1195,7 @@ void drawPrimitive(IWineD3DDevice *iface,
     /* Ok, we will be updating the screen from here onwards so grab the lock */
     ENTER_GL();
 
-    /* TODO: Find the correct context for the render target / thread */
-    context = &This->contexts[This->activeContext];
-
-    /* Apply dirty states */
-    for(i=0; i < context->numDirtyEntries; i++) {
-        dirtyState = context->dirtyArray[i];
-        idx = dirtyState >> 5;
-        shift = dirtyState & 0x1f;
-        context->isStateDirty[idx] &= ~(1 << shift);
-        StateTable[dirtyState].apply(dirtyState, This->stateBlock, context);
-    }
-    context->numDirtyEntries = 0; /* This makes the whole list clean */
+    ActivateContext(This, This->render_targets[0], CTXUSAGE_DRAWPRIM);
 
     if (TRACE_ON(d3d_draw) && wined3d_settings.offscreen_rendering_mode == ORM_FBO) {
         check_fbo_status(iface);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 76bf29c..ab3e947 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -290,6 +290,7 @@ do {
 typedef struct IWineD3DStateBlockImpl IWineD3DStateBlockImpl;
 typedef struct IWineD3DSurfaceImpl    IWineD3DSurfaceImpl;
 typedef struct IWineD3DPaletteImpl    IWineD3DPaletteImpl;
+typedef struct IWineD3DDeviceImpl     IWineD3DDeviceImpl;
 
 /* Tracking */
 
@@ -478,6 +479,14 @@ struct WineD3DContext {
     GLenum                  tracking_parm;     /* Which source is tracking current colour         */
 };
 
+typedef enum ContextUsage {
+    CTXUSAGE_RESOURCELOAD       = 1,    /* Only loads textures: No State is applied */
+    CTXUSAGE_DRAWPRIM           = 2,    /* OpenGL states are set up for blitting DirectDraw surfacs */
+    CTXUSAGE_BLIT               = 3,    /* OpenGL states are set up 3D drawing */
+} ContextUsage;
+
+void ActivateContext(IWineD3DDeviceImpl *device, IWineD3DSurface *target, ContextUsage usage);
+
 /* Routine to fill gl caps for swapchains and IWineD3D */
 BOOL IWineD3DImpl_FillGLCaps(IWineD3D *iface, Display* display);
 
@@ -575,7 +584,7 @@ void dumpResources(ResourceList *resources);
 /*****************************************************************************
  * IWineD3DDevice implementation structure
  */
-typedef struct IWineD3DDeviceImpl
+struct IWineD3DDeviceImpl
 {
     /* IUnknown fields      */
     const IWineD3DDeviceVtbl *lpVtbl;
@@ -688,7 +697,7 @@ typedef struct IWineD3DDeviceImpl
     WineD3DContext          contexts[1];   /* Dynamic array later */
     UINT                    activeContext; /* Only 0 for now      */
     UINT                    numContexts;   /* Always 1 for now    */
-} IWineD3DDeviceImpl;
+};
 
 extern const IWineD3DDeviceVtbl IWineD3DDevice_Vtbl;
 
-- 
1.4.4.3



More information about the wine-patches mailing list