Bläddra i källkod

Replaced glfwGetDesktopMode with glfwGetVideoMode.

Camilla Berglund 13 år sedan
förälder
incheckning
89b42d084d
13 ändrade filer med 57 tillägg och 67 borttagningar
  1. 1 1
      include/GL/glfw3.h
  2. 1 0
      readme.html
  3. 10 4
      src/cocoa_fullscreen.m
  4. 0 4
      src/cocoa_init.m
  5. 1 1
      src/cocoa_platform.h
  6. 6 5
      src/fullscreen.c
  7. 1 1
      src/internal.h
  8. 13 5
      src/win32_fullscreen.c
  9. 10 32
      src/x11_fullscreen.c
  10. 1 1
      tests/fsfocus.c
  11. 4 4
      tests/gamma.c
  12. 4 4
      tests/iconify.c
  13. 5 5
      tests/modes.c

+ 1 - 1
include/GL/glfw3.h

@@ -539,7 +539,7 @@ GLFWAPI GLFWmonitor glfwGetNextMonitor(GLFWmonitor iterator);
 
 /* Video mode functions */
 GLFWAPI GLFWvidmode* glfwGetVideoModes(GLFWmonitor monitor, int* count);
-GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode);
+GLFWAPI void glfwGetVideoMode(GLFWmonitor monitor, GLFWvidmode* mode);
 
 /* Gamma ramp functions */
 GLFWAPI void glfwSetGamma(float gamma);

+ 1 - 0
readme.html

@@ -303,6 +303,7 @@ version of GLFW.</p>
   <li>Renamed <code>glfwGetJoystickPos</code> to <code>glfwGetJoystickAxes</code> to match <code>glfwGetJoystickButtons</code></li>
   <li>Renamed mouse position functions to cursor position equivalents</li>
   <li>Replaced <code>glfwOpenWindow</code> and <code>glfwCloseWindow</code> with <code>glfwCreateWindow</code> and <code>glfwDestroyWindow</code></li>
+  <li>Replaced <code>glfwGetDesktopMode</code> width <code>glfwGetVideoMode</code></li>
   <li>Replaced ad hoc build system with CMake</li>
   <li>Replaced layout-dependent key codes with single, platform-independent set based on US layout</li>
   <li>Replaced mouse wheel interface with two-dimensional, floating point scrolling interface</li>

+ 10 - 4
src/cocoa_fullscreen.m

@@ -167,6 +167,8 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate)
         return GL_FALSE;
     }
 
+    _glfwLibrary.NS.previousMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
+
     CGDisplayCapture(CGMainDisplayID());
     CGDisplaySetDisplayMode(CGMainDisplayID(), bestMode, NULL);
 
@@ -182,7 +184,7 @@ GLboolean _glfwSetVideoMode(int* width, int* height, int* bpp, int* refreshRate)
 void _glfwRestoreVideoMode(void)
 {
     CGDisplaySetDisplayMode(CGMainDisplayID(),
-                            _glfwLibrary.NS.desktopMode,
+                            _glfwLibrary.NS.previousMode,
                             NULL);
 
     CGDisplayRelease(CGMainDisplayID());
@@ -227,11 +229,15 @@ GLFWvidmode* _glfwPlatformGetVideoModes(int* found)
 
 
 //========================================================================
-// Get the desktop video mode
+// Get the current video mode for the specified monitor
 //========================================================================
 
-void _glfwPlatformGetDesktopMode(GLFWvidmode *mode)
+void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode *mode)
 {
-    *mode = vidmodeFromCGDisplayMode(_glfwLibrary.NS.desktopMode);
+    CGDisplayModeRef displayMode;
+
+    displayMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
+    *mode = vidmodeFromCGDisplayMode(displayMode);
+    CGDisplayModeRelease(displayMode);
 }
 

+ 0 - 4
src/cocoa_init.m

@@ -92,8 +92,6 @@ int _glfwPlatformInit(void)
 
     changeToResourcesDirectory();
 
-    _glfwLibrary.NS.desktopMode = CGDisplayCopyDisplayMode(CGMainDisplayID());
-
     // Save the original gamma ramp
     _glfwLibrary.originalRampSize = CGDisplayGammaTableCapacity(CGMainDisplayID());
     _glfwPlatformGetGammaRamp(&_glfwLibrary.originalRamp);
