[Bf-blender-cvs] [6fa46ad] master: Support for "virtual pixelsize" on 4k screens.

Lukas Tönne noreply at git.blender.org
Tue Sep 30 18:30:17 CEST 2014


Commit: 6fa46ad315ceb46dbf47d6c6ffdda032d0e885ed
Author: Lukas Tönne
Date:   Tue Sep 30 18:29:32 2014 +0200
Branches: master
https://developer.blender.org/rB6fa46ad315ceb46dbf47d6c6ffdda032d0e885ed

Support for "virtual pixelsize" on 4k screens.

On 4k devices the default pixel size leads to tiny OpenGL drawing
that is hardly usable without doubling the DPI. The retina system
on OSX aims to alleviate this problem by introducing a general 2x
pixel size.

No equivalent feature exists on other platforms so far. However,
to emulate the effect this patch introduces a "virtual" pixel size
factor for OpenGL drawing.

Note that the user currently has to enable this manually by selecting
the "Virtual Pixel Mode" in the user preferences (defaults to native).
All windows of a Blender instance share the same virtual pixel size as well.
It may be possible to handle this on a per-window basis and automate
the selection somewhat (if enabled by the user), so working with
multiple screens becomes more convenient, but technical limitations
make this a bit difficult (on X11 with nvidia drivers the actual screen size
is not reported correctly).

Reviewers: ton, campbellbarton

Differential Revision: https://developer.blender.org/D669

===================================================================

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/windowmanager/intern/wm_window.c
M	source/blender/windowmanager/wm_window.h

===================================================================

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index 59b842a..dc18dd7 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -383,6 +383,11 @@ class USERPREF_PT_system(Panel):
         col = colsplit.column()
         col.label(text="General:")
         col.prop(system, "dpi")
+        col.label("Virtual Pixel Mode:")
+        col.prop(system, "virtual_pixel_mode", text="")
+
+        col.separator()
+
         col.prop(system, "frame_server_port")
         col.prop(system, "scrollback", text="Console Scrollback")
 
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index ed59014..d33e3be 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -534,6 +534,8 @@ typedef struct UserDef {
 	
 	float fcu_inactive_alpha;	/* opacity of inactive F-Curves in F-Curve Editor */
 	float pixelsize;			/* private, set by GHOST, to multiply DPI with */
+	int virtual_pixel;			/* virtual pixelsize mode */
+	int pad2;
 
 	short pie_interaction_type;     /* if keeping a pie menu spawn button pressed after this time, it turns into
 	                             * a drag/release pie menu */
@@ -854,6 +856,11 @@ typedef enum eImageDrawMethod {
 	IMAGE_DRAW_METHOD_DRAWPIXELS = 3,
 } eImageDrawMethod;
 
+typedef enum eUserpref_VirtualPixel {
+	VIRTUAL_PIXEL_NATIVE = 0,
+	VIRTUAL_PIXEL_DOUBLE = 1,
+} eUserpref_VirtualPixel;
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index aa37895..7fdc9ba 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -120,6 +120,16 @@ static void rna_userdef_dpi_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Po
 	WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);    /* refresh region sizes */
 }
 
+static void rna_userdef_virtual_pixel_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
+{
+	/* font's are stored at each DPI level, without this we can easy load 100's of fonts */
+	BLF_cache_clear();
+	
+	BKE_userdef_state();
+	WM_main_add_notifier(NC_WINDOW, NULL);      /* full redraw */
+	WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);    /* refresh region sizes */
+}
+
 static void rna_userdef_language_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
 {
 	BLF_cache_clear();
@@ -3743,6 +3753,12 @@ static void rna_def_userdef_system(BlenderRNA *brna)
 	    {0, NULL, 0, NULL, NULL}
 	};
 
