[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53746] trunk/blender: Mac HiDPI ("retina" ) handling:

Ton Roosendaal ton at blender.org
Sat Jan 12 18:07:54 CET 2013


Revision: 53746
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53746
Author:   ton
Date:     2013-01-12 17:07:49 +0000 (Sat, 12 Jan 2013)
Log Message:
-----------
Mac HiDPI ("retina") handling:

OK - so you have this nice crisp screen, and still you want to add extra 
monitors to the laptop! That means Blender should switch back and forth to HiDPI 
modes, when you move a window to another monitor.

This code makes the pixelsize scale factor a window property, and handles
an event when a window moves to another monitor. It then changes the
native pixelsize nicely and refreshes entire UI.

You can also have one Blender window on high, and other on low resolution.

Stretching a Blender window from 1 monitor to the other works too, but that
is Apple magic handling it.

Modified Paths:
--------------
    trunk/blender/intern/ghost/GHOST_C-api.h
    trunk/blender/intern/ghost/GHOST_ISystem.h
    trunk/blender/intern/ghost/GHOST_IWindow.h
    trunk/blender/intern/ghost/GHOST_Types.h
    trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
    trunk/blender/intern/ghost/intern/GHOST_System.cpp
    trunk/blender/intern/ghost/intern/GHOST_System.h
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
    trunk/blender/intern/ghost/intern/GHOST_Window.cpp
    trunk/blender/intern/ghost/intern/GHOST_Window.h
    trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm
    trunk/blender/source/blender/blenkernel/intern/blender.c
    trunk/blender/source/blender/windowmanager/intern/wm_files.c
    trunk/blender/source/blender/windowmanager/intern/wm_window.c

Modified: trunk/blender/intern/ghost/GHOST_C-api.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_C-api.h	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/GHOST_C-api.h	2013-01-12 17:07:49 UTC (rev 53746)
@@ -860,7 +860,7 @@
 /**
  * If window was opened using native pixel size, it returns scaling factor.
  */
-extern float GHOST_GetNativePixelSize(void);
+extern float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle);
 
 
 #ifdef __cplusplus

Modified: trunk/blender/intern/ghost/GHOST_ISystem.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_ISystem.h	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/GHOST_ISystem.h	2013-01-12 17:07:49 UTC (rev 53746)
@@ -297,10 +297,8 @@
 	
 	/**
 	 * Native pixel size support (MacBook 'retina').
-	 * \return The pixel size in float.
 	 */
 	virtual bool useNativePixel(void) = 0;
-	virtual float getNativePixelSize(void) = 0;
 
 	/***************************************************************************************
 	 * Event management functionality

Modified: trunk/blender/intern/ghost/GHOST_IWindow.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_IWindow.h	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/GHOST_IWindow.h	2013-01-12 17:07:49 UTC (rev 53746)
@@ -305,6 +305,10 @@
 	 */
 	virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds, GHOST_TInt32 mouse_ungrab_xy[2]) { return GHOST_kSuccess; }
 
+	
+	virtual float getNativePixelSize(void) = 0;
+
+	
 #ifdef WITH_CXX_GUARDEDALLOC
 	MEM_CXX_CLASS_ALLOC_FUNCS("GHOST:GHOST_IWindow")
 #endif

Modified: trunk/blender/intern/ghost/GHOST_Types.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_Types.h	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/GHOST_Types.h	2013-01-12 17:07:49 UTC (rev 53746)
@@ -183,6 +183,7 @@
 	GHOST_kEventDraggingDropDone,
 	
 	GHOST_kEventOpenMainFile, // Needed for Cocoa to open double-clicked .blend file at startup
+	GHOST_kEventNativeResolutionChange, // Needed for Cocoa when window moves to other display
 
 	GHOST_kEventTimer,
 

Modified: trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2013-01-12 17:07:49 UTC (rev 53746)
@@ -885,9 +885,11 @@
 	return system->useNativePixel();
 }
 
-float GHOST_GetNativePixelSize(void)
+float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle)
 {
-	GHOST_ISystem *system = GHOST_ISystem::getSystem();
-	return system->getNativePixelSize();
+	GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
+	if (window)
+		return window->getNativePixelSize();
+	return 1.0f;
 }
 

Modified: trunk/blender/intern/ghost/intern/GHOST_System.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_System.cpp	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_System.cpp	2013-01-12 17:07:49 UTC (rev 53746)
@@ -46,7 +46,6 @@
 
 GHOST_System::GHOST_System()
 	: m_nativePixel(false),
-	m_nativePixelSize(1),
 	m_displayManager(0),
 	m_timerManager(0),
 	m_windowManager(0),
@@ -382,9 +381,3 @@
 	return 1;
 }
 
-float GHOST_System::getNativePixelSize(void)
-{
-	if (m_nativePixel)
-		return m_nativePixelSize;
-	return 1.0f;
-}

Modified: trunk/blender/intern/ghost/intern/GHOST_System.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_System.h	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_System.h	2013-01-12 17:07:49 UTC (rev 53746)
@@ -175,9 +175,6 @@
 	virtual bool useNativePixel(void);
 	bool m_nativePixel;
 
-	virtual float getNativePixelSize(void);
-	float m_nativePixelSize;
-
 	/***************************************************************************************
 	 * Event management functionality
 	 ***************************************************************************************/

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm	2013-01-12 17:07:49 UTC (rev 53746)
@@ -1054,6 +1054,13 @@
 					//m_ignoreWindowSizedMessages = true;
 				}
 				break;
