[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43286] trunk/blender: Added mode-getting functions for GHOST under X11 (GNU/Linux).

Alex Fraser alex at phatcore.com
Wed Jan 11 13:28:37 CET 2012


Revision: 43286
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43286
Author:   z0r
Date:     2012-01-11 12:28:31 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
Added mode-getting functions for GHOST under X11 (GNU/Linux).
Enabled xvidmode by default in cmake.
Patch approved by Campbell.

Modified Paths:
--------------
    trunk/blender/CMakeLists.txt
    trunk/blender/intern/ghost/intern/GHOST_DisplayManagerX11.cpp

Modified: trunk/blender/CMakeLists.txt
===================================================================
--- trunk/blender/CMakeLists.txt	2012-01-11 11:59:57 UTC (rev 43285)
+++ trunk/blender/CMakeLists.txt	2012-01-11 12:28:31 UTC (rev 43286)
@@ -156,7 +156,7 @@
 
 if(UNIX AND NOT APPLE)
 	option(WITH_X11_XINPUT "Enable X11 Xinput (tablet support and unicode input)"	ON)
-	option(WITH_X11_XF86VMODE "Enable X11 video mode switching"	OFF)
+	option(WITH_X11_XF86VMODE "Enable X11 video mode switching"	ON)
 	option(WITH_BUILTIN_GLEW "Use GLEW OpenGL wrapper library bundled with blender" ON)
 	option(WITH_XDG_USER_DIRS    "Build with XDG Base Directory Specification (only config and documents for now)" OFF)
 	mark_as_advanced(WITH_XDG_USER_DIRS)

Modified: trunk/blender/intern/ghost/intern/GHOST_DisplayManagerX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_DisplayManagerX11.cpp	2012-01-11 11:59:57 UTC (rev 43285)
+++ trunk/blender/intern/ghost/intern/GHOST_DisplayManagerX11.cpp	2012-01-11 12:28:31 UTC (rev 43286)
@@ -67,10 +67,32 @@
 	GHOST_TUns8 display,
 	GHOST_TInt32& numSettings
 ) const{
-	
+#ifdef WITH_X11_XF86VMODE
+	int majorVersion, minorVersion;
+	XF86VidModeModeInfo **vidmodes;
+	Display *dpy = m_system->getXDisplay();
+
+	GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
+
+	if (dpy == NULL)
+		return GHOST_kFailure;
+
+	majorVersion = minorVersion = 0;
+	if (!XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion)) {
+		fprintf(stderr, "Error: XF86VidMode extension missing!\n");
+		return GHOST_kFailure;
+	}
+
+	/* The X11 man page says vidmodes needs to be freed, but doing so causes a
+	 * segfault. - z0r */
+	XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &numSettings, &vidmodes);
+
+#else
 	// We only have one X11 setting at the moment.
 	GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");	
 	numSettings = GHOST_TInt32(1);
+#endif
+
 	return GHOST_kSuccess;
 }
 
@@ -81,7 +103,34 @@
 	GHOST_TInt32 index,
 	GHOST_DisplaySetting& setting
 ) const {
-	
+
+#ifdef WITH_X11_XF86VMODE
+	int majorVersion, minorVersion;
+	XF86VidModeModeInfo **vidmodes;
+	Display *dpy = m_system->getXDisplay();
+	int numSettings;
+
+	GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");
+
+	if (dpy == NULL)
+		return GHOST_kFailure;
+
+	majorVersion = minorVersion = 0;
+	if (!XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion)) {
+		fprintf(stderr, "Error: XF86VidMode extension missing!\n");
+		return GHOST_kFailure;
+	}
+
+	/* The X11 man page says vidmodes needs to be freed, but doing so causes a
+	 * segfault. - z0r */
+	XF86VidModeGetAllModeLines(dpy, DefaultScreen(dpy), &numSettings, &vidmodes);
+	GHOST_ASSERT(index < numSettings, "Requested setting outside of valid range.\n");
+
+	setting.xPixels = vidmodes[index]->hdisplay;
+	setting.yPixels = vidmodes[index]->vdisplay;
+	setting.bpp = DefaultDepth(dpy,DefaultScreen(dpy));
+
+#else
 	GHOST_ASSERT(display < 1, "Only single display systems are currently supported.\n");	
 	GHOST_ASSERT(index < 1, "Requested setting outside of valid range.\n");	
 	
@@ -94,6 +143,7 @@
 	setting.xPixels  = DisplayWidth(x_display, DefaultScreen(x_display));
 	setting.yPixels = DisplayHeight(x_display, DefaultScreen(x_display));
 	setting.bpp = DefaultDepth(x_display,DefaultScreen(x_display));
+#endif
 
 	// Don't think it's possible to get this value from X!
 	// So let's guess!!
@@ -108,6 +158,9 @@
 	GHOST_TUns8 display,
 	GHOST_DisplaySetting& setting
 ) const {
+	/* According to the xf86vidmodegetallmodelines man page,
+	 * "The first element of the array corresponds to the current video mode."
+	 */
 	return getDisplaySetting(display,GHOST_TInt32(0),setting);
 }
 
@@ -130,6 +183,9 @@
 	int scrnum, num_vidmodes;
 	int best_fit, best_dist, dist, x, y;
 
+	if (dpy == NULL)
+		return GHOST_kFailure;
+
 	scrnum = DefaultScreen(dpy);
 
 	// Get video mode list
@@ -143,6 +199,8 @@
 			majorVersion, minorVersion);
 #  endif
 
+	/* The X11 man page says vidmodes needs to be freed, but doing so causes a
+	 * segfault. - z0r */
 	XF86VidModeGetAllModeLines(dpy, scrnum, &num_vidmodes, &vidmodes);
 
 	best_dist = 9999999;



More information about the Bf-blender-cvs mailing list