From c429ceec3230d4782ab0f9d07313d4cb8ce2cc63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 5 Feb 2010 13:20:51 +0100
Subject: [PATCH 02/12] WineD3D: wined3d_event_query_issue

---
 dlls/wined3d/query.c           |  100 +++++++++++++++++++++-------------------
 dlls/wined3d/wined3d_private.h |    1 +
 2 files changed, 53 insertions(+), 48 deletions(-)

diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c
index fea4a98..43c27d8 100644
--- a/dlls/wined3d/query.c
+++ b/dlls/wined3d/query.c
@@ -237,7 +237,6 @@ static WINED3DQUERYTYPE  WINAPI IWineD3DQueryImpl_GetType(IWineD3DQuery* iface){
     return This->type;
 }
 
-
 static HRESULT  WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface,  DWORD dwIssueFlags) {
     IWineD3DQueryImpl *This = (IWineD3DQueryImpl *)iface;
 
@@ -245,53 +244,7 @@ static HRESULT  WINAPI IWineD3DEventQueryImpl_Issue(IWineD3DQuery* iface,  DWORD
     if (dwIssueFlags & WINED3DISSUE_END)
     {
         struct wined3d_event_query *query = This->extendedData;
-        const struct wined3d_gl_info *gl_info;
-        struct wined3d_context *context;
-
-        if (query->context)
-        {
-            if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
-            {
-                context_free_event_query(query);
-                context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
-                context_alloc_event_query(context, query);
-            }
-            else
-            {
-                context = context_acquire(This->device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
-            }
-        }
-        else
-        {
-            context = context_acquire(This->device, NULL, CTXUSAGE_RESOURCELOAD);
-            context_alloc_event_query(context, query);
-        }
-
-        gl_info = context->gl_info;
-
-        ENTER_GL();
-
-        if (gl_info->supported[ARB_SYNC])
-        {
-            if (query->object.sync) GL_EXTCALL(glDeleteSync(query->object.sync));
-            checkGLcall("glDeleteSync");
-            query->object.sync = GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
-            checkGLcall("glFenceSync");
-        }
-        else if (gl_info->supported[APPLE_FENCE])
-        {
-            GL_EXTCALL(glSetFenceAPPLE(query->object.id));
-            checkGLcall("glSetFenceAPPLE");
-        }
-        else if (gl_info->supported[NV_FENCE])
-        {
-            GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
-            checkGLcall("glSetFenceNV");
-        }
-
-        LEAVE_GL();
-
-        context_release(context);
+        wined3d_event_query_issue(query, This->device);
     }
     else if(dwIssueFlags & WINED3DISSUE_BEGIN)
     {
@@ -562,3 +515,54 @@ enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_qu
     context_release(context);
     return ret;
 }
+
+void wined3d_event_query_issue(struct wined3d_event_query *query, IWineD3DDeviceImpl *device)
+{
+    const struct wined3d_gl_info *gl_info;
+    struct wined3d_context *context;
+
+    if (query->context)
+    {
+        if (!query->context->gl_info->supported[ARB_SYNC] && query->context->tid != GetCurrentThreadId())
+        {
+            context_free_event_query(query);
+            context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+            context_alloc_event_query(context, query);
+        }
+        else
+        {
+            context = context_acquire(device, query->context->current_rt, CTXUSAGE_RESOURCELOAD);
+        }
+    }
+    else
+    {
+        context = context_acquire(device, NULL, CTXUSAGE_RESOURCELOAD);
+        context_alloc_event_query(context, query);
+    }
+
+    gl_info = context->gl_info;
+
+    ENTER_GL();
+
+    if (gl_info->supported[ARB_SYNC])
+    {
+        if (query->object.sync) GL_EXTCALL(glDeleteSync(query->object.sync));
+        checkGLcall("glDeleteSync");
+        query->object.sync = GL_EXTCALL(glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0));
+        checkGLcall("glFenceSync");
+    }
+    else if (gl_info->supported[APPLE_FENCE])
+    {
+        GL_EXTCALL(glSetFenceAPPLE(query->object.id));
+        checkGLcall("glSetFenceAPPLE");
+    }
+    else if (gl_info->supported[NV_FENCE])
+    {
+        GL_EXTCALL(glSetFenceNV(query->object.id, GL_ALL_COMPLETED_NV));
+        checkGLcall("glSetFenceNV");
+    }
+
+    LEAVE_GL();
+
+    context_release(context);
+}
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index c33a303..4244652 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1040,6 +1040,7 @@ enum wined3d_event_query_result
 };
 
 enum wined3d_event_query_result wined3d_event_query_test(struct wined3d_event_query *query, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
+void wined3d_event_query_issue(struct wined3d_event_query *query, IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
 
 struct wined3d_context
 {
-- 
1.6.4.4