+	static EnumPropertyItem virtual_pixel_mode_items[] = {
+		{VIRTUAL_PIXEL_NATIVE, "NATIVE", 0, "Native", "Use native pixel size of the display"},
+		{VIRTUAL_PIXEL_DOUBLE, "DOUBLE", 0, "Double", "Use double the native pixel size of the display"},
+		{0, NULL, 0, NULL, NULL}
+	};
+
 	srna = RNA_def_struct(brna, "UserPreferencesSystem", NULL);
 	RNA_def_struct_sdna(srna, "UserDef");
 	RNA_def_struct_nested(brna, srna, "UserPreferences");
@@ -3762,6 +3778,12 @@ static void rna_def_userdef_system(BlenderRNA *brna)
 	RNA_def_property_ui_text(prop, "DPI", "Font size and resolution for display");
 	RNA_def_property_update(prop, 0, "rna_userdef_dpi_update");
 
+	prop = RNA_def_property(srna, "virtual_pixel_mode", PROP_ENUM, PROP_NONE);
+	RNA_def_property_enum_sdna(prop, NULL, "virtual_pixel");
+	RNA_def_property_enum_items(prop, virtual_pixel_mode_items);
+	RNA_def_property_ui_text(prop, "Virtual Pixel Mode", "Modify the pixel size for hi-res devices");
+	RNA_def_property_update(prop, 0, "rna_userdef_virtual_pixel_update");
+
 	prop = RNA_def_property(srna, "font_path_ui", PROP_STRING, PROP_FILEPATH);
 	RNA_def_property_string_sdna(prop, NULL, "font_path_ui");
 	RNA_def_property_ui_text(prop, "Interface Font", "Path to interface font");
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 56e0948..ec806fb 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -339,6 +339,19 @@ void wm_window_title(wmWindowManager *wm, wmWindow *win)
 	}
 }
 
+float wm_window_pixelsize(wmWindow *win)
+{
+	float pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
+	
+	switch (U.virtual_pixel) {
+		default:
+		case VIRTUAL_PIXEL_NATIVE:
+			return pixelsize;
+		case VIRTUAL_PIXEL_DOUBLE:
+			return 2.0f * pixelsize;
+	}
+}
+
 /* belongs to below */
 static void wm_window_add_ghostwindow(const char *title, wmWindow *win)
 {
@@ -397,7 +410,7 @@ static void wm_window_add_ghostwindow(const char *title, wmWindow *win)
 		
 		/* displays with larger native pixels, like Macbook. Used to scale dpi with */
 		/* needed here, because it's used before it reads userdef */
-		U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
+		U.pixelsize = wm_window_pixelsize(win);
 		BKE_userdef_state();
 		
 		wm_window_swap_buffers(win);
@@ -686,7 +699,7 @@ void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
 		GHOST_ActivateWindowDrawingContext(win->ghostwin);
 		
 		/* this can change per window */
-		U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
+		U.pixelsize = wm_window_pixelsize(win);
 		BKE_userdef_state();
 	}
 }
@@ -1046,7 +1059,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
 			case GHOST_kEventNativeResolutionChange:
 				// printf("change, pixel size %f\n", GHOST_GetNativePixelSize(win->ghostwin));
 				
-				U.pixelsize = GHOST_GetNativePixelSize(win->ghostwin);
+				U.pixelsize = wm_window_pixelsize(win);
 				BKE_userdef_state();
 				WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
 				WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h
index e0639b0..bf96e02 100644
--- a/source/blender/windowmanager/wm_window.h
+++ b/source/blender/windowmanager/wm_window.h
@@ -61,6 +61,8 @@ void		wm_window_swap_buffers	(wmWindow *win);
 void		wm_window_set_swap_interval	(wmWindow *win, int interval);
 int			wm_window_get_swap_interval	(wmWindow *win);
 
+float		wm_window_pixelsize(wmWindow *win);
+
 void		wm_get_cursor_position	(wmWindow *win, int *x, int *y);
 
 wmWindow	*wm_window_copy			(bContext *C, wmWindow *winorig);




More information about the Bf-blender-cvs mailing list