[MPlayer-cvslog] r24334 - in trunk/libvo: gl_common.c w32_common.c

reimar subversion at mplayerhq.hu
Mon Sep 3 10:44:36 CEST 2007


Author: reimar
Date: Mon Sep  3 10:44:36 2007
New Revision: 24334

Log:
Remove global vo_hdc, since it is recommended to release a DC as soon as possible.


Modified:
   trunk/libvo/gl_common.c
   trunk/libvo/w32_common.c

Modified: trunk/libvo/gl_common.c
==============================================================================
--- trunk/libvo/gl_common.c	(original)
+++ trunk/libvo/gl_common.c	Mon Sep  3 10:44:36 2007
@@ -1341,6 +1341,7 @@ int setGlWindow(int *vinfo, HGLRC *conte
   HDC windc = GetDC(win);
   HGLRC new_context = 0;
   int keep_context = 0;
+  int res = SET_WINDOW_FAILED;
 
   // should only be needed when keeping context, but not doing glFinish
   // can cause flickering even when we do not keep it.
@@ -1356,7 +1357,7 @@ int setGlWindow(int *vinfo, HGLRC *conte
     new_context = wglCreateContext(windc);
     if (!new_context) {
       mp_msg(MSGT_VO, MSGL_FATAL, "[gl] Could not create GL context!\n");
-      return SET_WINDOW_FAILED;
+      goto out;
     }
   }
 
@@ -1366,12 +1367,11 @@ int setGlWindow(int *vinfo, HGLRC *conte
     if (!keep_context) {
       wglDeleteContext(new_context);
     }
-    return SET_WINDOW_FAILED;
+    goto out;
   }
 
   // set new values
   vo_w32_window = win;
-  vo_hdc = windc;
   {
     RECT rect;
     GetClientRect(win, &rect);
@@ -1386,9 +1386,13 @@ int setGlWindow(int *vinfo, HGLRC *conte
     getFunctions(w32gpa, NULL);
 
     // and inform that reinit is neccessary
-    return SET_WINDOW_REINIT;
-  }
-  return SET_WINDOW_OK;
+    res = SET_WINDOW_REINIT;
+  } else
+    res = SET_WINDOW_OK;
+
+out:
+  ReleaseDC(windc);
+  return res;
 }
 
 void releaseGlContext(int *vinfo, HGLRC *context) {
@@ -1401,7 +1405,9 @@ void releaseGlContext(int *vinfo, HGLRC 
 }
 
 void swapGlBuffers() {
+  HDC vo_hdc = GetDC(vo_w32_window);
   SwapBuffers(vo_hdc);
+  ReleaseDC(vo_hdc);
 }
 #else
 #ifdef HAVE_LIBDL

Modified: trunk/libvo/w32_common.c
==============================================================================
--- trunk/libvo/w32_common.c	(original)
+++ trunk/libvo/w32_common.c	Mon Sep  3 10:44:36 2007
@@ -20,7 +20,6 @@ extern int enable_mouse_movements;
 
 static const char* classname = "MPlayer - Media player for Win32";
 int vo_vm = 0;
-HDC vo_hdc = 0;
 
 // last non-fullscreen extends
 int prev_width;
@@ -250,6 +249,7 @@ static void resetMode(void) {
 static int createRenderingContext(void) {
     HWND layer = HWND_NOTOPMOST;
     PIXELFORMATDESCRIPTOR pfd;
+    HDC vo_hdc = GetDC(vo_window);
     RECT r;
     int pf;
   if (WinID < 0) {
@@ -308,6 +308,7 @@ static int createRenderingContext(void) 
     pf = ChoosePixelFormat(vo_hdc, &pfd);
     if (!pf) {
             mp_msg(MSGT_VO, MSGL_ERR, "vo: win32: unable to select a valid pixel format!\n");
+        ReleaseDC(vo_hdc);
         return 0;
     }
 
@@ -315,6 +316,7 @@ static int createRenderingContext(void) 
     
     mp_msg(MSGT_VO, MSGL_V, "vo: win32: running at %dx%d with depth %d\n", vo_screenwidth, vo_screenheight, vo_depthonscreen);
 
+    ReleaseDC(vo_hdc);
     return 1;
 }
 
@@ -369,8 +371,6 @@ int vo_w32_init(void) {
     }
     }
 
-    vo_hdc = GetDC(vo_window);
-
     myMonitorFromWindow = NULL;
     myGetMonitorInfo = NULL;
     myEnumDisplayMonitors = NULL;



More information about the MPlayer-cvslog mailing list