Henri Verbeet : wined3d: Move device context array functions to device.c.

Alexandre Julliard julliard at winehq.org
Mon Mar 15 12:19:42 CDT 2010


Module: wine
Branch: master
Commit: 4b671f4d5471662b3ab98acb69ecc17778fd4978
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=4b671f4d5471662b3ab98acb69ecc17778fd4978

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Sun Mar 14 21:53:25 2010 +0100

wined3d: Move device context array functions to device.c.

---

 dlls/wined3d/context.c         |   94 +---------------------------------------
 dlls/wined3d/device.c          |   62 ++++++++++++++++++++++++++
 dlls/wined3d/wined3d_private.h |    2 +
 3 files changed, 66 insertions(+), 92 deletions(-)

diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 428e670..c8dcb6e 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -920,35 +920,6 @@ static void Context_MarkStateDirty(struct wined3d_context *context, DWORD state,
     context->isStateDirty[idx] |= (1 << shift);
 }
 
-/*****************************************************************************
- * AddContextToArray
- *
- * Adds a context to the context array. Helper function for context_create().
- *
- * This method is not called in performance-critical code paths, only when a
- * new render target or swapchain is created. Thus performance is not an issue
- * here.
- *
- *****************************************************************************/
-static BOOL AddContextToArray(IWineD3DDeviceImpl *This, struct wined3d_context *context)
-{
-    struct wined3d_context **oldArray = This->contexts;
-
-    This->contexts = HeapAlloc(GetProcessHeap(), 0, sizeof(*This->contexts) * (This->numContexts + 1));
-    if(This->contexts == NULL) {
-        ERR("Unable to grow the context array\n");
-        This->contexts = oldArray;
-        return FALSE;
-    }
-    if(oldArray) {
-        memcpy(This->contexts, oldArray, sizeof(*This->contexts) * This->numContexts);
-    }
-    HeapFree(GetProcessHeap(), 0, oldArray);
-    This->contexts[This->numContexts++] = context;
-
-    return TRUE;
-}
-
 /* This function takes care of WineD3D pixel format selection. */
 static int WineD3D_ChoosePixelFormat(IWineD3DDeviceImpl *This, HDC hdc,
         const struct GlPixelFormatDesc *color_format_desc, const struct GlPixelFormatDesc *ds_format_desc,
@@ -1289,7 +1260,7 @@ struct wined3d_context *context_create(IWineD3DDeviceImpl *This, IWineD3DSurface
         goto out;
     }
 
-    if (!AddContextToArray(This, ret))
+    if (!device_context_add(This, ret))
     {
         ERR("Failed to add the newly created context to the context list\n");
         if (!pwglDeleteContext(ctx))
@@ -1474,67 +1445,6 @@ out:
 }
 
 /*****************************************************************************
- * RemoveContextFromArray
- *
- * Removes a context from the context manager. The opengl context is not
- * destroyed or unset. context is not a valid pointer after that call.
- *
- * Similar to the former call this isn't a performance critical function. A
- * helper function for context_destroy().
- *
- * Params:
- *  This: Device to activate the context for
- *  context: Context to remove
- *
- *****************************************************************************/
-static void RemoveContextFromArray(IWineD3DDeviceImpl *This, struct wined3d_context *context)
-{
-    struct wined3d_context **new_array;
-    BOOL found = FALSE;
-    UINT i;
-
-    TRACE("Removing ctx %p\n", context);
-
-    for (i = 0; i < This->numContexts; ++i)
-    {
-        if (This->contexts[i] == context)
-        {
-            found = TRUE;
-            break;
-        }
-    }
-
-    if (!found)
-    {
-        ERR("Context %p doesn't exist in context array\n", context);
-        return;
-    }
-
-    while (i < This->numContexts - 1)
-    {
-        This->contexts[i] = This->contexts[i + 1];
-        ++i;
-    }
-
-    --This->numContexts;
-    if (!This->numContexts)
-    {
-        HeapFree(GetProcessHeap(), 0, This->contexts);
-        This->contexts = NULL;
-        return;
-    }
-
-    new_array = HeapReAlloc(GetProcessHeap(), 0, This->contexts, This->numContexts * sizeof(*This->contexts));
-    if (!new_array)
-    {
-        ERR("Failed to shrink context array. Oh well.\n");
-        return;
-    }
-
-    This->contexts = new_array;
-}
-
-/*****************************************************************************
  * context_destroy
  *
  * Destroys a wined3d context
@@ -1564,7 +1474,7 @@ void context_destroy(IWineD3DDeviceImpl *This, struct wined3d_context *context)
 
     HeapFree(GetProcessHeap(), 0, context->vshader_const_dirty);
     HeapFree(GetProcessHeap(), 0, context->pshader_const_dirty);
-    RemoveContextFromArray(This, context);
+    device_context_remove(This, context);
     if (destroy) HeapFree(GetProcessHeap(), 0, context);
 }
 
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 2747517..38bde16 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -494,6 +494,68 @@ void device_preload_textures(IWineD3DDeviceImpl *device)
     }
 }
 
+BOOL device_context_add(IWineD3DDeviceImpl *device, struct wined3d_context *context)
+{
+    struct wined3d_context **new_array;
+
+    TRACE("Adding context %p.\n", context);
+
+    if (!device->contexts) new_array = HeapAlloc(GetProcessHeap(), 0, sizeof(*new_array));
+    else new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts, sizeof(*new_array) * (device->numContexts + 1));
+
+    if (!new_array)
+    {
+        ERR("Failed to grow the context array.\n");
+        return FALSE;
+    }
+
+    new_array[device->numContexts++] = context;
+    device->contexts = new_array;
+    return TRUE;
+}
+
+void device_context_remove(IWineD3DDeviceImpl *device, struct wined3d_context *context)
+{
+    struct wined3d_context **new_array;
+    BOOL found = FALSE;
+    UINT i;
+
+    TRACE("Removing context %p.\n", context);
+
+    for (i = 0; i < device->numContexts; ++i)
+    {
+        if (device->contexts[i] == context)
+        {
+            found = TRUE;
+            break;
+        }
+    }
+
+    if (!found)
+    {
+        ERR("Context %p doesn't exist in context array.\n", context);
+        return;
+    }
+
+    if (!--device->numContexts)
+    {
+        HeapFree(GetProcessHeap(), 0, device->contexts);
+        device->contexts = NULL;
+        return;
+    }
+
+    memmove(&device->contexts[i], &device->contexts[i + 1], (device->numContexts - i) * sizeof(*device->contexts));
+    new_array = HeapReAlloc(GetProcessHeap(), 0, device->contexts, device->numContexts * sizeof(*device->contexts));
+    if (!new_array)
+    {
+        ERR("Failed to shrink context array. Oh well.\n");
+        return;
+    }
+
+    device->contexts = new_array;
+}
+
+
 /**********************************************************
  * IUnknown parts follows
  **********************************************************/
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 0537ff1..750b36e 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1710,6 +1710,8 @@ struct IWineD3DDeviceImpl
     struct WineD3DRectPatch *currentPatch;
 };
 
+BOOL device_context_add(IWineD3DDeviceImpl *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
+void device_context_remove(IWineD3DDeviceImpl *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
 HRESULT device_init(IWineD3DDeviceImpl *device, IWineD3DImpl *wined3d,
         UINT adapter_idx, WINED3DDEVTYPE device_type, HWND focus_window, DWORD flags,
         IUnknown *parent, IWineD3DDeviceParent *device_parent) DECLSPEC_HIDDEN;




More information about the wine-cvs mailing list