changeset 14776:0eb1b1eb2c76

Detect Carbon's CGDisplayBitsPerPixel during configure. Use it if present. Provide a replacement if it is not. * m4/acinclude.m4 (OCTAVE_CARBON_CGDISPLAYBITSPERPIXEL): New macro. * configure.ac: Use it. * display.cc: Define DisplayBitsPerPixel, and use it if CGDisplayBitsPerPixel is missing.
author Ben Abbott <bpabbott@mac.com>
date Sun, 17 Jun 2012 17:20:38 -0400
parents 4e86b0fa6c2d
children 1230d5d58d2d
files configure.ac m4/acinclude.m4 src/display.cc
diffstat 3 files changed, 47 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Fri Jun 15 21:15:23 2012 -0400
+++ b/configure.ac	Sun Jun 17 17:20:38 2012 -0400
@@ -654,6 +654,8 @@
 OCTAVE_CXX_COMPLEX_SETTERS
 OCTAVE_CXX_COMPLEX_REFERENCE_ACCESSORS
 
+OCTAVE_CARBON_CGDISPLAYBITSPERPIXEL
+
 ### Check for the QHull library
 
 OCTAVE_CHECK_LIBRARY(qhull, QHull,
--- a/m4/acinclude.m4	Fri Jun 15 21:15:23 2012 -0400
+++ b/m4/acinclude.m4	Sun Jun 17 17:20:38 2012 -0400
@@ -158,6 +158,25 @@
 AC_LANG_POP(C++)
 ])
 dnl
+dnl See if the Carbon Framework defines CGDisplayBitsPerPixel.
+dnl
+AC_DEFUN([OCTAVE_CARBON_CGDISPLAYBITSPERPIXEL],
+[AC_CACHE_CHECK([whether CGDisplayBitsPerPixel is defined in the Carbon Framework],
+octave_cv_carbon_cgdisplaybitsperpixel,
+[AC_LANG_PUSH(C++)
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <Carbon/Carbon.h>
+]], [[
+CGDirectDisplayID display = CGMainDisplayID ();
+size_t depth = CGDisplayBitsPerPixel (display);
+]])],
+octave_cv_carbon_cgdisplaybitsperpixel=yes, octave_cv_carbon_cgdisplaybitsperpixel=no)])
+if test $octave_cv_carbon_cgdisplaybitsperpixel = yes; then
+AC_DEFINE(HAVE_CARBON_CGDISPLAYBITSPERPIXEL,1,[Define if Carbon Framework has CGDisplayBitsPerPixel])
+fi
+AC_LANG_POP(C++)
+])
+dnl
 dnl The following test is from Karl Berry's Kpathseach library.  I'm
 dnl including it here in case we someday want to make the use of
 dnl kpathsea optional.
--- a/src/display.cc	Fri Jun 15 21:15:23 2012 -0400
+++ b/src/display.cc	Sun Jun 17 17:20:38 2012 -0400
@@ -41,6 +41,23 @@
 
 display_info *display_info::instance = 0;
 
+#if defined (HAVE_FRAMEWORK_CARBON) && ! defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL)
+// FIXME - This will only work for MacOS > 10.5. For earlier versions
+// this code is not needed (use CGDisplayBitsPerPixel instead).
+size_t DisplayBitsPerPixel (CGDirectDisplayID display)
+{
+  CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display);
+  CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode);
+
+  if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0)
+    return 32;
+  else if (CFStringCompare (pixelEncoding, CFSTR (IO16BitDirectPixels), 0) == 0)
+    return 16;
+  else 
+    return 8;
+}
+#endif
+
 void
 display_info::init (bool query)
 {
@@ -72,16 +89,21 @@
 
       if (display)
         {
+#  if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL)
+          // For MacOS < 10.7 use the line below
           dp = CGDisplayBitsPerPixel (display);
+#  else
+          // For MacOS > 10.5 use the line below
+          dp = DisplayBitsPerPixel (display);
+#  endif
 
           ht = CGDisplayPixelsHigh (display);
           wd = CGDisplayPixelsWide (display);
 
           CGSize sz_mm = CGDisplayScreenSize (display);
-
-          // On modern Mac systems (>= 10.5) CGSize is a struct keeping 2
-          // CGFloat values, but the CGFloat typedef is not present on
-          // older systems, so use double instead.
+          // For MacOS >= 10.6, CGSize is a struct keeping 2 CGFloat values,
+          // but the CGFloat typedef is not present on older systems,
+          // so use double instead.
           double ht_mm = sz_mm.height;
           double wd_mm = sz_mm.width;