Skip to content
This repository
Browse code

Update GL windows to support multiple resolutions as well.

  • Loading branch information...
commit a9505b60de6e6894921992dee49630333ba4b5cd 1 parent 9d7e685
Jeremy Nicholl authored May 15, 2012
21  src/video/playbook/SDL_playbookvideo.c
@@ -68,23 +68,6 @@
68 68
 #include <stdio.h>
69 69
 #include <math.h>
70 70
 
71  
-/*
72  
- * The following will make major differences in how the content is laid out on the screen.
73  
- * Most of these have only really been tested with the 1024x600 PlayBook screen.
74  
- *
75  
- * __STRETCHED__ will stretch arbitrary resolutions onto the full screen, distorting if needed.
76  
- * __STRETCH_PRESERVE_ASPECT__ will stretch uniformly until one dimension is the screen dimension,
77  
- *    and letterbox with black in the other dimension.
78  
- * __NOSCALE__ will center a window of the correct resolution in the middle of the full screen.
79  
- *
80  
- * __STRETCH_PRESERVE_ASPECT__ is the default.
81  
- * You should leave only one of these options uncommented.
82  
- */
83  
-
84  
-#define __STRETCH_PRESERVE_ASPECT__ 1
85  
-//#define __STRETCHED__ 1
86  
-//#define __NOSCALE__ 1
87  
-
88 71
 #define PLAYBOOKVID_DRIVER_NAME "playbook"
89 72
 
90 73
 static int PLAYBOOK_Available(void)
@@ -517,7 +500,7 @@ screen_window_t PLAYBOOK_CreateWindow(_THIS, SDL_Surface *current,
517 500
 	return screenWindow;
518 501
 }
519 502
 
520  
-static int SetupStretch(_THIS, screen_window_t screenWindow, int width, int height)
  503