@@ -132,8 +130,6 @@ int _glfwPlatformTerminate(void)
     if (_glfwLibrary.rampChanged)
         _glfwPlatformSetGammaRamp(&_glfwLibrary.originalRamp);
 
-    CGDisplayModeRelease(_glfwLibrary.NS.desktopMode);
-
     [NSApp setDelegate:nil];
     [_glfwLibrary.NS.delegate release];
     _glfwLibrary.NS.delegate = nil;

+ 1 - 1
src/cocoa_platform.h

@@ -90,7 +90,7 @@ typedef struct _GLFWlibraryNS
         double resolution;
     } timer;
 
-    CGDisplayModeRef desktopMode;
+    CGDisplayModeRef previousMode;
     CGEventSourceRef eventSource;
     id               delegate;
     id               autoreleasePool;

+ 6 - 5
src/fullscreen.c

@@ -150,11 +150,13 @@ GLFWAPI GLFWvidmode* glfwGetVideoModes(GLFWmonitor handle, int* count)
 
 
 //========================================================================
-// Get the desktop video mode
+// Get the current video mode for the specified monitor
 //========================================================================
 
-GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode)
+GLFWAPI void glfwGetVideoMode(GLFWmonitor handle, GLFWvidmode* mode)
 {
+    _GLFWmonitor* monitor = (_GLFWmonitor*) handle;
+
     if (!_glfwInitialized)
     {
         _glfwSetError(GLFW_NOT_INITIALIZED, NULL);
@@ -163,11 +165,10 @@ GLFWAPI void glfwGetDesktopMode(GLFWvidmode* mode)
 
     if (mode == NULL)
     {
-        _glfwSetError(GLFW_INVALID_VALUE,
-                      "glfwGetDesktopMode: Parameter 'mode' cannot be NULL");
+        _glfwSetError(GLFW_INVALID_VALUE, NULL);
         return;
     }
 
-    _glfwPlatformGetDesktopMode(mode);
+    _glfwPlatformGetVideoMode(monitor, mode);
 }
 

+ 1 - 1
src/internal.h

@@ -286,7 +286,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode);
 
 // Video mode support
 GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* count);
-void _glfwPlatformGetDesktopMode(GLFWvidmode* mode);
+void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode);
 
 // Gamma ramp support
 void _glfwPlatformGetGammaRamp(GLFWgammaramp* ramp);

+ 13 - 5
src/win32_fullscreen.c

@@ -268,18 +268,26 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
 
 
 //========================================================================
-// Get the desktop video mode
+// Get the current video mode for the specified monitor
 //========================================================================
 
