# HG changeset patch # User John W. Eaton # Date 1450533240 21600 # Node ID ecb95c6384f2f8ec39715a2c209b8ab1f093d1b6 # Parent 6eff66fb8a023f9a49a2e8542b1296b4ecf29f70 backout changeset e74e617060cf diff -r 6eff66fb8a02 -r ecb95c6384f2 libinterp/corefcn/cdisplay.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/cdisplay.c Sat Dec 19 07:54:00 2015 -0600 @@ -0,0 +1,164 @@ +/* + +Copyright (C) 2009-2014 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#if defined (OCTAVE_USE_WINDOWS_API) +#include +#elif defined (HAVE_FRAMEWORK_CARBON) +#include +#elif defined (HAVE_X_WINDOWS) +#include +#endif + +#include "cdisplay.h" + +const char * +octave_get_display_info (int *ht, int *wd, int *dp, double *rx, double *ry, + int *dpy_avail) +{ + const char *msg = 0; + + *dpy_avail = 0; + +#if defined (OCTAVE_USE_WINDOWS_API) + + HDC hdc = GetDC (0); + + if (hdc) + { + *dp = GetDeviceCaps (hdc, BITSPIXEL); + + *ht = GetDeviceCaps (hdc, VERTRES); + *wd = GetDeviceCaps (hdc, HORZRES); + + double ht_mm = GetDeviceCaps (hdc, VERTSIZE); + double wd_mm = GetDeviceCaps (hdc, HORZSIZE); + + *rx = *wd * 25.4 / wd_mm; + *ry = *ht * 25.4 / ht_mm; + + *dpy_avail = 1; + } + else + msg = "no graphical display found"; + +#elif defined (HAVE_FRAMEWORK_CARBON) + + CGDirectDisplayID display = CGMainDisplayID (); + + if (display) + { +#if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL) + + *dp = CGDisplayBitsPerPixel (display); + +#else + + /* FIXME: This will only work for MacOS > 10.5. For earlier versions + this code is not needed (use CGDisplayBitsPerPixel instead). */ + + CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display); + CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode); + + if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0) + *dp = 32; + else if (CFStringCompare (pixelEncoding, + CFSTR (IO16BitDirectPixels), 0) == 0) + *dp = 16; + else + *dp = 8; + +#endif + + *ht = CGDisplayPixelsHigh (display); + *wd = CGDisplayPixelsWide (display); + + CGSize sz_mm = CGDisplayScreenSize (display); + + /* 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; + + *rx = *wd * 25.4 / wd_mm; + *ry = *ht * 25.4 / ht_mm; + + *dpy_avail = 1; + } + else + msg = "no graphical display found"; + +#elif defined (HAVE_X_WINDOWS) + + const char *display_name = getenv ("DISPLAY"); + + if (display_name && *display_name) + { + Display *display = XOpenDisplay (display_name); + + if (display) + { + Screen *screen = DefaultScreenOfDisplay (display); + + if (screen) + { + *dp = DefaultDepthOfScreen (screen); + + *ht = HeightOfScreen (screen); + *wd = WidthOfScreen (screen); + + int screen_number = XScreenNumberOfScreen (screen); + + double ht_mm = DisplayHeightMM (display, screen_number); + double wd_mm = DisplayWidthMM (display, screen_number); + + *rx = *wd * 25.4 / wd_mm; + *ry = *ht * 25.4 / ht_mm; + } + else + msg = "X11 display has no default screen"; + + XCloseDisplay (display); + + *dpy_avail = 1; + } + else + msg = "unable to open X11 DISPLAY"; + } + else + msg = "X11 DISPLAY environment variable not set"; + +#else + + msg = "no graphical display found"; + +#endif + + return msg; +} diff -r 6eff66fb8a02 -r ecb95c6384f2 libinterp/corefcn/cdisplay.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/cdisplay.h Sat Dec 19 07:54:00 2015 -0600 @@ -0,0 +1,38 @@ +/* + +Copyright (C) 2014-2015 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if ! defined (octave_cdisplay_h) +#define octave_cdisplay_h 1 + +#ifdef __cplusplus +extern "C" { +#endif + +OCTINTERP_API extern const char * +octave_get_display_info (int *ht, int *wd, int *dp, double *rx, double *ry, + int *dpy_avail); + +#ifdef __cplusplus +} +#endif + +#endif diff -r 6eff66fb8a02 -r ecb95c6384f2 libinterp/corefcn/display.cc --- a/libinterp/corefcn/display.cc Fri Dec 18 22:39:36 2015 -0500 +++ b/libinterp/corefcn/display.cc Sat Dec 19 07:54:00 2015 -0600 @@ -20,141 +20,33 @@ */ -#include "display.h" +#ifdef HAVE_CONFIG_H +#include +#endif -#if defined (OCTAVE_USE_WINDOWS_API) -#include -#elif defined (HAVE_FRAMEWORK_CARBON) -#include -#elif defined (HAVE_X_WINDOWS) -#include -#endif +#include "singleton-cleanup.h" + +#include "cdisplay.h" +#include "display.h" +#include "error.h" display_info *display_info::instance = 0; void display_info::init (bool query) { - if (!query) - return; - -#if defined (OCTAVE_USE_WINDOWS_API) - - HDC hdc = GetDC (0); - - if (hdc) + if (query) { - dp = GetDeviceCaps (hdc, BITSPIXEL); - - ht = GetDeviceCaps (hdc, VERTRES); - wd = GetDeviceCaps (hdc, HORZRES); - - double ht_mm = GetDeviceCaps (hdc, VERTSIZE); - double wd_mm = GetDeviceCaps (hdc, HORZSIZE); - - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - - dpy_avail = true; - } - else - err_msg = "no graphical display found"; - -#elif defined (HAVE_FRAMEWORK_CARBON) - - CGDirectDisplayID display = CGMainDisplayID (); - - if (display) - { -#if defined (HAVE_CARBON_CGDISPLAYBITSPERPIXEL) - - dp = CGDisplayBitsPerPixel (display); - -#else - - // FIXME: This will only work for MacOS > 10.5. For earlier - // versions this code is not needed (use CGDisplayBitsPerPixel - // instead). - - CGDisplayModeRef mode = CGDisplayCopyDisplayMode (display); - CFStringRef pixelEncoding = CGDisplayModeCopyPixelEncoding (mode); - - if (CFStringCompare (pixelEncoding, CFSTR (IO32BitDirectPixels), 0) == 0) - dp = 32; - else if (CFStringCompare (pixelEncoding, - CFSTR (IO16BitDirectPixels), 0) == 0) - dp = 16; - else - dp = 8; - -#endif - - ht = CGDisplayPixelsHigh (display); - wd = CGDisplayPixelsWide (display); - - CGSize sz_mm = CGDisplayScreenSize (display); + int avail = 0; - // 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; - - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - - dpy_avail = true; - } - else - err_msg = "no graphical display found"; - -#elif defined (HAVE_X_WINDOWS) - - const char *display_name = std::getenv ("DISPLAY"); - - if (display_name && *display_name) - { - Display *display = XOpenDisplay (display_name); - - if (display) - { - Screen *screen = DefaultScreenOfDisplay (display); - - if (screen) - { - dp = DefaultDepthOfScreen (screen); + const char *msg = octave_get_display_info (&ht, &wd, &dp, &rx, &ry, + &avail); - ht = HeightOfScreen (screen); - wd = WidthOfScreen (screen); - - int screen_number = XScreenNumberOfScreen (screen); - - double ht_mm = DisplayHeightMM (display, screen_number); - double wd_mm = DisplayWidthMM (display, screen_number); - - rx = wd * 25.4 / wd_mm; - ry = ht * 25.4 / ht_mm; - } - else - err_msg = "X11 display has no default screen"; + dpy_avail = avail; - XCloseDisplay (display); - - dpy_avail = true; - } - else - err_msg = "unable to open X11 DISPLAY"; + if (msg) + err_msg = msg; } - else - err_msg = "X11 DISPLAY environment variable not set"; - -#else - - err_msg = "no graphical display found"; - -#endif - } bool diff -r 6eff66fb8a02 -r ecb95c6384f2 libinterp/corefcn/display.h --- a/libinterp/corefcn/display.h Fri Dec 18 22:39:36 2015 -0500 +++ b/libinterp/corefcn/display.h Sat Dec 19 07:54:00 2015 -0600 @@ -23,16 +23,9 @@ #if ! defined (octave_display_h) #define octave_display_h 1 -#ifdef HAVE_CONFIG_H -#include -#endif +#include -#include -#include - -#include "singleton-cleanup.h" - -#include "error.h" +class Matrix; class OCTINTERP_API diff -r 6eff66fb8a02 -r ecb95c6384f2 libinterp/corefcn/module.mk --- a/libinterp/corefcn/module.mk Fri Dec 18 22:39:36 2015 -0500 +++ b/libinterp/corefcn/module.mk Sat Dec 19 07:54:00 2015 -0600 @@ -26,6 +26,7 @@ COREFCN_INC = \ libinterp/corefcn/Cell.h \ libinterp/corefcn/c-file-ptr-stream.h \ + libinterp/corefcn/cdisplay.h \ libinterp/corefcn/comment-list.h \ libinterp/corefcn/data.h \ libinterp/corefcn/debug.h \ @@ -127,6 +128,7 @@ libinterp/corefcn/bitfcns.cc \ libinterp/corefcn/bsxfun.cc \ libinterp/corefcn/c-file-ptr-stream.cc \ + libinterp/corefcn/cdisplay.c \ libinterp/corefcn/cellfun.cc \ libinterp/corefcn/colloc.cc \ libinterp/corefcn/comment-list.cc \