Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Update GL windows to support multiple resolutions as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnicholl committed May 15, 2012
1 parent 9d7e685 commit a9505b6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 51 deletions.
21 changes: 2 additions & 19 deletions src/video/playbook/SDL_playbookvideo.c
Expand Up @@ -68,23 +68,6 @@
#include <stdio.h>
#include <math.h>

/*
* The following will make major differences in how the content is laid out on the screen.
* Most of these have only really been tested with the 1024x600 PlayBook screen.
*
* __STRETCHED__ will stretch arbitrary resolutions onto the full screen, distorting if needed.
* __STRETCH_PRESERVE_ASPECT__ will stretch uniformly until one dimension is the screen dimension,
* and letterbox with black in the other dimension.
* __NOSCALE__ will center a window of the correct resolution in the middle of the full screen.
*
* __STRETCH_PRESERVE_ASPECT__ is the default.
* You should leave only one of these options uncommented.
*/

#define __STRETCH_PRESERVE_ASPECT__ 1
//#define __STRETCHED__ 1
//#define __NOSCALE__ 1

#define PLAYBOOKVID_DRIVER_NAME "playbook"

static int PLAYBOOK_Available(void)
Expand Down Expand Up @@ -517,7 +500,7 @@ screen_window_t PLAYBOOK_CreateWindow(_THIS, SDL_Surface *current,
return screenWindow;
}