-void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
+void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
 {
     DEVMODE dm;
+    WCHAR* deviceName;
+
+    deviceName = _glfwCreateWideStringFromUTF8(monitor->Win32.name);
+    if (!deviceName)
+    {
+        _glfwSetError(GLFW_PLATFORM_ERROR, "Win32: Failed to convert device name");
+        return;
+    }
 
-    // Get desktop display mode
+    ZeroMemory(&dm, sizeof(DEVMODE));
     dm.dmSize = sizeof(DEVMODE);
-    EnumDisplaySettings(NULL, ENUM_REGISTRY_SETTINGS, &dm);
 
-    // Return desktop mode parameters
+    EnumDisplaySettings(deviceName, ENUM_REGISTRY_SETTINGS, &dm);
+
     mode->width  = dm.dmPelsWidth;
     mode->height = dm.dmPelsHeight;
     _glfwSplitBPP(dm.dmBitsPerPel,

+ 10 - 32
src/x11_fullscreen.c

@@ -514,40 +514,18 @@ GLFWvidmode* _glfwPlatformGetVideoModes(_GLFWmonitor* monitor, int* found)
 
 
 //========================================================================
-// Get the desktop video mode
+// Get the current video mode for the specified monitor
 //========================================================================
 
-void _glfwPlatformGetDesktopMode(GLFWvidmode* mode)
+void _glfwPlatformGetVideoMode(_GLFWmonitor* monitor, GLFWvidmode* mode)
 {
-    int bpp;
-
-    // Get and split display depth
-    bpp = DefaultDepth(_glfwLibrary.X11.display, _glfwLibrary.X11.screen);
-    _glfwSplitBPP(bpp, &mode->redBits, &mode->greenBits, &mode->blueBits);
-
-    if (_glfwLibrary.X11.FS.modeChanged)
-    {
-        if (_glfwLibrary.X11.RandR.available)
-        {
-#if defined(_GLFW_HAS_XRANDR)
-            mode->width  = _glfwLibrary.X11.FS.oldWidth;
-            mode->height = _glfwLibrary.X11.FS.oldHeight;
-#endif /*_GLFW_HAS_XRANDR*/
-        }
-        else if (_glfwLibrary.X11.VidMode.available)
-        {
-#if defined(_GLFW_HAS_XF86VIDMODE)
-            mode->width  = _glfwLibrary.X11.FS.oldMode.hdisplay;
-            mode->height = _glfwLibrary.X11.FS.oldMode.vdisplay;
-#endif /*_GLFW_HAS_XF86VIDMODE*/
-        }
-    }
-    else
-    {
-        mode->width = DisplayWidth(_glfwLibrary.X11.display,
-                                   _glfwLibrary.X11.screen);
-        mode->height = DisplayHeight(_glfwLibrary.X11.display,
-                                     _glfwLibrary.X11.screen);
-    }
+    _glfwSplitBPP(DefaultDepth(_glfwLibrary.X11.display,
+                               _glfwLibrary.X11.screen),
+                  &mode->redBits, &mode->greenBits, &mode->blueBits);
+
+    mode->width = DisplayWidth(_glfwLibrary.X11.display,
+                               _glfwLibrary.X11.screen);
+    mode->height = DisplayHeight(_glfwLibrary.X11.display,
+                                 _glfwLibrary.X11.screen);
 }
 

+ 1 - 1
tests/fsfocus.c

@@ -24,7 +24,7 @@
 //========================================================================
 //
 // This test is used to test window activation and iconfication for
-// fullscreen windows with a video mode differing from the desktop mode
+// fullscreen windows with a video mode differing from the current mode
 //
 //========================================================================
 

+ 4 - 4
tests/gamma.c

@@ -119,10 +119,10 @@ int main(int argc, char** argv)
 
     if (mode == GLFW_FULLSCREEN)
     {
-        GLFWvidmode desktop_mode;
-        glfwGetDesktopMode(&desktop_mode);
-        width = desktop_mode.width;
-        height = desktop_mode.height;
+        GLFWvidmode mode;
+        glfwGetVideoMode(glfwGetNextMonitor(NULL), &mode);
+        width = mode.width;
+        height = mode.height;
     }
     else
     {

+ 4 - 4
tests/iconify.c

@@ -100,10 +100,10 @@ int main(int argc, char** argv)
 
     if (mode == GLFW_FULLSCREEN)
     {
-        GLFWvidmode desktop_mode;
-        glfwGetDesktopMode(&desktop_mode);
-        width = desktop_mode.width;
-        height = desktop_mode.height;
+        GLFWvidmode current_mode;
+        glfwGetVideoMode(glfwGetNextMonitor(NULL), &current_mode);
+        width = current_mode.width;
+        height = current_mode.height;
     }
     else
     {

+ 5 - 5
tests/modes.c

@@ -93,11 +93,11 @@ static void key_callback(GLFWwindow dummy, int key, int action)
 static void list_modes(GLFWmonitor monitor)
 {
     int count, i;
-    GLFWvidmode desktop_mode;
+    GLFWvidmode mode;
     GLFWvidmode* modes = glfwGetVideoModes(monitor, &count);
 
-    glfwGetDesktopMode(&desktop_mode);
-    printf("Desktop mode: %s\n", format_mode(&desktop_mode));
+    glfwGetVideoMode(monitor, &mode);
+    printf("Current mode: %s\n", format_mode(&mode));
 
     printf("Monitor %s (%ix%i mm):\n",
            glfwGetMonitorString(monitor, GLFW_MONITOR_NAME),
@@ -108,8 +108,8 @@ static void list_modes(GLFWmonitor monitor)
     {
         printf("%3u: %s", (unsigned int) i, format_mode(modes + i));
 
-        if (memcmp(&desktop_mode, modes + i, sizeof(GLFWvidmode)) == 0)
-            printf(" (desktop mode)");
+        if (memcmp(&mode, modes + i, sizeof(GLFWvidmode)) == 0)
+            printf(" (current mode)");
 
         putchar('\n');
     }