+int PLAYBOOK_SetupStretch(_THIS, screen_window_t screenWindow, int width, int height)
521 504
 {
522 505
 	int hwResolution[2];
523 506
 
@@ -599,7 +582,7 @@ SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
599 582
 	int rc;
600 583
 	int format = 0;
601 584
 
602  
-	rc = SetupStretch(this, screenWindow, width, height);
  585
+	rc = PLAYBOOK_SetupStretch(this, screenWindow, width, height);
603 586
 	if (rc) {
604 587
 		screen_destroy_window(screenWindow);
605 588
 		return NULL;
20  src/video/playbook/SDL_playbookvideo_c.h
@@ -14,6 +14,26 @@
14 14
 #include "SDL_playbookvideo.h"
15 15
 #include <screen/screen.h>
16 16
 
  17
+/*
  18
+ * The following will make major differences in how the content is laid out on the screen.
  19
+ * Most of these have only really been tested with the 1024x600 PlayBook screen.
  20
+ *
  21
+ * __STRETCHED__ will stretch arbitrary resolutions onto the full screen, distorting if needed.
  22
+ * __STRETCH_PRESERVE_ASPECT__ will stretch uniformly until one dimension is the screen dimension,
  23
+ *    and letterbox with black in the other dimension.
  24
+ * __NOSCALE__ will center a window of the correct resolution in the middle of the full screen.
  25
+ *
  26
+ * __STRETCH_PRESERVE_ASPECT__ is the default.
  27
+ * You should leave only one of these options uncommented.
  28
+ */
  29
+
  30
+#define __STRETCH_PRESERVE_ASPECT__ 1
  31
+//#define __STRETCHED__ 1
  32
+//#define __NOSCALE__ 1
  33
+
  34
+/* Function to handle the stretch options above */
  35
+extern int PLAYBOOK_SetupStretch(_THIS, screen_window_t screenWindow, int width, int height);
  36
+
17 37
 /* Initialization/Query functions */
18 38
 extern int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat);
19 39
 extern SDL_Rect **PLAYBOOK_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
72  src/video/playbook/SDL_playbookvideo_gl.c
@@ -74,25 +74,44 @@ SDL_Surface *PLAYBOOK_SetVideoMode_GL(_THIS, SDL_Surface *current,
74 74
 	EGLint configCount;
75 75
 	screen_window_t screenWindow;
76 76
 	int format = SCREEN_FORMAT_RGBX8888;
77  
-	int sizeOfWindow[2] = {1024, 600};
  77
+	int sizeOfWindow[2] = {1024, 600}; // set a sane default
78 78
 	int sizeOfBuffer[2] = {width, height};
79 79
 	int usage = SCREEN_USAGE_OPENGL_ES1;
80 80
 	EGLint eglSurfaceAttributes[3] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };
81 81
 
82  
-	if (_priv->screenWindow) {
83  
-		fprintf(stderr, "OpenGL window already created... this WILL fail\n"); // FIXME
84  
-	}
85  
-
86  
-	_priv->eglInfo.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
87  
-	if (_priv->eglInfo.eglDisplay == EGL_NO_DISPLAY) {
88  
-		egl_perror("eglGetDisplay");
  82
+	rc = screen_get_window_property_iv(_priv->mainWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow);
  83
+	if (rc) {
  84
+		SDL_SetError("Cannot get resolution: %s", strerror(errno));
89 85
 		goto error1;
90 86
 	}
91 87
 
92  
-	rc = eglInitialize(_priv->eglInfo.eglDisplay, NULL, NULL);
93  
-	if (rc != EGL_TRUE) {
94  
-		egl_perror("eglInitialize");
95  
-		goto error1;
  88
+	if (_priv->screenWindow) {
  89
+		rc = eglMakeCurrent(_priv->eglInfo.eglDisplay, 0, 0, 0);
  90
+		if (rc != EGL_TRUE) {
  91
+			egl_perror("eglMakeNoneCurrent");
  92
+			goto error1;
  93
+		}
  94
+		rc = eglDestroySurface(_priv->eglInfo.eglDisplay, _priv->eglInfo.eglSurface);
  95
+		if (rc != EGL_TRUE) {
  96
+			egl_perror("eglDestroySurface");
  97
+			goto error1;
  98
+		}
  99
+
  100
+		_priv->eglInfo.eglSurface = 0;
  101
+	}
  102
+
  103
+	if (!_priv->eglInfo.eglDisplay) {
  104
+		_priv->eglInfo.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
  105
+		if (_priv->eglInfo.eglDisplay == EGL_NO_DISPLAY) {
  106
+			egl_perror("eglGetDisplay");
  107
+			goto error1;
  108
+		}
  109
+
  110
+		rc = eglInitialize(_priv->eglInfo.eglDisplay, NULL, NULL);
  111
+		if (rc != EGL_TRUE) {
  112
+			egl_perror("eglInitialize");
  113
+			goto error1;
  114
+		}
96 115
 	}
97 116
 
98 117
 	rc = eglBindAPI(EGL_OPENGL_ES_API);
@@ -103,18 +122,19 @@ SDL_Surface *PLAYBOOK_SetVideoMode_GL(_THIS, SDL_Surface *current,
103 122
 
104 123
 	rc = eglChooseConfig(_priv->eglInfo.eglDisplay, attributes, configs, 1, &configCount);
105 124
 	if (rc != EGL_TRUE)	{
106  
-		egl_perror("eglBindAPI");
107  
-		eglTerminate(_priv->eglInfo.eglDisplay);
108  
-		return NULL;
  125
+		egl_perror("eglChooseConfig");
  126
+		goto error2;
109 127
 	} else if (configCount <= 0)	{
110 128
 		fprintf(stderr, "No matching configurations found.");
111 129
 		goto error2;
112 130
 	}
113 131
 
114  
-	_priv->eglInfo.eglContext = eglCreateContext(_priv->eglInfo.eglDisplay, configs[0], EGL_NO_CONTEXT, contextAttributes);
115  
-	if (_priv->eglInfo.eglContext == EGL_NO_CONTEXT)	{
116  
-		egl_perror("eglCreateContext");
117  
-		goto error2;
  132
+	if (!_priv->eglInfo.eglContext) {
  133
+		_priv->eglInfo.eglContext = eglCreateContext(_priv->eglInfo.eglDisplay, configs[0], EGL_NO_CONTEXT, contextAttributes);
  134
+		if (_priv->eglInfo.eglContext == EGL_NO_CONTEXT)	{
  135
+			egl_perror("eglCreateContext");
  136
+			goto error2;
  137
+		}
118 138
 	}
119 139
 
120 140
 	screenWindow = PLAYBOOK_CreateWindow(this, current, width, height, bpp);
@@ -122,19 +142,7 @@ SDL_Surface *PLAYBOOK_SetVideoMode_GL(_THIS, SDL_Surface *current,
122 142
 		goto error3;
123 143
 	}
124 144
 
125  
-	rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow);
126  
-	if (rc) {
127  
-		SDL_SetError("Cannot resize window: %s", strerror(errno));
128  
-		screen_destroy_window(screenWindow);
129  
-		return NULL;
130  
-	}
131  
-
132  
-//		rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer);
133  
-//		if (rc) {
134  
-//			SDL_SetError("Cannot resize window buffer: %s", strerror(errno));
135  
-//			screen_destroy_window(screenWindow);
136  
-//			return NULL;
137  
-//		}
  145
+	rc = PLAYBOOK_SetupStretch(this, screenWindow, width, height);
138 146
 
139 147
 	rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_FORMAT, &format);
140 148
 	if (rc) {

0 notes on commit a9505b6

Please sign in to comment.
Something went wrong with that request. Please try again.