+			case GHOST_kEventNativeResolutionChange:
+				
+				if (m_nativePixel) {
+					window->setNativePixelSize();
+					pushEvent( new GHOST_Event(getMilliSeconds(), GHOST_kEventNativeResolutionChange, window) );
+				}
+
 			default:
 				return GHOST_kFailure;
 				break;

Modified: trunk/blender/intern/ghost/intern/GHOST_Window.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_Window.cpp	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_Window.cpp	2013-01-12 17:07:49 UTC (rev 53746)
@@ -61,6 +61,8 @@
 	
 	m_cursorGrabAccumPos[0] = 0;
 	m_cursorGrabAccumPos[1] = 0;
+	
+	m_nativePixelSize = 1.0f;
 
 	m_fullScreen = state == GHOST_kWindowStateFullScreen;
 	if (m_fullScreen) {
@@ -194,3 +196,4 @@
 {
 	return m_isUnsavedChanges;
 }
+

Modified: trunk/blender/intern/ghost/intern/GHOST_Window.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_Window.h	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_Window.h	2013-01-12 17:07:49 UTC (rev 53746)
@@ -257,6 +257,13 @@
 	{
 		m_userData = userData;
 	}
+	
+	virtual float getNativePixelSize(void)
+	{
+		if (m_nativePixelSize > 0.0f)
+			return m_nativePixelSize;
+		return 1.0f;
+	}
 
 protected:
 	/**
@@ -351,6 +358,9 @@
 	GHOST_TUns32 m_fullScreenWidth;
 	/** Full-screen height */
 	GHOST_TUns32 m_fullScreenHeight;
+	
+	/* OSX only, retina screens */
+	float m_nativePixelSize;
 };
 
 

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h	2013-01-12 17:07:49 UTC (rev 53746)
@@ -262,6 +262,11 @@
 	 * Hides the progress bar icon
 	 */
 	virtual GHOST_TSuccess endProgressBar();
+	
+	
+	virtual void setNativePixelSize(void);
+
+	
 protected:
 	/**
 	 * Tries to install a rendering context in this window.

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm	2013-01-12 17:07:49 UTC (rev 53746)
@@ -74,8 +74,10 @@
 - (void)windowDidMove:(NSNotification *)notification;
 - (void)windowWillMove:(NSNotification *)notification;
 - (BOOL)windowShouldClose:(id)sender;	
+- (void)windowDidChangeBackingProperties:(NSNotification *)notification;
 @end
 
+
 @implementation CocoaWindowDelegate : NSObject
 - (void)setSystemAndWindowCocoa:(GHOST_SystemCocoa *)sysCocoa windowCocoa:(GHOST_WindowCocoa *)winCocoa
 {
@@ -128,6 +130,11 @@
 	}*/
 }
 
+- (void)windowDidChangeBackingProperties:(NSNotification *)notification
+{
+	systemCocoa->handleWindowEvent(GHOST_kEventNativeResolutionChange, associatedWindow);
+}
+
 - (BOOL)windowShouldClose:(id)sender;
 {
 	//Let Blender close the window rather than closing immediately
@@ -593,7 +600,7 @@
 			[m_openGLView setWantsBestResolutionOpenGLSurface:YES];
 		
 			NSRect backingBounds = [m_openGLView convertRectToBacking:[m_openGLView bounds]];
-			m_systemCocoa->m_nativePixelSize = (float)backingBounds.size.width / (float)rect.size.width;
+			m_nativePixelSize = (float)backingBounds.size.width / (float)rect.size.width;
 		}
 	}
 	
@@ -911,7 +918,18 @@
 	return [m_window screen];
 }
 
+/* called for event, when window leaves monitor to another */
+void GHOST_WindowCocoa::setNativePixelSize(void)
+{
+	NSRect backingBounds = [m_openGLView convertRectToBacking:[m_openGLView bounds]];
+	
+	GHOST_Rect rect;
+	getClientBounds(rect);
 
+	m_nativePixelSize = (float)backingBounds.size.width / (float)rect.getWidth();
+
+}
+
 /**
  * \note Fullscreen switch is not actual fullscreen with display capture.
  * As this capture removes all OS X window manager features.

Modified: trunk/blender/source/blender/blenkernel/intern/blender.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/blender.c	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/source/blender/blenkernel/intern/blender.c	2013-01-12 17:07:49 UTC (rev 53746)
@@ -426,6 +426,9 @@
 /* handle changes in settings that need recalc */
 void BKE_userdef_state(void)
 {
+	/* prevent accidents */
+	if (U.pixelsize == 0) U.pixelsize = 1;
+	
 	BLF_default_dpi(U.pixelsize * U.dpi);
 	U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72;
 

Modified: trunk/blender/source/blender/windowmanager/intern/wm_files.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_files.c	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/source/blender/windowmanager/intern/wm_files.c	2013-01-12 17:07:49 UTC (rev 53746)
@@ -302,11 +302,6 @@
 
 	/* update tempdir from user preferences */
 	BLI_init_temporary_dir(U.tempdir);
-	
-	/* displays with larger native pixels, like Macbook. Used to scale dpi with */
-	if (G.background == FALSE)
-		U.pixelsize = GHOST_GetNativePixelSize();
-	if (U.pixelsize == 0) U.pixelsize = 1;
 
 	BKE_userdef_state();
 }

Modified: trunk/blender/source/blender/windowmanager/intern/wm_window.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_window.c	2013-01-12 16:49:37 UTC (rev 53745)
+++ trunk/blender/source/blender/windowmanager/intern/wm_window.c	2013-01-12 17:07:49 UTC (rev 53746)
@@ -377,7 +377,7 @@
 		
 		/* displays with larger native pixels, like Macbook. Used to scale dpi with */

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list