From ccc1aea30598cebc42616ecb494841dddc76dda8 Mon Sep 17 00:00:00 2001
From: Ken Thomases <ken@codeweavers.com>
Date: Thu, 27 Feb 2014 14:50:48 -0600
Subject: opengl32: Define custom WGL extension WGL_WINE_surface.
To: wine-patches <wine-patches@winehq.org>

---
 dlls/opengl32/make_opengl  |   11 ++++++-
 dlls/opengl32/opengl_ext.h |    7 ++++
 dlls/opengl32/wgl.c        |   67 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 1 deletions(-)

diff --git a/dlls/opengl32/make_opengl b/dlls/opengl32/make_opengl
index b0b9c00..ed0a92c 100755
--- a/dlls/opengl32/make_opengl
+++ b/dlls/opengl32/make_opengl
@@ -139,6 +139,7 @@ my %debug_conv =
      "HGLRC" => "%p",
      "HPBUFFERARB" => "%p",
      "HPBUFFEREXT" => "%p",
+     "HSURFACEWINE" => "%p",
     );
 
 #
@@ -196,6 +197,7 @@ sub ConvertType($)
               "GLDEBUGPROCKHR" => "void *",
               "HPBUFFERARB" => "struct wgl_pbuffer *",
               "HPBUFFEREXT" => "struct wgl_pbuffer *",
+              "HSURFACEWINE" => "struct wgl_surface *",
         );
 
     foreach my $org (reverse sort keys %hash) {
@@ -559,6 +561,11 @@ my %ext_functions  =
     "glDeleteObjectBufferATI" => [ "void", [ [ "GLuint", "buffer" ] ], [ "GL_ATI_vertex_array_object" ] ],
     "wglSetPixelFormatWINE" => [ "BOOL", [ [ "HDC", "hdc" ],
                                            [ "int", "format" ] ], [ "WGL_WINE_pixel_format_passthrough" ] ],
+    "wglCreateSurfaceWINE" => [ "HSURFACEWINE", [ [ "HDC", "hdc" ] ], [ "WGL_WINE_surface" ] ],
+    "wglDestroySurfaceWINE" => [ "BOOL", [ [ "HSURFACEWINE", "surface" ] ], [ "WGL_WINE_surface" ] ],
+    "wglGetSurfaceDCWINE" => [ "HDC", [ [ "HSURFACEWINE", "surface" ] ], [ "WGL_WINE_surface" ] ],
+    "wglReleaseSurfaceDCWINE" => [ "BOOL", [ [ "HSURFACEWINE", "surface" ],
+                                             [ "HDC", "hdc" ] ], [ "WGL_WINE_surface" ] ],
    );
 
 
@@ -597,6 +604,7 @@ my %supported_wgl_extensions =
     "WGL_EXT_swap_control" => 1,
     "WGL_NV_vertex_array_range" => 1,
     "WGL_WINE_pixel_format_passthrough" => 1,
+    "WGL_WINE_surface" => 1,
    );
 
 my %enums = ();
@@ -745,7 +753,8 @@ print HEADER "#endif\n\n";
 printf HEADER "#define WINE_WGL_DRIVER_VERSION %u\n\n", $wgl_version + 1;
 
 print HEADER "struct wgl_context;\n";
-print HEADER "struct wgl_pbuffer;\n\n";
+print HEADER "struct wgl_pbuffer;\n";
+print HEADER "struct wgl_surface;\n\n";
 
 print HEADER "struct opengl_funcs\n{\n";
 print HEADER "    struct\n    {\n";
diff --git a/dlls/opengl32/opengl_ext.h b/dlls/opengl32/opengl_ext.h
index 5748e0c..d30f7f0 100644
--- a/dlls/opengl32/opengl_ext.h
+++ b/dlls/opengl32/opengl_ext.h
@@ -33,4 +33,11 @@ extern const int extension_registry_size;
 
 extern BOOL WINAPI wglSetPixelFormatWINE( HDC hdc, int format );
 