static int SetupStretch(_THIS, screen_window_t screenWindow, int width, int height)
int PLAYBOOK_SetupStretch(_THIS, screen_window_t screenWindow, int width, int height)
{
int hwResolution[2];

Expand Down Expand Up @@ -599,7 +582,7 @@ SDL_Surface *PLAYBOOK_SetVideoMode(_THIS, SDL_Surface *current,
int rc;
int format = 0;

rc = SetupStretch(this, screenWindow, width, height);
rc = PLAYBOOK_SetupStretch(this, screenWindow, width, height);
if (rc) {
screen_destroy_window(screenWindow);
return NULL;
Expand Down
20 changes: 20 additions & 0 deletions src/video/playbook/SDL_playbookvideo_c.h
Expand Up @@ -14,6 +14,26 @@
#include "SDL_playbookvideo.h"
#include <screen/screen.h>

/*
* The following will make major differences in how the content is laid out on the screen.
* Most of these have only really been tested with the 1024x600 PlayBook screen.
*
* __STRETCHED__ will stretch arbitrary resolutions onto the full screen, distorting if needed.
* __STRETCH_PRESERVE_ASPECT__ will stretch uniformly until one dimension is the screen dimension,
* and letterbox with black in the other dimension.
* __NOSCALE__ will center a window of the correct resolution in the middle of the full screen.
*
* __STRETCH_PRESERVE_ASPECT__ is the default.
* You should leave only one of these options uncommented.
*/

#define __STRETCH_PRESERVE_ASPECT__ 1
//#define __STRETCHED__ 1
//#define __NOSCALE__ 1

/* Function to handle the stretch options above */
extern int PLAYBOOK_SetupStretch(_THIS, screen_window_t screenWindow, int width, int height);

/* Initialization/Query functions */
extern int PLAYBOOK_VideoInit(_THIS, SDL_PixelFormat *vformat);
extern SDL_Rect **PLAYBOOK_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags);
Expand Down
72 changes: 40 additions & 32 deletions src/video/playbook/SDL_playbookvideo_gl.c
Expand Up @@ -74,25 +74,44 @@ SDL_Surface *PLAYBOOK_SetVideoMode_GL(_THIS, SDL_Surface *current,
EGLint configCount;
screen_window_t screenWindow;
int format = SCREEN_FORMAT_RGBX8888;
int sizeOfWindow[2] = {1024, 600};
int sizeOfWindow[2] = {1024, 600}; // set a sane default
int sizeOfBuffer[2] = {width, height};
int usage = SCREEN_USAGE_OPENGL_ES1;
EGLint eglSurfaceAttributes[3] = { EGL_RENDER_BUFFER, EGL_BACK_BUFFER, EGL_NONE };

if (_priv->screenWindow) {
fprintf(stderr, "OpenGL window already created... this WILL fail\n"); // FIXME
}

_priv->eglInfo.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (_priv->eglInfo.eglDisplay == EGL_NO_DISPLAY) {
egl_perror("eglGetDisplay");
rc = screen_get_window_property_iv(_priv->mainWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow);
if (rc) {
SDL_SetError("Cannot get resolution: %s", strerror(errno));
goto error1;
}

rc = eglInitialize(_priv->eglInfo.eglDisplay, NULL, NULL);
if (rc != EGL_TRUE) {
egl_perror("eglInitialize");
goto error1;
if (_priv->screenWindow) {
rc = eglMakeCurrent(_priv->eglInfo.eglDisplay, 0, 0, 0);
if (rc != EGL_TRUE) {
egl_perror("eglMakeNoneCurrent");
goto error1;
}
rc = eglDestroySurface(_priv->eglInfo.eglDisplay, _priv->eglInfo.eglSurface);
if (rc != EGL_TRUE) {
egl_perror("eglDestroySurface");
goto error1;
}

_priv->eglInfo.eglSurface = 0;
}

if (!_priv->eglInfo.eglDisplay) {
_priv->eglInfo.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (_priv->eglInfo.eglDisplay == EGL_NO_DISPLAY) {
egl_perror("eglGetDisplay");
goto error1;
}

rc = eglInitialize(_priv->eglInfo.eglDisplay, NULL, NULL);
if (rc != EGL_TRUE) {
egl_perror("eglInitialize");
goto error1;
}
}

rc = eglBindAPI(EGL_OPENGL_ES_API);
Expand All @@ -103,38 +122,27 @@ SDL_Surface *PLAYBOOK_SetVideoMode_GL(_THIS, SDL_Surface *current,

rc = eglChooseConfig(_priv->eglInfo.eglDisplay, attributes, configs, 1, &configCount);
if (rc != EGL_TRUE) {
egl_perror("eglBindAPI");
eglTerminate(_priv->eglInfo.eglDisplay);
return NULL;
egl_perror("eglChooseConfig");
goto error2;
} else if (configCount <= 0) {
fprintf(stderr, "No matching configurations found.");
goto error2;
}

_priv->eglInfo.eglContext = eglCreateContext(_priv->eglInfo.eglDisplay, configs[0], EGL_NO_CONTEXT, contextAttributes);
if (_priv->eglInfo.eglContext == EGL_NO_CONTEXT) {
egl_perror("eglCreateContext");
goto error2;
if (!_priv->eglInfo.eglContext) {
_priv->eglInfo.eglContext = eglCreateContext(_priv->eglInfo.eglDisplay, configs[0], EGL_NO_CONTEXT, contextAttributes);
if (_priv->eglInfo.eglContext == EGL_NO_CONTEXT) {
egl_perror("eglCreateContext");
goto error2;
}
}

screenWindow = PLAYBOOK_CreateWindow(this, current, width, height, bpp);
if (screenWindow == NULL) {
goto error3;
}

rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_SIZE, sizeOfWindow);
if (rc) {
SDL_SetError("Cannot resize window: %s", strerror(errno));
screen_destroy_window(screenWindow);
return NULL;
}

// rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_BUFFER_SIZE, sizeOfBuffer);
// if (rc) {
// SDL_SetError("Cannot resize window buffer: %s", strerror(errno));
// screen_destroy_window(screenWindow);
// return NULL;
// }
rc = PLAYBOOK_SetupStretch(this, screenWindow, width, height);

rc = screen_set_window_property_iv(screenWindow, SCREEN_PROPERTY_FORMAT, &format);
if (rc) {
Expand Down

0 comments on commit a9505b6

Please sign in to comment.