Temporary mode-setting hack works
authorNathan Heisey <nathanheisey@gmail.com>
Sat, 20 Aug 2011 15:16:13 +0000
changeset 5938b85b6326c498
parent 5937 74870d003e32
child 5939 d9e9c343d264
Temporary mode-setting hack works
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_bframebuffer.cc
src/video/bwindow/SDL_bmodes.cc
src/video/bwindow/SDL_bopengl.cc
src/video/bwindow/SDL_bopengl.h
src/video/bwindow/SDL_bwindow.cc
     1.1 --- a/src/video/bwindow/SDL_BWin.h	Wed Aug 17 13:31:18 2011 +0000
     1.2 +++ b/src/video/bwindow/SDL_BWin.h	Sat Aug 20 15:16:13 2011 +0000
     1.3 @@ -185,6 +185,9 @@
     1.4      			_bits = (uint8*) info->bits;
     1.5      			_row_bytes = info->bytes_per_row;
     1.6      			_bounds = info->window_bounds;
     1.7 +printf("Bounds = (%i,%i,%i,%i), Frame = (%0.f,%0.f,%0.f,%0.f)\n", _bounds.left,
     1.8 +	_bounds.top, _bounds.right, _bounds.bottom, Frame().left, Frame().top,
     1.9 +	Frame().right, Frame().bottom);
    1.10      			_bytes_per_px = info->bits_per_pixel / 8;
    1.11      			_buffer_dirty = true;
    1.12      		}
    1.13 @@ -572,12 +575,27 @@
    1.14  
    1.15      void _SetFullScreen(BMessage *msg) {
    1.16      	bool fullscreen;
    1.17 +
    1.18 +    	BRect rc1 = Bounds(),
    1.19 +    		  rc2 = Frame();
    1.20 +printf(__FILE__": %d - bounds = (%.0f,%.0f,%.0f,%.0f), frame = (%.0f,%.0f,%.0f,%.0f\n", __LINE__, rc1.left, rc1.top, rc1.right, rc1.bottom,
    1.21 +rc2.left, rc2.top, rc2.right, rc2.bottom);
    1.22      	if(
    1.23  			msg->FindBool("fullscreen", &fullscreen) != B_OK
    1.24  		) {
    1.25  			return;
    1.26      	}
    1.27 +
    1.28 +if(fullscreen) {
    1.29 +	printf("Setting fullscreen...\n");
    1.30 +} else {
    1.31 +	printf("Unsetting fullscreen...\n");
    1.32 +}
    1.33 +#if 1
    1.34      	SetFullScreen(fullscreen);
    1.35 +#endif
    1.36 +printf(__FILE__": %d - bounds = (%.0f,%.0f,%.0f,%.0f), frame = (%.0f,%.0f,%.0f,%.0f\n", __LINE__, rc1.left, rc1.top, rc1.right, rc1.bottom,
    1.37 +rc2.left, rc2.top, rc2.right, rc2.bottom);
    1.38      }
    1.39      
    1.40      /* Members */
     2.1 --- a/src/video/bwindow/SDL_bframebuffer.cc	Wed Aug 17 13:31:18 2011 +0000
     2.2 +++ b/src/video/bwindow/SDL_bframebuffer.cc	Sat Aug 20 15:16:13 2011 +0000
     2.3 @@ -125,7 +125,10 @@
     2.4  	while(bwin->ConnectionEnabled()) {
     2.5  		if( bwin->Connected() && bwin->BufferExists() && bwin->BufferIsDirty() ) {
     2.6  			bwin->LockBuffer();
     2.7 -			BBitmap *bitmap = bwin->GetBitmap();
     2.8 +			BBitmap *bitmap = NULL;
     2.9 +//			while(!bitmap) {
    2.10 +				bitmap = bwin->GetBitmap();
    2.11 +//			}
    2.12  			int32 windowPitch = bitmap->BytesPerRow();
    2.13  			int32 bufferPitch = bwin->GetRowBytes();
    2.14  			uint8 *windowpx;
    2.15 @@ -193,6 +196,12 @@
    2.16  }
    2.17  
    2.18  
    2.19 +/*
    2.20 + * TODO:
    2.21 + * This was written to test if certain errors were caused by threading issues.
    2.22 + * The specific issues have since become rare enough that they may have been
    2.23 + * solved, but I doubt it- they were pretty sporadic before now.
    2.24 + */
    2.25  int32 BE_UpdateOnce(SDL_Window *window) {
    2.26  	SDL_BWin *bwin = _ToBeWin(window);
    2.27  	BScreen bscreen;
     3.1 --- a/src/video/bwindow/SDL_bmodes.cc	Wed Aug 17 13:31:18 2011 +0000
     3.2 +++ b/src/video/bwindow/SDL_bmodes.cc	Sat Aug 20 15:16:13 2011 +0000
     3.3 @@ -26,13 +26,20 @@
     3.4  #include "SDL_bmodes.h"
     3.5  #include "SDL_BWin.h"
     3.6  
     3.7 +#if SDL_VIDEO_OPENGL
     3.8 +#include "SDL_bopengl.h"
     3.9 +#endif
    3.10 +
    3.11  #include "../../main/beos/SDL_BApp.h"
    3.12  
    3.13  #ifdef __cplusplus
    3.14  extern "C" {
    3.15  #endif
    3.16  
    3.17 -#if 1
    3.18 +
    3.19 +#define WRAP_BMODE 1
    3.20 +
    3.21 +#if WRAP_BMODE
    3.22  /* This wrapper is here so that the driverdata can be freed */
    3.23  typedef struct SDL_DisplayModeData {
    3.24  	display_mode *bmode;
    3.25 @@ -121,7 +128,7 @@
    3.26  	mode->w = bmode->virtual_width;
    3.27  	mode->h = bmode->virtual_height;
    3.28  	mode->refresh_rate = (int)get_refresh_rate(*bmode);
    3.29 -#if 1
    3.30 +#if WRAP_BMODE
    3.31  	SDL_DisplayModeData *data = (SDL_DisplayModeData*)SDL_calloc(1, sizeof(SDL_DisplayModeData));
    3.32  	data->bmode = bmode;
    3.33  	
    3.34 @@ -206,8 +213,159 @@
    3.35  	free(bmodes);
    3.36  }
    3.37  
    3.38 +
    3.39 +
    3.40 +
    3.41 +
    3.42 +
    3.43 +
    3.44 +
    3.45 +
    3.46 +
    3.47 +
    3.48 +
    3.49 +
    3.50 +
    3.51 +static int get_combine_mode(display_mode &mode) {
    3.52 +	if ((mode.flags & B_SCROLL) == 0)
    3.53 +		return 0;
    3.54 +
    3.55 +	if (mode.virtual_width == mode.timing.h_display * 2)
    3.56 +		return 1;
    3.57 +
    3.58 +	if (mode.virtual_height == mode.timing.v_display * 2)
    3.59 +		return 2;
    3.60 +     
    3.61 +		return 0;
    3.62 +}
    3.63 +#if 0
    3.64 +bool _GetDisplayMode(const screen_mode& mode, display_mode& displayMode)
    3.65 +{
    3.66 + 	uint16 virtualWidth, virtualHeight;
    3.67 + 	int32 bestIndex = -1;
    3.68 + 	float bestDiff = 999;
    3.69 + 
    3.70 + 	virtualWidth = mode.combine == kCombineHorizontally
    3.71 + 		? mode.width * 2 : mode.width;
    3.72 + 	virtualHeight = mode.combine == kCombineVertically
    3.73 + 		? mode.height * 2 : mode.height;
    3.74 + 
    3.75 + 	// try to find mode in list provided by driver
    3.76 + 	for (uint32 i = 0; i < fModeCount; i++) {
    3.77 + 		if (fModeList[i].virtual_width != virtualWidth
    3.78 + 			|| fModeList[i].virtual_height != virtualHeight
    3.79 + 			|| (color_space)fModeList[i].space != mode.space)
    3.80 + 			continue;
    3.81 + 
    3.82 + 		// Accept the mode if the computed refresh rate of the mode is within
    3.83 + 		// 0.6 percent of the refresh rate specified by the caller.  Note that
    3.84 + 		// refresh rates computed from mode parameters is not exact; especially
    3.85 + 		// some of the older modes such as 640x480, 800x600, and 1024x768.
    3.86 + 		// The tolerance of 0.6% was obtained by examining the various possible
    3.87 + 		// modes.
    3.88 +
    3.89 + 		float refreshDiff = fabs(get_refresh_rate(fModeList[i]) - mode.refresh);
    3.90 + 		if (refreshDiff < 0.006 * mode.refresh) {
    3.91 + 			// Accept this mode.
    3.92 + 			displayMode = fModeList[i];
    3.93 + 			displayMode.h_display_start = 0;
    3.94 + 			displayMode.v_display_start = 0;
    3.95 + 
    3.96 +			// Since the computed refresh rate of the selected mode might differ
    3.97 + 			// from selected refresh rate by a few tenths (e.g. 60.2 instead of
    3.98 + 			// 60.0), tweak the pixel clock so the the refresh rate of the mode
    3.99 + 			// matches the selected refresh rate.
   3.100 + 
   3.101 + 			displayMode.timing.pixel_clock = uint32(((displayMode.timing.h_total
   3.102 + 				* displayMode.timing.v_total * mode.refresh) / 1000.0) + 0.5);
   3.103 + 			return true;
   3.104 + 		}
   3.105 + 
   3.106 +		// Mode not acceptable.
   3.107 + 
   3.108 + 		if (refreshDiff < bestDiff) {
   3.109 + 			bestDiff = refreshDiff;
   3.110 + 			bestIndex = i;
   3.111 +		}
   3.112 +	}
   3.113 + 
   3.114 + 	// we didn't find the exact mode, but something very similar?
   3.115 + 	if (bestIndex == -1)
   3.116 + 		return false;
   3.117 + 
   3.118 + 	displayMode = fModeList[bestIndex];
   3.119 + 	displayMode.h_display_start = 0;
   3.120 + 	displayMode.v_display_start = 0;
   3.121 + 
   3.122 + 	// For the mode selected by the width, height, and refresh rate, compute
   3.123 + 	// the video timing parameters for the mode by using the VESA Generalized
   3.124 + 	// Timing Formula (GTF).
   3.125 + 
   3.126 +	ComputeGTFVideoTiming(displayMode.timing.h_display,
   3.127 + 		displayMode.timing.v_display, mode.refresh, displayMode.timing);
   3.128 +
   3.129 +	return true;
   3.130 +}
   3.131 +#endif
   3.132 +
   3.133 +void _SpoutModeData(display_mode *bmode) {
   3.134 +	printf("BMode:\n");
   3.135 +	printf("\tw,h = (%i,%i)\n", bmode->virtual_width, bmode->virtual_height);
   3.136 +	printf("\th,v = (%i,%i)\n", bmode->h_display_start, 
   3.137 +			bmode->v_display_start);
   3.138 +	printf("\tcombine mode = %i\n", get_combine_mode(*bmode));
   3.139 +	if(bmode->flags) {
   3.140 +		printf("\tFlags:\n");
   3.141 +		if(bmode->flags & B_SCROLL) {
   3.142 +			printf("\t\tB_SCROLL\n");
   3.143 +		}
   3.144 +		if(bmode->flags & B_8_BIT_DAC) {
   3.145 +			printf("\t\tB_8_BIT_DAC\n");
   3.146 +		}
   3.147 +		if(bmode->flags & B_HARDWARE_CURSOR) {
   3.148 +			printf("\t\tB_HARDWARE_CURSOR\n");
   3.149 +		}
   3.150 +		if(bmode->flags & B_PARALLEL_ACCESS) {
   3.151 +			printf("\t\tB_PARALLEL_ACCESS\n");
   3.152 +		}
   3.153 +		if(bmode->flags & B_DPMS) {
   3.154 +			printf("\t\tB_DPMS\n");
   3.155 +		}
   3.156 +		if(bmode->flags & B_IO_FB_NA) {
   3.157 +			printf("\t\tB_IO_FB_NA\n");
   3.158 +		}
   3.159 +	}
   3.160 +	printf("\tTiming:\n");
   3.161 +	printf("\t\tpx clock: %i\n", bmode->timing.pixel_clock);
   3.162 +	printf("\t\th - display: %i sync start: %i sync end: %i total: %i\n",
   3.163 +		bmode->timing.h_display, bmode->timing.h_sync_start,
   3.164 +		bmode->timing.h_sync_end, bmode->timing.h_total);
   3.165 +	printf("\t\tv - display: %i sync start: %i sync end: %i total: %i\n",
   3.166 +		bmode->timing.v_display, bmode->timing.v_sync_start,
   3.167 +		bmode->timing.v_sync_end, bmode->timing.v_total);
   3.168 +	if(bmode->timing.flags) {
   3.169 +		printf("\t\tFlags:\n");
   3.170 +		if(bmode->timing.flags & B_BLANK_PEDESTAL) {
   3.171 +			printf("\t\t\tB_BLANK_PEDESTAL\n");
   3.172 +		}
   3.173 +		if(bmode->timing.flags & B_TIMING_INTERLACED) {
   3.174 +			printf("\t\t\tB_TIMING_INTERLACED\n");
   3.175 +		}
   3.176 +		if(bmode->timing.flags & B_POSITIVE_HSYNC) {
   3.177 +			printf("\t\t\tB_POSITIVE_HSYNC\n");
   3.178 +		}
   3.179 +		if(bmode->timing.flags & B_POSITIVE_VSYNC) {
   3.180 +			printf("\t\t\tB_POSITIVE_VSYNC\n");
   3.181 +		}
   3.182 +		if(bmode->timing.flags & B_SYNC_ON_GREEN) {
   3.183 +			printf("\t\t\tB_SYNC_ON_GREEN\n");
   3.184 +		}
   3.185 +	}
   3.186 +}
   3.187 +
   3.188  int BE_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode){
   3.189  	/* Get the current screen */
   3.190 +printf(__FILE__": %d\n", __LINE__);
   3.191  	BScreen bscreen;
   3.192  	if(!bscreen.IsValid()) {
   3.193  		printf(__FILE__": %d - ERROR: BAD SCREEN\n", __LINE__);
   3.194 @@ -216,31 +374,39 @@
   3.195  	/* Set the mode using the driver data */
   3.196  	display_mode *bmode = _ExtractBMode(mode);
   3.197  
   3.198 -	status_t s;
   3.199 -	if((s = bscreen.SetMode(bmode)) == B_OK) {
   3.200 -		return 0;	/* No error */
   3.201 +
   3.202 +_SpoutModeData(bmode);
   3.203 +printf("\n");
   3.204 +uint32 c = 0, i, x = 0;
   3.205 +#define RES 0
   3.206 +display_mode *bmode_list;
   3.207 +bscreen.GetModeList(&bmode_list, &c);
   3.208 +for(i = 0; i < c; ++i) {
   3.209 +	if(	bmode_list[i].space == bmode->space &&
   3.210 +		bmode_list[i].virtual_width == bmode->virtual_width &&
   3.211 +		bmode_list[i].virtual_height == bmode->virtual_height ) {
   3.212 +			if(x == RES)
   3.213 +				bmode = &bmode_list[i];
   3.214 +			
   3.215 +			++x;
   3.216 +			_SpoutModeData(&bmode_list[i]);
   3.217 +//			break;
   3.218  	}
   3.219 -printf(__FILE__": %d - ERROR: FAILED TO CHANGE VIDEO MODE; s = %i, status = B_BAD_VALUE? %i\n", __LINE__, s, s == B_BAD_VALUE);
   3.220 -	display_mode *bmode_list;
   3.221 -	uint32 count;
   3.222 -	bscreen.GetModeList(&bmode_list, &count);
   3.223 -	s = bscreen.ProposeMode(bmode, &bmode_list[count - 1], &bmode_list[0]);
   3.224 -	switch(s) {
   3.225 -	case B_OK:
   3.226 -		printf(__FILE__": %d - B_OK\n", __LINE__);
   3.227 -		break;
   3.228 -	case B_BAD_VALUE:
   3.229 -		printf(__FILE__": %d - B_BAD_VALUE\n", __LINE__);
   3.230 -		break;
   3.231 -	case B_ERROR:
   3.232 -		printf(__FILE__": %d - B_ERROR\n", __LINE__);
   3.233 -		break;
   3.234 -	default:
   3.235 -		printf(__FILE__": %d - (unknown error code)\n", __LINE__);
   3.236 -		break;
   3.237 +}
   3.238 +
   3.239 +	if(bscreen.SetMode(bmode) != B_OK) {
   3.240 +		SDL_SetError("Bad video mode\n");
   3.241 +		return -1;
   3.242  	}
   3.243 -	free(bmode_list);
   3.244 -	return -1;
   3.245 +free(bmode_list);
   3.246 +	
   3.247 +#if SDL_VIDEO_OPENGL
   3.248 +	/* The OpenGL context may need to be rebooted */
   3.249 +//	BE_GL_RebootContexts(_this);
   3.250 +#endif
   3.251 +
   3.252 +printf(__FILE__": %d\n", __LINE__);
   3.253 +	return 0;
   3.254  }
   3.255  
   3.256  #ifdef __cplusplus
     4.1 --- a/src/video/bwindow/SDL_bopengl.cc	Wed Aug 17 13:31:18 2011 +0000
     4.2 +++ b/src/video/bwindow/SDL_bopengl.cc	Sat Aug 20 15:16:13 2011 +0000
     4.3 @@ -31,6 +31,9 @@
     4.4  extern "C" {
     4.5  #endif
     4.6  
     4.7 +
     4.8 +#define BGL_FLAGS BGL_RGB | BGL_DOUBLE
     4.9 +
    4.10  static inline SDL_BWin *_ToBeWin(SDL_Window *window) {
    4.11  	return ((SDL_BWin*)(window->driverdata));
    4.12  }
    4.13 @@ -152,12 +155,13 @@
    4.14  	/* FIXME: Not sure what flags should be included here; may want to have
    4.15  	   most of them */
    4.16  	SDL_BWin *bwin = _ToBeWin(window);
    4.17 -	bwin->CreateGLView(BGL_RGB | BGL_DOUBLE);
    4.18 +	bwin->CreateGLView(BGL_FLAGS);
    4.19  	return (SDL_GLContext)(bwin);
    4.20  }
    4.21  
    4.22  void BE_GL_DeleteContext(_THIS, SDL_GLContext context) {
    4.23  	/* Currently, automatically unlocks the view */
    4.24 +printf(__FILE__": %d\n", __LINE__);
    4.25  	((SDL_BWin*)context)->RemoveGLView();
    4.26  }
    4.27  
    4.28 @@ -179,7 +183,19 @@
    4.29  
    4.30  
    4.31  
    4.32 -
    4.33 +void BE_GL_RebootContexts(_THIS) {
    4.34 +	SDL_Window *window = _this->windows;
    4.35 +	while(window) {
    4.36 +		SDL_BWin *bwin = _ToBeWin(window);
    4.37 +		if(bwin->GetGLView()) {
    4.38 +			bwin->LockLooper();
    4.39 +			bwin->RemoveGLView();
    4.40 +			bwin->CreateGLView(BGL_FLAGS);
    4.41 +			bwin->UnlockLooper();
    4.42 +		}
    4.43 +		window = window->next;
    4.44 +	}
    4.45 +}
    4.46  
    4.47  
    4.48  #if 0 /* Functions from 1.2 that do not appear to be used in 1.3 */
     5.1 --- a/src/video/bwindow/SDL_bopengl.h	Wed Aug 17 13:31:18 2011 +0000
     5.2 +++ b/src/video/bwindow/SDL_bopengl.h	Sat Aug 20 15:16:13 2011 +0000
     5.3 @@ -32,7 +32,6 @@
     5.4  extern int BE_GL_LoadLibrary(_THIS, const char *path);					//FIXME
     5.5  extern void *BE_GL_GetProcAddress(_THIS, const char *proc);				//FIXME
     5.6  extern void BE_GL_UnloadLibrary(_THIS);									//TODO
     5.7 -//extern int BE_GL_SetupWindow(_THIS, SDL_Window * window);				//TODO
     5.8  extern int BE_GL_MakeCurrent(_THIS, SDL_Window * window,
     5.9                                SDL_GLContext context);
    5.10  extern int BE_GL_SetSwapInterval(_THIS, int interval);					//TODO
    5.11 @@ -41,7 +40,7 @@
    5.12  extern SDL_GLContext BE_GL_CreateContext(_THIS, SDL_Window * window);
    5.13  extern void BE_GL_DeleteContext(_THIS, SDL_GLContext context);
    5.14  
    5.15 -
    5.16 +extern void BE_GL_RebootContexts(_THIS);
    5.17  
    5.18  #ifdef __cplusplus
    5.19  }
     6.1 --- a/src/video/bwindow/SDL_bwindow.cc	Wed Aug 17 13:31:18 2011 +0000
     6.2 +++ b/src/video/bwindow/SDL_bwindow.cc	Sat Aug 20 15:16:13 2011 +0000
     6.3 @@ -71,7 +71,6 @@
     6.4  	if(_InitWindow(_this, window) == ENOMEM)
     6.5  		return ENOMEM;
     6.6  	
     6.7 -	printf("Flags = 0x%x\n", window->flags);
     6.8  	/* Start window loop */
     6.9      _ToBeWin(window)->Show();
    6.10      return 0;