+DECLARE_HANDLE(HSURFACEWINE);
+extern HSURFACEWINE WINAPI wglCreateSurfaceWINE( HDC hdc );
+extern HDC WINAPI wglGetSurfaceDCWINE( HSURFACEWINE surface );
+extern BOOL WINAPI wglReleaseSurfaceDCWINE( HSURFACEWINE surface, HDC hdc );
+extern BOOL WINAPI wglDestroySurfaceWINE( HSURFACEWINE surface );
+
+
 #endif /* __DLLS_OPENGL32_OPENGL_EXT_H */
diff --git a/dlls/opengl32/wgl.c b/dlls/opengl32/wgl.c
index 9255e34..84ae7bd 100644
--- a/dlls/opengl32/wgl.c
+++ b/dlls/opengl32/wgl.c
@@ -53,6 +53,7 @@ enum wgl_handle_type
 {
     HANDLE_CONTEXT = 0 << 12,
     HANDLE_PBUFFER = 1 << 12,
+    HANDLE_SURFACE = 2 << 12,
     HANDLE_TYPE_MASK = 15 << 12
 };
 
@@ -73,6 +74,7 @@ struct wgl_handle
     {
         struct opengl_context *context;  /* for HANDLE_CONTEXT */
         struct wgl_pbuffer    *pbuffer;  /* for HANDLE_PBUFFER */
+        struct wgl_surface    *surface;  /* for HANDLE_SURFACE */
         struct wgl_handle     *next;     /* for free handles */
     } u;
 };
@@ -1090,6 +1092,71 @@ BOOL WINAPI wglSetPixelFormatWINE( HDC hdc, int format )
 }
 
 /***********************************************************************
+ *		wglCreateSurfaceWINE
+ *
+ * Provided by the WGL_WINE_surface extension.
+ */
+HSURFACEWINE WINAPI wglCreateSurfaceWINE( HDC hdc )
+{
+    HSURFACEWINE ret = 0;
+    struct wgl_surface *surface;
+    struct opengl_funcs *funcs = get_dc_funcs( hdc );
+
+    if (!funcs || !funcs->ext.p_wglCreateSurfaceWINE) return 0;
+    if (!(surface = funcs->ext.p_wglCreateSurfaceWINE( hdc ))) return 0;
+    ret = alloc_handle( HANDLE_SURFACE, funcs, surface );
+    if (!ret) funcs->ext.p_wglDestroySurfaceWINE( surface );
+    return ret;
+}
+
+/***********************************************************************
+ *		wglGetSurfaceDCWINE
+ *
+ * Provided by the WGL_WINE_surface extension.
+ */
+HDC WINAPI wglGetSurfaceDCWINE( HSURFACEWINE surface )
+{
+    struct wgl_handle *ptr = get_handle_ptr( surface, HANDLE_SURFACE );
+    HDC ret;
+
+    if (!ptr) return 0;
+    ret = ptr->funcs->ext.p_wglGetSurfaceDCWINE( ptr->u.surface );
+    release_handle_ptr( ptr );
+    return ret;
+}
+
+/***********************************************************************
+ *		wglReleaseSurfaceDCWINE
+ *
+ * Provided by the WGL_WINE_surface extension.
+ */
+BOOL WINAPI wglReleaseSurfaceDCWINE( HSURFACEWINE surface, HDC hdc )
+{
+    struct wgl_handle *ptr = get_handle_ptr( surface, HANDLE_SURFACE );
+    BOOL ret;
+
+    if (!ptr) return FALSE;
+    ret = ptr->funcs->ext.p_wglReleaseSurfaceDCWINE( ptr->u.surface, hdc );
+    release_handle_ptr( ptr );
+    return ret;
+}
+
+/***********************************************************************
+ *		wglDestroySurfaceWINE
+ *
+ * Provided by the WGL_WINE_surface extension.
+ */
+BOOL WINAPI wglDestroySurfaceWINE( HSURFACEWINE surface )
+{
+    struct wgl_handle *ptr = get_handle_ptr( surface, HANDLE_SURFACE );
+
+    if (!ptr) return FALSE;
+    ptr->funcs->ext.p_wglDestroySurfaceWINE( ptr->u.surface );
+    free_handle_ptr( ptr );
+    return TRUE;
+}
+
+/***********************************************************************
  *		wglUseFontBitmaps_common
  */
 static BOOL wglUseFontBitmaps_common( HDC hdc, DWORD first, DWORD count, DWORD listBase, BOOL unicode )
-- 
1.7.7.4

