Commit 483f2ba3 authored by Sam Lantinga's avatar Sam Lantinga

indent

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403608
parent 3071101f
...@@ -174,7 +174,8 @@ void ...@@ -174,7 +174,8 @@ void
drawBlank(int x, int y) drawBlank(int x, int y)
{ {
SDL_Rect rect = { x, y, GLYPH_SIZE_SCREEN, GLYPH_SIZE_SCREEN }; SDL_Rect rect = { x, y, GLYPH_SIZE_SCREEN, GLYPH_SIZE_SCREEN };
SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b, bg_color.unused); SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
bg_color.unused);
SDL_RenderFill(&rect); SDL_RenderFill(&rect);
} }
...@@ -254,7 +255,8 @@ main(int argc, char *argv[]) ...@@ -254,7 +255,8 @@ main(int argc, char *argv[])
loadFont(); loadFont();
/* draw the background, we'll just paint over it */ /* draw the background, we'll just paint over it */
SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b, bg_color.unused); SDL_SetRenderDrawColor(bg_color.r, bg_color.g, bg_color.b,
bg_color.unused);
SDL_RenderFill(NULL); SDL_RenderFill(NULL);
SDL_RenderPresent(); SDL_RenderPresent();
......
...@@ -973,7 +973,8 @@ extern "C" ...@@ -973,7 +973,8 @@ extern "C"
/* GL_OES_query_matrix */ /* GL_OES_query_matrix */
#ifndef GL_OES_query_matrix #ifndef GL_OES_query_matrix
#define GL_OES_query_matrix 1 #define GL_OES_query_matrix 1
GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16], GLint exponent[16]); GL_API GLbitfield GL_APIENTRY glQueryMatrixxOES(GLfixed mantissa[16],
GLint exponent[16]);
#endif /* GL_OES_query_matrix */ #endif /* GL_OES_query_matrix */
/* GL_OES_point_sprite */ /* GL_OES_point_sprite */
...@@ -984,25 +985,34 @@ extern "C" ...@@ -984,25 +985,34 @@ extern "C"
/* GL_OES_draw_texture */ /* GL_OES_draw_texture */
#ifndef GL_OES_draw_texture #ifndef GL_OES_draw_texture
#define GL_OES_draw_texture 1 #define GL_OES_draw_texture 1
GL_API void GL_APIENTRY glDrawTexsOES (GLshort x, GLshort y, GLshort z, GLshort width, GLshort height); GL_API void GL_APIENTRY glDrawTexsOES(GLshort x, GLshort y, GLshort z,
GL_API void GL_APIENTRY glDrawTexiOES (GLint x, GLint y, GLint z, GLint width, GLint height); GLshort width, GLshort height);
GL_API void GL_APIENTRY glDrawTexxOES (GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height); GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z,
GL_API void GL_APIENTRY glDrawTexsvOES (const GLshort *coords); GLint width, GLint height);
GL_API void GL_APIENTRY glDrawTexivOES (const GLint *coords); GL_API void GL_APIENTRY glDrawTexxOES(GLfixed x, GLfixed y, GLfixed z,
GL_API void GL_APIENTRY glDrawTexxvOES (const GLfixed *coords); GLfixed width, GLfixed height);
GL_API void GL_APIENTRY glDrawTexfOES (GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height); GL_API void GL_APIENTRY glDrawTexsvOES(const GLshort * coords);
GL_API void GL_APIENTRY glDrawTexfvOES (const GLfloat *coords); GL_API void GL_APIENTRY glDrawTexivOES(const GLint * coords);
GL_API void GL_APIENTRY glDrawTexxvOES(const GLfixed * coords);
GL_API void GL_APIENTRY glDrawTexfOES(GLfloat x, GLfloat y, GLfloat z,
GLfloat width, GLfloat height);
GL_API void GL_APIENTRY glDrawTexfvOES(const GLfloat * coords);
#endif /* GL_OES_draw_texture */ #endif /* GL_OES_draw_texture */
/* GL_OES_single_precision */ /* GL_OES_single_precision */
#ifndef GL_OES_single_precision #ifndef GL_OES_single_precision
#define GL_OES_single_precision 1 #define GL_OES_single_precision 1
GL_API void GL_APIENTRY glDepthRangefOES (GLclampf zNear, GLclampf zFar); GL_API void GL_APIENTRY glDepthRangefOES(GLclampf zNear, GLclampf zFar);
GL_API void GL_APIENTRY glFrustumfOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); GL_API void GL_APIENTRY glFrustumfOES(GLfloat left, GLfloat right,
GL_API void GL_APIENTRY glOrthofOES (GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar); GLfloat bottom, GLfloat top,
GL_API void GL_APIENTRY glClipPlanefOES (GLenum plane, const GLfloat *equation); GLfloat zNear, GLfloat zFar);
GL_API void GL_APIENTRY glGetClipPlanefOES (GLenum pname, GLfloat eqn[4]); GL_API void GL_APIENTRY glOrthofOES(GLfloat left, GLfloat right,
GL_API void GL_APIENTRY glClearDepthfOES (GLclampf depth); GLfloat bottom, GLfloat top,
GLfloat zNear, GLfloat zFar);
GL_API void GL_APIENTRY glClipPlanefOES(GLenum plane,
const GLfloat * equation);
GL_API void GL_APIENTRY glGetClipPlanefOES(GLenum pname, GLfloat eqn[4]);
GL_API void GL_APIENTRY glClearDepthfOES(GLclampf depth);
#endif /* GL_OES_single_precision */ #endif /* GL_OES_single_precision */
/* GL_OES_vertex_buffer_object */ /* GL_OES_vertex_buffer_object */
...@@ -1012,8 +1022,10 @@ extern "C" ...@@ -1012,8 +1022,10 @@ extern "C"
GL_API void APIENTRY glDeleteBuffersOES(GLsizei, const GLuint *); GL_API void APIENTRY glDeleteBuffersOES(GLsizei, const GLuint *);
GL_API void APIENTRY glGenBuffersOES(GLsizei, GLuint *); GL_API void APIENTRY glGenBuffersOES(GLsizei, GLuint *);
GL_API GLboolean APIENTRY glIsBufferOES(GLuint); GL_API GLboolean APIENTRY glIsBufferOES(GLuint);
GL_API void APIENTRY glBufferDataOES(GLenum, GLsizeiptr, const GLvoid *, GLenum); GL_API void APIENTRY glBufferDataOES(GLenum, GLsizeiptr, const GLvoid *,
GL_API void APIENTRY glBufferSubDataOES(GLenum, GLintptr, GLsizeiptr, const GLvoid *); GLenum);
GL_API void APIENTRY glBufferSubDataOES(GLenum, GLintptr, GLsizeiptr,
const GLvoid *);
GL_API void APIENTRY glGetBufferParameterivOES(GLenum, GLenum, GLint *); GL_API void APIENTRY glGetBufferParameterivOES(GLenum, GLenum, GLint *);
#endif /* GL_OES_vertex_buffer_object */ #endif /* GL_OES_vertex_buffer_object */
......
...@@ -477,7 +477,8 @@ SDL_RunAudio(void *devicep) ...@@ -477,7 +477,8 @@ SDL_RunAudio(void *devicep)
/* Wait for an audio buffer to become available */ /* Wait for an audio buffer to become available */
current_audio.impl.WaitDevice(device); current_audio.impl.WaitDevice(device);
} else { } else {
SDL_Delay((device->spec.samples * 1000) / device->spec.freq); SDL_Delay((device->spec.samples * 1000) /
device->spec.freq);
} }
} }
......
...@@ -59,15 +59,14 @@ ...@@ -59,15 +59,14 @@
struct BuggyCards struct BuggyCards
{ {
char* cardname; char *cardname;
unsigned long bugtype; unsigned long bugtype;
}; };
#define QSA_WA_CARDS 3 #define QSA_WA_CARDS 3
#define QSA_MAX_CARD_NAME_LENGTH 33 #define QSA_MAX_CARD_NAME_LENGTH 33
struct BuggyCards buggycards[QSA_WA_CARDS]= struct BuggyCards buggycards[QSA_WA_CARDS] = {
{
{"Sound Blaster Live!", QSA_MMAP_WORKAROUND}, {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
{"Vortex 8820", QSA_MMAP_WORKAROUND}, {"Vortex 8820", QSA_MMAP_WORKAROUND},
{"Vortex 8830", QSA_MMAP_WORKAROUND}, {"Vortex 8830", QSA_MMAP_WORKAROUND},
...@@ -90,28 +89,27 @@ uint32_t qsa_playback_devices; ...@@ -90,28 +89,27 @@ uint32_t qsa_playback_devices;
QSA_Device qsa_capture_device[QSA_MAX_DEVICES]; QSA_Device qsa_capture_device[QSA_MAX_DEVICES];
uint32_t qsa_capture_devices; uint32_t qsa_capture_devices;
static inline void QSA_SetError(const char* fn, int status) static inline void
QSA_SetError(const char *fn, int status)
{ {
SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status)); SDL_SetError("QSA: %s() failed: %s", fn, snd_strerror(status));
} }
/* card names check to apply the workarounds */ /* card names check to apply the workarounds */
static int QSA_CheckBuggyCards(_THIS, unsigned long checkfor) static int
QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
{ {
char scardname[QSA_MAX_CARD_NAME_LENGTH]; char scardname[QSA_MAX_CARD_NAME_LENGTH];
int it; int it;
if (snd_card_get_name(this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH-1)<0) if (snd_card_get_name
{ (this->hidden->cardno, scardname, QSA_MAX_CARD_NAME_LENGTH - 1) < 0) {
return 0; return 0;
} }
for (it=0; it<QSA_WA_CARDS; it++) for (it = 0; it < QSA_WA_CARDS; it++) {
{ if (SDL_strcmp(buggycards[it].cardname, scardname) == 0) {
if (SDL_strcmp(buggycards[it].cardname, scardname)==0) if (buggycards[it].bugtype == checkfor) {
{
if (buggycards[it].bugtype==checkfor)
{
return 1; return 1;
} }
} }
...@@ -120,50 +118,50 @@ static int QSA_CheckBuggyCards(_THIS, unsigned long checkfor) ...@@ -120,50 +118,50 @@ static int QSA_CheckBuggyCards(_THIS, unsigned long checkfor)
return 0; return 0;
} }
static void QSA_ThreadInit(_THIS) static void
QSA_ThreadInit(_THIS)
{ {
struct sched_param param; struct sched_param param;
int status; int status;
/* Increase default 10 priority to 25 to avoid jerky sound */ /* Increase default 10 priority to 25 to avoid jerky sound */
status=SchedGet(0, 0, &param); status = SchedGet(0, 0, &param);
param.sched_priority=param.sched_curpriority + 15; param.sched_priority = param.sched_curpriority + 15;
status=SchedSet(0, 0, SCHED_NOCHANGE, &param); status = SchedSet(0, 0, SCHED_NOCHANGE, &param);
} }
/* PCM channel parameters initialize function */ /* PCM channel parameters initialize function */
static void QSA_InitAudioParams(snd_pcm_channel_params_t* cpars) static void
QSA_InitAudioParams(snd_pcm_channel_params_t * cpars)
{ {
SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t)); SDL_memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
cpars->channel=SND_PCM_CHANNEL_PLAYBACK; cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
cpars->mode=SND_PCM_MODE_BLOCK; cpars->mode = SND_PCM_MODE_BLOCK;
cpars->start_mode=SND_PCM_START_DATA; cpars->start_mode = SND_PCM_START_DATA;
cpars->stop_mode=SND_PCM_STOP_STOP; cpars->stop_mode = SND_PCM_STOP_STOP;
cpars->format.format=SND_PCM_SFMT_S16_LE; cpars->format.format = SND_PCM_SFMT_S16_LE;
cpars->format.interleave=1; cpars->format.interleave = 1;
cpars->format.rate=DEFAULT_CPARAMS_RATE; cpars->format.rate = DEFAULT_CPARAMS_RATE;
cpars->format.voices=DEFAULT_CPARAMS_VOICES; cpars->format.voices = DEFAULT_CPARAMS_VOICES;
cpars->buf.block.frag_size=DEFAULT_CPARAMS_FRAG_SIZE; cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
cpars->buf.block.frags_min=DEFAULT_CPARAMS_FRAGS_MIN; cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
cpars->buf.block.frags_max=DEFAULT_CPARAMS_FRAGS_MAX; cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
} }
/* This function waits until it is possible to write a full sound buffer */ /* This function waits until it is possible to write a full sound buffer */
static void QSA_WaitDevice(_THIS) static void
QSA_WaitDevice(_THIS)
{ {
fd_set wfds; fd_set wfds;
fd_set rfds; fd_set rfds;
int selectret; int selectret;
struct timeval timeout; struct timeval timeout;
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{
FD_ZERO(&wfds); FD_ZERO(&wfds);
FD_SET(this->hidden->audio_fd, &wfds); FD_SET(this->hidden->audio_fd, &wfds);
} } else {
else
{
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(this->hidden->audio_fd, &rfds); FD_SET(this->hidden->audio_fd, &rfds);
} }
...@@ -173,21 +171,21 @@ static void QSA_WaitDevice(_THIS) ...@@ -173,21 +171,21 @@ static void QSA_WaitDevice(_THIS)
/* If timeout occured than something wrong with hardware or driver */ /* If timeout occured than something wrong with hardware or driver */
/* For example, Vortex 8820 audio driver stucks on second DAC because */ /* For example, Vortex 8820 audio driver stucks on second DAC because */
/* it doesn't exist ! */ /* it doesn't exist ! */
timeout.tv_sec=2; timeout.tv_sec = 2;
timeout.tv_usec=0; timeout.tv_usec = 0;
this->hidden->timeout_on_wait=0; this->hidden->timeout_on_wait = 0;
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ selectret =
selectret=select(this->hidden->audio_fd+1, NULL, &wfds, NULL, &timeout); select(this->hidden->audio_fd + 1, NULL, &wfds, NULL,
} &timeout);
else } else {
{ selectret =
selectret=select(this->hidden->audio_fd+1, &rfds, NULL, NULL, &timeout); select(this->hidden->audio_fd + 1, &rfds, NULL, NULL,
&timeout);
} }
switch(selectret) switch (selectret) {
{
case -1: case -1:
{ {
SDL_SetError("QSA: select() failed: %s\n", strerror(errno)); SDL_SetError("QSA: select() failed: %s\n", strerror(errno));
...@@ -197,23 +195,18 @@ static void QSA_WaitDevice(_THIS) ...@@ -197,23 +195,18 @@ static void QSA_WaitDevice(_THIS)
case 0: case 0:
{ {
SDL_SetError("QSA: timeout on buffer waiting occured\n"); SDL_SetError("QSA: timeout on buffer waiting occured\n");
this->hidden->timeout_on_wait=1; this->hidden->timeout_on_wait = 1;
return; return;
} }
break; break;
default: default:
{ {
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ if (FD_ISSET(this->hidden->audio_fd, &wfds)) {
if (FD_ISSET(this->hidden->audio_fd, &wfds))
{
return; return;
} }
} } else {
else if (FD_ISSET(this->hidden->audio_fd, &rfds)) {
{
if (FD_ISSET(this->hidden->audio_fd, &rfds))
{
return; return;
} }
} }
...@@ -223,16 +216,16 @@ static void QSA_WaitDevice(_THIS) ...@@ -223,16 +216,16 @@ static void QSA_WaitDevice(_THIS)
} while (1); } while (1);
} }
static void QSA_PlayDevice(_THIS) static void
QSA_PlayDevice(_THIS)
{ {
snd_pcm_channel_status_t cstatus; snd_pcm_channel_status_t cstatus;
int written; int written;
int status; int status;
int towrite; int towrite;
void* pcmbuffer; void *pcmbuffer;
if ((!this->enabled) || (!this->hidden)) if ((!this->enabled) || (!this->hidden)) {
{
return; return;
} }
...@@ -241,143 +234,132 @@ static void QSA_PlayDevice(_THIS) ...@@ -241,143 +234,132 @@ static void QSA_PlayDevice(_THIS)
/* Write the audio data, checking for EAGAIN (buffer full) and underrun */ /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
do { do {
written=snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer, towrite); written =
if (written!=towrite) snd_pcm_plugin_write(this->hidden->audio_handle, pcmbuffer,
{ towrite);
if (written != towrite) {
/* Check if samples playback got stuck somewhere in hardware or in */ /* Check if samples playback got stuck somewhere in hardware or in */
/* the audio device driver */ /* the audio device driver */
if ((errno==EAGAIN) && (written==0)) if ((errno == EAGAIN) && (written == 0)) {
{ if (this->hidden->timeout_on_wait != 0) {
if (this->hidden->timeout_on_wait!=0)
{
SDL_SetError("QSA: buffer playback timeout\n"); SDL_SetError("QSA: buffer playback timeout\n");
return; return;
} }
} }
/* Check for errors or conditions */ /* Check for errors or conditions */
if ((errno==EAGAIN)||(errno==EWOULDBLOCK)) if ((errno == EAGAIN) || (errno == EWOULDBLOCK)) {
{
/* Let a little CPU time go by and try to write again */ /* Let a little CPU time go by and try to write again */
SDL_Delay(1); SDL_Delay(1);
/* if we wrote some data */ /* if we wrote some data */
towrite-=written; towrite -= written;
pcmbuffer+=written*this->spec.channels; pcmbuffer += written * this->spec.channels;
continue; continue;
} } else {
else if ((errno == EINVAL) || (errno == EIO)) {
{
if ((errno==EINVAL)||(errno==EIO))
{
SDL_memset(&cstatus, 0, sizeof(cstatus)); SDL_memset(&cstatus, 0, sizeof(cstatus));
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
cstatus.channel=SND_PCM_CHANNEL_PLAYBACK; } else {
} cstatus.channel = SND_PCM_CHANNEL_CAPTURE;
else
{
cstatus.channel=SND_PCM_CHANNEL_CAPTURE;
} }
status=snd_pcm_plugin_status(this->hidden->audio_handle, &cstatus); status =
if (status<0) snd_pcm_plugin_status(this->hidden->audio_handle,
{ &cstatus);
if (status < 0) {
QSA_SetError("snd_pcm_plugin_status", status); QSA_SetError("snd_pcm_plugin_status", status);
return; return;
} }
if ((cstatus.status==SND_PCM_STATUS_UNDERRUN) || if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) ||
(cstatus.status==SND_PCM_STATUS_READY)) (cstatus.status == SND_PCM_STATUS_READY)) {
{ if (!this->hidden->iscapture) {
if (!this->hidden->iscapture) status =
{ snd_pcm_plugin_prepare(this->hidden->
status=snd_pcm_plugin_prepare(this->hidden->audio_handle, audio_handle,
SND_PCM_CHANNEL_PLAYBACK); SND_PCM_CHANNEL_PLAYBACK);
} } else {
else status =
{ snd_pcm_plugin_prepare(this->hidden->
status=snd_pcm_plugin_prepare(this->hidden->audio_handle, audio_handle,
SND_PCM_CHANNEL_CAPTURE); SND_PCM_CHANNEL_CAPTURE);
} }
if (status<0) if (status < 0) {
{
QSA_SetError("snd_pcm_plugin_prepare", status); QSA_SetError("snd_pcm_plugin_prepare", status);
return; return;
} }
} }
continue; continue;
} } else {
else
{
return; return;
} }
} }
} } else {
else
{
/* we wrote all remaining data */ /* we wrote all remaining data */
towrite -= written; towrite -= written;
pcmbuffer += written * this->spec.channels; pcmbuffer += written * this->spec.channels;
} }
} while ((towrite>0) && (this->enabled)); } while ((towrite > 0) && (this->enabled));
/* If we couldn't write, assume fatal error for now */ /* If we couldn't write, assume fatal error for now */
if (towrite!=0) if (towrite != 0) {
{ this->enabled = 0;
this->enabled=0;
} }
} }
static Uint8* QSA_GetDeviceBuf(_THIS) static Uint8 *
QSA_GetDeviceBuf(_THIS)
{ {
return this->hidden->pcm_buf; return this->hidden->pcm_buf;
} }
static void QSA_CloseDevice(_THIS) static void
QSA_CloseDevice(_THIS)
{ {
if (this->hidden!=NULL) if (this->hidden != NULL) {
{ if (this->hidden->audio_handle != NULL) {
if (this->hidden->audio_handle!=NULL) if (!this->hidden->iscapture) {
{
if (!this->hidden->iscapture)
{
/* Finish playing available samples */ /* Finish playing available samples */
snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK); snd_pcm_plugin_flush(this->hidden->audio_handle,
} SND_PCM_CHANNEL_PLAYBACK);
else } else {
{
/* Cancel unread samples during capture */ /* Cancel unread samples during capture */
snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE); snd_pcm_plugin_flush(this->hidden->audio_handle,
SND_PCM_CHANNEL_CAPTURE);
} }
snd_pcm_close(this->hidden->audio_handle); snd_pcm_close(this->hidden->audio_handle);
this->hidden->audio_handle=NULL; this->hidden->audio_handle = NULL;
} }
if (this->hidden->pcm_buf!=NULL) if (this->hidden->pcm_buf != NULL) {
{
SDL_FreeAudioMem(this->hidden->pcm_buf); SDL_FreeAudioMem(this->hidden->pcm_buf);
this->hidden->pcm_buf=NULL; this->hidden->pcm_buf = NULL;
} }
SDL_free(this->hidden); SDL_free(this->hidden);
this->hidden=NULL; this->hidden = NULL;
} }
} }
static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) static int
QSA_OpenDevice(_THIS, const char *devname, int iscapture)
{ {
int status=0; int status = 0;
int format=0; int format = 0;
SDL_AudioFormat test_format=0; SDL_AudioFormat test_format = 0;
int found=0; int found = 0;
snd_pcm_channel_setup_t csetup; snd_pcm_channel_setup_t csetup;
snd_pcm_channel_params_t cparams; snd_pcm_channel_params_t cparams;
/* Initialize all variables that we clean on shutdown */ /* Initialize all variables that we clean on shutdown */
this->hidden=(struct SDL_PrivateAudioData*)SDL_calloc(1, (sizeof(struct SDL_PrivateAudioData))); this->hidden =
if (this->hidden==NULL) (struct SDL_PrivateAudioData *) SDL_calloc(1,
{ (sizeof
(struct
SDL_PrivateAudioData)));
if (this->hidden == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return 0; return 0;
} }
...@@ -387,110 +369,100 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) ...@@ -387,110 +369,100 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
QSA_InitAudioParams(&cparams); QSA_InitAudioParams(&cparams);
/* Initialize channel direction: capture or playback */ /* Initialize channel direction: capture or playback */
this->hidden->iscapture=iscapture; this->hidden->iscapture = iscapture;
/* Find deviceid and cardid by device name for playback */ /* Find deviceid and cardid by device name for playback */
if ((!this->hidden->iscapture) && (devname!=NULL)) if ((!this->hidden->iscapture) && (devname != NULL)) {
{
uint32_t device; uint32_t device;
int32_t status; int32_t status;
/* Search in the playback devices */ /* Search in the playback devices */
device=0; device = 0;
do { do {
status=SDL_strcmp(qsa_playback_device[device].name, devname); status = SDL_strcmp(qsa_playback_device[device].name, devname);
if (status==0) if (status == 0) {
{
/* Found requested device */ /* Found requested device */
this->hidden->deviceno=qsa_playback_device[device].deviceno; this->hidden->deviceno = qsa_playback_device[device].deviceno;
this->hidden->cardno=qsa_playback_device[device].cardno; this->hidden->cardno = qsa_playback_device[device].cardno;
break; break;
} }
device++; device++;
if (device>=qsa_playback_devices) if (device >= qsa_playback_devices) {
{
QSA_CloseDevice(this); QSA_CloseDevice(this);
SDL_SetError("No such playback device"); SDL_SetError("No such playback device");
return 0; return 0;
} }
} while(1); } while (1);
} }
/* Find deviceid and cardid by device name for capture */ /* Find deviceid and cardid by device name for capture */
if ((this->hidden->iscapture) && (devname!=NULL)) if ((this->hidden->iscapture) && (devname != NULL)) {
{
/* Search in the capture devices */ /* Search in the capture devices */
uint32_t device; uint32_t device;
int32_t status; int32_t status;
/* Searching in the playback devices */ /* Searching in the playback devices */
device=0; device = 0;
do { do {
status=SDL_strcmp(qsa_capture_device[device].name, devname); status = SDL_strcmp(qsa_capture_device[device].name, devname);
if (status==0) if (status == 0) {
{
/* Found requested device */ /* Found requested device */
this->hidden->deviceno=qsa_capture_device[device].deviceno; this->hidden->deviceno = qsa_capture_device[device].deviceno;
this->hidden->cardno=qsa_capture_device[device].cardno; this->hidden->cardno = qsa_capture_device[device].cardno;
break; break;
} }
device++; device++;
if (device>=qsa_capture_devices) if (device >= qsa_capture_devices) {
{
QSA_CloseDevice(this); QSA_CloseDevice(this);
SDL_SetError("No such capture device"); SDL_SetError("No such capture device");
return 0; return 0;
} }
} while(1); } while (1);
} }
/* Check if SDL requested default audio device */ /* Check if SDL requested default audio device */
if (devname==NULL) if (devname == NULL) {
{
/* Open system default audio device */ /* Open system default audio device */
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ status = snd_pcm_open_preferred(&this->hidden->audio_handle,
status=snd_pcm_open_preferred(&this->hidden->audio_handle,
&this->hidden->cardno, &this->hidden->cardno,
&this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK); &this->hidden->deviceno,
} SND_PCM_OPEN_PLAYBACK);
else } else {
{ status = snd_pcm_open_preferred(&this->hidden->audio_handle,
status=snd_pcm_open_preferred(&this->hidden->audio_handle,
&this->hidden->cardno, &this->hidden->cardno,
&this->hidden->deviceno, SND_PCM_OPEN_CAPTURE); &this->hidden->deviceno,
SND_PCM_OPEN_CAPTURE);
} }
} } else {
else
{
/* Open requested audio device */ /* Open requested audio device */
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ status =
status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno, snd_pcm_open(&this->hidden->audio_handle,
this->hidden->deviceno, SND_PCM_OPEN_PLAYBACK); this->hidden->cardno, this->hidden->deviceno,
} SND_PCM_OPEN_PLAYBACK);
else } else {
{ status =
status=snd_pcm_open(&this->hidden->audio_handle, this->hidden->cardno, snd_pcm_open(&this->hidden->audio_handle,
this->hidden->deviceno, SND_PCM_OPEN_CAPTURE); this->hidden->cardno, this->hidden->deviceno,
SND_PCM_OPEN_CAPTURE);
} }
} }
/* Check if requested device is opened */ /* Check if requested device is opened */
if (status<0) if (status < 0) {
{ this->hidden->audio_handle = NULL;
this->hidden->audio_handle=NULL;
QSA_CloseDevice(this); QSA_CloseDevice(this);
QSA_SetError("snd_pcm_open", status); QSA_SetError("snd_pcm_open", status);
return 0; return 0;
} }
if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) if (!QSA_CheckBuggyCards(this, QSA_MMAP_WORKAROUND)) {
{
/* Disable QSA MMAP plugin for buggy audio drivers */ /* Disable QSA MMAP plugin for buggy audio drivers */
status=snd_pcm_plugin_set_disable(this->hidden->audio_handle, PLUGIN_DISABLE_MMAP); status =
if (status<0) snd_pcm_plugin_set_disable(this->hidden->audio_handle,
{ PLUGIN_DISABLE_MMAP);
if (status < 0) {
QSA_CloseDevice(this); QSA_CloseDevice(this);
QSA_SetError("snd_pcm_plugin_set_disable", status); QSA_SetError("snd_pcm_plugin_set_disable", status);
return 0; return 0;
...@@ -502,69 +474,67 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) ...@@ -502,69 +474,67 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
/* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */ /* can't use format as SND_PCM_SFMT_U8 = 0 in qsa */
found = 0; found = 0;
for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) for (test_format = SDL_FirstAudioFormat(this->spec.format); !found;) {
{
/* if match found set format to equivalent QSA format */ /* if match found set format to equivalent QSA format */
switch (test_format) switch (test_format) {
{
case AUDIO_U8: case AUDIO_U8:
{ {
format=SND_PCM_SFMT_U8; format = SND_PCM_SFMT_U8;
found=1; found = 1;
} }
break; break;
case AUDIO_S8: case AUDIO_S8:
{ {
format=SND_PCM_SFMT_S8; format = SND_PCM_SFMT_S8;
found=1; found = 1;
} }
break; break;
case AUDIO_S16LSB: case AUDIO_S16LSB:
{ {
format=SND_PCM_SFMT_S16_LE; format = SND_PCM_SFMT_S16_LE;
found=1; found = 1;
} }
break; break;
case AUDIO_S16MSB: case AUDIO_S16MSB:
{ {
format=SND_PCM_SFMT_S16_BE; format = SND_PCM_SFMT_S16_BE;
found=1; found = 1;
} }
break; break;
case AUDIO_U16LSB: case AUDIO_U16LSB:
{ {
format=SND_PCM_SFMT_U16_LE; format = SND_PCM_SFMT_U16_LE;
found=1; found = 1;
} }
break; break;
case AUDIO_U16MSB: case AUDIO_U16MSB:
{ {
format=SND_PCM_SFMT_U16_BE; format = SND_PCM_SFMT_U16_BE;
found=1; found = 1;
} }
break; break;
case AUDIO_S32LSB: case AUDIO_S32LSB:
{ {
format=SND_PCM_SFMT_S32_LE; format = SND_PCM_SFMT_S32_LE;
found=1; found = 1;
} }
break; break;
case AUDIO_S32MSB: case AUDIO_S32MSB:
{ {
format=SND_PCM_SFMT_S32_BE; format = SND_PCM_SFMT_S32_BE;
found=1; found = 1;
} }
break; break;
case AUDIO_F32LSB: case AUDIO_F32LSB:
{ {
format=SND_PCM_SFMT_FLOAT_LE; format = SND_PCM_SFMT_FLOAT_LE;
found=1; found = 1;
} }
break; break;
case AUDIO_F32MSB: case AUDIO_F32MSB:
{ {
format=SND_PCM_SFMT_FLOAT_BE; format = SND_PCM_SFMT_FLOAT_BE;
found=1; found = 1;
} }
break; break;
default: default:
...@@ -573,35 +543,32 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) ...@@ -573,35 +543,32 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
} }
} }
if (!found) if (!found) {
{
test_format = SDL_NextAudioFormat(); test_format = SDL_NextAudioFormat();
} }
} }
/* assumes test_format not 0 on success */ /* assumes test_format not 0 on success */
if (test_format==0) if (test_format == 0) {
{
QSA_CloseDevice(this); QSA_CloseDevice(this);
SDL_SetError("QSA: Couldn't find any hardware audio formats"); SDL_SetError("QSA: Couldn't find any hardware audio formats");
return 0; return 0;
} }
this->spec.format=test_format; this->spec.format = test_format;
/* Set the audio format */ /* Set the audio format */
cparams.format.format=format; cparams.format.format = format;
/* Set mono/stereo/4ch/6ch/8ch audio */ /* Set mono/stereo/4ch/6ch/8ch audio */
cparams.format.voices=this->spec.channels; cparams.format.voices = this->spec.channels;
/* Set rate */ /* Set rate */
cparams.format.rate=this->spec.freq; cparams.format.rate = this->spec.freq;
/* Setup the transfer parameters according to cparams */ /* Setup the transfer parameters according to cparams */
status=snd_pcm_plugin_params(this->hidden->audio_handle, &cparams); status = snd_pcm_plugin_params(this->hidden->audio_handle, &cparams);
if (status<0) if (status < 0) {
{
QSA_CloseDevice(this); QSA_CloseDevice(this);
QSA_SetError("snd_pcm_channel_params", status); QSA_SetError("snd_pcm_channel_params", status);
return 0; return 0;
...@@ -609,18 +576,14 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) ...@@ -609,18 +576,14 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
/* Make sure channel is setup right one last time */ /* Make sure channel is setup right one last time */
SDL_memset(&csetup, '\0', sizeof(csetup)); SDL_memset(&csetup, '\0', sizeof(csetup));
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
csetup.channel=SND_PCM_CHANNEL_PLAYBACK; } else {
} csetup.channel = SND_PCM_CHANNEL_CAPTURE;
else
{
csetup.channel=SND_PCM_CHANNEL_CAPTURE;
} }
/* Setup an audio channel */ /* Setup an audio channel */
if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) if (snd_pcm_plugin_setup(this->hidden->audio_handle, &csetup) < 0) {
{
QSA_CloseDevice(this); QSA_CloseDevice(this);
SDL_SetError("QSA: Unable to setup channel\n"); SDL_SetError("QSA: Unable to setup channel\n");
return 0; return 0;
...@@ -631,9 +594,9 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) ...@@ -631,9 +594,9 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
this->hidden->pcm_len = this->spec.size; this->hidden->pcm_len = this->spec.size;
if (this->hidden->pcm_len==0) if (this->hidden->pcm_len == 0) {
{ this->hidden->pcm_len =
this->hidden->pcm_len=csetup.buf.block.frag_size * this->spec.channels * csetup.buf.block.frag_size * this->spec.channels *
(snd_pcm_format_width(format) / 8); (snd_pcm_format_width(format) / 8);
} }
...@@ -642,48 +605,47 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) ...@@ -642,48 +605,47 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
* (Note that buffer size must be a multiple of fragment size, so find * (Note that buffer size must be a multiple of fragment size, so find
* closest multiple) * closest multiple)
*/ */
this->hidden->pcm_buf=(Uint8*)SDL_AllocAudioMem(this->hidden->pcm_len); this->hidden->pcm_buf =
if (this->hidden->pcm_buf==NULL) (Uint8 *) SDL_AllocAudioMem(this->hidden->pcm_len);
{ if (this->hidden->pcm_buf == NULL) {
QSA_CloseDevice(this); QSA_CloseDevice(this);
SDL_OutOfMemory(); SDL_OutOfMemory();
return 0; return 0;
} }
SDL_memset(this->hidden->pcm_buf, this->spec.silence, this->hidden->pcm_len); SDL_memset(this->hidden->pcm_buf, this->spec.silence,
this->hidden->pcm_len);
/* get the file descriptor */ /* get the file descriptor */
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ this->hidden->audio_fd =
this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle, snd_pcm_file_descriptor(this->hidden->audio_handle,
SND_PCM_CHANNEL_PLAYBACK); SND_PCM_CHANNEL_PLAYBACK);
} } else {
else this->hidden->audio_fd =
{ snd_pcm_file_descriptor(this->hidden->audio_handle,
this->hidden->audio_fd=snd_pcm_file_descriptor(this->hidden->audio_handle,
SND_PCM_CHANNEL_CAPTURE); SND_PCM_CHANNEL_CAPTURE);
} }
if (this->hidden->audio_fd<0) if (this->hidden->audio_fd < 0) {
{
QSA_CloseDevice(this); QSA_CloseDevice(this);
QSA_SetError("snd_pcm_file_descriptor", status); QSA_SetError("snd_pcm_file_descriptor", status);
return 0; return 0;
} }
/* Prepare an audio channel */ /* Prepare an audio channel */
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{
/* Prepare audio playback */ /* Prepare audio playback */
status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK); status =
} snd_pcm_plugin_prepare(this->hidden->audio_handle,
else SND_PCM_CHANNEL_PLAYBACK);
{ } else {
/* Prepare audio capture */ /* Prepare audio capture */
status=snd_pcm_plugin_prepare(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE); status =
snd_pcm_plugin_prepare(this->hidden->audio_handle,
SND_PCM_CHANNEL_CAPTURE);
} }
if (status<0) if (status < 0) {
{
QSA_CloseDevice(this); QSA_CloseDevice(this);
QSA_SetError("snd_pcm_plugin_prepare", status); QSA_SetError("snd_pcm_plugin_prepare", status);
return 0; return 0;
...@@ -693,7 +655,8 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture) ...@@ -693,7 +655,8 @@ static int QSA_OpenDevice(_THIS, const char* devname, int iscapture)
return 1; return 1;
} }
int QSA_DetectDevices(int iscapture) int
QSA_DetectDevices(int iscapture)
{ {
uint32_t it; uint32_t it;
uint32_t cards; uint32_t cards;
...@@ -702,160 +665,147 @@ int QSA_DetectDevices(int iscapture) ...@@ -702,160 +665,147 @@ int QSA_DetectDevices(int iscapture)
/* Detect amount of available devices */ /* Detect amount of available devices */
/* this value can be changed in the runtime */ /* this value can be changed in the runtime */
cards=snd_cards(); cards = snd_cards();
/* If io-audio manager is not running we will get 0 as number */ /* If io-audio manager is not running we will get 0 as number */
/* of available audio devices */ /* of available audio devices */
if (cards==0) if (cards == 0) {
{
/* We have no any available audio devices */ /* We have no any available audio devices */
return 0; return 0;
} }
/* Find requested devices by type */ /* Find requested devices by type */
if (!iscapture) if (!iscapture) {
{
/* Playback devices enumeration requested */ /* Playback devices enumeration requested */
for(it=0; it<cards; it++) for (it = 0; it < cards; it++) {
{ devices = 0;
devices=0;
do { do {
status=snd_card_get_longname(it, qsa_playback_device[qsa_playback_devices].name, QSA_MAX_NAME_LENGTH); status =
if (status==EOK) snd_card_get_longname(it,
{ qsa_playback_device
snd_pcm_t* handle; [qsa_playback_devices].name,
QSA_MAX_NAME_LENGTH);
if (status == EOK) {
snd_pcm_t *handle;
/* Add device number to device name */ /* Add device number to device name */
sprintf(qsa_playback_device[qsa_playback_devices].name + SDL_strlen(qsa_playback_device[qsa_playback_devices].name), " d%d", devices); sprintf(qsa_playback_device[qsa_playback_devices].name +
SDL_strlen(qsa_playback_device
[qsa_playback_devices].name), " d%d",
devices);
/* Store associated card number id */ /* Store associated card number id */
qsa_playback_device[qsa_playback_devices].cardno=it; qsa_playback_device[qsa_playback_devices].cardno = it;
/* Check if this device id could play anything */ /* Check if this device id could play anything */
status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_PLAYBACK); status =
if (status==EOK) snd_pcm_open(&handle, it, devices,
{ SND_PCM_OPEN_PLAYBACK);
qsa_playback_device[qsa_playback_devices].deviceno=devices; if (status == EOK) {
status=snd_pcm_close(handle); qsa_playback_device[qsa_playback_devices].deviceno =
if (status==EOK) devices;
{ status = snd_pcm_close(handle);
if (status == EOK) {
qsa_playback_devices++; qsa_playback_devices++;
} }
} } else {
else
{
/* Check if we got end of devices list */ /* Check if we got end of devices list */
if (status==-ENOENT) if (status == -ENOENT) {
{
break; break;
} }
} }
} } else {
else
{
break; break;
} }
/* Check if we reached maximum devices count */ /* Check if we reached maximum devices count */
if (qsa_playback_devices>=QSA_MAX_DEVICES) if (qsa_playback_devices >= QSA_MAX_DEVICES) {
{
break; break;
} }
devices++; devices++;
} while(1); } while (1);
/* Check if we reached maximum devices count */ /* Check if we reached maximum devices count */
if (qsa_playback_devices>=QSA_MAX_DEVICES) if (qsa_playback_devices >= QSA_MAX_DEVICES) {
{
break; break;
} }
} }
} } else {
else
{
/* Capture devices enumeration requested */ /* Capture devices enumeration requested */
for(it=0; it<cards; it++) for (it = 0; it < cards; it++) {
{ devices = 0;
devices=0;
do { do {
status=snd_card_get_longname(it, qsa_capture_device[qsa_capture_devices].name, QSA_MAX_NAME_LENGTH); status =
if (status==EOK) snd_card_get_longname(it,
{ qsa_capture_device
snd_pcm_t* handle; [qsa_capture_devices].name,
QSA_MAX_NAME_LENGTH);
if (status == EOK) {
snd_pcm_t *handle;
/* Add device number to device name */ /* Add device number to device name */
sprintf(qsa_capture_device[qsa_capture_devices].name + SDL_strlen(qsa_capture_device[qsa_capture_devices].name), " d%d", devices); sprintf(qsa_capture_device[qsa_capture_devices].name +
SDL_strlen(qsa_capture_device
[qsa_capture_devices].name), " d%d",
devices);
/* Store associated card number id */ /* Store associated card number id */
qsa_capture_device[qsa_capture_devices].cardno=it; qsa_capture_device[qsa_capture_devices].cardno = it;
/* Check if this device id could play anything */ /* Check if this device id could play anything */
status=snd_pcm_open(&handle, it, devices, SND_PCM_OPEN_CAPTURE); status =
if (status==EOK) snd_pcm_open(&handle, it, devices,
{ SND_PCM_OPEN_CAPTURE);
qsa_capture_device[qsa_capture_devices].deviceno=devices; if (status == EOK) {
status=snd_pcm_close(handle); qsa_capture_device[qsa_capture_devices].deviceno =
if (status==EOK) devices;
{ status = snd_pcm_close(handle);
if (status == EOK) {
qsa_capture_devices++; qsa_capture_devices++;
} }
} } else {
else
{
/* Check if we got end of devices list */ /* Check if we got end of devices list */
if (status==-ENOENT) if (status == -ENOENT) {
{
break; break;
} }
} }
/* Check if we reached maximum devices count */ /* Check if we reached maximum devices count */
if (qsa_capture_devices>=QSA_MAX_DEVICES) if (qsa_capture_devices >= QSA_MAX_DEVICES) {
{
break; break;
} }
} } else {
else
{
break; break;
} }
devices++; devices++;
} while(1); } while (1);
/* Check if we reached maximum devices count */ /* Check if we reached maximum devices count */
if (qsa_capture_devices>=QSA_MAX_DEVICES) if (qsa_capture_devices >= QSA_MAX_DEVICES) {
{
break; break;
} }
} }
} }
/* Return amount of available playback or capture devices */ /* Return amount of available playback or capture devices */
if (!iscapture) if (!iscapture) {
{
return qsa_playback_devices; return qsa_playback_devices;
} } else {
else
{
return qsa_capture_devices; return qsa_capture_devices;
} }
} }
const char* QSA_GetDeviceName(int index, int iscapture) const char *
QSA_GetDeviceName(int index, int iscapture)
{ {
if (!iscapture) if (!iscapture) {
{ if (index >= qsa_playback_devices) {
if (index>=qsa_playback_devices)
{
return "No such playback device"; return "No such playback device";
} }
return qsa_playback_device[index].name; return qsa_playback_device[index].name;
} } else {
else if (index >= qsa_capture_devices) {
{
if (index>=qsa_capture_devices)
{
return "No such capture device"; return "No such capture device";
} }
...@@ -863,73 +813,76 @@ const char* QSA_GetDeviceName(int index, int iscapture) ...@@ -863,73 +813,76 @@ const char* QSA_GetDeviceName(int index, int iscapture)
} }
} }
void QSA_WaitDone(_THIS) void
QSA_WaitDone(_THIS)
{ {
if (!this->hidden->iscapture) if (!this->hidden->iscapture) {
{ if (this->hidden->audio_handle != NULL) {
if (this->hidden->audio_handle!=NULL)
{
/* Wait till last fragment is played and stop channel */ /* Wait till last fragment is played and stop channel */
snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_PLAYBACK); snd_pcm_plugin_flush(this->hidden->audio_handle,
} SND_PCM_CHANNEL_PLAYBACK);
} }
else } else {
{ if (this->hidden->audio_handle != NULL) {
if (this->hidden->audio_handle!=NULL)
{
/* Discard all unread data and stop channel */ /* Discard all unread data and stop channel */
snd_pcm_plugin_flush(this->hidden->audio_handle, SND_PCM_CHANNEL_CAPTURE); snd_pcm_plugin_flush(this->hidden->audio_handle,
SND_PCM_CHANNEL_CAPTURE);
} }
} }
} }
void QSA_Deinitialize(void) void
QSA_Deinitialize(void)
{ {
/* Clear devices array on shutdown */ /* Clear devices array on shutdown */
SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES); SDL_memset(qsa_playback_device, 0x00,
SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES); sizeof(QSA_Device) * QSA_MAX_DEVICES);
qsa_playback_devices=0; SDL_memset(qsa_capture_device, 0x00,
qsa_capture_devices=0; sizeof(QSA_Device) * QSA_MAX_DEVICES);
qsa_playback_devices = 0;
qsa_capture_devices = 0;
} }
static int QSA_Init(SDL_AudioDriverImpl* impl) static int
QSA_Init(SDL_AudioDriverImpl * impl)
{ {
snd_pcm_t* handle=NULL; snd_pcm_t *handle = NULL;
int32_t status=0; int32_t status = 0;
/* Clear devices array */ /* Clear devices array */
SDL_memset(qsa_playback_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES); SDL_memset(qsa_playback_device, 0x00,
SDL_memset(qsa_capture_device, 0x00, sizeof(QSA_Device)*QSA_MAX_DEVICES); sizeof(QSA_Device) * QSA_MAX_DEVICES);
qsa_playback_devices=0; SDL_memset(qsa_capture_device, 0x00,
qsa_capture_devices=0; sizeof(QSA_Device) * QSA_MAX_DEVICES);
qsa_playback_devices = 0;
qsa_capture_devices = 0;
/* Set function pointers */ /* Set function pointers */
/* DeviceLock and DeviceUnlock functions are used default, */ /* DeviceLock and DeviceUnlock functions are used default, */
/* provided by SDL, which uses pthread_mutex for lock/unlock */ /* provided by SDL, which uses pthread_mutex for lock/unlock */
impl->DetectDevices=QSA_DetectDevices; impl->DetectDevices = QSA_DetectDevices;
impl->GetDeviceName=QSA_GetDeviceName; impl->GetDeviceName = QSA_GetDeviceName;
impl->OpenDevice=QSA_OpenDevice; impl->OpenDevice = QSA_OpenDevice;
impl->ThreadInit=QSA_ThreadInit; impl->ThreadInit = QSA_ThreadInit;
impl->WaitDevice=QSA_WaitDevice; impl->WaitDevice = QSA_WaitDevice;
impl->PlayDevice=QSA_PlayDevice; impl->PlayDevice = QSA_PlayDevice;
impl->GetDeviceBuf=QSA_GetDeviceBuf; impl->GetDeviceBuf = QSA_GetDeviceBuf;
impl->CloseDevice=QSA_CloseDevice; impl->CloseDevice = QSA_CloseDevice;
impl->WaitDone=QSA_WaitDone; impl->WaitDone = QSA_WaitDone;
impl->Deinitialize=QSA_Deinitialize; impl->Deinitialize = QSA_Deinitialize;
impl->LockDevice=NULL; impl->LockDevice = NULL;
impl->UnlockDevice=NULL; impl->UnlockDevice = NULL;
impl->OnlyHasDefaultOutputDevice=0; impl->OnlyHasDefaultOutputDevice = 0;
impl->ProvidesOwnCallbackThread=0; impl->ProvidesOwnCallbackThread = 0;
impl->SkipMixerLock=0; impl->SkipMixerLock = 0;
impl->HasCaptureSupport=1; impl->HasCaptureSupport = 1;
impl->OnlyHasDefaultOutputDevice=0; impl->OnlyHasDefaultOutputDevice = 0;
impl->OnlyHasDefaultInputDevice=0; impl->OnlyHasDefaultInputDevice = 0;
/* Check if io-audio manager is running or not */ /* Check if io-audio manager is running or not */
status=snd_cards(); status = snd_cards();
if (status==0) if (status == 0) {
{
/* if no, return immediately */ /* if no, return immediately */
return 1; return 1;
} }
...@@ -938,8 +891,7 @@ static int QSA_Init(SDL_AudioDriverImpl* impl) ...@@ -938,8 +891,7 @@ static int QSA_Init(SDL_AudioDriverImpl* impl)
return 2; return 2;
} }
AudioBootStrap QSAAUDIO_bootstrap= AudioBootStrap QSAAUDIO_bootstrap = {
{
DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0 DRIVER_NAME, "QNX QSA Audio", QSA_Init, 0
}; };
......
...@@ -44,7 +44,7 @@ struct SDL_PrivateAudioData ...@@ -44,7 +44,7 @@ struct SDL_PrivateAudioData
/* The audio device handle */ /* The audio device handle */
int cardno; int cardno;
int deviceno; int deviceno;
snd_pcm_t* audio_handle; snd_pcm_t *audio_handle;
/* The audio file descriptor */ /* The audio file descriptor */
int audio_fd; int audio_fd;
...@@ -53,7 +53,7 @@ struct SDL_PrivateAudioData ...@@ -53,7 +53,7 @@ struct SDL_PrivateAudioData
uint32_t timeout_on_wait; uint32_t timeout_on_wait;
/* Raw mixing buffer */ /* Raw mixing buffer */
Uint8* pcm_buf; Uint8 *pcm_buf;
Uint32 pcm_len; Uint32 pcm_len;
}; };
......
...@@ -34,7 +34,8 @@ ...@@ -34,7 +34,8 @@
/* Empty function stub to get OpenGL ES 1.0 support without */ /* Empty function stub to get OpenGL ES 1.0 support without */
/* OpenGL ES extension GL_OES_draw_texture_supported */ /* OpenGL ES extension GL_OES_draw_texture_supported */
GL_API void GL_APIENTRY glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height) GL_API void GL_APIENTRY
glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
{ {
return; return;
} }
...@@ -105,8 +106,7 @@ SDL_RenderDriver GL_ES_RenderDriver = { ...@@ -105,8 +106,7 @@ SDL_RenderDriver GL_ES_RenderDriver = {
{ {
/* OpenGL ES 1.x supported formats list */ /* OpenGL ES 1.x supported formats list */
SDL_PIXELFORMAT_BGR24, SDL_PIXELFORMAT_BGR24,
SDL_PIXELFORMAT_ABGR8888 SDL_PIXELFORMAT_ABGR8888},
},
0, 0,
0} 0}
}; };
...@@ -351,7 +351,7 @@ power_of_2(int input) ...@@ -351,7 +351,7 @@ power_of_2(int input)
} }
static int static int
GLES_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
SDL_Window *window = SDL_GetWindowFromID(renderer->window); SDL_Window *window = SDL_GetWindowFromID(renderer->window);
...@@ -533,8 +533,8 @@ GLES_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -533,8 +533,8 @@ GLES_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
} }
static int static int
GLES_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture, GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect *rect, const void *pixels, int pitch) const SDL_Rect * rect, const void *pixels, int pitch)
{ {
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata; GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata; GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
...@@ -858,7 +858,7 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, ...@@ -858,7 +858,7 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
} }
static void static void
GLES_RenderPresent(SDL_Renderer *renderer) GLES_RenderPresent(SDL_Renderer * renderer)
{ {
SDL_GL_SwapWindow(renderer->window); SDL_GL_SwapWindow(renderer->window);
} }
......
...@@ -1496,8 +1496,7 @@ SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags) ...@@ -1496,8 +1496,7 @@ SDL_CreateRenderer(SDL_WindowID windowID, int index, Uint32 flags)
window->renderer = SDL_CurrentDisplay.render_drivers[index] window->renderer = SDL_CurrentDisplay.render_drivers[index]
.CreateRenderer(window, flags); .CreateRenderer(window, flags);
if (window->renderer==NULL) if (window->renderer == NULL) {
{
/* Assuming renderer set its error */ /* Assuming renderer set its error */
return -1; return -1;
} }
...@@ -2719,7 +2718,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) ...@@ -2719,7 +2718,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
{ {
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES #if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params); void (APIENTRY * glGetIntegervFunc) (GLenum pname, GLint * params);
GLenum (APIENTRY * glGetErrorFunc) (void); GLenum(APIENTRY * glGetErrorFunc) (void);
GLenum attrib = 0; GLenum attrib = 0;
GLenum error = 0; GLenum error = 0;
...@@ -2734,7 +2733,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) ...@@ -2734,7 +2733,7 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
} }
/* Clear value in any case */ /* Clear value in any case */
*value=0; *value = 0;
switch (attr) { switch (attr) {
case SDL_GL_RETAINED_BACKING: case SDL_GL_RETAINED_BACKING:
...@@ -2842,11 +2841,9 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value) ...@@ -2842,11 +2841,9 @@ SDL_GL_GetAttribute(SDL_GLattr attr, int *value)
} }
glGetIntegervFunc(attrib, (GLint *) value); glGetIntegervFunc(attrib, (GLint *) value);
error=glGetErrorFunc(); error = glGetErrorFunc();
if (error!=GL_NO_ERROR) if (error != GL_NO_ERROR) {
{ switch (error) {
switch (error)
{
case GL_INVALID_ENUM: case GL_INVALID_ENUM:
{ {
SDL_SetError("OpenGL error: GL_INVALID_ENUM"); SDL_SetError("OpenGL error: GL_INVALID_ENUM");
......
...@@ -107,8 +107,14 @@ typedef struct ...@@ -107,8 +107,14 @@ typedef struct
{ NDSTX_BG, NDSTX_SPR } type; /* represented in a bg or sprite. */ { NDSTX_BG, NDSTX_SPR } type; /* represented in a bg or sprite. */
int hw_index; /* index of sprite in OAM or bg from libnds */ int hw_index; /* index of sprite in OAM or bg from libnds */
int pitch, bpp; /* useful information about the texture */ int pitch, bpp; /* useful information about the texture */
struct { int x,y; } scale; /* x/y stretch (24.8 fixed point) */ struct
struct { int x,y; } scroll; /* x/y offset */ {
int x, y;
} scale; /* x/y stretch (24.8 fixed point) */
struct
{
int x, y;
} scroll; /* x/y offset */
int rotate; /* -32768 to 32767, texture rotation */ int rotate; /* -32768 to 32767, texture rotation */
u16 *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */ u16 *vram_pixels; /* where the pixel data is stored (a pointer into VRAM) */
u16 *vram_palette; /* where the palette data is stored if it's indexed. */ u16 *vram_palette; /* where the palette data is stored if it's indexed. */
...@@ -310,7 +316,8 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -310,7 +316,8 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
txdat->dim.vdy = 0x100; txdat->dim.vdy = 0x100;
txdat->dim.pitch = pitch; txdat->dim.pitch = pitch;
txdat->dim.bpp = bpp; txdat->dim.bpp = bpp;
txdat->vram_pixels = (u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX); txdat->vram_pixels =
(u16 *) (data->sub ? SPRITE_GFX_SUB : SPRITE_GFX);
/* FIXME: use tileIdx*boundary /* FIXME: use tileIdx*boundary
to point to proper location */ to point to proper location */
} else { } else {
...@@ -332,20 +339,26 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -332,20 +339,26 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
// hard-coded for 256x256 for now... // hard-coded for 256x256 for now...
// TODO: a series of if-elseif-else's to find the closest but larger size. // TODO: a series of if-elseif-else's to find the closest but larger size.
if(!data->sub) { if (!data->sub) {
if(bpp==8) { if (bpp == 8) {
txdat->hw_index = bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0); txdat->hw_index =
bgInit(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0);
} else { } else {
txdat->hw_index = bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0); txdat->hw_index =
bgInit(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0,
0);
} }
} else { } else {
if(bpp==8) { if (bpp == 8) {
txdat->hw_index = bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0, 0); txdat->hw_index =
bgInitSub(whichbg, BgType_Bmp8, BgSize_B8_256x256, 0,
0);
} else { } else {
txdat->hw_index = bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256, 0, 0); txdat->hw_index =
bgInitSub(whichbg, BgType_Bmp16, BgSize_B16_256x256,
0, 0);
} }
} }
...@@ -357,14 +370,14 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) ...@@ -357,14 +370,14 @@ NDS_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
bgUpdate(bg3); bgUpdate(bg3);
*/ */
txdat->type = NDSTX_BG; txdat->type = NDSTX_BG;
txdat->pitch = (texture->w)*(bpp/8); txdat->pitch = (texture->w) * (bpp / 8);
txdat->bpp = bpp; txdat->bpp = bpp;
txdat->rotate = 0; txdat->rotate = 0;
txdat->scale.x = 0x100; txdat->scale.x = 0x100;
txdat->scale.y = 0x100; txdat->scale.y = 0x100;
txdat->scroll.x = 0; txdat->scroll.x = 0;
txdat->scroll.y = 0; txdat->scroll.y = 0;
txdat->vram_pixels = (u16*)bgGetGfxPtr(txdat->hw_index); txdat->vram_pixels = (u16 *) bgGetGfxPtr(txdat->hw_index);
bgSetCenter(txdat->hw_index, 0, 0); bgSetCenter(txdat->hw_index, 0, 0);
bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x, bgSetRotateScale(txdat->hw_index, txdat->rotate, txdat->scale.x,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
/* GF headers must be included first for the Photon GF functions */ /* GF headers must be included first for the Photon GF functions */
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
#include <gf/gf.h> #include <gf/gf.h>
#include <GLES/egl.h> #include <GLES/egl.h>
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
#include "SDL_config.h" #include "SDL_config.h"
...@@ -48,14 +48,14 @@ typedef struct SDL_VideoData ...@@ -48,14 +48,14 @@ typedef struct SDL_VideoData
PhRid_t rid[SDL_VIDEO_PHOTON_MAX_RIDS]; PhRid_t rid[SDL_VIDEO_PHOTON_MAX_RIDS];
uint32_t avail_rids; uint32_t avail_rids;
uint32_t current_device_id; uint32_t current_device_id;
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
gf_dev_t gfdev; /* GF device handle */ gf_dev_t gfdev; /* GF device handle */
gf_dev_info_t gfdev_info; /* GF device information */ gf_dev_info_t gfdev_info; /* GF device information */
SDL_bool gfinitialized; /* GF device initialization status */ SDL_bool gfinitialized; /* GF device initialization status */
EGLDisplay egldisplay; /* OpenGL ES display connection */ EGLDisplay egldisplay; /* OpenGL ES display connection */
uint32_t egl_refcount; /* OpenGL ES reference count */ uint32_t egl_refcount; /* OpenGL ES reference count */
uint32_t swapinterval; /* OpenGL ES default swap interval */ uint32_t swapinterval; /* OpenGL ES default swap interval */
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} SDL_VideoData; } SDL_VideoData;
/* This is hardcoded value in photon/Pg.h */ /* This is hardcoded value in photon/Pg.h */
...@@ -73,13 +73,13 @@ typedef struct SDL_DisplayData ...@@ -73,13 +73,13 @@ typedef struct SDL_DisplayData
uint8_t description[SDL_VIDEO_PHOTON_DEVICENAME_MAX]; uint8_t description[SDL_VIDEO_PHOTON_DEVICENAME_MAX];
/* Device description */ /* Device description */
uint32_t caps; /* Device capabilities */ uint32_t caps; /* Device capabilities */
PhCursorDef_t* cursor; /* Global cursor settings */ PhCursorDef_t *cursor; /* Global cursor settings */
SDL_bool cursor_visible; /* SDL_TRUE if cursor visible */ SDL_bool cursor_visible; /* SDL_TRUE if cursor visible */
uint32_t cursor_size; /* Cursor size in memory w/ structure */ uint32_t cursor_size; /* Cursor size in memory w/ structure */
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
gf_display_t display; /* GF display handle */ gf_display_t display; /* GF display handle */
gf_display_info_t display_info; /* GF display information */ gf_display_info_t display_info; /* GF display information */
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} SDL_DisplayData; } SDL_DisplayData;
/* Maximum amount of OpenGL ES framebuffer configurations */ /* Maximum amount of OpenGL ES framebuffer configurations */
...@@ -87,9 +87,9 @@ typedef struct SDL_DisplayData ...@@ -87,9 +87,9 @@ typedef struct SDL_DisplayData
typedef struct SDL_WindowData typedef struct SDL_WindowData
{ {
SDL_bool uses_gles; /* if true window must support OpenGL ES*/ SDL_bool uses_gles; /* if true window must support OpenGL ES */
PtWidget_t* window; /* window handle */ PtWidget_t *window; /* window handle */
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
EGLConfig gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS]; EGLConfig gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
/* OpenGL ES framebuffer confs */ /* OpenGL ES framebuffer confs */
EGLint gles_config; /* OpenGL ES configuration index */ EGLint gles_config; /* OpenGL ES configuration index */
...@@ -97,8 +97,8 @@ typedef struct SDL_WindowData ...@@ -97,8 +97,8 @@ typedef struct SDL_WindowData
EGLint gles_attributes[256]; /* OpenGL ES attributes for context */ EGLint gles_attributes[256]; /* OpenGL ES attributes for context */
EGLSurface gles_surface; /* OpenGL ES target rendering surface */ EGLSurface gles_surface; /* OpenGL ES target rendering surface */
gf_surface_t gfsurface; /* OpenGL ES GF's surface */ gf_surface_t gfsurface; /* OpenGL ES GF's surface */
PdOffscreenContext_t* phsurface; /* OpenGL ES Photon's surface */ PdOffscreenContext_t *phsurface; /* OpenGL ES Photon's surface */
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} SDL_WindowData; } SDL_WindowData;
/****************************************************************************/ /****************************************************************************/
...@@ -106,7 +106,7 @@ typedef struct SDL_WindowData ...@@ -106,7 +106,7 @@ typedef struct SDL_WindowData
/****************************************************************************/ /****************************************************************************/
typedef struct Photon_DeviceCaps typedef struct Photon_DeviceCaps
{ {
uint8_t* name; uint8_t *name;
uint32_t caps; uint32_t caps;
} Photon_DeviceCaps; } Photon_DeviceCaps;
...@@ -123,38 +123,39 @@ typedef struct Photon_DeviceCaps ...@@ -123,38 +123,39 @@ typedef struct Photon_DeviceCaps
int photon_videoinit(_THIS); int photon_videoinit(_THIS);
void photon_videoquit(_THIS); void photon_videoquit(_THIS);
void photon_getdisplaymodes(_THIS); void photon_getdisplaymodes(_THIS);
int photon_setdisplaymode(_THIS, SDL_DisplayMode* mode); int photon_setdisplaymode(_THIS, SDL_DisplayMode * mode);
int photon_setdisplaypalette(_THIS, SDL_Palette* palette); int photon_setdisplaypalette(_THIS, SDL_Palette * palette);
int photon_getdisplaypalette(_THIS, SDL_Palette* palette); int photon_getdisplaypalette(_THIS, SDL_Palette * palette);
int photon_setdisplaygammaramp(_THIS, Uint16* ramp); int photon_setdisplaygammaramp(_THIS, Uint16 * ramp);
int photon_getdisplaygammaramp(_THIS, Uint16* ramp); int photon_getdisplaygammaramp(_THIS, Uint16 * ramp);
int photon_createwindow(_THIS, SDL_Window* window); int photon_createwindow(_THIS, SDL_Window * window);
int photon_createwindowfrom(_THIS, SDL_Window* window, const void* data); int photon_createwindowfrom(_THIS, SDL_Window * window, const void *data);
void photon_setwindowtitle(_THIS, SDL_Window* window); void photon_setwindowtitle(_THIS, SDL_Window * window);
void photon_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon); void photon_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon);
void photon_setwindowposition(_THIS, SDL_Window* window); void photon_setwindowposition(_THIS, SDL_Window * window);
void photon_setwindowsize(_THIS, SDL_Window* window); void photon_setwindowsize(_THIS, SDL_Window * window);
void photon_showwindow(_THIS, SDL_Window* window); void photon_showwindow(_THIS, SDL_Window * window);
void photon_hidewindow(_THIS, SDL_Window* window); void photon_hidewindow(_THIS, SDL_Window * window);
void photon_raisewindow(_THIS, SDL_Window* window); void photon_raisewindow(_THIS, SDL_Window * window);
void photon_maximizewindow(_THIS, SDL_Window* window); void photon_maximizewindow(_THIS, SDL_Window * window);
void photon_minimizewindow(_THIS, SDL_Window* window); void photon_minimizewindow(_THIS, SDL_Window * window);
void photon_restorewindow(_THIS, SDL_Window* window); void photon_restorewindow(_THIS, SDL_Window * window);
void photon_setwindowgrab(_THIS, SDL_Window* window); void photon_setwindowgrab(_THIS, SDL_Window * window);
void photon_destroywindow(_THIS, SDL_Window* window); void photon_destroywindow(_THIS, SDL_Window * window);
/* Window manager function */ /* Window manager function */
SDL_bool photon_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info); SDL_bool photon_getwindowwminfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
/* OpenGL/OpenGL ES functions */ /* OpenGL/OpenGL ES functions */
int photon_gl_loadlibrary(_THIS, const char* path); int photon_gl_loadlibrary(_THIS, const char *path);
void* photon_gl_getprocaddres(_THIS, const char* proc); void *photon_gl_getprocaddres(_THIS, const char *proc);
void photon_gl_unloadlibrary(_THIS); void photon_gl_unloadlibrary(_THIS);
SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window* window); SDL_GLContext photon_gl_createcontext(_THIS, SDL_Window * window);
int photon_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context); int photon_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context);
int photon_gl_setswapinterval(_THIS, int interval); int photon_gl_setswapinterval(_THIS, int interval);
int photon_gl_getswapinterval(_THIS); int photon_gl_getswapinterval(_THIS);
void photon_gl_swapwindow(_THIS, SDL_Window* window); void photon_gl_swapwindow(_THIS, SDL_Window * window);
void photon_gl_deletecontext(_THIS, SDL_GLContext context); void photon_gl_deletecontext(_THIS, SDL_GLContext context);
/* Event handling function */ /* Event handling function */
......
...@@ -34,51 +34,50 @@ ...@@ -34,51 +34,50 @@
#include "SDL_photon_keycodes.h" #include "SDL_photon_keycodes.h"
/* Mouse related functions */ /* Mouse related functions */
SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y); SDL_Cursor *photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y);
int photon_showcursor(SDL_Cursor* cursor); int photon_showcursor(SDL_Cursor * cursor);
void photon_movecursor(SDL_Cursor* cursor); void photon_movecursor(SDL_Cursor * cursor);
void photon_freecursor(SDL_Cursor* cursor); void photon_freecursor(SDL_Cursor * cursor);
void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y); void photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y);
void photon_freemouse(SDL_Mouse* mouse); void photon_freemouse(SDL_Mouse * mouse);
int32_t photon_addinputdevices(_THIS) int32_t
photon_addinputdevices(_THIS)
{ {
SDL_VideoData* phdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *phdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayData* didata=NULL; SDL_DisplayData *didata = NULL;
struct SDL_Mouse photon_mouse; struct SDL_Mouse photon_mouse;
SDL_MouseData* mdata=NULL; SDL_MouseData *mdata = NULL;
SDL_Keyboard photon_keyboard; SDL_Keyboard photon_keyboard;
SDLKey keymap[SDL_NUM_SCANCODES]; SDLKey keymap[SDL_NUM_SCANCODES];
uint32_t it; uint32_t it;
for (it=0; it<_this->num_displays; it++) for (it = 0; it < _this->num_displays; it++) {
{
/* Clear SDL mouse structure */ /* Clear SDL mouse structure */
SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse)); SDL_memset(&photon_mouse, 0x00, sizeof(struct SDL_Mouse));
/* Allocate SDL_MouseData structure */ /* Allocate SDL_MouseData structure */
mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData)); mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData));
if (mdata==NULL) if (mdata == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
/* Mark this mouse with ID 0 */ /* Mark this mouse with ID 0 */
photon_mouse.id=it; photon_mouse.id = it;
photon_mouse.driverdata=(void*)mdata; photon_mouse.driverdata = (void *) mdata;
photon_mouse.CreateCursor=photon_createcursor; photon_mouse.CreateCursor = photon_createcursor;
photon_mouse.ShowCursor=photon_showcursor; photon_mouse.ShowCursor = photon_showcursor;
photon_mouse.MoveCursor=photon_movecursor; photon_mouse.MoveCursor = photon_movecursor;
photon_mouse.FreeCursor=photon_freecursor; photon_mouse.FreeCursor = photon_freecursor;
photon_mouse.WarpMouse=photon_warpmouse; photon_mouse.WarpMouse = photon_warpmouse;
photon_mouse.FreeMouse=photon_freemouse; photon_mouse.FreeMouse = photon_freemouse;
/* Get display data */ /* Get display data */
didata=(SDL_DisplayData*)_this->displays[it].driverdata; didata = (SDL_DisplayData *) _this->displays[it].driverdata;
/* Store SDL_DisplayData pointer in the mouse driver internals */ /* Store SDL_DisplayData pointer in the mouse driver internals */
mdata->didata=didata; mdata->didata = didata;
/* Register mouse cursor in SDL */ /* Register mouse cursor in SDL */
SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1); SDL_AddMouse(&photon_mouse, "Photon mouse cursor", 0, 0, 1);
...@@ -95,7 +94,8 @@ int32_t photon_addinputdevices(_THIS) ...@@ -95,7 +94,8 @@ int32_t photon_addinputdevices(_THIS)
return 0; return 0;
} }
int32_t photon_delinputdevices(_THIS) int32_t
photon_delinputdevices(_THIS)
{ {
/* Destroy all of the mice */ /* Destroy all of the mice */
SDL_MouseQuit(); SDL_MouseQuit();
...@@ -104,12 +104,13 @@ int32_t photon_delinputdevices(_THIS) ...@@ -104,12 +104,13 @@ int32_t photon_delinputdevices(_THIS)
/*****************************************************************************/ /*****************************************************************************/
/* Photon mouse related functions */ /* Photon mouse related functions */
/*****************************************************************************/ /*****************************************************************************/
SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y) SDL_Cursor *
photon_createcursor(SDL_Surface * surface, int hot_x, int hot_y)
{ {
PhCursorDef_t* internal_cursor; PhCursorDef_t *internal_cursor;
SDL_Cursor* sdl_cursor; SDL_Cursor *sdl_cursor;
uint8_t* image0=NULL; uint8_t *image0 = NULL;
uint8_t* image1=NULL; uint8_t *image1 = NULL;
uint32_t it; uint32_t it;
uint32_t jt; uint32_t jt;
uint32_t shape_color; uint32_t shape_color;
...@@ -117,90 +118,98 @@ SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y) ...@@ -117,90 +118,98 @@ SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
/* SDL converts monochrome cursor shape to 32bpp cursor shape */ /* SDL converts monochrome cursor shape to 32bpp cursor shape */
/* and we must convert it back to monochrome, this routine handles */ /* and we must convert it back to monochrome, this routine handles */
/* 24/32bpp surfaces only */ /* 24/32bpp surfaces only */
if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24)) if ((surface->format->BitsPerPixel != 32)
{ && (surface->format->BitsPerPixel != 24)) {
SDL_SetError("Photon: Cursor shape is not 24/32bpp."); SDL_SetError("Photon: Cursor shape is not 24/32bpp.");
return NULL; return NULL;
} }
/* Checking data parameters */ /* Checking data parameters */
if ((surface->w==0) || (surface->h==0)) if ((surface->w == 0) || (surface->h == 0)) {
{
SDL_SetError("Photon: Cursor shape dimensions are zero"); SDL_SetError("Photon: Cursor shape dimensions are zero");
return NULL; return NULL;
} }
/* Allocate memory for the internal cursor format */ /* Allocate memory for the internal cursor format */
internal_cursor=(PhCursorDef_t*)SDL_calloc(1, sizeof(PhCursorDef_t)+ internal_cursor = (PhCursorDef_t *) SDL_calloc(1, sizeof(PhCursorDef_t) +
((((surface->w+7)>>3)*surface->h)*2)-1); ((((surface->w +
if (internal_cursor==NULL) 7) >> 3) *
{ surface->h) * 2) - 1);
if (internal_cursor == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
/* Allocate memory for the SDL cursor */ /* Allocate memory for the SDL cursor */
sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor)); sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor));
if (sdl_cursor==NULL) if (sdl_cursor == NULL) {
{
SDL_free(internal_cursor); SDL_free(internal_cursor);
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
/* Set driverdata as photon cursor format */ /* Set driverdata as photon cursor format */
image0=(uint8_t*)internal_cursor; image0 = (uint8_t *) internal_cursor;
image0+=sizeof(PhCursorDef_t)-1; image0 += sizeof(PhCursorDef_t) - 1;
image1=image0; image1 = image0;
image1+=((surface->w+7)>>3)*surface->h; image1 += ((surface->w + 7) >> 3) * surface->h;
sdl_cursor->driverdata=(void*)internal_cursor; sdl_cursor->driverdata = (void *) internal_cursor;
internal_cursor->hdr.len=(sizeof(PhCursorDef_t)-sizeof(PhRegionDataHdr_t))+ internal_cursor->hdr.len =
((((surface->w+7)>>3)*surface->h)*2)-1; (sizeof(PhCursorDef_t) - sizeof(PhRegionDataHdr_t)) +
internal_cursor->hdr.type=Ph_RDATA_CURSOR; ((((surface->w + 7) >> 3) * surface->h) * 2) - 1;
internal_cursor->size1.x=surface->w; internal_cursor->hdr.type = Ph_RDATA_CURSOR;
internal_cursor->size1.y=surface->h; internal_cursor->size1.x = surface->w;
internal_cursor->size2.x=surface->w; internal_cursor->size1.y = surface->h;
internal_cursor->size2.y=surface->h; internal_cursor->size2.x = surface->w;
internal_cursor->offset1.x=hot_x; internal_cursor->size2.y = surface->h;
internal_cursor->offset1.y=hot_y; internal_cursor->offset1.x = hot_x;
internal_cursor->offset2.x=hot_x; internal_cursor->offset1.y = hot_y;
internal_cursor->offset2.y=hot_y; internal_cursor->offset2.x = hot_x;
internal_cursor->bytesperline1=((surface->w+7)>>3); internal_cursor->offset2.y = hot_y;
internal_cursor->bytesperline2=((surface->w+7)>>3); internal_cursor->bytesperline1 = ((surface->w + 7) >> 3);
internal_cursor->color1=(SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF; internal_cursor->bytesperline2 = ((surface->w + 7) >> 3);
internal_cursor->color2=(SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF; internal_cursor->color1 = (SDL_PHOTON_MOUSE_COLOR_BLACK) & 0x00FFFFFF;
internal_cursor->color2 = (SDL_PHOTON_MOUSE_COLOR_WHITE) & 0x00FFFFFF;
/* Convert cursor from 32 bpp */ /* Convert cursor from 32 bpp */
for (jt=0; jt<surface->h; jt++) for (jt = 0; jt < surface->h; jt++) {
{ for (it = 0; it < surface->w; it++) {
for (it=0; it<surface->w; it++) shape_color =
{ *((uint32_t *) ((uint8_t *) surface->pixels +
shape_color=*((uint32_t*)((uint8_t*)surface->pixels+jt*surface->pitch+it*surface->format->BytesPerPixel)); jt * surface->pitch +
switch(shape_color) it * surface->format->BytesPerPixel));
{ switch (shape_color) {
case SDL_PHOTON_MOUSE_COLOR_BLACK: case SDL_PHOTON_MOUSE_COLOR_BLACK:
{ {
*(image0+jt*(internal_cursor->bytesperline1)+(it>>3))|=0x80>>(it%8); *(image0 + jt * (internal_cursor->bytesperline1) +
*(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8)); (it >> 3)) |= 0x80 >> (it % 8);
*(image1 + jt * (internal_cursor->bytesperline2) +
(it >> 3)) &= ~(0x80 >> (it % 8));
} }
break; break;
case SDL_PHOTON_MOUSE_COLOR_WHITE: case SDL_PHOTON_MOUSE_COLOR_WHITE:
{ {
*(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8)); *(image0 + jt * (internal_cursor->bytesperline1) +
*(image1+jt*(internal_cursor->bytesperline2)+(it>>3))|=0x80>>(it%8); (it >> 3)) &= ~(0x80 >> (it % 8));
*(image1 + jt * (internal_cursor->bytesperline2) +
(it >> 3)) |= 0x80 >> (it % 8);
} }
break; break;
case SDL_PHOTON_MOUSE_COLOR_TRANS: case SDL_PHOTON_MOUSE_COLOR_TRANS:
{ {
*(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8)); *(image0 + jt * (internal_cursor->bytesperline1) +
*(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8)); (it >> 3)) &= ~(0x80 >> (it % 8));
*(image1 + jt * (internal_cursor->bytesperline2) +
(it >> 3)) &= ~(0x80 >> (it % 8));
} }
break; break;
default: default:
{ {
/* The same as transparent color, must not happen */ /* The same as transparent color, must not happen */
*(image0+jt*(internal_cursor->bytesperline1)+(it>>3))&=~(0x80>>(it%8)); *(image0 + jt * (internal_cursor->bytesperline1) +
*(image1+jt*(internal_cursor->bytesperline2)+(it>>3))&=~(0x80>>(it%8)); (it >> 3)) &= ~(0x80 >> (it % 8));
*(image1 + jt * (internal_cursor->bytesperline2) +
(it >> 3)) &= ~(0x80 >> (it % 8));
} }
break; break;
} }
...@@ -210,152 +219,137 @@ SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y) ...@@ -210,152 +219,137 @@ SDL_Cursor* photon_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
return sdl_cursor; return sdl_cursor;
} }
int photon_showcursor(SDL_Cursor* cursor) int
photon_showcursor(SDL_Cursor * cursor)
{ {
SDL_VideoDisplay* display; SDL_VideoDisplay *display;
SDL_DisplayData* didata; SDL_DisplayData *didata;
SDL_Window* window; SDL_Window *window;
SDL_WindowData* wdata; SDL_WindowData *wdata;
SDL_WindowID window_id; SDL_WindowID window_id;
PhCursorDef_t* internal_cursor; PhCursorDef_t *internal_cursor;
int32_t status; int32_t status;
/* Get current window id */ /* Get current window id */
window_id=SDL_GetFocusWindow(); window_id = SDL_GetFocusWindow();
if (window_id<=0) if (window_id <= 0) {
{ SDL_MouseData *mdata = NULL;
SDL_MouseData* mdata=NULL;
/* If there is no current window, then someone calls this function */ /* If there is no current window, then someone calls this function */
/* to set global mouse settings during SDL initialization */ /* to set global mouse settings during SDL initialization */
if (cursor!=NULL) if (cursor != NULL) {
{
/* Store cursor for future usage */ /* Store cursor for future usage */
mdata=(SDL_MouseData*)cursor->mouse->driverdata; mdata = (SDL_MouseData *) cursor->mouse->driverdata;
didata=(SDL_DisplayData*)mdata->didata; didata = (SDL_DisplayData *) mdata->didata;
internal_cursor=(PhCursorDef_t*)cursor->driverdata; internal_cursor = (PhCursorDef_t *) cursor->driverdata;
if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t))) if (didata->cursor_size >=
{ (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) {
SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)); SDL_memcpy(didata->cursor, internal_cursor,
} internal_cursor->hdr.len +
else sizeof(PhRegionDataHdr_t));
{ } else {
/* Partitial cursor image */ /* Partitial cursor image */
SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size); SDL_memcpy(didata->cursor, internal_cursor,
didata->cursor_size);
} }
didata->cursor_visible=SDL_TRUE; didata->cursor_visible = SDL_TRUE;
return 0; return 0;
} } else {
else
{
/* We can't get SDL_DisplayData at this point, return fake success */ /* We can't get SDL_DisplayData at this point, return fake success */
return 0; return 0;
} }
} } else {
else
{
/* Sanity checks */ /* Sanity checks */
window=SDL_GetWindowFromID(window_id); window = SDL_GetWindowFromID(window_id);
if (window!=NULL) if (window != NULL) {
{ display = SDL_GetDisplayFromWindow(window);
display=SDL_GetDisplayFromWindow(window); if (display != NULL) {
if (display!=NULL) didata = (SDL_DisplayData *) display->driverdata;
{ if (didata != NULL) {
didata=(SDL_DisplayData*)display->driverdata; wdata = (SDL_WindowData *) window->driverdata;
if (didata!=NULL) if (wdata == NULL) {
{
wdata=(SDL_WindowData*)window->driverdata;
if (wdata==NULL)
{
return -1; return -1;
} }
} } else {
else
{
return -1; return -1;
} }
} } else {
else
{
return -1; return -1;
} }
} } else {
else
{
return -1; return -1;
} }
} }
/* return if window widget has been destroyed already */ /* return if window widget has been destroyed already */
if (wdata->window==NULL) if (wdata->window == NULL) {
{
return; return;
} }
/* Check if we need to set new shape or disable cursor shape */ /* Check if we need to set new shape or disable cursor shape */
if (cursor!=NULL) if (cursor != NULL) {
{
/* Retrieve photon cursor shape */ /* Retrieve photon cursor shape */
internal_cursor=(PhCursorDef_t*)cursor->driverdata; internal_cursor = (PhCursorDef_t *) cursor->driverdata;
if (internal_cursor==NULL) if (internal_cursor == NULL) {
{
SDL_SetError("Photon: Internal cursor data is absent"); SDL_SetError("Photon: Internal cursor data is absent");
return -1; return -1;
} }
/* Setup cursor type */ /* Setup cursor type */
status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP, 0); status =
if (status!=0) PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_BITMAP,
{ 0);
if (status != 0) {
SDL_SetError("Photon: Failed to set cursor type to bitmap"); SDL_SetError("Photon: Failed to set cursor type to bitmap");
return -1; return -1;
} }
/* Setup cursor color to default */ /* Setup cursor color to default */
status=PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR, Ph_CURSOR_DEFAULT_COLOR, 0); status =
if (status!=0) PtSetResource(wdata->window, Pt_ARG_CURSOR_COLOR,
{ Ph_CURSOR_DEFAULT_COLOR, 0);
if (status != 0) {
SDL_SetError("Photon: Failed to set cursor color"); SDL_SetError("Photon: Failed to set cursor color");
return -1; return -1;
} }
/* Setup cursor shape */ /* Setup cursor shape */
status=PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR, internal_cursor, status =
internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)); PtSetResource(wdata->window, Pt_ARG_BITMAP_CURSOR,
if (status!=0) internal_cursor,
{ internal_cursor->hdr.len +
sizeof(PhRegionDataHdr_t));
if (status != 0) {
SDL_SetError("Photon: Failed to set cursor color"); SDL_SetError("Photon: Failed to set cursor color");
return -1; return -1;
} }
/* Store current cursor for future usage */ /* Store current cursor for future usage */
if (didata->cursor_size>=(internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t))) if (didata->cursor_size >=
{ (internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t))) {
SDL_memcpy(didata->cursor, internal_cursor, internal_cursor->hdr.len+sizeof(PhRegionDataHdr_t)); SDL_memcpy(didata->cursor, internal_cursor,
} internal_cursor->hdr.len + sizeof(PhRegionDataHdr_t));
else } else {
{
/* Partitial cursor image */ /* Partitial cursor image */
SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size); SDL_memcpy(didata->cursor, internal_cursor, didata->cursor_size);
} }
/* Set cursor visible */ /* Set cursor visible */
didata->cursor_visible=SDL_TRUE; didata->cursor_visible = SDL_TRUE;
} } else {
else
{
/* SDL requests to disable cursor */ /* SDL requests to disable cursor */
status=PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE, 0); status =
if (status!=0) PtSetResource(wdata->window, Pt_ARG_CURSOR_TYPE, Ph_CURSOR_NONE,
{ 0);
if (status != 0) {
SDL_SetError("Photon: Can't disable cursor"); SDL_SetError("Photon: Can't disable cursor");
return -1; return -1;
} }
/* Set cursor invisible */ /* Set cursor invisible */
didata->cursor_visible=SDL_FALSE; didata->cursor_visible = SDL_FALSE;
} }
/* Flush all pending widget data */ /* Flush all pending widget data */
...@@ -365,51 +359,39 @@ int photon_showcursor(SDL_Cursor* cursor) ...@@ -365,51 +359,39 @@ int photon_showcursor(SDL_Cursor* cursor)
return 0; return 0;
} }
void photon_movecursor(SDL_Cursor* cursor) void
photon_movecursor(SDL_Cursor * cursor)
{ {
SDL_VideoDisplay* display; SDL_VideoDisplay *display;
SDL_DisplayData* didata; SDL_DisplayData *didata;
SDL_Window* window; SDL_Window *window;
SDL_WindowData* wdata; SDL_WindowData *wdata;
SDL_WindowID window_id; SDL_WindowID window_id;
int32_t status; int32_t status;
/* Get current window id */ /* Get current window id */
window_id=SDL_GetFocusWindow(); window_id = SDL_GetFocusWindow();
if (window_id<=0) if (window_id <= 0) {
{ didata = (SDL_DisplayData *) cursor->mouse->driverdata;
didata=(SDL_DisplayData*)cursor->mouse->driverdata; } else {
}
else
{
/* Sanity checks */ /* Sanity checks */
window=SDL_GetWindowFromID(window_id); window = SDL_GetWindowFromID(window_id);
if (window!=NULL) if (window != NULL) {
{ display = SDL_GetDisplayFromWindow(window);
display=SDL_GetDisplayFromWindow(window); if (display != NULL) {
if (display!=NULL) didata = (SDL_DisplayData *) display->driverdata;
{ if (didata != NULL) {
didata=(SDL_DisplayData*)display->driverdata; wdata = (SDL_WindowData *) window->driverdata;
if (didata!=NULL) if (wdata == NULL) {
{
wdata=(SDL_WindowData*)window->driverdata;
if (wdata==NULL)
{
return; return;
} }
} } else {
else
{
return; return;
} }
} } else {
else
{
return; return;
} }
} } else {
else
{
return; return;
} }
} }
...@@ -419,338 +401,328 @@ void photon_movecursor(SDL_Cursor* cursor) ...@@ -419,338 +401,328 @@ void photon_movecursor(SDL_Cursor* cursor)
return; return;
} }
void photon_freecursor(SDL_Cursor* cursor) void
photon_freecursor(SDL_Cursor * cursor)
{ {
PhCursorDef_t* internal_cursor=NULL; PhCursorDef_t *internal_cursor = NULL;
if (cursor!=NULL) if (cursor != NULL) {
{ internal_cursor = (PhCursorDef_t *) cursor->driverdata;
internal_cursor=(PhCursorDef_t*)cursor->driverdata; if (internal_cursor != NULL) {
if (internal_cursor!=NULL)
{
SDL_free(internal_cursor); SDL_free(internal_cursor);
cursor->driverdata=NULL; cursor->driverdata = NULL;
} }
} }
} }
void photon_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y) void
photon_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
{ {
SDL_VideoDisplay* display; SDL_VideoDisplay *display;
SDL_DisplayData* didata; SDL_DisplayData *didata;
SDL_Window* window; SDL_Window *window;
SDL_WindowData* wdata; SDL_WindowData *wdata;
int16_t wx; int16_t wx;
int16_t wy; int16_t wy;
/* Sanity checks */ /* Sanity checks */
window=SDL_GetWindowFromID(windowID); window = SDL_GetWindowFromID(windowID);
if (window!=NULL) if (window != NULL) {
{ display = SDL_GetDisplayFromWindow(window);
display=SDL_GetDisplayFromWindow(window); if (display != NULL) {
if (display!=NULL) didata = (SDL_DisplayData *) display->driverdata;
{ if (didata != NULL) {
didata=(SDL_DisplayData*)display->driverdata; wdata = (SDL_WindowData *) window->driverdata;
if (didata!=NULL) if (wdata == NULL) {
{
wdata=(SDL_WindowData*)window->driverdata;
if (wdata==NULL)
{
return; return;
} }
} } else {
else
{
return; return;
} }
} } else {
else
{
return; return;
} }
} } else {
else
{
return; return;
} }
PtGetAbsPosition(wdata->window, &wx, &wy); PtGetAbsPosition(wdata->window, &wx, &wy);
PhMoveCursorAbs(PhInputGroup(NULL), wx+x, wy+y); PhMoveCursorAbs(PhInputGroup(NULL), wx + x, wy + y);
return; return;
} }
void photon_freemouse(SDL_Mouse* mouse) void
photon_freemouse(SDL_Mouse * mouse)
{ {
if (mouse->driverdata==NULL) if (mouse->driverdata == NULL) {
{
return; return;
} }
/* Mouse framework doesn't deletes automatically our driverdata */ /* Mouse framework doesn't deletes automatically our driverdata */
SDL_free(mouse->driverdata); SDL_free(mouse->driverdata);
mouse->driverdata=NULL; mouse->driverdata = NULL;
return; return;
} }
SDL_scancode photon_to_sdl_keymap(uint32_t key) SDL_scancode
photon_to_sdl_keymap(uint32_t key)
{ {
SDL_scancode scancode=SDL_SCANCODE_UNKNOWN; SDL_scancode scancode = SDL_SCANCODE_UNKNOWN;
switch(key & 0x0000007F) switch (key & 0x0000007F) {
{
case PHOTON_SCANCODE_ESCAPE: case PHOTON_SCANCODE_ESCAPE:
scancode=SDL_SCANCODE_ESCAPE; scancode = SDL_SCANCODE_ESCAPE;
break; break;
case PHOTON_SCANCODE_F1: case PHOTON_SCANCODE_F1:
scancode=SDL_SCANCODE_F1; scancode = SDL_SCANCODE_F1;
break; break;
case PHOTON_SCANCODE_F2: case PHOTON_SCANCODE_F2:
scancode=SDL_SCANCODE_F2; scancode = SDL_SCANCODE_F2;
break; break;
case PHOTON_SCANCODE_F3: case PHOTON_SCANCODE_F3:
scancode=SDL_SCANCODE_F3; scancode = SDL_SCANCODE_F3;
break; break;
case PHOTON_SCANCODE_F4: case PHOTON_SCANCODE_F4:
scancode=SDL_SCANCODE_F4; scancode = SDL_SCANCODE_F4;
break; break;
case PHOTON_SCANCODE_F5: case PHOTON_SCANCODE_F5:
scancode=SDL_SCANCODE_F5; scancode = SDL_SCANCODE_F5;
break; break;
case PHOTON_SCANCODE_F6: case PHOTON_SCANCODE_F6:
scancode=SDL_SCANCODE_F6; scancode = SDL_SCANCODE_F6;
break; break;
case PHOTON_SCANCODE_F7: case PHOTON_SCANCODE_F7:
scancode=SDL_SCANCODE_F7; scancode = SDL_SCANCODE_F7;
break; break;
case PHOTON_SCANCODE_F8: case PHOTON_SCANCODE_F8:
scancode=SDL_SCANCODE_F8; scancode = SDL_SCANCODE_F8;
break; break;
case PHOTON_SCANCODE_F9: case PHOTON_SCANCODE_F9:
scancode=SDL_SCANCODE_F9; scancode = SDL_SCANCODE_F9;
break; break;
case PHOTON_SCANCODE_F10: case PHOTON_SCANCODE_F10:
scancode=SDL_SCANCODE_F10; scancode = SDL_SCANCODE_F10;
break; break;
case PHOTON_SCANCODE_F11: case PHOTON_SCANCODE_F11:
scancode=SDL_SCANCODE_F11; scancode = SDL_SCANCODE_F11;
break; break;
case PHOTON_SCANCODE_F12: case PHOTON_SCANCODE_F12:
scancode=SDL_SCANCODE_F12; scancode = SDL_SCANCODE_F12;
break; break;
case PHOTON_SCANCODE_BACKQOUTE: case PHOTON_SCANCODE_BACKQOUTE:
scancode=SDL_SCANCODE_GRAVE; scancode = SDL_SCANCODE_GRAVE;
break; break;
case PHOTON_SCANCODE_1: case PHOTON_SCANCODE_1:
scancode=SDL_SCANCODE_1; scancode = SDL_SCANCODE_1;
break; break;
case PHOTON_SCANCODE_2: case PHOTON_SCANCODE_2:
scancode=SDL_SCANCODE_2; scancode = SDL_SCANCODE_2;
break; break;
case PHOTON_SCANCODE_3: case PHOTON_SCANCODE_3:
scancode=SDL_SCANCODE_3; scancode = SDL_SCANCODE_3;
break; break;
case PHOTON_SCANCODE_4: case PHOTON_SCANCODE_4:
scancode=SDL_SCANCODE_4; scancode = SDL_SCANCODE_4;
break; break;
case PHOTON_SCANCODE_5: case PHOTON_SCANCODE_5:
scancode=SDL_SCANCODE_5; scancode = SDL_SCANCODE_5;
break; break;
case PHOTON_SCANCODE_6: case PHOTON_SCANCODE_6:
scancode=SDL_SCANCODE_6; scancode = SDL_SCANCODE_6;
break; break;
case PHOTON_SCANCODE_7: case PHOTON_SCANCODE_7:
scancode=SDL_SCANCODE_7; scancode = SDL_SCANCODE_7;
break; break;
case PHOTON_SCANCODE_8: case PHOTON_SCANCODE_8:
scancode=SDL_SCANCODE_8; scancode = SDL_SCANCODE_8;
break; break;
case PHOTON_SCANCODE_9: case PHOTON_SCANCODE_9:
scancode=SDL_SCANCODE_9; scancode = SDL_SCANCODE_9;
break; break;
case PHOTON_SCANCODE_0: case PHOTON_SCANCODE_0:
scancode=SDL_SCANCODE_0; scancode = SDL_SCANCODE_0;
break; break;
case PHOTON_SCANCODE_MINUS: case PHOTON_SCANCODE_MINUS:
scancode=SDL_SCANCODE_MINUS; scancode = SDL_SCANCODE_MINUS;
break; break;
case PHOTON_SCANCODE_EQUAL: case PHOTON_SCANCODE_EQUAL:
scancode=SDL_SCANCODE_EQUALS; scancode = SDL_SCANCODE_EQUALS;
break; break;
case PHOTON_SCANCODE_BACKSPACE: case PHOTON_SCANCODE_BACKSPACE:
scancode=SDL_SCANCODE_BACKSPACE; scancode = SDL_SCANCODE_BACKSPACE;
break; break;
case PHOTON_SCANCODE_TAB: case PHOTON_SCANCODE_TAB:
scancode=SDL_SCANCODE_TAB; scancode = SDL_SCANCODE_TAB;
break; break;
case PHOTON_SCANCODE_Q: case PHOTON_SCANCODE_Q:
scancode=SDL_SCANCODE_Q; scancode = SDL_SCANCODE_Q;
break; break;
case PHOTON_SCANCODE_W: case PHOTON_SCANCODE_W:
scancode=SDL_SCANCODE_W; scancode = SDL_SCANCODE_W;
break; break;
case PHOTON_SCANCODE_E: case PHOTON_SCANCODE_E:
scancode=SDL_SCANCODE_E; scancode = SDL_SCANCODE_E;
break; break;
case PHOTON_SCANCODE_R: case PHOTON_SCANCODE_R:
scancode=SDL_SCANCODE_R; scancode = SDL_SCANCODE_R;
break; break;
case PHOTON_SCANCODE_T: case PHOTON_SCANCODE_T:
scancode=SDL_SCANCODE_T; scancode = SDL_SCANCODE_T;
break; break;
case PHOTON_SCANCODE_Y: case PHOTON_SCANCODE_Y:
scancode=SDL_SCANCODE_Y; scancode = SDL_SCANCODE_Y;
break; break;
case PHOTON_SCANCODE_U: case PHOTON_SCANCODE_U:
scancode=SDL_SCANCODE_U; scancode = SDL_SCANCODE_U;
break; break;
case PHOTON_SCANCODE_I: case PHOTON_SCANCODE_I:
scancode=SDL_SCANCODE_I; scancode = SDL_SCANCODE_I;
break; break;
case PHOTON_SCANCODE_O: case PHOTON_SCANCODE_O:
scancode=SDL_SCANCODE_O; scancode = SDL_SCANCODE_O;
break; break;
case PHOTON_SCANCODE_P: case PHOTON_SCANCODE_P:
scancode=SDL_SCANCODE_P; scancode = SDL_SCANCODE_P;
break; break;
case PHOTON_SCANCODE_LEFT_SQ_BR: case PHOTON_SCANCODE_LEFT_SQ_BR:
scancode=SDL_SCANCODE_LEFTBRACKET; scancode = SDL_SCANCODE_LEFTBRACKET;
break; break;
case PHOTON_SCANCODE_RIGHT_SQ_BR: case PHOTON_SCANCODE_RIGHT_SQ_BR:
scancode=SDL_SCANCODE_RIGHTBRACKET; scancode = SDL_SCANCODE_RIGHTBRACKET;
break; break;
case PHOTON_SCANCODE_ENTER: case PHOTON_SCANCODE_ENTER:
scancode=SDL_SCANCODE_RETURN; scancode = SDL_SCANCODE_RETURN;
break; break;
case PHOTON_SCANCODE_CAPSLOCK: case PHOTON_SCANCODE_CAPSLOCK:
scancode=SDL_SCANCODE_CAPSLOCK; scancode = SDL_SCANCODE_CAPSLOCK;
break; break;
case PHOTON_SCANCODE_A: case PHOTON_SCANCODE_A:
scancode=SDL_SCANCODE_A; scancode = SDL_SCANCODE_A;
break; break;
case PHOTON_SCANCODE_S: case PHOTON_SCANCODE_S:
scancode=SDL_SCANCODE_S; scancode = SDL_SCANCODE_S;
break; break;
case PHOTON_SCANCODE_D: case PHOTON_SCANCODE_D:
scancode=SDL_SCANCODE_D; scancode = SDL_SCANCODE_D;
break; break;
case PHOTON_SCANCODE_F: case PHOTON_SCANCODE_F:
scancode=SDL_SCANCODE_F; scancode = SDL_SCANCODE_F;
break; break;
case PHOTON_SCANCODE_G: case PHOTON_SCANCODE_G:
scancode=SDL_SCANCODE_G; scancode = SDL_SCANCODE_G;
break; break;
case PHOTON_SCANCODE_H: case PHOTON_SCANCODE_H:
scancode=SDL_SCANCODE_H; scancode = SDL_SCANCODE_H;
break; break;
case PHOTON_SCANCODE_J: case PHOTON_SCANCODE_J:
scancode=SDL_SCANCODE_J; scancode = SDL_SCANCODE_J;
break; break;
case PHOTON_SCANCODE_K: case PHOTON_SCANCODE_K:
scancode=SDL_SCANCODE_K; scancode = SDL_SCANCODE_K;
break; break;
case PHOTON_SCANCODE_L: case PHOTON_SCANCODE_L:
scancode=SDL_SCANCODE_L; scancode = SDL_SCANCODE_L;
break; break;
case PHOTON_SCANCODE_SEMICOLON: case PHOTON_SCANCODE_SEMICOLON:
scancode=SDL_SCANCODE_SEMICOLON; scancode = SDL_SCANCODE_SEMICOLON;
break; break;
case PHOTON_SCANCODE_QUOTE: case PHOTON_SCANCODE_QUOTE:
scancode=SDL_SCANCODE_APOSTROPHE; scancode = SDL_SCANCODE_APOSTROPHE;
break; break;
case PHOTON_SCANCODE_BACKSLASH: case PHOTON_SCANCODE_BACKSLASH:
scancode=SDL_SCANCODE_BACKSLASH; scancode = SDL_SCANCODE_BACKSLASH;
break; break;
case PHOTON_SCANCODE_LEFT_SHIFT: case PHOTON_SCANCODE_LEFT_SHIFT:
scancode=SDL_SCANCODE_LSHIFT; scancode = SDL_SCANCODE_LSHIFT;
break; break;
case PHOTON_SCANCODE_Z: case PHOTON_SCANCODE_Z:
scancode=SDL_SCANCODE_Z; scancode = SDL_SCANCODE_Z;
break; break;
case PHOTON_SCANCODE_X: case PHOTON_SCANCODE_X:
scancode=SDL_SCANCODE_X; scancode = SDL_SCANCODE_X;
break; break;
case PHOTON_SCANCODE_C: case PHOTON_SCANCODE_C:
scancode=SDL_SCANCODE_C; scancode = SDL_SCANCODE_C;
break; break;
case PHOTON_SCANCODE_V: case PHOTON_SCANCODE_V:
scancode=SDL_SCANCODE_V; scancode = SDL_SCANCODE_V;
break; break;
case PHOTON_SCANCODE_B: case PHOTON_SCANCODE_B:
scancode=SDL_SCANCODE_B; scancode = SDL_SCANCODE_B;
break; break;
case PHOTON_SCANCODE_N: case PHOTON_SCANCODE_N:
scancode=SDL_SCANCODE_N; scancode = SDL_SCANCODE_N;
break; break;
case PHOTON_SCANCODE_M: case PHOTON_SCANCODE_M:
scancode=SDL_SCANCODE_M; scancode = SDL_SCANCODE_M;
break; break;
case PHOTON_SCANCODE_COMMA: case PHOTON_SCANCODE_COMMA:
scancode=SDL_SCANCODE_COMMA; scancode = SDL_SCANCODE_COMMA;
break; break;
case PHOTON_SCANCODE_POINT: case PHOTON_SCANCODE_POINT:
scancode=SDL_SCANCODE_PERIOD; scancode = SDL_SCANCODE_PERIOD;
break; break;
case PHOTON_SCANCODE_SLASH: case PHOTON_SCANCODE_SLASH:
scancode=SDL_SCANCODE_SLASH; scancode = SDL_SCANCODE_SLASH;
break; break;
case PHOTON_SCANCODE_RIGHT_SHIFT: case PHOTON_SCANCODE_RIGHT_SHIFT:
scancode=SDL_SCANCODE_RSHIFT; scancode = SDL_SCANCODE_RSHIFT;
break; break;
case PHOTON_SCANCODE_CTRL: case PHOTON_SCANCODE_CTRL:
scancode=SDL_SCANCODE_LCTRL; scancode = SDL_SCANCODE_LCTRL;
break; break;
case PHOTON_SCANCODE_WFLAG: case PHOTON_SCANCODE_WFLAG:
scancode=SDL_SCANCODE_LGUI; scancode = SDL_SCANCODE_LGUI;
break; break;
case PHOTON_SCANCODE_ALT: case PHOTON_SCANCODE_ALT:
scancode=SDL_SCANCODE_LALT; scancode = SDL_SCANCODE_LALT;
break; break;
case PHOTON_SCANCODE_SPACE: case PHOTON_SCANCODE_SPACE:
scancode=SDL_SCANCODE_SPACE; scancode = SDL_SCANCODE_SPACE;
break; break;
case PHOTON_SCANCODE_MENU: case PHOTON_SCANCODE_MENU:
scancode=SDL_SCANCODE_MENU; scancode = SDL_SCANCODE_MENU;
break; break;
case PHOTON_SCANCODE_PRNSCR: case PHOTON_SCANCODE_PRNSCR:
scancode=SDL_SCANCODE_PRINTSCREEN; scancode = SDL_SCANCODE_PRINTSCREEN;
break; break;
case PHOTON_SCANCODE_SCROLLLOCK: case PHOTON_SCANCODE_SCROLLLOCK:
scancode=SDL_SCANCODE_SCROLLLOCK; scancode = SDL_SCANCODE_SCROLLLOCK;
break; break;
case PHOTON_SCANCODE_INSERT: case PHOTON_SCANCODE_INSERT:
scancode=SDL_SCANCODE_INSERT; scancode = SDL_SCANCODE_INSERT;
break; break;
case PHOTON_SCANCODE_HOME: case PHOTON_SCANCODE_HOME:
scancode=SDL_SCANCODE_HOME; scancode = SDL_SCANCODE_HOME;
break; break;
case PHOTON_SCANCODE_PAGEUP: case PHOTON_SCANCODE_PAGEUP:
scancode=SDL_SCANCODE_PAGEUP; scancode = SDL_SCANCODE_PAGEUP;
break; break;
case PHOTON_SCANCODE_DELETE: case PHOTON_SCANCODE_DELETE:
scancode=SDL_SCANCODE_DELETE; scancode = SDL_SCANCODE_DELETE;
break; break;
case PHOTON_SCANCODE_END: case PHOTON_SCANCODE_END:
scancode=SDL_SCANCODE_END; scancode = SDL_SCANCODE_END;
break; break;
case PHOTON_SCANCODE_PAGEDOWN: case PHOTON_SCANCODE_PAGEDOWN:
scancode=SDL_SCANCODE_PAGEDOWN; scancode = SDL_SCANCODE_PAGEDOWN;
break; break;
case PHOTON_SCANCODE_UP: case PHOTON_SCANCODE_UP:
scancode=SDL_SCANCODE_UP; scancode = SDL_SCANCODE_UP;
break; break;
case PHOTON_SCANCODE_DOWN: case PHOTON_SCANCODE_DOWN:
scancode=SDL_SCANCODE_DOWN; scancode = SDL_SCANCODE_DOWN;
break; break;
case PHOTON_SCANCODE_LEFT: case PHOTON_SCANCODE_LEFT:
scancode=SDL_SCANCODE_LEFT; scancode = SDL_SCANCODE_LEFT;
break; break;
case PHOTON_SCANCODE_RIGHT: case PHOTON_SCANCODE_RIGHT:
scancode=SDL_SCANCODE_RIGHT; scancode = SDL_SCANCODE_RIGHT;
break; break;
case PHOTON_SCANCODE_NUMLOCK: case PHOTON_SCANCODE_NUMLOCK:
scancode=SDL_SCANCODE_NUMLOCKCLEAR; scancode = SDL_SCANCODE_NUMLOCKCLEAR;
break; break;
default: default:
break; break;
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
typedef struct SDL_MouseData typedef struct SDL_MouseData
{ {
SDL_DisplayData* didata; SDL_DisplayData *didata;
} SDL_MouseData; } SDL_MouseData;
int32_t photon_addinputdevices(_THIS); int32_t photon_addinputdevices(_THIS);
......
...@@ -106,7 +106,9 @@ ...@@ -106,7 +106,9 @@
#define PHOTON_SCANCODE_PRNSCR 0x54 /* only key pressed event, no release */ #define PHOTON_SCANCODE_PRNSCR 0x54 /* only key pressed event, no release */
#define PHOTON_SCANCODE_SCROLLLOCK 0x46 #define PHOTON_SCANCODE_SCROLLLOCK 0x46
/* #define PHOTON_SCANCODE_PAUSE 0x?? */ /* pause doesn't generates a scancode */ #if 0 /* pause doesn't generates a scancode */
#define PHOTON_SCANCODE_PAUSE 0x??
#endif
#define PHOTON_SCANCODE_INSERT 0x52 #define PHOTON_SCANCODE_INSERT 0x52
#define PHOTON_SCANCODE_HOME 0x47 #define PHOTON_SCANCODE_HOME 0x47
#define PHOTON_SCANCODE_PAGEUP 0x49 #define PHOTON_SCANCODE_PAGEUP 0x49
......
...@@ -26,10 +26,10 @@ ...@@ -26,10 +26,10 @@
#include "SDL_photon_pixelfmt.h" #include "SDL_photon_pixelfmt.h"
uint32_t photon_bits_to_sdl_pixelformat(uint32_t pixelfmt) uint32_t
photon_bits_to_sdl_pixelformat(uint32_t pixelfmt)
{ {
switch(pixelfmt) switch (pixelfmt) {
{
case 8: case 8:
{ {
return SDL_PIXELFORMAT_INDEX8; return SDL_PIXELFORMAT_INDEX8;
...@@ -58,10 +58,10 @@ uint32_t photon_bits_to_sdl_pixelformat(uint32_t pixelfmt) ...@@ -58,10 +58,10 @@ uint32_t photon_bits_to_sdl_pixelformat(uint32_t pixelfmt)
} }
} }
uint32_t photon_sdl_to_bits_pixelformat(uint32_t pixelfmt) uint32_t
photon_sdl_to_bits_pixelformat(uint32_t pixelfmt)
{ {
switch(pixelfmt) switch (pixelfmt) {
{
case SDL_PIXELFORMAT_INDEX8: case SDL_PIXELFORMAT_INDEX8:
{ {
return 8; return 8;
...@@ -122,10 +122,10 @@ uint32_t photon_sdl_to_bits_pixelformat(uint32_t pixelfmt) ...@@ -122,10 +122,10 @@ uint32_t photon_sdl_to_bits_pixelformat(uint32_t pixelfmt)
return 0; return 0;
} }
uint32_t photon_image_to_sdl_pixelformat(uint32_t pixelfmt) uint32_t
photon_image_to_sdl_pixelformat(uint32_t pixelfmt)
{ {
switch(pixelfmt) switch (pixelfmt) {
{
case Pg_IMAGE_PALETTE_BYTE: case Pg_IMAGE_PALETTE_BYTE:
{ {
return SDL_PIXELFORMAT_INDEX8; return SDL_PIXELFORMAT_INDEX8;
...@@ -161,10 +161,10 @@ uint32_t photon_image_to_sdl_pixelformat(uint32_t pixelfmt) ...@@ -161,10 +161,10 @@ uint32_t photon_image_to_sdl_pixelformat(uint32_t pixelfmt)
return 0; return 0;
} }
uint32_t photon_sdl_to_image_pixelformat(uint32_t pixelfmt) uint32_t
photon_sdl_to_image_pixelformat(uint32_t pixelfmt)
{ {
switch(pixelfmt) switch (pixelfmt) {
{
case SDL_PIXELFORMAT_INDEX8: case SDL_PIXELFORMAT_INDEX8:
{ {
return Pg_IMAGE_PALETTE_BYTE; return Pg_IMAGE_PALETTE_BYTE;
......
...@@ -34,31 +34,53 @@ ...@@ -34,31 +34,53 @@
#include "SDL_photon_render.h" #include "SDL_photon_render.h"
#include "SDL_photon.h" #include "SDL_photon.h"
static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags); static SDL_Renderer *photon_createrenderer(SDL_Window * window, Uint32 flags);
static int photon_displaymodechanged(SDL_Renderer* renderer); static int photon_displaymodechanged(SDL_Renderer * renderer);
static int photon_activaterenderer(SDL_Renderer* renderer); static int photon_activaterenderer(SDL_Renderer * renderer);
static int photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture); static int photon_createtexture(SDL_Renderer * renderer,
static int photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch); SDL_Texture * texture);
static int photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors); static int photon_querytexturepixels(SDL_Renderer * renderer,
static int photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors); SDL_Texture * texture, void **pixels,
static int photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture); int *pitch);
static int photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture); static int photon_settexturepalette(SDL_Renderer * renderer,
static int photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture); SDL_Texture * texture,
static int photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture); const SDL_Color * colors, int firstcolor,
static int photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch); int ncolors);
static int photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch); static int photon_gettexturepalette(SDL_Renderer * renderer,
static void photon_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture); SDL_Texture * texture, SDL_Color * colors,
static void photon_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects); int firstcolor, int ncolors);
static int photon_renderpoint(SDL_Renderer* renderer, int x, int y); static int photon_settexturecolormod(SDL_Renderer * renderer,
static int photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2); SDL_Texture * texture);
static int photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect); static int photon_settexturealphamod(SDL_Renderer * renderer,
static int photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect); SDL_Texture * texture);
static void photon_renderpresent(SDL_Renderer* renderer); static int photon_settextureblendmode(SDL_Renderer * renderer,
static void photon_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture); SDL_Texture * texture);
static void photon_destroyrenderer(SDL_Renderer* renderer); static int photon_settexturescalemode(SDL_Renderer * renderer,
SDL_Texture * texture);
SDL_RenderDriver photon_renderdriver= static int photon_updatetexture(SDL_Renderer * renderer,
{ SDL_Texture * texture, const SDL_Rect * rect,
const void *pixels, int pitch);
static int photon_locktexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty,
void **pixels, int *pitch);
static void photon_unlocktexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static void photon_dirtytexture(SDL_Renderer * renderer,
SDL_Texture * texture, int numrects,
const SDL_Rect * rects);
static int photon_renderpoint(SDL_Renderer * renderer, int x, int y);
static int photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2,
int y2);
static int photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect);
static int photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect);
static void photon_renderpresent(SDL_Renderer * renderer);
static void photon_destroytexture(SDL_Renderer * renderer,
SDL_Texture * texture);
static void photon_destroyrenderer(SDL_Renderer * renderer);
SDL_RenderDriver photon_renderdriver = {
photon_createrenderer, photon_createrenderer,
{ {
"photon", "photon",
...@@ -85,56 +107,53 @@ SDL_RenderDriver photon_renderdriver= ...@@ -85,56 +107,53 @@ SDL_RenderDriver photon_renderdriver=
SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_YUY2,
SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_UYVY,
SDL_PIXELFORMAT_YVYU SDL_PIXELFORMAT_YVYU},
},
0, 0,
0 0}
}
}; };
static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags) static SDL_Renderer *
photon_createrenderer(SDL_Window * window, Uint32 flags)
{ {
SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata; SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
SDL_Renderer* renderer = NULL; SDL_Renderer *renderer = NULL;
SDL_RenderData* rdata = NULL; SDL_RenderData *rdata = NULL;
/* Allocate new renderer structure */ /* Allocate new renderer structure */
renderer=(SDL_Renderer*)SDL_calloc(1, sizeof(SDL_Renderer)); renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(SDL_Renderer));
if (renderer==NULL) if (renderer == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
/* Allocate renderer data */ /* Allocate renderer data */
rdata=(SDL_RenderData*)SDL_calloc(1, sizeof(SDL_RenderData)); rdata = (SDL_RenderData *) SDL_calloc(1, sizeof(SDL_RenderData));
if (rdata==NULL) if (rdata == NULL) {
{
SDL_free(renderer); SDL_free(renderer);
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
renderer->DisplayModeChanged=photon_displaymodechanged; renderer->DisplayModeChanged = photon_displaymodechanged;
renderer->ActivateRenderer=photon_activaterenderer; renderer->ActivateRenderer = photon_activaterenderer;
renderer->CreateTexture=photon_createtexture; renderer->CreateTexture = photon_createtexture;
renderer->QueryTexturePixels=photon_querytexturepixels; renderer->QueryTexturePixels = photon_querytexturepixels;
renderer->SetTexturePalette=photon_settexturepalette; renderer->SetTexturePalette = photon_settexturepalette;
renderer->GetTexturePalette=photon_gettexturepalette; renderer->GetTexturePalette = photon_gettexturepalette;
renderer->SetTextureAlphaMod=photon_settexturealphamod; renderer->SetTextureAlphaMod = photon_settexturealphamod;
renderer->SetTextureColorMod=photon_settexturecolormod; renderer->SetTextureColorMod = photon_settexturecolormod;
renderer->SetTextureBlendMode=photon_settextureblendmode; renderer->SetTextureBlendMode = photon_settextureblendmode;
renderer->SetTextureScaleMode=photon_settexturescalemode; renderer->SetTextureScaleMode = photon_settexturescalemode;
renderer->UpdateTexture=photon_updatetexture; renderer->UpdateTexture = photon_updatetexture;
renderer->LockTexture=photon_locktexture; renderer->LockTexture = photon_locktexture;
renderer->UnlockTexture=photon_unlocktexture; renderer->UnlockTexture = photon_unlocktexture;
renderer->DirtyTexture=photon_dirtytexture; renderer->DirtyTexture = photon_dirtytexture;
renderer->RenderPoint=photon_renderpoint; renderer->RenderPoint = photon_renderpoint;
renderer->RenderLine=photon_renderline; renderer->RenderLine = photon_renderline;
renderer->RenderFill=photon_renderfill; renderer->RenderFill = photon_renderfill;
renderer->RenderCopy=photon_rendercopy; renderer->RenderCopy = photon_rendercopy;
renderer->RenderPresent = photon_renderpresent; renderer->RenderPresent = photon_renderpresent;
renderer->DestroyTexture = photon_destroytexture; renderer->DestroyTexture = photon_destroytexture;
renderer->DestroyRenderer = photon_destroyrenderer; renderer->DestroyRenderer = photon_destroyrenderer;
...@@ -143,67 +162,54 @@ static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags) ...@@ -143,67 +162,54 @@ static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags)
renderer->driverdata = rdata; renderer->driverdata = rdata;
/* Set render acceleration flag in case it is accelerated */ /* Set render acceleration flag in case it is accelerated */
if ((didata->caps & SDL_PHOTON_ACCELERATED)==SDL_PHOTON_ACCELERATED) if ((didata->caps & SDL_PHOTON_ACCELERATED) == SDL_PHOTON_ACCELERATED) {
{ renderer->info.flags = SDL_RENDERER_ACCELERATED;
renderer->info.flags=SDL_RENDERER_ACCELERATED; } else {
} renderer->info.flags &= ~(SDL_RENDERER_ACCELERATED);
else
{
renderer->info.flags&=~(SDL_RENDERER_ACCELERATED);
} }
rdata->window=window; rdata->window = window;
/* Check if upper level requested synchronization on vsync signal */ /* Check if upper level requested synchronization on vsync signal */
if ((flags & SDL_RENDERER_PRESENTVSYNC)==SDL_RENDERER_PRESENTVSYNC) if ((flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) {
{ rdata->enable_vsync = SDL_TRUE;
rdata->enable_vsync=SDL_TRUE; } else {
} rdata->enable_vsync = SDL_FALSE;
else
{
rdata->enable_vsync=SDL_FALSE;
} }
/* Check what buffer copy/flip scheme is requested */ /* Check what buffer copy/flip scheme is requested */
rdata->surfaces_count=0; rdata->surfaces_count = 0;
if ((flags & SDL_RENDERER_SINGLEBUFFER)==SDL_RENDERER_SINGLEBUFFER) if ((flags & SDL_RENDERER_SINGLEBUFFER) == SDL_RENDERER_SINGLEBUFFER) {
{ if ((flags & SDL_RENDERER_PRESENTDISCARD) ==
if ((flags & SDL_RENDERER_PRESENTDISCARD)==SDL_RENDERER_PRESENTDISCARD) SDL_RENDERER_PRESENTDISCARD) {
{ renderer->info.flags |=
renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD; SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD;
} else {
renderer->info.flags |=
SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
} }
else rdata->surfaces_count = 1;
{ rdata->surface_visible_idx = 0;
renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY; rdata->surface_render_idx = 0;
} } else {
rdata->surfaces_count=1; if ((flags & SDL_RENDERER_PRESENTFLIP2) == SDL_RENDERER_PRESENTFLIP2) {
rdata->surface_visible_idx=0; renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
rdata->surface_render_idx=0; rdata->surfaces_count = 2;
} rdata->surface_visible_idx = 0;
else rdata->surface_render_idx = 1;
{ } else {
if ((flags & SDL_RENDERER_PRESENTFLIP2)==SDL_RENDERER_PRESENTFLIP2) if ((flags & SDL_RENDERER_PRESENTFLIP3) ==
{ SDL_RENDERER_PRESENTFLIP3) {
renderer->info.flags|=SDL_RENDERER_PRESENTFLIP2; renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
rdata->surfaces_count=2; rdata->surfaces_count = 3;
rdata->surface_visible_idx=0; rdata->surface_visible_idx = 0;
rdata->surface_render_idx=1; rdata->surface_render_idx = 1;
} } else {
else renderer->info.flags |=
{ SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
if ((flags & SDL_RENDERER_PRESENTFLIP3)==SDL_RENDERER_PRESENTFLIP3) rdata->surfaces_count = 1;
{ rdata->surface_visible_idx = 0;
renderer->info.flags|=SDL_RENDERER_PRESENTFLIP3; rdata->surface_render_idx = 0;
rdata->surfaces_count=3;
rdata->surface_visible_idx=0;
rdata->surface_render_idx=1;
}
else
{
renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
rdata->surfaces_count=1;
rdata->surface_visible_idx=0;
rdata->surface_render_idx=0;
} }
} }
} }
...@@ -211,12 +217,12 @@ static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags) ...@@ -211,12 +217,12 @@ static SDL_Renderer* photon_createrenderer(SDL_Window* window, Uint32 flags)
return renderer; return renderer;
} }
void photon_addrenderdriver(_THIS) void
photon_addrenderdriver(_THIS)
{ {
uint32_t it; uint32_t it;
for (it=0; it<_this->num_displays; it++) for (it = 0; it < _this->num_displays; it++) {
{
SDL_AddRenderDriver(it, &photon_renderdriver); SDL_AddRenderDriver(it, &photon_renderdriver);
} }
} }
...@@ -224,9 +230,10 @@ void photon_addrenderdriver(_THIS) ...@@ -224,9 +230,10 @@ void photon_addrenderdriver(_THIS)
/****************************************************************************/ /****************************************************************************/
/* SDL render interface */ /* SDL render interface */
/****************************************************************************/ /****************************************************************************/
static int photon_displaymodechanged(SDL_Renderer* renderer) static int
photon_displaymodechanged(SDL_Renderer * renderer)
{ {
SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
/* Remove all allocated surfaces, they are no more valid */ /* Remove all allocated surfaces, they are no more valid */
...@@ -235,106 +242,134 @@ static int photon_displaymodechanged(SDL_Renderer* renderer) ...@@ -235,106 +242,134 @@ static int photon_displaymodechanged(SDL_Renderer* renderer)
return 0; return 0;
} }
static int photon_activaterenderer(SDL_Renderer* renderer) static int
photon_activaterenderer(SDL_Renderer * renderer)
{ {
SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(rdata->window); SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(rdata->window);
SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata; SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
return 0; return 0;
} }
static int photon_createtexture(SDL_Renderer* renderer, SDL_Texture* texture) static int
photon_createtexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
SDL_RenderData* renderdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *renderdata = (SDL_RenderData *) renderer->driverdata;
SDL_Window* window=SDL_GetWindowFromID(renderer->window); SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay* display=SDL_GetDisplayFromWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_TextureData* tdata=NULL; SDL_TextureData *tdata = NULL;
/* Allocate texture driver data */ /* Allocate texture driver data */
tdata=(SDL_TextureData*)SDL_calloc(1, sizeof(SDL_TextureData)); tdata = (SDL_TextureData *) SDL_calloc(1, sizeof(SDL_TextureData));
if (tdata==NULL) if (tdata == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
/* Set texture driver data */ /* Set texture driver data */
texture->driverdata=tdata; texture->driverdata = tdata;
} }
static int photon_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch) static int
photon_querytexturepixels(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch)
{ {
} }
static int photon_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors) static int
photon_settexturepalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors)
{ {
} }
static int photon_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors) static int
photon_gettexturepalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
{ {
} }
static int photon_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture) static int
photon_settexturecolormod(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int photon_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture) static int
photon_settexturealphamod(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int photon_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture) static int
photon_settextureblendmode(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int photon_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture) static int
photon_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int photon_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch) static int
photon_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{ {
} }
static int photon_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch) static int
photon_locktexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch)
{ {
} }
static void photon_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture) static void
photon_unlocktexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static void photon_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects) static void
photon_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects)
{ {
} }
static int photon_renderpoint(SDL_Renderer* renderer, int x, int y) static int
photon_renderpoint(SDL_Renderer * renderer, int x, int y)
{ {
} }
static int photon_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2) static int
photon_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
{ {
} }
static int photon_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect) static int
photon_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect)
{ {
} }
static int photon_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect) static int
photon_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
{ {
} }
static void photon_renderpresent(SDL_Renderer* renderer) static void
photon_renderpresent(SDL_Renderer * renderer)
{ {
} }
static void photon_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture) static void
photon_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static void photon_destroyrenderer(SDL_Renderer* renderer) static void
photon_destroyrenderer(SDL_Renderer * renderer)
{ {
SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
uint32_t it; uint32_t it;
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
typedef struct SDL_RenderData typedef struct SDL_RenderData
{ {
SDL_Window* window; /* SDL window type */ SDL_Window *window; /* SDL window type */
SDL_bool enable_vsync; /* VSYNC flip synchronization enable */ SDL_bool enable_vsync; /* VSYNC flip synchronization enable */
uint32_t surface_visible_idx; /* Index of visible surface */ uint32_t surface_visible_idx; /* Index of visible surface */
uint32_t surface_render_idx; /* Index of render surface */ uint32_t surface_render_idx; /* Index of render surface */
......
...@@ -37,55 +37,54 @@ ...@@ -37,55 +37,54 @@
#include "SDL_hiddi_joystick.h" #include "SDL_hiddi_joystick.h"
/* Mouse related functions */ /* Mouse related functions */
SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y); SDL_Cursor *gf_createcursor(SDL_Surface * surface, int hot_x, int hot_y);
int gf_showcursor(SDL_Cursor* cursor); int gf_showcursor(SDL_Cursor * cursor);
void gf_movecursor(SDL_Cursor* cursor); void gf_movecursor(SDL_Cursor * cursor);
void gf_freecursor(SDL_Cursor* cursor); void gf_freecursor(SDL_Cursor * cursor);
void gf_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y); void gf_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y);
void gf_freemouse(SDL_Mouse* mouse); void gf_freemouse(SDL_Mouse * mouse);
/* HIDDI interacting functions */ /* HIDDI interacting functions */
static int32_t hiddi_connect_devices(); static int32_t hiddi_connect_devices();
static int32_t hiddi_disconnect_devices(); static int32_t hiddi_disconnect_devices();
int32_t gf_addinputdevices(_THIS) int32_t
gf_addinputdevices(_THIS)
{ {
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayData* didata; SDL_DisplayData *didata;
struct SDL_Mouse gf_mouse; struct SDL_Mouse gf_mouse;
SDL_Keyboard gf_keyboard; SDL_Keyboard gf_keyboard;
SDLKey keymap[SDL_NUM_SCANCODES]; SDLKey keymap[SDL_NUM_SCANCODES];
SDL_MouseData* mdata; SDL_MouseData *mdata;
uint32_t it; uint32_t it;
for (it=0; it<_this->num_displays; it++) for (it = 0; it < _this->num_displays; it++) {
{
/* Clear SDL mouse structure */ /* Clear SDL mouse structure */
SDL_memset(&gf_mouse, 0x00, sizeof(struct SDL_Mouse)); SDL_memset(&gf_mouse, 0x00, sizeof(struct SDL_Mouse));
/* Allocate SDL_MouseData structure */ /* Allocate SDL_MouseData structure */
mdata=(SDL_MouseData*)SDL_calloc(1, sizeof(SDL_MouseData)); mdata = (SDL_MouseData *) SDL_calloc(1, sizeof(SDL_MouseData));
if (mdata==NULL) if (mdata == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
/* Mark this mouse with ID 0 */ /* Mark this mouse with ID 0 */
gf_mouse.id=it; gf_mouse.id = it;
gf_mouse.driverdata=(void*)mdata; gf_mouse.driverdata = (void *) mdata;
gf_mouse.CreateCursor=gf_createcursor; gf_mouse.CreateCursor = gf_createcursor;
gf_mouse.ShowCursor=gf_showcursor; gf_mouse.ShowCursor = gf_showcursor;
gf_mouse.MoveCursor=gf_movecursor; gf_mouse.MoveCursor = gf_movecursor;
gf_mouse.FreeCursor=gf_freecursor; gf_mouse.FreeCursor = gf_freecursor;
gf_mouse.WarpMouse=gf_warpmouse; gf_mouse.WarpMouse = gf_warpmouse;
gf_mouse.FreeMouse=gf_freemouse; gf_mouse.FreeMouse = gf_freemouse;
/* Get display data */ /* Get display data */
didata=(SDL_DisplayData*)_this->displays[it].driverdata; didata = (SDL_DisplayData *) _this->displays[it].driverdata;
/* Store SDL_DisplayData pointer in the mouse driver internals */ /* Store SDL_DisplayData pointer in the mouse driver internals */
mdata->didata=didata; mdata->didata = didata;
/* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */ /* Set cursor pos to 0,0 to avoid cursor disappearing in some drivers */
gf_cursor_set_pos(didata->display, 0, 0, 0); gf_cursor_set_pos(didata->display, 0, 0, 0);
...@@ -109,7 +108,8 @@ int32_t gf_addinputdevices(_THIS) ...@@ -109,7 +108,8 @@ int32_t gf_addinputdevices(_THIS)
return 0; return 0;
} }
int32_t gf_delinputdevices(_THIS) int32_t
gf_delinputdevices(_THIS)
{ {
/* Disconnect from HID server and release input devices */ /* Disconnect from HID server and release input devices */
hiddi_disconnect_devices(); hiddi_disconnect_devices();
...@@ -124,12 +124,13 @@ int32_t gf_delinputdevices(_THIS) ...@@ -124,12 +124,13 @@ int32_t gf_delinputdevices(_THIS)
/*****************************************************************************/ /*****************************************************************************/
/* GF Mouse related functions */ /* GF Mouse related functions */
/*****************************************************************************/ /*****************************************************************************/
SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y) SDL_Cursor *
gf_createcursor(SDL_Surface * surface, int hot_x, int hot_y)
{ {
gf_cursor_t* internal_cursor; gf_cursor_t *internal_cursor;
SDL_Cursor* sdl_cursor; SDL_Cursor *sdl_cursor;
uint8_t* image0=NULL; uint8_t *image0 = NULL;
uint8_t* image1=NULL; uint8_t *image1 = NULL;
uint32_t it; uint32_t it;
uint32_t jt; uint32_t jt;
uint32_t shape_color; uint32_t shape_color;
...@@ -137,48 +138,43 @@ SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y) ...@@ -137,48 +138,43 @@ SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
/* SDL converts monochrome cursor shape to 32bpp cursor shape */ /* SDL converts monochrome cursor shape to 32bpp cursor shape */
/* and we must convert it back to monochrome, this routine handles */ /* and we must convert it back to monochrome, this routine handles */
/* 24/32bpp surfaces only */ /* 24/32bpp surfaces only */
if ((surface->format->BitsPerPixel!=32) && (surface->format->BitsPerPixel!=24)) if ((surface->format->BitsPerPixel != 32)
{ && (surface->format->BitsPerPixel != 24)) {
SDL_SetError("GF: Cursor shape is not 24/32bpp."); SDL_SetError("GF: Cursor shape is not 24/32bpp.");
return NULL; return NULL;
} }
/* Since GF is not checking data, we must check */ /* Since GF is not checking data, we must check */
if ((surface->w==0) || (surface->h==0)) if ((surface->w == 0) || (surface->h == 0)) {
{
SDL_SetError("GF: Cursor shape dimensions are zero"); SDL_SetError("GF: Cursor shape dimensions are zero");
return NULL; return NULL;
} }
/* Allocate memory for the internal cursor format */ /* Allocate memory for the internal cursor format */
internal_cursor=(gf_cursor_t*)SDL_calloc(1, sizeof(gf_cursor_t)); internal_cursor = (gf_cursor_t *) SDL_calloc(1, sizeof(gf_cursor_t));
if (internal_cursor==NULL) if (internal_cursor == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
/* Allocate memory for the SDL cursor */ /* Allocate memory for the SDL cursor */
sdl_cursor=(SDL_Cursor*)SDL_calloc(1, sizeof(SDL_Cursor)); sdl_cursor = (SDL_Cursor *) SDL_calloc(1, sizeof(SDL_Cursor));
if (sdl_cursor==NULL) if (sdl_cursor == NULL) {
{
SDL_free(internal_cursor); SDL_free(internal_cursor);
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
/* Allocate two monochrome images */ /* Allocate two monochrome images */
image0=(uint8_t*)SDL_calloc(1, ((surface->w+7)/8)*surface->h); image0 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) / 8) * surface->h);
if (image0==NULL) if (image0 == NULL) {
{
SDL_free(sdl_cursor); SDL_free(sdl_cursor);
SDL_free(internal_cursor); SDL_free(internal_cursor);
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
image1=(uint8_t*)SDL_calloc(1, ((surface->w+7)>>3)*surface->h); image1 = (uint8_t *) SDL_calloc(1, ((surface->w + 7) >> 3) * surface->h);
if (image1==NULL) if (image1 == NULL) {
{
SDL_free(image0); SDL_free(image0);
SDL_free(sdl_cursor); SDL_free(sdl_cursor);
SDL_free(internal_cursor); SDL_free(internal_cursor);
...@@ -187,51 +183,59 @@ SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y) ...@@ -187,51 +183,59 @@ SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
} }
/* Set driverdata as GF cursor format */ /* Set driverdata as GF cursor format */
sdl_cursor->driverdata=(void*)internal_cursor; sdl_cursor->driverdata = (void *) internal_cursor;
internal_cursor->type=GF_CURSOR_BITMAP; internal_cursor->type = GF_CURSOR_BITMAP;
internal_cursor->hotspot.x=hot_x; internal_cursor->hotspot.x = hot_x;
internal_cursor->hotspot.y=hot_y; internal_cursor->hotspot.y = hot_y;
internal_cursor->cursor.bitmap.w=surface->w; internal_cursor->cursor.bitmap.w = surface->w;
internal_cursor->cursor.bitmap.h=surface->h; internal_cursor->cursor.bitmap.h = surface->h;
internal_cursor->cursor.bitmap.color0=SDL_GF_MOUSE_COLOR_BLACK; internal_cursor->cursor.bitmap.color0 = SDL_GF_MOUSE_COLOR_BLACK;
internal_cursor->cursor.bitmap.color1=SDL_GF_MOUSE_COLOR_WHITE; internal_cursor->cursor.bitmap.color1 = SDL_GF_MOUSE_COLOR_WHITE;
/* Setup cursor shape images */ /* Setup cursor shape images */
internal_cursor->cursor.bitmap.stride=((surface->w+7)>>3); internal_cursor->cursor.bitmap.stride = ((surface->w + 7) >> 3);
internal_cursor->cursor.bitmap.image0=image0; internal_cursor->cursor.bitmap.image0 = image0;
internal_cursor->cursor.bitmap.image1=image1; internal_cursor->cursor.bitmap.image1 = image1;
/* Convert cursor from 32 bpp */ /* Convert cursor from 32 bpp */
for (jt=0; jt<surface->h; jt++) for (jt = 0; jt < surface->h; jt++) {
{ for (it = 0; it < surface->w; it++) {
for (it=0; it<surface->w; it++) shape_color =
{ *((uint32_t *) ((uint8_t *) surface->pixels +
shape_color=*((uint32_t*)((uint8_t*)surface->pixels+jt*surface->pitch+it*surface->format->BytesPerPixel)); jt * surface->pitch +
switch(shape_color) it * surface->format->BytesPerPixel));
{ switch (shape_color) {
case SDL_GF_MOUSE_COLOR_BLACK: case SDL_GF_MOUSE_COLOR_BLACK:
{ {
*(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))|=0x80>>(it%8); *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
*(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); (it >> 3)) |= 0x80 >> (it % 8);
*(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
(it >> 3)) &= ~(0x80 >> (it % 8));
} }
break; break;
case SDL_GF_MOUSE_COLOR_WHITE: case SDL_GF_MOUSE_COLOR_WHITE:
{ {
*(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
*(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))|=0x80>>(it%8); (it >> 3)) &= ~(0x80 >> (it % 8));
*(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
(it >> 3)) |= 0x80 >> (it % 8);
} }
break; break;
case SDL_GF_MOUSE_COLOR_TRANS: case SDL_GF_MOUSE_COLOR_TRANS:
{ {
*(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
*(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); (it >> 3)) &= ~(0x80 >> (it % 8));
*(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
(it >> 3)) &= ~(0x80 >> (it % 8));
} }
break; break;
default: default:
{ {
/* The same as transparent color, must not happen */ /* The same as transparent color, must not happen */
*(image0+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); *(image0 + jt * (internal_cursor->cursor.bitmap.stride) +
*(image1+jt*(internal_cursor->cursor.bitmap.stride)+(it>>3))&=~(0x80>>(it%8)); (it >> 3)) &= ~(0x80 >> (it % 8));
*(image1 + jt * (internal_cursor->cursor.bitmap.stride) +
(it >> 3)) &= ~(0x80 >> (it % 8));
} }
break; break;
} }
...@@ -241,333 +245,281 @@ SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y) ...@@ -241,333 +245,281 @@ SDL_Cursor* gf_createcursor(SDL_Surface* surface, int hot_x, int hot_y)
return sdl_cursor; return sdl_cursor;
} }
int gf_showcursor(SDL_Cursor* cursor) int
gf_showcursor(SDL_Cursor * cursor)
{ {
SDL_VideoDisplay* display; SDL_VideoDisplay *display;
SDL_DisplayData* didata; SDL_DisplayData *didata;
SDL_Window* window; SDL_Window *window;
SDL_WindowID window_id; SDL_WindowID window_id;
gf_cursor_t* internal_cursor; gf_cursor_t *internal_cursor;
int32_t status; int32_t status;
/* Get current window id */ /* Get current window id */
window_id=SDL_GetFocusWindow(); window_id = SDL_GetFocusWindow();
if (window_id<=0) if (window_id <= 0) {
{ SDL_MouseData *mdata = NULL;
SDL_MouseData* mdata=NULL;
/* If there is no current window, then someone calls this function */ /* If there is no current window, then someone calls this function */
/* to set global mouse settings during SDL initialization */ /* to set global mouse settings during SDL initialization */
if (cursor!=NULL) if (cursor != NULL) {
{ mdata = (SDL_MouseData *) cursor->mouse->driverdata;
mdata=(SDL_MouseData*)cursor->mouse->driverdata; didata = (SDL_DisplayData *) mdata->didata;
didata=(SDL_DisplayData*)mdata->didata; if ((didata == NULL) || (mdata == NULL)) {
if ((didata==NULL) || (mdata==NULL))
{
return; return;
} }
} } else {
else
{
/* We can't get SDL_DisplayData at this point, return fake success */ /* We can't get SDL_DisplayData at this point, return fake success */
return 0; return 0;
} }
} } else {
else
{
/* Sanity checks */ /* Sanity checks */
window=SDL_GetWindowFromID(window_id); window = SDL_GetWindowFromID(window_id);
if (window!=NULL) if (window != NULL) {
{ display = SDL_GetDisplayFromWindow(window);
display=SDL_GetDisplayFromWindow(window); if (display != NULL) {
if (display!=NULL) didata = (SDL_DisplayData *) display->driverdata;
{ if (didata == NULL) {
didata=(SDL_DisplayData*)display->driverdata;
if (didata==NULL)
{
return -1; return -1;
} }
} } else {
else
{
return -1; return -1;
} }
} } else {
else
{
return -1; return -1;
} }
} }
/* Check if we need to set new shape or disable cursor shape */ /* Check if we need to set new shape or disable cursor shape */
if (cursor!=NULL) if (cursor != NULL) {
{
/* Retrieve GF cursor shape */ /* Retrieve GF cursor shape */
internal_cursor=(gf_cursor_t*)cursor->driverdata; internal_cursor = (gf_cursor_t *) cursor->driverdata;
if (internal_cursor==NULL) if (internal_cursor == NULL) {
{
SDL_SetError("GF: Internal cursor data is absent"); SDL_SetError("GF: Internal cursor data is absent");
return -1; return -1;
} }
if ((internal_cursor->cursor.bitmap.image0==NULL) || if ((internal_cursor->cursor.bitmap.image0 == NULL) ||
(internal_cursor->cursor.bitmap.image1==NULL)) (internal_cursor->cursor.bitmap.image1 == NULL)) {
{
SDL_SetError("GF: Cursor shape is absent"); SDL_SetError("GF: Cursor shape is absent");
return -1; return -1;
} }
/* Store last shown cursor to display data */ /* Store last shown cursor to display data */
didata->cursor.type=internal_cursor->type; didata->cursor.type = internal_cursor->type;
didata->cursor.hotspot.x=internal_cursor->hotspot.x; didata->cursor.hotspot.x = internal_cursor->hotspot.x;
didata->cursor.hotspot.y=internal_cursor->hotspot.y; didata->cursor.hotspot.y = internal_cursor->hotspot.y;
if (internal_cursor->cursor.bitmap.w>SDL_VIDEO_GF_MAX_CURSOR_SIZE) if (internal_cursor->cursor.bitmap.w > SDL_VIDEO_GF_MAX_CURSOR_SIZE) {
{ didata->cursor.cursor.bitmap.w = SDL_VIDEO_GF_MAX_CURSOR_SIZE;
didata->cursor.cursor.bitmap.w=SDL_VIDEO_GF_MAX_CURSOR_SIZE; } else {
} didata->cursor.cursor.bitmap.w = internal_cursor->cursor.bitmap.w;
else }
{
didata->cursor.cursor.bitmap.w=internal_cursor->cursor.bitmap.w; if (didata->cursor.cursor.bitmap.h > SDL_VIDEO_GF_MAX_CURSOR_SIZE) {
} didata->cursor.cursor.bitmap.h = SDL_VIDEO_GF_MAX_CURSOR_SIZE;
} else {
if (didata->cursor.cursor.bitmap.h>SDL_VIDEO_GF_MAX_CURSOR_SIZE) didata->cursor.cursor.bitmap.h = internal_cursor->cursor.bitmap.h;
{ }
didata->cursor.cursor.bitmap.h=SDL_VIDEO_GF_MAX_CURSOR_SIZE;
} didata->cursor.cursor.bitmap.color0 =
else internal_cursor->cursor.bitmap.color0;
{ didata->cursor.cursor.bitmap.color1 =
didata->cursor.cursor.bitmap.h=internal_cursor->cursor.bitmap.h; internal_cursor->cursor.bitmap.color1;
} didata->cursor.cursor.bitmap.stride =
internal_cursor->cursor.bitmap.stride;
didata->cursor.cursor.bitmap.color0=internal_cursor->cursor.bitmap.color0;
didata->cursor.cursor.bitmap.color1=internal_cursor->cursor.bitmap.color1;
didata->cursor.cursor.bitmap.stride=internal_cursor->cursor.bitmap.stride;
SDL_memcpy(didata->cursor.cursor.bitmap.image0, SDL_memcpy(didata->cursor.cursor.bitmap.image0,
internal_cursor->cursor.bitmap.image0, internal_cursor->cursor.bitmap.image0,
((internal_cursor->cursor.bitmap.w+7)/(sizeof(uint8_t)*8))*internal_cursor->cursor.bitmap.h); ((internal_cursor->cursor.bitmap.w +
7) / (sizeof(uint8_t) * 8)) *
internal_cursor->cursor.bitmap.h);
SDL_memcpy(didata->cursor.cursor.bitmap.image1, SDL_memcpy(didata->cursor.cursor.bitmap.image1,
internal_cursor->cursor.bitmap.image1, internal_cursor->cursor.bitmap.image1,
((internal_cursor->cursor.bitmap.w+7)/(sizeof(uint8_t)*8))*internal_cursor->cursor.bitmap.h); ((internal_cursor->cursor.bitmap.w +
7) / (sizeof(uint8_t) * 8)) *
internal_cursor->cursor.bitmap.h);
/* Setup cursor shape */ /* Setup cursor shape */
status=gf_cursor_set(didata->display, 0, internal_cursor); status = gf_cursor_set(didata->display, 0, internal_cursor);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{ if (status != GF_ERR_NOSUPPORT) {
if (status!=GF_ERR_NOSUPPORT)
{
SDL_SetError("GF: Can't set hardware cursor shape"); SDL_SetError("GF: Can't set hardware cursor shape");
return -1; return -1;
} }
} }
/* Enable just set cursor */ /* Enable just set cursor */
status=gf_cursor_enable(didata->display, 0); status = gf_cursor_enable(didata->display, 0);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{ if (status != GF_ERR_NOSUPPORT) {
if (status!=GF_ERR_NOSUPPORT)
{
SDL_SetError("GF: Can't enable hardware cursor"); SDL_SetError("GF: Can't enable hardware cursor");
return -1; return -1;
} }
} }
/* Set cursor visible */ /* Set cursor visible */
didata->cursor_visible=SDL_TRUE; didata->cursor_visible = SDL_TRUE;
} } else {
else
{
/* SDL requests to disable cursor */ /* SDL requests to disable cursor */
status=gf_cursor_disable(didata->display, 0); status = gf_cursor_disable(didata->display, 0);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{ if (status != GF_ERR_NOSUPPORT) {
if (status!=GF_ERR_NOSUPPORT)
{
SDL_SetError("GF: Can't disable hardware cursor"); SDL_SetError("GF: Can't disable hardware cursor");
return -1; return -1;
} }
} }
/* Set cursor invisible */ /* Set cursor invisible */
didata->cursor_visible=SDL_FALSE; didata->cursor_visible = SDL_FALSE;
} }
/* New cursor shape is set */ /* New cursor shape is set */
return 0; return 0;
} }
void gf_movecursor(SDL_Cursor* cursor) void
gf_movecursor(SDL_Cursor * cursor)
{ {
SDL_VideoDisplay* display; SDL_VideoDisplay *display;
SDL_DisplayData* didata; SDL_DisplayData *didata;
SDL_Window* window; SDL_Window *window;
SDL_WindowID window_id; SDL_WindowID window_id;
int32_t status; int32_t status;
uint32_t xmax; uint32_t xmax;
uint32_t ymax; uint32_t ymax;
/* Get current window id */ /* Get current window id */
window_id=SDL_GetFocusWindow(); window_id = SDL_GetFocusWindow();
if (window_id<=0) if (window_id <= 0) {
{ didata = (SDL_DisplayData *) cursor->mouse->driverdata;
didata=(SDL_DisplayData*)cursor->mouse->driverdata; if (didata == NULL) {
if (didata==NULL)
{
return; return;
} }
} } else {
else
{
/* Sanity checks */ /* Sanity checks */
window=SDL_GetWindowFromID(window_id); window = SDL_GetWindowFromID(window_id);
if (window!=NULL) if (window != NULL) {
{ display = SDL_GetDisplayFromWindow(window);
display=SDL_GetDisplayFromWindow(window); if (display != NULL) {
if (display!=NULL) didata = (SDL_DisplayData *) display->driverdata;
{ if (didata == NULL) {
didata=(SDL_DisplayData*)display->driverdata;
if (didata==NULL)
{
return; return;
} }
} } else {
else
{
return; return;
} }
} } else {
else
{
return; return;
} }
} }
/* Add checks for out of screen bounds position */ /* Add checks for out of screen bounds position */
if (cursor->mouse->x<0) if (cursor->mouse->x < 0) {
{ cursor->mouse->x = 0;
cursor->mouse->x=0;
} }
if (cursor->mouse->y<0) if (cursor->mouse->y < 0) {
{ cursor->mouse->y = 0;
cursor->mouse->y=0;
} }
/* Get window size to clamp maximum coordinates */ /* Get window size to clamp maximum coordinates */
SDL_GetWindowSize(window_id, &xmax, &ymax); SDL_GetWindowSize(window_id, &xmax, &ymax);
if (cursor->mouse->x>=xmax) if (cursor->mouse->x >= xmax) {
{ cursor->mouse->x = xmax - 1;
cursor->mouse->x=xmax-1;
} }
if (cursor->mouse->y>=ymax) if (cursor->mouse->y >= ymax) {
{ cursor->mouse->y = ymax - 1;
cursor->mouse->y=ymax-1;
} }
status=gf_cursor_set_pos(didata->display, 0, cursor->mouse->x, cursor->mouse->y); status =
if (status!=GF_ERR_OK) gf_cursor_set_pos(didata->display, 0, cursor->mouse->x,
{ cursor->mouse->y);
if (status!=GF_ERR_NOSUPPORT) if (status != GF_ERR_OK) {
{ if (status != GF_ERR_NOSUPPORT) {
SDL_SetError("GF: Can't set hardware cursor position"); SDL_SetError("GF: Can't set hardware cursor position");
return; return;
} }
} }
} }
void gf_freecursor(SDL_Cursor* cursor) void
gf_freecursor(SDL_Cursor * cursor)
{ {
gf_cursor_t* internal_cursor; gf_cursor_t *internal_cursor;
if (cursor!=NULL) if (cursor != NULL) {
{ internal_cursor = (gf_cursor_t *) cursor->driverdata;
internal_cursor=(gf_cursor_t*)cursor->driverdata; if (internal_cursor != NULL) {
if (internal_cursor!=NULL) if (internal_cursor->cursor.bitmap.image0 != NULL) {
{ SDL_free((uint8_t *) internal_cursor->cursor.bitmap.image0);
if (internal_cursor->cursor.bitmap.image0!=NULL)
{
SDL_free((uint8_t*)internal_cursor->cursor.bitmap.image0);
} }
if (internal_cursor->cursor.bitmap.image1!=NULL) if (internal_cursor->cursor.bitmap.image1 != NULL) {
{ SDL_free((uint8_t *) internal_cursor->cursor.bitmap.image1);
SDL_free((uint8_t*)internal_cursor->cursor.bitmap.image1);
} }
SDL_free(internal_cursor); SDL_free(internal_cursor);
} }
} }
} }
void gf_warpmouse(SDL_Mouse* mouse, SDL_WindowID windowID, int x, int y) void
gf_warpmouse(SDL_Mouse * mouse, SDL_WindowID windowID, int x, int y)
{ {
SDL_VideoDisplay* display; SDL_VideoDisplay *display;
SDL_DisplayData* didata; SDL_DisplayData *didata;
SDL_Window* window; SDL_Window *window;
uint32_t xmax; uint32_t xmax;
uint32_t ymax; uint32_t ymax;
int32_t status; int32_t status;
/* Sanity checks */ /* Sanity checks */
window=SDL_GetWindowFromID(windowID); window = SDL_GetWindowFromID(windowID);
if (window!=NULL) if (window != NULL) {
{ display = SDL_GetDisplayFromWindow(window);
display=SDL_GetDisplayFromWindow(window); if (display != NULL) {
if (display!=NULL) didata = (SDL_DisplayData *) display->driverdata;
{ if (didata == NULL) {
didata=(SDL_DisplayData*)display->driverdata;
if (didata==NULL)
{
return; return;
} }
} } else {
else
{
return; return;
} }
} } else {
else
{
return; return;
} }
/* Add checks for out of screen bounds position */ /* Add checks for out of screen bounds position */
if (x<0) if (x < 0) {
{ x = 0;
x=0;
} }
if (y<0) if (y < 0) {
{ y = 0;
y=0;
} }
/* Get window size to clamp maximum coordinates */ /* Get window size to clamp maximum coordinates */
SDL_GetWindowSize(windowID, &xmax, &ymax); SDL_GetWindowSize(windowID, &xmax, &ymax);
if (x>=xmax) if (x >= xmax) {
{ x = xmax - 1;
x=xmax-1;
} }
if (y>=ymax) if (y >= ymax) {
{ y = ymax - 1;
y=ymax-1;
} }
status=gf_cursor_set_pos(didata->display, 0, x, y); status = gf_cursor_set_pos(didata->display, 0, x, y);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{ if (status != GF_ERR_NOSUPPORT) {
if (status!=GF_ERR_NOSUPPORT)
{
SDL_SetError("GF: Can't set hardware cursor position"); SDL_SetError("GF: Can't set hardware cursor position");
return; return;
} }
} }
} }
void gf_freemouse(SDL_Mouse* mouse) void
gf_freemouse(SDL_Mouse * mouse)
{ {
if (mouse->driverdata==NULL) if (mouse->driverdata == NULL) {
{
return; return;
} }
/* Mouse framework doesn't deletes automatically our driverdata */ /* Mouse framework doesn't deletes automatically our driverdata */
SDL_free(mouse->driverdata); SDL_free(mouse->driverdata);
mouse->driverdata=NULL; mouse->driverdata = NULL;
return; return;
} }
...@@ -577,25 +529,24 @@ void gf_freemouse(SDL_Mouse* mouse) ...@@ -577,25 +529,24 @@ void gf_freemouse(SDL_Mouse* mouse)
/*****************************************************************************/ /*****************************************************************************/
static key_packet key_last_state[SDL_HIDDI_MAX_DEVICES]; static key_packet key_last_state[SDL_HIDDI_MAX_DEVICES];
static void hiddi_keyboard_handler(uint32_t devno, uint8_t* report_data, uint32_t report_len) static void
hiddi_keyboard_handler(uint32_t devno, uint8_t * report_data,
uint32_t report_len)
{ {
key_packet* packet; key_packet *packet;
uint32_t it; uint32_t it;
uint32_t jt; uint32_t jt;
packet=(key_packet*)report_data; packet = (key_packet *) report_data;
/* Check for special states */ /* Check for special states */
switch (report_len) switch (report_len) {
{
case 8: /* 8 bytes of report length */ case 8: /* 8 bytes of report length */
{ {
for (it=0; it<6; it++) for (it = 0; it < 6; it++) {
{
/* Check for keyboard overflow, when it can't handle */ /* Check for keyboard overflow, when it can't handle */
/* many simultaneous pressed keys */ /* many simultaneous pressed keys */
if (packet->codes[it]==HIDDI_KEY_OVERFLOW) if (packet->codes[it] == HIDDI_KEY_OVERFLOW) {
{
return; return;
} }
} }
...@@ -610,155 +561,145 @@ static void hiddi_keyboard_handler(uint32_t devno, uint8_t* report_data, uint32_ ...@@ -610,155 +561,145 @@ static void hiddi_keyboard_handler(uint32_t devno, uint8_t* report_data, uint32_
} }
/* Check if modifier key was pressed */ /* Check if modifier key was pressed */
if (packet->modifiers!=key_last_state[devno].modifiers) if (packet->modifiers != key_last_state[devno].modifiers) {
{ if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) ==
if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL)==HIDDI_MKEY_LEFT_CTRL) && HIDDI_MKEY_LEFT_CTRL)
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL)==0) && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) {
{
/* Left Ctrl key was pressed */ /* Left Ctrl key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LCTRL); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LCTRL);
} }
if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL)==0) && if (((packet->modifiers & HIDDI_MKEY_LEFT_CTRL) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL)==HIDDI_MKEY_LEFT_CTRL) (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_CTRL) ==
{ HIDDI_MKEY_LEFT_CTRL) {
/* Left Ctrl key was released */ /* Left Ctrl key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LCTRL); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LCTRL);
} }
if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT)==HIDDI_MKEY_LEFT_SHIFT) && if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) ==
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT)==0) HIDDI_MKEY_LEFT_SHIFT)
{ && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) {
/* Left Shift key was pressed */ /* Left Shift key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LSHIFT); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LSHIFT);
} }
if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT)==0) && if (((packet->modifiers & HIDDI_MKEY_LEFT_SHIFT) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT)==HIDDI_MKEY_LEFT_SHIFT) (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_SHIFT) ==
{ HIDDI_MKEY_LEFT_SHIFT) {
/* Left Shift key was released */ /* Left Shift key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LSHIFT); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LSHIFT);
} }
if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT)==HIDDI_MKEY_LEFT_ALT) && if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == HIDDI_MKEY_LEFT_ALT)
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT)==0) && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) == 0) {
{
/* Left Alt key was pressed */ /* Left Alt key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LALT); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LALT);
} }
if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT)==0) && if (((packet->modifiers & HIDDI_MKEY_LEFT_ALT) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT)==HIDDI_MKEY_LEFT_ALT) (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_ALT) ==
{ HIDDI_MKEY_LEFT_ALT) {
/* Left Alt key was released */ /* Left Alt key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LALT); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LALT);
} }
if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG)==HIDDI_MKEY_LEFT_WFLAG) && if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) ==
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG)==0) HIDDI_MKEY_LEFT_WFLAG)
{ && (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) {
/* Left Windows flag key was pressed */ /* Left Windows flag key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LGUI); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_LGUI);
} }
if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG)==0) && if (((packet->modifiers & HIDDI_MKEY_LEFT_WFLAG) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG)==HIDDI_MKEY_LEFT_WFLAG) (key_last_state[devno].modifiers & HIDDI_MKEY_LEFT_WFLAG) ==
{ HIDDI_MKEY_LEFT_WFLAG) {
/* Left Windows flag key was released */ /* Left Windows flag key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LGUI); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_LGUI);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL)==HIDDI_MKEY_RIGHT_CTRL) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) ==
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL)==0) HIDDI_MKEY_RIGHT_CTRL)
{ && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) {
/* Right Ctrl key was pressed */ /* Right Ctrl key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RCTRL); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RCTRL);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL)==0) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_CTRL) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL)==HIDDI_MKEY_RIGHT_CTRL) (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_CTRL) ==
{ HIDDI_MKEY_RIGHT_CTRL) {
/* Right Ctrl key was released */ /* Right Ctrl key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RCTRL); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RCTRL);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT)==HIDDI_MKEY_RIGHT_SHIFT) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT)==0) HIDDI_MKEY_RIGHT_SHIFT)
{ && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
0) {
/* Right Shift key was pressed */ /* Right Shift key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RSHIFT); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RSHIFT);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT)==0) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_SHIFT) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT)==HIDDI_MKEY_RIGHT_SHIFT) (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_SHIFT) ==
{ HIDDI_MKEY_RIGHT_SHIFT) {
/* Right Shift key was released */ /* Right Shift key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RSHIFT); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RSHIFT);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT)==HIDDI_MKEY_RIGHT_ALT) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) ==
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT)==0) HIDDI_MKEY_RIGHT_ALT)
{ && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) {
/* Right Alt key was pressed */ /* Right Alt key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RALT); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RALT);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT)==0) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_ALT) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT)==HIDDI_MKEY_RIGHT_ALT) (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_ALT) ==
{ HIDDI_MKEY_RIGHT_ALT) {
/* Right Alt key was released */ /* Right Alt key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RALT); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RALT);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG)==HIDDI_MKEY_RIGHT_WFLAG) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG)==0) HIDDI_MKEY_RIGHT_WFLAG)
{ && (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
0) {
/* Right Windows flag key was pressed */ /* Right Windows flag key was pressed */
SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RGUI); SDL_SendKeyboardKey(0, SDL_PRESSED, SDL_SCANCODE_RGUI);
} }
if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG)==0) && if (((packet->modifiers & HIDDI_MKEY_RIGHT_WFLAG) == 0) &&
(key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG)==HIDDI_MKEY_RIGHT_WFLAG) (key_last_state[devno].modifiers & HIDDI_MKEY_RIGHT_WFLAG) ==
{ HIDDI_MKEY_RIGHT_WFLAG) {
/* Right Windows flag key was released */ /* Right Windows flag key was released */
SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RGUI); SDL_SendKeyboardKey(0, SDL_RELEASED, SDL_SCANCODE_RGUI);
} }
} }
/* Check each key in the press/release buffer */ /* Check each key in the press/release buffer */
switch (report_len) switch (report_len) {
{
case 8: /* 8 bytes of report length */ case 8: /* 8 bytes of report length */
{ {
/* Check if at least one key was unpressed */ /* Check if at least one key was unpressed */
for (it=0; it<6; it++) for (it = 0; it < 6; it++) {
{ if (key_last_state[devno].codes[it] == HIDDI_KEY_UNPRESSED) {
if (key_last_state[devno].codes[it]==HIDDI_KEY_UNPRESSED)
{
/* if stored keycode is zero, find another */ /* if stored keycode is zero, find another */
continue; continue;
} }
for (jt=0; jt<6; jt++) for (jt = 0; jt < 6; jt++) {
{
/* Find stored keycode in the current pressed codes */ /* Find stored keycode in the current pressed codes */
if (packet->codes[jt]==key_last_state[devno].codes[it]) if (packet->codes[jt] == key_last_state[devno].codes[it]) {
{
/* If found then particular key state is not changed */ /* If found then particular key state is not changed */
break; break;
} }
} }
/* Check if pressed key can't longer be found */ /* Check if pressed key can't longer be found */
if (jt==6) if (jt == 6) {
{ SDL_SendKeyboardKey(0, SDL_RELEASED,
SDL_SendKeyboardKey(0, SDL_RELEASED, key_last_state[devno].codes[it]); key_last_state[devno].codes[it]);
} }
} }
/* Check if at least one new key was pressed */ /* Check if at least one new key was pressed */
for (it=0; it<6; it++) for (it = 0; it < 6; it++) {
{ if (packet->codes[it] == HIDDI_KEY_UNPRESSED) {
if (packet->codes[it]==HIDDI_KEY_UNPRESSED)
{
continue; continue;
} }
for (jt=0; jt<6; jt++) for (jt = 0; jt < 6; jt++) {
{
/* Find new keycode it the array of old pressed keys */ /* Find new keycode it the array of old pressed keys */
if (packet->codes[it]==key_last_state[devno].codes[jt]) if (packet->codes[it] == key_last_state[devno].codes[jt]) {
{
break; break;
} }
} }
/* Check if new key was pressed */ /* Check if new key was pressed */
if (jt==6) if (jt == 6) {
{
SDL_SendKeyboardKey(0, SDL_PRESSED, packet->codes[it]); SDL_SendKeyboardKey(0, SDL_PRESSED, packet->codes[it]);
} }
} }
...@@ -771,87 +712,84 @@ static void hiddi_keyboard_handler(uint32_t devno, uint8_t* report_data, uint32_ ...@@ -771,87 +712,84 @@ static void hiddi_keyboard_handler(uint32_t devno, uint8_t* report_data, uint32_
} }
/* Store last state */ /* Store last state */
key_last_state[devno]=*packet; key_last_state[devno] = *packet;
} }
static uint32_t mouse_last_state_button[SDL_HIDDI_MAX_DEVICES]; static uint32_t mouse_last_state_button[SDL_HIDDI_MAX_DEVICES];
static uint32_t collect_reports=0; static uint32_t collect_reports = 0;
static void hiddi_mouse_handler(uint32_t devno, uint8_t* report_data, uint32_t report_len) static void
hiddi_mouse_handler(uint32_t devno, uint8_t * report_data,
uint32_t report_len)
{ {
uint32_t it; uint32_t it;
uint32_t sdlbutton; uint32_t sdlbutton;
/* We do not want to collect stored events */ /* We do not want to collect stored events */
if (collect_reports==0) if (collect_reports == 0) {
{
return; return;
} }
/* Check for special states */ /* Check for special states */
switch (report_len) switch (report_len) {
{
case 8: /* 8 bytes of report length, usually multi-button USB mice */ case 8: /* 8 bytes of report length, usually multi-button USB mice */
{ {
mouse_packet8* packet; mouse_packet8 *packet;
packet=(mouse_packet8*)report_data; packet = (mouse_packet8 *) report_data;
/* Send motion event if motion really was */ /* Send motion event if motion really was */
if ((packet->horizontal_precision!=0) || (packet->vertical_precision!=0)) if ((packet->horizontal_precision != 0)
{ || (packet->vertical_precision != 0)) {
SDL_SendMouseMotion(0, 1, packet->horizontal_precision, packet->vertical_precision, 0); SDL_SendMouseMotion(0, 1, packet->horizontal_precision,
packet->vertical_precision, 0);
} }
/* Send mouse button press/release events */ /* Send mouse button press/release events */
if (mouse_last_state_button[devno]!=packet->buttons) if (mouse_last_state_button[devno] != packet->buttons) {
{
/* Cycle all buttons status */ /* Cycle all buttons status */
for (it=0; it<8; it++) for (it = 0; it < 8; it++) {
{
/* convert hiddi button id to sdl button id */ /* convert hiddi button id to sdl button id */
switch(it) switch (it) {
{
case 0: case 0:
{ {
sdlbutton=SDL_BUTTON_LEFT; sdlbutton = SDL_BUTTON_LEFT;
} }
break; break;
case 1: case 1:
{ {
sdlbutton=SDL_BUTTON_RIGHT; sdlbutton = SDL_BUTTON_RIGHT;
} }
break; break;
case 2: case 2:
{ {
sdlbutton=SDL_BUTTON_MIDDLE; sdlbutton = SDL_BUTTON_MIDDLE;
} }
break; break;
default: default:
{ {
sdlbutton=it+1; sdlbutton = it + 1;
} }
break; break;
} }
/* Button pressed */ /* Button pressed */
if (((packet->buttons & (0x01<<it))==(0x01<<it)) && if (((packet->buttons & (0x01 << it)) == (0x01 << it)) &&
((mouse_last_state_button[devno] & (0x01<<it))==0x00)) ((mouse_last_state_button[devno] & (0x01 << it)) ==
{ 0x00)) {
SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton); SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
} }
/* Button released */ /* Button released */
if (((packet->buttons & (0x01<<it))==0x00) && if (((packet->buttons & (0x01 << it)) == 0x00) &&
((mouse_last_state_button[devno] & (0x01<<it))==(0x01<<it))) ((mouse_last_state_button[devno] & (0x01 << it)) ==
{ (0x01 << it))) {
SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
} }
} }
mouse_last_state_button[devno]=packet->buttons; mouse_last_state_button[devno] = packet->buttons;
} }
/* Send mouse wheel events */ /* Send mouse wheel events */
if (packet->wheel!=0) if (packet->wheel != 0) {
{
/* Send vertical wheel event only */ /* Send vertical wheel event only */
SDL_SendMouseWheel(0, 0, packet->wheel); SDL_SendMouseWheel(0, 0, packet->wheel);
} }
...@@ -859,65 +797,61 @@ static void hiddi_mouse_handler(uint32_t devno, uint8_t* report_data, uint32_t r ...@@ -859,65 +797,61 @@ static void hiddi_mouse_handler(uint32_t devno, uint8_t* report_data, uint32_t r
break; break;
case 4: /* 4 bytes of report length, usually PS/2 mice */ case 4: /* 4 bytes of report length, usually PS/2 mice */
{ {
mouse_packet4* packet; mouse_packet4 *packet;
packet=(mouse_packet4*)report_data; packet = (mouse_packet4 *) report_data;
/* Send motion event if motion really was */ /* Send motion event if motion really was */
if ((packet->horizontal!=0) || (packet->vertical!=0)) if ((packet->horizontal != 0) || (packet->vertical != 0)) {
{ SDL_SendMouseMotion(0, 1, packet->horizontal,
SDL_SendMouseMotion(0, 1, packet->horizontal, packet->vertical, 0); packet->vertical, 0);
} }
/* Send mouse button press/release events */ /* Send mouse button press/release events */
if (mouse_last_state_button[devno]!=packet->buttons) if (mouse_last_state_button[devno] != packet->buttons) {
{
/* Cycle all buttons status */ /* Cycle all buttons status */
for (it=0; it<8; it++) for (it = 0; it < 8; it++) {
{
/* convert hiddi button id to sdl button id */ /* convert hiddi button id to sdl button id */
switch(it) switch (it) {
{
case 0: case 0:
{ {
sdlbutton=SDL_BUTTON_LEFT; sdlbutton = SDL_BUTTON_LEFT;
} }
break; break;
case 1: case 1:
{ {
sdlbutton=SDL_BUTTON_RIGHT; sdlbutton = SDL_BUTTON_RIGHT;
} }
break; break;
case 2: case 2:
{ {
sdlbutton=SDL_BUTTON_MIDDLE; sdlbutton = SDL_BUTTON_MIDDLE;
} }
break; break;
default: default:
{ {
sdlbutton=it+1; sdlbutton = it + 1;
} }
break; break;
} }
/* Button pressed */ /* Button pressed */
if (((packet->buttons & (0x01<<it))==(0x01<<it)) && if (((packet->buttons & (0x01 << it)) == (0x01 << it)) &&
((mouse_last_state_button[devno] & (0x01<<it))==0x00)) ((mouse_last_state_button[devno] & (0x01 << it)) ==
{ 0x00)) {
SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton); SDL_SendMouseButton(0, SDL_PRESSED, sdlbutton);
} }
/* Button released */ /* Button released */
if (((packet->buttons & (0x01<<it))==0x00) && if (((packet->buttons & (0x01 << it)) == 0x00) &&
((mouse_last_state_button[devno] & (0x01<<it))==(0x01<<it))) ((mouse_last_state_button[devno] & (0x01 << it)) ==
{ (0x01 << it))) {
SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton); SDL_SendMouseButton(0, SDL_RELEASED, sdlbutton);
} }
} }
mouse_last_state_button[devno]=packet->buttons; mouse_last_state_button[devno] = packet->buttons;
} }
/* Send mouse wheel events */ /* Send mouse wheel events */
if (packet->wheel!=0) if (packet->wheel != 0) {
{
/* Send vertical wheel event only */ /* Send vertical wheel event only */
SDL_SendMouseWheel(0, 0, packet->wheel); SDL_SendMouseWheel(0, 0, packet->wheel);
} }
...@@ -929,107 +863,121 @@ static void hiddi_mouse_handler(uint32_t devno, uint8_t* report_data, uint32_t r ...@@ -929,107 +863,121 @@ static void hiddi_mouse_handler(uint32_t devno, uint8_t* report_data, uint32_t r
/*****************************************************************************/ /*****************************************************************************/
/* HIDDI interacting code */ /* HIDDI interacting code */
/*****************************************************************************/ /*****************************************************************************/
static hidd_device_ident_t hiddevice= static hidd_device_ident_t hiddevice = {
{
HIDD_CONNECT_WILDCARD, /* vendor id: any */ HIDD_CONNECT_WILDCARD, /* vendor id: any */
HIDD_CONNECT_WILDCARD, /* product id: any */ HIDD_CONNECT_WILDCARD, /* product id: any */
HIDD_CONNECT_WILDCARD, /* version: any */ HIDD_CONNECT_WILDCARD, /* version: any */
}; };
static hidd_connect_parm_t hidparams={NULL, HID_VERSION, HIDD_VERSION, 0, 0, &hiddevice, NULL, 0}; static hidd_connect_parm_t hidparams =
{ NULL, HID_VERSION, HIDD_VERSION, 0, 0, &hiddevice, NULL, 0 };
static void hiddi_insertion(struct hidd_connection* connection, hidd_device_instance_t* device_instance); static void hiddi_insertion(struct hidd_connection *connection,
static void hiddi_removal(struct hidd_connection* connection, hidd_device_instance_t* instance); hidd_device_instance_t * device_instance);
static void hiddi_report(struct hidd_connection* connection, struct hidd_report* report, void* report_data, uint32_t report_len, uint32_t flags, void* user); static void hiddi_removal(struct hidd_connection *connection,
hidd_device_instance_t * instance);
static void hiddi_report(struct hidd_connection *connection,
struct hidd_report *report, void *report_data,
uint32_t report_len, uint32_t flags, void *user);
static hidd_funcs_t hidfuncs={_HIDDI_NFUNCS, hiddi_insertion, hiddi_removal, hiddi_report, NULL}; static hidd_funcs_t hidfuncs =
{ _HIDDI_NFUNCS, hiddi_insertion, hiddi_removal, hiddi_report, NULL };
/* HID handle, singletone */ /* HID handle, singletone */
struct hidd_connection* connection=NULL; struct hidd_connection *connection = NULL;
/* SDL detected input device types, singletone */ /* SDL detected input device types, singletone */
static uint32_t sdl_input_devices[SDL_HIDDI_MAX_DEVICES]; static uint32_t sdl_input_devices[SDL_HIDDI_MAX_DEVICES];
static int hiddi_register_for_reports(struct hidd_collection* col, hidd_device_instance_t* device_instance) static int
hiddi_register_for_reports(struct hidd_collection *col,
hidd_device_instance_t * device_instance)
{ {
int it; int it;
uint16_t num_col; uint16_t num_col;
struct hidd_collection** hidd_collections; struct hidd_collection **hidd_collections;
struct hidd_report_instance* report_instance; struct hidd_report_instance *report_instance;
struct hidd_report* report; struct hidd_report *report;
int status=0; int status = 0;
hidview_device_t* device; hidview_device_t *device;
for (it=0 ; it<10 && !status; it++) for (it = 0; it < 10 && !status; it++) {
{ status =
status=hidd_get_report_instance(col, it, HID_INPUT_REPORT, &report_instance); hidd_get_report_instance(col, it, HID_INPUT_REPORT,
if (status==EOK) &report_instance);
{ if (status == EOK) {
status=hidd_report_attach(connection, device_instance, report_instance, 0, sizeof(hidview_device_t), &report); status =
if (status==EOK) hidd_report_attach(connection, device_instance,
{ report_instance, 0,
device=hidd_report_extra(report); sizeof(hidview_device_t), &report);
device->report=report; if (status == EOK) {
device->instance=report_instance; device = hidd_report_extra(report);
device->report = report;
device->instance = report_instance;
} }
} }
} }
hidd_get_collections(NULL, col, &hidd_collections, &num_col); hidd_get_collections(NULL, col, &hidd_collections, &num_col);
for (it=0; it<num_col; it++) for (it = 0; it < num_col; it++) {
{
hiddi_register_for_reports(hidd_collections[it], device_instance); hiddi_register_for_reports(hidd_collections[it], device_instance);
} }
return EOK; return EOK;
} }
static void hiddi_insertion(struct hidd_connection* connection, hidd_device_instance_t* device_instance) static void
hiddi_insertion(struct hidd_connection *connection,
hidd_device_instance_t * device_instance)
{ {
uint32_t it; uint32_t it;
struct hidd_collection** hidd_collections; struct hidd_collection **hidd_collections;
uint16_t num_col; uint16_t num_col;
/* get root level collections */ /* get root level collections */
hidd_get_collections(device_instance, NULL, &hidd_collections, &num_col); hidd_get_collections(device_instance, NULL, &hidd_collections, &num_col);
for (it=0; it<num_col; it++) for (it = 0; it < num_col; it++) {
{
hiddi_register_for_reports(hidd_collections[it], device_instance); hiddi_register_for_reports(hidd_collections[it], device_instance);
} }
} }
static void hiddi_removal(struct hidd_connection* connection, hidd_device_instance_t* instance) static void
hiddi_removal(struct hidd_connection *connection,
hidd_device_instance_t * instance)
{ {
hidd_reports_detach(connection, instance); hidd_reports_detach(connection, instance);
} }
static void hiddi_report(struct hidd_connection* connection, hidd_report_t* report, void* report_data, uint32_t report_len, uint32_t flags, void* user) static void
hiddi_report(struct hidd_connection *connection, hidd_report_t * report,
void *report_data, uint32_t report_len, uint32_t flags,
void *user)
{ {
if (report->dev_inst->devno>=SDL_HIDDI_MAX_DEVICES) if (report->dev_inst->devno >= SDL_HIDDI_MAX_DEVICES) {
{
/* Unknown HID device, with devno number out of supported range */ /* Unknown HID device, with devno number out of supported range */
return; return;
} }
/* Check device type which generates event */ /* Check device type which generates event */
switch (sdl_input_devices[report->dev_inst->devno]) switch (sdl_input_devices[report->dev_inst->devno]) {
{
case SDL_GF_HIDDI_NONE: case SDL_GF_HIDDI_NONE:
{ {
/* We do not handle other devices type*/ /* We do not handle other devices type */
return; return;
} }
break; break;
case SDL_GF_HIDDI_MOUSE: case SDL_GF_HIDDI_MOUSE:
{ {
/* Call mouse handler */ /* Call mouse handler */
hiddi_mouse_handler(report->dev_inst->devno, report_data, report_len); hiddi_mouse_handler(report->dev_inst->devno, report_data,
report_len);
} }
break; break;
case SDL_GF_HIDDI_KEYBOARD: case SDL_GF_HIDDI_KEYBOARD:
{ {
/* Call keyboard handler */ /* Call keyboard handler */
hiddi_keyboard_handler(report->dev_inst->devno, report_data, report_len); hiddi_keyboard_handler(report->dev_inst->devno, report_data,
report_len);
} }
break; break;
case SDL_GF_HIDDI_JOYSTICK: case SDL_GF_HIDDI_JOYSTICK:
...@@ -1040,45 +988,39 @@ static void hiddi_report(struct hidd_connection* connection, hidd_report_t* repo ...@@ -1040,45 +988,39 @@ static void hiddi_report(struct hidd_connection* connection, hidd_report_t* repo
} }
} }
static hiddi_get_device_type(uint8_t* report_data, uint16_t report_length) static
hiddi_get_device_type(uint8_t * report_data, uint16_t report_length)
{ {
hid_byte_t byte; hid_byte_t byte;
uint16_t usage_page=0; uint16_t usage_page = 0;
uint16_t usage=0; uint16_t usage = 0;
uint16_t data=0; uint16_t data = 0;
while (report_length && !(usage_page && usage)) while (report_length && !(usage_page && usage)) {
{ if (hidp_analyse_byte(*report_data, &byte)) {
if (hidp_analyse_byte(*report_data, &byte))
{
/* Error in parser, do nothing */ /* Error in parser, do nothing */
} }
data=hidp_get_data((report_data+1), &byte); data = hidp_get_data((report_data + 1), &byte);
switch (byte.HIDB_Type) switch (byte.HIDB_Type) {
{
case HID_TYPE_GLOBAL: case HID_TYPE_GLOBAL:
if (!usage_page && byte.HIDB_Tag==HID_GLOBAL_USAGE_PAGE) if (!usage_page && byte.HIDB_Tag == HID_GLOBAL_USAGE_PAGE) {
{ usage_page = data;
usage_page=data;
} }
break; break;
case HID_TYPE_LOCAL: case HID_TYPE_LOCAL:
if (!usage && byte.HIDB_Tag==HID_LOCAL_USAGE) if (!usage && byte.HIDB_Tag == HID_LOCAL_USAGE) {
{ usage = data;
usage=data;
} }
break; break;
} }
report_data+=byte.HIDB_Length+1; report_data += byte.HIDB_Length + 1;
report_length-=byte.HIDB_Length+1; report_length -= byte.HIDB_Length + 1;
} }
switch (usage_page) switch (usage_page) {
{
case HIDD_PAGE_DESKTOP: case HIDD_PAGE_DESKTOP:
{ {
switch (usage) switch (usage) {
{
case HIDD_USAGE_MOUSE: case HIDD_USAGE_MOUSE:
{ {
return SDL_GF_HIDDI_MOUSE; return SDL_GF_HIDDI_MOUSE;
...@@ -1112,84 +1054,85 @@ static hiddi_get_device_type(uint8_t* report_data, uint16_t report_length) ...@@ -1112,84 +1054,85 @@ static hiddi_get_device_type(uint8_t* report_data, uint16_t report_length)
return SDL_GF_HIDDI_NONE; return SDL_GF_HIDDI_NONE;
} }
static int32_t hiddi_connect_devices() static int32_t
hiddi_connect_devices()
{ {
int32_t status; int32_t status;
uint32_t it; uint32_t it;
uint8_t* report_data; uint8_t *report_data;
uint16_t report_length; uint16_t report_length;
hidd_device_instance_t instance; hidd_device_instance_t instance;
/* Cleanup initial keys and mice state */ /* Cleanup initial keys and mice state */
SDL_memset(key_last_state, 0x00, sizeof(key_packet)*SDL_HIDDI_MAX_DEVICES); SDL_memset(key_last_state, 0x00,
SDL_memset(mouse_last_state_button, 0x00, sizeof(uint32_t)*SDL_HIDDI_MAX_DEVICES); sizeof(key_packet) * SDL_HIDDI_MAX_DEVICES);
SDL_memset(mouse_last_state_button, 0x00,
sizeof(uint32_t) * SDL_HIDDI_MAX_DEVICES);
status=hidd_connect(&hidparams, &connection); status = hidd_connect(&hidparams, &connection);
if (status!=EOK) if (status != EOK) {
{
return -1; return -1;
} }
for (it=0; it<SDL_HIDDI_MAX_DEVICES; it++) for (it = 0; it < SDL_HIDDI_MAX_DEVICES; it++) {
{
/* Get device instance */ /* Get device instance */
status=hidd_get_device_instance(connection, it, &instance); status = hidd_get_device_instance(connection, it, &instance);
if (status!=EOK) if (status != EOK) {
{
continue; continue;
} }
status=hidd_get_report_desc(connection, &instance, &report_data, &report_length); status =
if (status!=EOK) hidd_get_report_desc(connection, &instance, &report_data,
{ &report_length);
if (status != EOK) {
continue; continue;
} }
status=hiddi_get_device_type(report_data, report_length); status = hiddi_get_device_type(report_data, report_length);
sdl_input_devices[it]=status; sdl_input_devices[it] = status;
free(report_data); free(report_data);
} }
/* Disconnect from HID server */ /* Disconnect from HID server */
status=hidd_disconnect(connection); status = hidd_disconnect(connection);
if (status!=EOK) if (status != EOK) {
{
return -1; return -1;
} }
/* Add handlers for HID devices */ /* Add handlers for HID devices */
hidparams.funcs=&hidfuncs; hidparams.funcs = &hidfuncs;
status=hidd_connect(&hidparams, &connection); status = hidd_connect(&hidparams, &connection);
if (status!=EOK) if (status != EOK) {
{
return -1; return -1;
} }
return 0; return 0;
} }
static int32_t hiddi_disconnect_devices() static int32_t
hiddi_disconnect_devices()
{ {
int32_t status; int32_t status;
hiddi_disable_mouse(); hiddi_disable_mouse();
/* Disconnect from HID server */ /* Disconnect from HID server */
status=hidd_disconnect(connection); status = hidd_disconnect(connection);
if (status!=EOK) if (status != EOK) {
{
return -1; return -1;
} }
} }
void hiddi_enable_mouse() void
hiddi_enable_mouse()
{ {
collect_reports=1; collect_reports = 1;
} }
void hiddi_disable_mouse() void
hiddi_disable_mouse()
{ {
collect_reports=0; collect_reports = 0;
} }
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
typedef struct SDL_MouseData typedef struct SDL_MouseData
{ {
SDL_DisplayData* didata; SDL_DisplayData *didata;
} SDL_MouseData; } SDL_MouseData;
int32_t gf_addinputdevices(_THIS); int32_t gf_addinputdevices(_THIS);
...@@ -90,29 +90,29 @@ typedef struct _hidd_local_item ...@@ -90,29 +90,29 @@ typedef struct _hidd_local_item
uint16_t type; uint16_t type;
uint8_t reserved[2]; uint8_t reserved[2];
uint32_t value; uint32_t value;
struct _hidd_local_item* next_local; struct _hidd_local_item *next_local;
struct _hidd_local_item* alt_local; struct _hidd_local_item *alt_local;
} hidd_local_item_t; } hidd_local_item_t;
typedef struct _hidd_local_table typedef struct _hidd_local_table
{ {
hidd_local_item_t* usage_info; hidd_local_item_t *usage_info;
hidd_local_item_t* designator_info; hidd_local_item_t *designator_info;
hidd_local_item_t* string_info; hidd_local_item_t *string_info;
uint8_t delimiter; uint8_t delimiter;
uint8_t reserved[3]; uint8_t reserved[3];
} hidd_local_table_t; } hidd_local_table_t;
typedef struct _hidd_field typedef struct _hidd_field
{ {
struct hidd_report_instance* report; struct hidd_report_instance *report;
struct hidd_collection* collection; struct hidd_collection *collection;
uint16_t report_offset; uint16_t report_offset;
uint16_t flags; uint16_t flags;
hidd_global_item_t gitem; hidd_global_item_t gitem;
hidd_local_table_t* ltable; hidd_local_table_t *ltable;
struct _hidd_field* next_field; struct _hidd_field *next_field;
void* user; void *user;
} hidd_field_t; } hidd_field_t;
typedef struct hidd_report_instance typedef struct hidd_report_instance
...@@ -120,30 +120,30 @@ typedef struct hidd_report_instance ...@@ -120,30 +120,30 @@ typedef struct hidd_report_instance
uint8_t report_id; uint8_t report_id;
uint8_t reserved[1]; uint8_t reserved[1];
uint16_t report_type; uint16_t report_type;
hidd_field_t* field; hidd_field_t *field;
uint16_t num_field; uint16_t num_field;
uint16_t byte_len; uint16_t byte_len;
uint16_t bit_len; uint16_t bit_len;
uint8_t reserved2[2]; uint8_t reserved2[2];
struct hidd_collection* collection; struct hidd_collection *collection;
struct hidd_report_instance* next_col_report; struct hidd_report_instance *next_col_report;
struct hidd_report_instance* next_report; struct hidd_report_instance *next_report;
} hidd_report_instance_t; } hidd_report_instance_t;
typedef struct hidd_report typedef struct hidd_report
{ {
TAILQ_ENTRY(hidd_report) link; TAILQ_ENTRY(hidd_report) link;
hidd_report_instance_t* rinst; hidd_report_instance_t *rinst;
hidd_device_instance_t* dev_inst; hidd_device_instance_t *dev_inst;
uint32_t flags; uint32_t flags;
struct hidd_connection* connection; struct hidd_connection *connection;
void* user; void *user;
} hidd_report_t; } hidd_report_t;
typedef struct hidview_device typedef struct hidview_device
{ {
struct hidd_report_instance* instance; struct hidd_report_instance *instance;
struct hidd_report* report; struct hidd_report *report;
} hidview_device_t; } hidview_device_t;
/*****************************************************************************/ /*****************************************************************************/
......
...@@ -30,21 +30,25 @@ ...@@ -30,21 +30,25 @@
/* This is OpenGL ES 1.0 helper functions from OpenGL ES 1.1 specification, */ /* This is OpenGL ES 1.0 helper functions from OpenGL ES 1.1 specification, */
/* which could be implemented independently from hardware, just wrappers */ /* which could be implemented independently from hardware, just wrappers */
GLAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param) GLAPI void APIENTRY
glTexParameteri(GLenum target, GLenum pname, GLint param)
{ {
glTexParameterx(target, pname, (GLfixed)param); glTexParameterx(target, pname, (GLfixed) param);
return; return;
} }
GLAPI void APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params) GLAPI void APIENTRY
glTexParameteriv(GLenum target, GLenum pname, const GLint * params)
{ {
/* Retrieve one parameter only */ /* Retrieve one parameter only */
glTexParameterx(target, pname, (GLfixed)*params); glTexParameterx(target, pname, (GLfixed) * params);
return; return;
} }
GLAPI void APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) GLAPI void APIENTRY
glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
{ {
glColor4f(((GLfloat)red)/255.f, ((GLfloat)green)/255.f, ((GLfloat)blue)/255.f, ((GLfloat)alpha)/255.f); glColor4f(((GLfloat) red) / 255.f, ((GLfloat) green) / 255.f,
((GLfloat) blue) / 255.f, ((GLfloat) alpha) / 255.f);
return; return;
} }
...@@ -31,7 +31,9 @@ ...@@ -31,7 +31,9 @@
#include <GLES/glext.h> #include <GLES/glext.h>
GLAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param); GLAPI void APIENTRY glTexParameteri(GLenum target, GLenum pname, GLint param);
GLAPI void APIENTRY glTexParameteriv(GLenum target, GLenum pname, const GLint* params); GLAPI void APIENTRY glTexParameteriv(GLenum target, GLenum pname,
GLAPI void APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha); const GLint * params);
GLAPI void APIENTRY glColor4ub(GLubyte red, GLubyte green, GLubyte blue,
GLubyte alpha);
#endif /* __SDL_GF_OPENGLES_H__ */ #endif /* __SDL_GF_OPENGLES_H__ */
...@@ -27,10 +27,10 @@ ...@@ -27,10 +27,10 @@
#include "SDL_config.h" #include "SDL_config.h"
#include "SDL_gf_pixelfmt.h" #include "SDL_gf_pixelfmt.h"
gf_format_t qnxgf_sdl_to_gf_pixelformat(uint32_t pixelfmt) gf_format_t
qnxgf_sdl_to_gf_pixelformat(uint32_t pixelfmt)
{ {
switch(pixelfmt) switch (pixelfmt) {
{
case SDL_PIXELFORMAT_INDEX8: case SDL_PIXELFORMAT_INDEX8:
{ {
return GF_FORMAT_PAL8; return GF_FORMAT_PAL8;
...@@ -91,10 +91,10 @@ gf_format_t qnxgf_sdl_to_gf_pixelformat(uint32_t pixelfmt) ...@@ -91,10 +91,10 @@ gf_format_t qnxgf_sdl_to_gf_pixelformat(uint32_t pixelfmt)
return GF_FORMAT_INVALID; return GF_FORMAT_INVALID;
} }
uint32_t qnxgf_gf_to_sdl_pixelformat(gf_format_t pixelfmt) uint32_t
qnxgf_gf_to_sdl_pixelformat(gf_format_t pixelfmt)
{ {
switch(pixelfmt) switch (pixelfmt) {
{
case GF_FORMAT_PAL8: case GF_FORMAT_PAL8:
{ {
return SDL_PIXELFORMAT_INDEX8; return SDL_PIXELFORMAT_INDEX8;
......
...@@ -34,31 +34,48 @@ ...@@ -34,31 +34,48 @@
#include "SDL_gf_render.h" #include "SDL_gf_render.h"
#include "SDL_qnxgf.h" #include "SDL_qnxgf.h"
static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags); static SDL_Renderer *gf_createrenderer(SDL_Window * window, Uint32 flags);
static int gf_displaymodechanged(SDL_Renderer* renderer); static int gf_displaymodechanged(SDL_Renderer * renderer);
static int gf_activaterenderer(SDL_Renderer* renderer); static int gf_activaterenderer(SDL_Renderer * renderer);
static int gf_createtexture(SDL_Renderer* renderer, SDL_Texture* texture); static int gf_createtexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int gf_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch); static int gf_querytexturepixels(SDL_Renderer * renderer,
static int gf_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors); SDL_Texture * texture, void **pixels,
static int gf_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors); int *pitch);
static int gf_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture); static int gf_settexturepalette(SDL_Renderer * renderer,
static int gf_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture); SDL_Texture * texture,
static int gf_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture); const SDL_Color * colors, int firstcolor,
static int gf_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture); int ncolors);
static int gf_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch); static int gf_gettexturepalette(SDL_Renderer * renderer,
static int gf_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch); SDL_Texture * texture, SDL_Color * colors,
static void gf_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture); int firstcolor, int ncolors);
static void gf_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects); static int gf_settexturecolormod(SDL_Renderer * renderer,
static int gf_renderpoint(SDL_Renderer* renderer, int x, int y); SDL_Texture * texture);
static int gf_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2); static int gf_settexturealphamod(SDL_Renderer * renderer,
static int gf_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect); SDL_Texture * texture);
static int gf_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect); static int gf_settextureblendmode(SDL_Renderer * renderer,
static void gf_renderpresent(SDL_Renderer* renderer); SDL_Texture * texture);
static void gf_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture); static int gf_settexturescalemode(SDL_Renderer * renderer,
static void gf_destroyrenderer(SDL_Renderer* renderer); SDL_Texture * texture);
static int gf_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_RenderDriver gf_renderdriver= const SDL_Rect * rect, const void *pixels,
{ int pitch);
static int gf_locktexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch);
static void gf_unlocktexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void gf_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture,
int numrects, const SDL_Rect * rects);
static int gf_renderpoint(SDL_Renderer * renderer, int x, int y);
static int gf_renderline(SDL_Renderer * renderer, int x1, int y1, int x2,
int y2);
static int gf_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect);
static int gf_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static void gf_renderpresent(SDL_Renderer * renderer);
static void gf_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void gf_destroyrenderer(SDL_Renderer * renderer);
SDL_RenderDriver gf_renderdriver = {
gf_createrenderer, gf_createrenderer,
{ {
"qnxgf", "qnxgf",
...@@ -85,66 +102,62 @@ SDL_RenderDriver gf_renderdriver= ...@@ -85,66 +102,62 @@ SDL_RenderDriver gf_renderdriver=
SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_YV12,
SDL_PIXELFORMAT_YUY2, SDL_PIXELFORMAT_YUY2,
SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_UYVY,
SDL_PIXELFORMAT_YVYU SDL_PIXELFORMAT_YVYU},
},
0, 0,
0 0}
}
}; };
static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags) static SDL_Renderer *
gf_createrenderer(SDL_Window * window, Uint32 flags)
{ {
SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata; SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
SDL_WindowData* wdata = (SDL_WindowData*)window->driverdata; SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
SDL_Renderer* renderer = NULL; SDL_Renderer *renderer = NULL;
SDL_RenderData* rdata = NULL; SDL_RenderData *rdata = NULL;
uint32_t it; uint32_t it;
int32_t jt; int32_t jt;
int32_t status; int32_t status;
/* Check if it is OpenGL ES window */ /* Check if it is OpenGL ES window */
if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL) if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
{
/* No error, just no need to create 2D renderer for OpenGL ES window */ /* No error, just no need to create 2D renderer for OpenGL ES window */
return NULL; return NULL;
} }
/* Allocate new renderer structure */ /* Allocate new renderer structure */
renderer=(SDL_Renderer*)SDL_calloc(1, sizeof(SDL_Renderer)); renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(SDL_Renderer));
if (renderer==NULL) if (renderer == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
/* Allocate renderer data */ /* Allocate renderer data */
rdata=(SDL_RenderData*)SDL_calloc(1, sizeof(SDL_RenderData)); rdata = (SDL_RenderData *) SDL_calloc(1, sizeof(SDL_RenderData));
if (rdata==NULL) if (rdata == NULL) {
{
SDL_free(renderer); SDL_free(renderer);
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
renderer->DisplayModeChanged=gf_displaymodechanged; renderer->DisplayModeChanged = gf_displaymodechanged;
renderer->ActivateRenderer=gf_activaterenderer; renderer->ActivateRenderer = gf_activaterenderer;
renderer->CreateTexture=gf_createtexture; renderer->CreateTexture = gf_createtexture;
renderer->QueryTexturePixels=gf_querytexturepixels; renderer->QueryTexturePixels = gf_querytexturepixels;
renderer->SetTexturePalette=gf_settexturepalette; renderer->SetTexturePalette = gf_settexturepalette;
renderer->GetTexturePalette=gf_gettexturepalette; renderer->GetTexturePalette = gf_gettexturepalette;
renderer->SetTextureAlphaMod=gf_settexturealphamod; renderer->SetTextureAlphaMod = gf_settexturealphamod;
renderer->SetTextureColorMod=gf_settexturecolormod; renderer->SetTextureColorMod = gf_settexturecolormod;
renderer->SetTextureBlendMode=gf_settextureblendmode; renderer->SetTextureBlendMode = gf_settextureblendmode;
renderer->SetTextureScaleMode=gf_settexturescalemode; renderer->SetTextureScaleMode = gf_settexturescalemode;
renderer->UpdateTexture=gf_updatetexture; renderer->UpdateTexture = gf_updatetexture;
renderer->LockTexture=gf_locktexture; renderer->LockTexture = gf_locktexture;
renderer->UnlockTexture=gf_unlocktexture; renderer->UnlockTexture = gf_unlocktexture;
renderer->DirtyTexture=gf_dirtytexture; renderer->DirtyTexture = gf_dirtytexture;
renderer->RenderPoint=gf_renderpoint; renderer->RenderPoint = gf_renderpoint;
renderer->RenderLine=gf_renderline; renderer->RenderLine = gf_renderline;
renderer->RenderFill=gf_renderfill; renderer->RenderFill = gf_renderfill;
renderer->RenderCopy=gf_rendercopy; renderer->RenderCopy = gf_rendercopy;
renderer->RenderPresent = gf_renderpresent; renderer->RenderPresent = gf_renderpresent;
renderer->DestroyTexture = gf_destroytexture; renderer->DestroyTexture = gf_destroytexture;
renderer->DestroyRenderer = gf_destroyrenderer; renderer->DestroyRenderer = gf_destroyrenderer;
...@@ -153,98 +166,83 @@ static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags) ...@@ -153,98 +166,83 @@ static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags)
renderer->driverdata = rdata; renderer->driverdata = rdata;
/* Set render acceleration flag in case it is accelerated */ /* Set render acceleration flag in case it is accelerated */
if ((didata->caps & SDL_GF_ACCELERATED)==SDL_GF_ACCELERATED) if ((didata->caps & SDL_GF_ACCELERATED) == SDL_GF_ACCELERATED) {
{ renderer->info.flags = SDL_RENDERER_ACCELERATED;
renderer->info.flags=SDL_RENDERER_ACCELERATED; } else {
} renderer->info.flags &= ~(SDL_RENDERER_ACCELERATED);
else
{
renderer->info.flags&=~(SDL_RENDERER_ACCELERATED);
} }
rdata->window=window; rdata->window = window;
/* Check if upper level requested synchronization on vsync signal */ /* Check if upper level requested synchronization on vsync signal */
if ((flags & SDL_RENDERER_PRESENTVSYNC)==SDL_RENDERER_PRESENTVSYNC) if ((flags & SDL_RENDERER_PRESENTVSYNC) == SDL_RENDERER_PRESENTVSYNC) {
{ rdata->enable_vsync = SDL_TRUE;
rdata->enable_vsync=SDL_TRUE; } else {
} rdata->enable_vsync = SDL_FALSE;
else
{
rdata->enable_vsync=SDL_FALSE;
} }
/* Check what buffer copy/flip scheme is requested */ /* Check what buffer copy/flip scheme is requested */
rdata->surfaces_count=0; rdata->surfaces_count = 0;
if ((flags & SDL_RENDERER_SINGLEBUFFER)==SDL_RENDERER_SINGLEBUFFER) if ((flags & SDL_RENDERER_SINGLEBUFFER) == SDL_RENDERER_SINGLEBUFFER) {
{ if ((flags & SDL_RENDERER_PRESENTDISCARD) ==
if ((flags & SDL_RENDERER_PRESENTDISCARD)==SDL_RENDERER_PRESENTDISCARD) SDL_RENDERER_PRESENTDISCARD) {
{ renderer->info.flags |=
renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD; SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD;
} else {
renderer->info.flags |=
SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
} }
else rdata->surfaces_count = 1;
{ rdata->surface_visible_idx = 0;
renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY; rdata->surface_render_idx = 0;
} } else {
rdata->surfaces_count=1; if ((flags & SDL_RENDERER_PRESENTFLIP2) == SDL_RENDERER_PRESENTFLIP2) {
rdata->surface_visible_idx=0; renderer->info.flags |= SDL_RENDERER_PRESENTFLIP2;
rdata->surface_render_idx=0; rdata->surfaces_count = 2;
} rdata->surface_visible_idx = 0;
else rdata->surface_render_idx = 1;
{ } else {
if ((flags & SDL_RENDERER_PRESENTFLIP2)==SDL_RENDERER_PRESENTFLIP2) if ((flags & SDL_RENDERER_PRESENTFLIP3) ==
{ SDL_RENDERER_PRESENTFLIP3) {
renderer->info.flags|=SDL_RENDERER_PRESENTFLIP2; renderer->info.flags |= SDL_RENDERER_PRESENTFLIP3;
rdata->surfaces_count=2; rdata->surfaces_count = 3;
rdata->surface_visible_idx=0; rdata->surface_visible_idx = 0;
rdata->surface_render_idx=1; rdata->surface_render_idx = 1;
} } else {
else renderer->info.flags |=
{ SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
if ((flags & SDL_RENDERER_PRESENTFLIP3)==SDL_RENDERER_PRESENTFLIP3) rdata->surfaces_count = 1;
{ rdata->surface_visible_idx = 0;
renderer->info.flags|=SDL_RENDERER_PRESENTFLIP3; rdata->surface_render_idx = 0;
rdata->surfaces_count=3;
rdata->surface_visible_idx=0;
rdata->surface_render_idx=1;
}
else
{
renderer->info.flags|=SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY;
rdata->surfaces_count=1;
rdata->surface_visible_idx=0;
rdata->surface_render_idx=0;
} }
} }
} }
/* Create layer surfaces, which could be visible */ /* Create layer surfaces, which could be visible */
for (it=0; it<rdata->surfaces_count; it++) for (it = 0; it < rdata->surfaces_count; it++) {
{
/* TODO: add palette creation */ /* TODO: add palette creation */
/* Create displayable surfaces */ /* Create displayable surfaces */
status=gf_surface_create_layer(&rdata->surface[it], &didata->layer, 1, 0, status =
didata->current_mode.w, didata->current_mode.h, gf_surface_create_layer(&rdata->surface[it], &didata->layer, 1, 0,
qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), NULL, didata->current_mode.w,
didata->current_mode.h,
qnxgf_sdl_to_gf_pixelformat(didata->
current_mode.
format), NULL,
GF_SURFACE_CREATE_2D_ACCESSIBLE); GF_SURFACE_CREATE_2D_ACCESSIBLE);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
/* Free already allocated surfaces */ /* Free already allocated surfaces */
for (jt=it-1; jt>0; jt--) for (jt = it - 1; jt > 0; jt--) {
{
gf_surface_free(rdata->surface[jt]); gf_surface_free(rdata->surface[jt]);
rdata->surface[jt]=NULL; rdata->surface[jt] = NULL;
} }
SDL_free(rdata); SDL_free(rdata);
SDL_free(renderer); SDL_free(renderer);
if (status==GF_ERR_MEM) if (status == GF_ERR_MEM) {
{
SDL_SetError("unsufficient free video memory"); SDL_SetError("unsufficient free video memory");
} } else {
else
{
SDL_SetError("error during displayable surface creation"); SDL_SetError("error during displayable surface creation");
} }
return NULL; return NULL;
...@@ -257,12 +255,12 @@ static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags) ...@@ -257,12 +255,12 @@ static SDL_Renderer* gf_createrenderer(SDL_Window* window, Uint32 flags)
return renderer; return renderer;
} }
void gf_addrenderdriver(_THIS) void
gf_addrenderdriver(_THIS)
{ {
uint32_t it; uint32_t it;
for (it=0; it<_this->num_displays; it++) for (it = 0; it < _this->num_displays; it++) {
{
SDL_AddRenderDriver(it, &gf_renderdriver); SDL_AddRenderDriver(it, &gf_renderdriver);
} }
} }
...@@ -270,9 +268,10 @@ void gf_addrenderdriver(_THIS) ...@@ -270,9 +268,10 @@ void gf_addrenderdriver(_THIS)
/****************************************************************************/ /****************************************************************************/
/* SDL render interface */ /* SDL render interface */
/****************************************************************************/ /****************************************************************************/
static int gf_displaymodechanged(SDL_Renderer* renderer) static int
gf_displaymodechanged(SDL_Renderer * renderer)
{ {
SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
/* Remove all allocated surfaces, they are no more valid */ /* Remove all allocated surfaces, they are no more valid */
...@@ -281,11 +280,12 @@ static int gf_displaymodechanged(SDL_Renderer* renderer) ...@@ -281,11 +280,12 @@ static int gf_displaymodechanged(SDL_Renderer* renderer)
return 0; return 0;
} }
static int gf_activaterenderer(SDL_Renderer* renderer) static int
gf_activaterenderer(SDL_Renderer * renderer)
{ {
SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
SDL_VideoDisplay* display = SDL_GetDisplayFromWindow(rdata->window); SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(rdata->window);
SDL_DisplayData* didata = (SDL_DisplayData*)display->driverdata; SDL_DisplayData *didata = (SDL_DisplayData *) display->driverdata;
/* Setup current surface as visible */ /* Setup current surface as visible */
// gf_layer_set_surfaces(didata->layer, &rdata->surface[rdata->surface_visible_idx], 1); // gf_layer_set_surfaces(didata->layer, &rdata->surface[rdata->surface_visible_idx], 1);
...@@ -296,103 +296,127 @@ static int gf_activaterenderer(SDL_Renderer* renderer) ...@@ -296,103 +296,127 @@ static int gf_activaterenderer(SDL_Renderer* renderer)
return 0; return 0;
} }
static int gf_createtexture(SDL_Renderer* renderer, SDL_Texture* texture) static int
gf_createtexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
SDL_RenderData* renderdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *renderdata = (SDL_RenderData *) renderer->driverdata;
SDL_Window* window=SDL_GetWindowFromID(renderer->window); SDL_Window *window = SDL_GetWindowFromID(renderer->window);
SDL_VideoDisplay* display=SDL_GetDisplayFromWindow(window); SDL_VideoDisplay *display = SDL_GetDisplayFromWindow(window);
SDL_TextureData* tdata=NULL; SDL_TextureData *tdata = NULL;
/* Allocate texture driver data */ /* Allocate texture driver data */
tdata=(SDL_TextureData*)SDL_calloc(1, sizeof(SDL_TextureData)); tdata = (SDL_TextureData *) SDL_calloc(1, sizeof(SDL_TextureData));
if (tdata==NULL) if (tdata == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
/* Set texture driver data */ /* Set texture driver data */
texture->driverdata=tdata; texture->driverdata = tdata;
} }
static int gf_querytexturepixels(SDL_Renderer* renderer, SDL_Texture* texture, void** pixels, int* pitch) static int
gf_querytexturepixels(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch)
{ {
} }
static int gf_settexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Color* colors, int firstcolor, int ncolors) static int
gf_settexturepalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
{ {
} }
static int gf_gettexturepalette(SDL_Renderer* renderer, SDL_Texture* texture, SDL_Color* colors, int firstcolor, int ncolors) static int
gf_gettexturepalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
{ {
} }
static int gf_settexturecolormod(SDL_Renderer* renderer, SDL_Texture* texture) static int
gf_settexturecolormod(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int gf_settexturealphamod(SDL_Renderer* renderer, SDL_Texture* texture) static int
gf_settexturealphamod(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int gf_settextureblendmode(SDL_Renderer* renderer, SDL_Texture* texture) static int
gf_settextureblendmode(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int gf_settexturescalemode(SDL_Renderer* renderer, SDL_Texture* texture) static int
gf_settexturescalemode(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static int gf_updatetexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, const void* pixels, int pitch) static int
gf_updatetexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{ {
} }
static int gf_locktexture(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* rect, int markDirty, void** pixels, int* pitch) static int
gf_locktexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, int markDirty, void **pixels,
int *pitch)
{ {
} }
static void gf_unlocktexture(SDL_Renderer* renderer, SDL_Texture* texture) static void
gf_unlocktexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static void gf_dirtytexture(SDL_Renderer* renderer, SDL_Texture* texture, int numrects, const SDL_Rect* rects) static void
gf_dirtytexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
const SDL_Rect * rects)
{ {
} }
static int gf_renderpoint(SDL_Renderer* renderer, int x, int y) static int
gf_renderpoint(SDL_Renderer * renderer, int x, int y)
{ {
} }
static int gf_renderline(SDL_Renderer* renderer, int x1, int y1, int x2, int y2) static int
gf_renderline(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
{ {
} }
static int gf_renderfill(SDL_Renderer* renderer, const SDL_Rect* rect) static int
gf_renderfill(SDL_Renderer * renderer, const SDL_Rect * rect)
{ {
} }
static int gf_rendercopy(SDL_Renderer* renderer, SDL_Texture* texture, const SDL_Rect* srcrect, const SDL_Rect* dstrect) static int
gf_rendercopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
{ {
} }
static void gf_renderpresent(SDL_Renderer* renderer) static void
gf_renderpresent(SDL_Renderer * renderer)
{ {
} }
static void gf_destroytexture(SDL_Renderer* renderer, SDL_Texture* texture) static void
gf_destroytexture(SDL_Renderer * renderer, SDL_Texture * texture)
{ {
} }
static void gf_destroyrenderer(SDL_Renderer* renderer) static void
gf_destroyrenderer(SDL_Renderer * renderer)
{ {
SDL_RenderData* rdata=(SDL_RenderData*)renderer->driverdata; SDL_RenderData *rdata = (SDL_RenderData *) renderer->driverdata;
uint32_t it; uint32_t it;
for (it=0; it<rdata->surfaces_count; it++) for (it = 0; it < rdata->surfaces_count; it++) {
{ if (rdata->surface[it] != NULL) {
if (rdata->surface[it]!=NULL)
{
gf_surface_free(rdata->surface[it]); gf_surface_free(rdata->surface[it]);
} }
} }
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
typedef struct SDL_RenderData typedef struct SDL_RenderData
{ {
SDL_Window* window; /* SDL window type */ SDL_Window *window; /* SDL window type */
SDL_bool enable_vsync; /* VSYNC flip synchronization enable */ SDL_bool enable_vsync; /* VSYNC flip synchronization enable */
gf_surface_t surface[SDL_GF_MAX_SURFACES]; /* Surface handles */ gf_surface_t surface[SDL_GF_MAX_SURFACES]; /* Surface handles */
gf_surface_info_t surface_info[SDL_GF_MAX_SURFACES]; /* Surface info */ gf_surface_info_t surface_info[SDL_GF_MAX_SURFACES]; /* Surface info */
......
...@@ -47,8 +47,7 @@ ...@@ -47,8 +47,7 @@
/* but some drivers are not. Later we can distinguish one driver from another */ /* but some drivers are not. Later we can distinguish one driver from another */
/* Feel free to add any new custom graphics mode */ /* Feel free to add any new custom graphics mode */
/******************************************************************************/ /******************************************************************************/
static SDL_DisplayMode generic_mode[]= static SDL_DisplayMode generic_mode[] = {
{
{0, 320, 200, 70, NULL}, /* 320x200 modes are 70Hz and 85Hz */ {0, 320, 200, 70, NULL}, /* 320x200 modes are 70Hz and 85Hz */
{0, 320, 200, 85, NULL}, {0, 320, 200, 85, NULL},
{0, 320, 240, 70, NULL}, /* 320x240 modes are 70Hz and 85Hz */ {0, 320, 240, 70, NULL}, /* 320x240 modes are 70Hz and 85Hz */
...@@ -101,8 +100,7 @@ static SDL_DisplayMode generic_mode[]= ...@@ -101,8 +100,7 @@ static SDL_DisplayMode generic_mode[]=
}; };
/* Low level device graphics driver names, which they are reporting */ /* Low level device graphics driver names, which they are reporting */
GF_DeviceCaps gf_devicename[]= GF_DeviceCaps gf_devicename[] = {
{
/* ATI Rage 128 graphics driver (devg-ati_rage128) */ /* ATI Rage 128 graphics driver (devg-ati_rage128) */
{"ati_rage128", SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION | {"ati_rage128", SDL_GF_ACCELERATED | SDL_GF_NOLOWRESOLUTION |
SDL_GF_UNACCELERATED_3D | SDL_GF_VIDEOMEMORY}, SDL_GF_UNACCELERATED_3D | SDL_GF_VIDEOMEMORY},
...@@ -195,16 +193,16 @@ GF_DeviceCaps gf_devicename[]= ...@@ -195,16 +193,16 @@ GF_DeviceCaps gf_devicename[]=
/* SDL Video Device initialization functions */ /* SDL Video Device initialization functions */
/*****************************************************************************/ /*****************************************************************************/
static int qnxgf_available(void) static int
qnxgf_available(void)
{ {
gf_dev_t gfdev; gf_dev_t gfdev;
gf_dev_info_t gfdev_info; gf_dev_info_t gfdev_info;
int status; int status;
/* Try to attach to graphics device driver */ /* Try to attach to graphics device driver */
status=gf_dev_attach(&gfdev, GF_DEVICE_INDEX(0), &gfdev_info); status = gf_dev_attach(&gfdev, GF_DEVICE_INDEX(0), &gfdev_info);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
return 0; return 0;
} }
...@@ -214,113 +212,110 @@ static int qnxgf_available(void) ...@@ -214,113 +212,110 @@ static int qnxgf_available(void)
return 1; return 1;
} }
static void qnxgf_destroy(SDL_VideoDevice* device) static void
qnxgf_destroy(SDL_VideoDevice * device)
{ {
SDL_VideoData* gfdata=(SDL_VideoData*) device->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) device->driverdata;
/* Detach from graphics device driver, if it was initialized */ /* Detach from graphics device driver, if it was initialized */
if (gfdata->gfinitialized!=SDL_FALSE) if (gfdata->gfinitialized != SDL_FALSE) {
{
gf_dev_detach(gfdata->gfdev); gf_dev_detach(gfdata->gfdev);
gfdata->gfdev=NULL; gfdata->gfdev = NULL;
} }
if (device->driverdata!=NULL) if (device->driverdata != NULL) {
{ device->driverdata = NULL;
device->driverdata=NULL;
} }
} }
static SDL_VideoDevice* qnxgf_create(int devindex) static SDL_VideoDevice *
qnxgf_create(int devindex)
{ {
SDL_VideoDevice* device; SDL_VideoDevice *device;
SDL_VideoData* gfdata; SDL_VideoData *gfdata;
int status; int status;
/* Initialize SDL_VideoDevice structure */ /* Initialize SDL_VideoDevice structure */
device=(SDL_VideoDevice*)SDL_calloc(1, sizeof(SDL_VideoDevice)); device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
if (device==NULL) if (device == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return NULL; return NULL;
} }
/* Initialize internal GF specific data */ /* Initialize internal GF specific data */
gfdata=(SDL_VideoData*)SDL_calloc(1, sizeof(SDL_VideoData)); gfdata = (SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
if (gfdata==NULL) if (gfdata == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_free(device); SDL_free(device);
return NULL; return NULL;
} }
device->driverdata=gfdata; device->driverdata = gfdata;
/* Try to attach to graphics device driver */ /* Try to attach to graphics device driver */
status=gf_dev_attach(&gfdata->gfdev, GF_DEVICE_INDEX(devindex), &gfdata->gfdev_info); status =
if (status!=GF_ERR_OK) gf_dev_attach(&gfdata->gfdev, GF_DEVICE_INDEX(devindex),
{ &gfdata->gfdev_info);
if (status != GF_ERR_OK) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_free(gfdata); SDL_free(gfdata);
SDL_free(device); SDL_free(device);
return NULL; return NULL;
} }
if (gfdata->gfdev_info.description==NULL) if (gfdata->gfdev_info.description == NULL) {
{
gf_dev_detach(gfdata->gfdev); gf_dev_detach(gfdata->gfdev);
SDL_SetError("GF: Failed to initialize graphics driver"); SDL_SetError("GF: Failed to initialize graphics driver");
return NULL; return NULL;
} }
/* Setup amount of available displays and current display */ /* Setup amount of available displays and current display */
device->num_displays=0; device->num_displays = 0;
device->current_display=0; device->current_display = 0;
/* Setup device shutdown function */ /* Setup device shutdown function */
gfdata->gfinitialized=SDL_TRUE; gfdata->gfinitialized = SDL_TRUE;
device->free=qnxgf_destroy; device->free = qnxgf_destroy;
/* Setup all functions which we can handle */ /* Setup all functions which we can handle */
device->VideoInit=qnxgf_videoinit; device->VideoInit = qnxgf_videoinit;
device->VideoQuit=qnxgf_videoquit; device->VideoQuit = qnxgf_videoquit;
device->GetDisplayModes=qnxgf_getdisplaymodes; device->GetDisplayModes = qnxgf_getdisplaymodes;
device->SetDisplayMode=qnxgf_setdisplaymode; device->SetDisplayMode = qnxgf_setdisplaymode;
device->SetDisplayPalette=qnxgf_setdisplaypalette; device->SetDisplayPalette = qnxgf_setdisplaypalette;
device->GetDisplayPalette=qnxgf_getdisplaypalette; device->GetDisplayPalette = qnxgf_getdisplaypalette;
device->SetDisplayGammaRamp=qnxgf_setdisplaygammaramp; device->SetDisplayGammaRamp = qnxgf_setdisplaygammaramp;
device->GetDisplayGammaRamp=qnxgf_getdisplaygammaramp; device->GetDisplayGammaRamp = qnxgf_getdisplaygammaramp;
device->CreateWindow=qnxgf_createwindow; device->CreateWindow = qnxgf_createwindow;
device->CreateWindowFrom=qnxgf_createwindowfrom; device->CreateWindowFrom = qnxgf_createwindowfrom;
device->SetWindowTitle=qnxgf_setwindowtitle; device->SetWindowTitle = qnxgf_setwindowtitle;
device->SetWindowIcon=qnxgf_setwindowicon; device->SetWindowIcon = qnxgf_setwindowicon;
device->SetWindowPosition=qnxgf_setwindowposition; device->SetWindowPosition = qnxgf_setwindowposition;
device->SetWindowSize=qnxgf_setwindowsize; device->SetWindowSize = qnxgf_setwindowsize;
device->ShowWindow=qnxgf_showwindow; device->ShowWindow = qnxgf_showwindow;
device->HideWindow=qnxgf_hidewindow; device->HideWindow = qnxgf_hidewindow;
device->RaiseWindow=qnxgf_raisewindow; device->RaiseWindow = qnxgf_raisewindow;
device->MaximizeWindow=qnxgf_maximizewindow; device->MaximizeWindow = qnxgf_maximizewindow;
device->MinimizeWindow=qnxgf_minimizewindow; device->MinimizeWindow = qnxgf_minimizewindow;
device->RestoreWindow=qnxgf_restorewindow; device->RestoreWindow = qnxgf_restorewindow;
device->SetWindowGrab=qnxgf_setwindowgrab; device->SetWindowGrab = qnxgf_setwindowgrab;
device->DestroyWindow=qnxgf_destroywindow; device->DestroyWindow = qnxgf_destroywindow;
device->GetWindowWMInfo=qnxgf_getwindowwminfo; device->GetWindowWMInfo = qnxgf_getwindowwminfo;
device->GL_LoadLibrary=qnxgf_gl_loadlibrary; device->GL_LoadLibrary = qnxgf_gl_loadlibrary;
device->GL_GetProcAddress=qnxgf_gl_getprocaddres; device->GL_GetProcAddress = qnxgf_gl_getprocaddres;
device->GL_UnloadLibrary=qnxgf_gl_unloadlibrary; device->GL_UnloadLibrary = qnxgf_gl_unloadlibrary;
device->GL_CreateContext=qnxgf_gl_createcontext; device->GL_CreateContext = qnxgf_gl_createcontext;
device->GL_MakeCurrent=qnxgf_gl_makecurrent; device->GL_MakeCurrent = qnxgf_gl_makecurrent;
device->GL_SetSwapInterval=qnxgf_gl_setswapinterval; device->GL_SetSwapInterval = qnxgf_gl_setswapinterval;
device->GL_GetSwapInterval=qnxgf_gl_getswapinterval; device->GL_GetSwapInterval = qnxgf_gl_getswapinterval;
device->GL_SwapWindow=qnxgf_gl_swapwindow; device->GL_SwapWindow = qnxgf_gl_swapwindow;
device->GL_DeleteContext=qnxgf_gl_deletecontext; device->GL_DeleteContext = qnxgf_gl_deletecontext;
device->PumpEvents=qnxgf_pumpevents; device->PumpEvents = qnxgf_pumpevents;
device->SuspendScreenSaver=qnxgf_suspendscreensaver; device->SuspendScreenSaver = qnxgf_suspendscreensaver;
return device; return device;
} }
VideoBootStrap qnxgf_bootstrap= VideoBootStrap qnxgf_bootstrap = {
{
"qnxgf", "qnxgf",
"SDL QNX Graphics Framework (GF) video driver", "SDL QNX Graphics Framework (GF) video driver",
qnxgf_available, qnxgf_available,
...@@ -330,131 +325,137 @@ VideoBootStrap qnxgf_bootstrap= ...@@ -330,131 +325,137 @@ VideoBootStrap qnxgf_bootstrap=
/*****************************************************************************/ /*****************************************************************************/
/* SDL Video and Display initialization/handling functions */ /* SDL Video and Display initialization/handling functions */
/*****************************************************************************/ /*****************************************************************************/
int qnxgf_videoinit(_THIS) int
qnxgf_videoinit(_THIS)
{ {
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
uint32_t it; uint32_t it;
uint32_t jt; uint32_t jt;
char* override; char *override;
int32_t status; int32_t status;
/* By default GF uses buffer swap on vsync */ /* By default GF uses buffer swap on vsync */
gfdata->swapinterval=1; gfdata->swapinterval = 1;
/* Add each detected output to SDL */ /* Add each detected output to SDL */
for (it=0; it<gfdata->gfdev_info.ndisplays; it++) for (it = 0; it < gfdata->gfdev_info.ndisplays; it++) {
{
SDL_VideoDisplay display; SDL_VideoDisplay display;
SDL_DisplayMode current_mode; SDL_DisplayMode current_mode;
SDL_DisplayData* didata; SDL_DisplayData *didata;
didata=(SDL_DisplayData*)SDL_calloc(1, sizeof(SDL_DisplayData)); didata = (SDL_DisplayData *) SDL_calloc(1, sizeof(SDL_DisplayData));
if (didata==NULL) if (didata == NULL) {
{
/* memory allocation problem */ /* memory allocation problem */
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
/* Set default cursor settings, maximum 128x128 cursor */ /* Set default cursor settings, maximum 128x128 cursor */
didata->cursor_visible=SDL_FALSE; didata->cursor_visible = SDL_FALSE;
didata->cursor.type=GF_CURSOR_BITMAP; didata->cursor.type = GF_CURSOR_BITMAP;
didata->cursor.hotspot.x=0; didata->cursor.hotspot.x = 0;
didata->cursor.hotspot.y=0; didata->cursor.hotspot.y = 0;
didata->cursor.cursor.bitmap.w=SDL_VIDEO_GF_MAX_CURSOR_SIZE; didata->cursor.cursor.bitmap.w = SDL_VIDEO_GF_MAX_CURSOR_SIZE;
didata->cursor.cursor.bitmap.h=SDL_VIDEO_GF_MAX_CURSOR_SIZE; didata->cursor.cursor.bitmap.h = SDL_VIDEO_GF_MAX_CURSOR_SIZE;
didata->cursor.cursor.bitmap.stride=(didata->cursor.cursor.bitmap.w+7)/ didata->cursor.cursor.bitmap.stride =
(sizeof(uint8_t)*8); (didata->cursor.cursor.bitmap.w + 7) / (sizeof(uint8_t) * 8);
didata->cursor.cursor.bitmap.color0=0x00000000; didata->cursor.cursor.bitmap.color0 = 0x00000000;
didata->cursor.cursor.bitmap.color1=0x00000000; didata->cursor.cursor.bitmap.color1 = 0x00000000;
didata->cursor.cursor.bitmap.image0=SDL_calloc(sizeof(uint8_t), (didata->cursor.cursor.bitmap.w+7)* didata->cursor.cursor.bitmap.image0 =
didata->cursor.cursor.bitmap.h/(sizeof(uint8_t)*8)); SDL_calloc(sizeof(uint8_t),
if (didata->cursor.cursor.bitmap.image0==NULL) (didata->cursor.cursor.bitmap.w +
{ 7) * didata->cursor.cursor.bitmap.h /
(sizeof(uint8_t) * 8));
if (didata->cursor.cursor.bitmap.image0 == NULL) {
SDL_free(didata); SDL_free(didata);
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
didata->cursor.cursor.bitmap.image1=SDL_calloc(sizeof(uint8_t), (didata->cursor.cursor.bitmap.w+7)* didata->cursor.cursor.bitmap.image1 =
didata->cursor.cursor.bitmap.h/(sizeof(uint8_t)*8)); SDL_calloc(sizeof(uint8_t),
if (didata->cursor.cursor.bitmap.image1==NULL) (didata->cursor.cursor.bitmap.w +
{ 7) * didata->cursor.cursor.bitmap.h /
(sizeof(uint8_t) * 8));
if (didata->cursor.cursor.bitmap.image1 == NULL) {
SDL_OutOfMemory(); SDL_OutOfMemory();
SDL_free((void*)didata->cursor.cursor.bitmap.image0); SDL_free((void *) didata->cursor.cursor.bitmap.image0);
SDL_free(didata); SDL_free(didata);
return -1; return -1;
} }
/* Query current display settings */ /* Query current display settings */
status=gf_display_query(gfdata->gfdev, it, &didata->display_info); status = gf_display_query(gfdata->gfdev, it, &didata->display_info);
if (status==GF_ERR_OK) if (status == GF_ERR_OK) {
{
SDL_zero(current_mode); SDL_zero(current_mode);
current_mode.w=didata->display_info.xres; current_mode.w = didata->display_info.xres;
current_mode.h=didata->display_info.yres; current_mode.h = didata->display_info.yres;
current_mode.refresh_rate=didata->display_info.refresh; current_mode.refresh_rate = didata->display_info.refresh;
current_mode.format=qnxgf_gf_to_sdl_pixelformat(didata->display_info.format); current_mode.format =
current_mode.driverdata=NULL; qnxgf_gf_to_sdl_pixelformat(didata->display_info.format);
} current_mode.driverdata = NULL;
else } else {
{
/* video initialization problem */ /* video initialization problem */
SDL_free((void*)didata->cursor.cursor.bitmap.image0); SDL_free((void *) didata->cursor.cursor.bitmap.image0);
SDL_free((void*)didata->cursor.cursor.bitmap.image1); SDL_free((void *) didata->cursor.cursor.bitmap.image1);
SDL_free(didata); SDL_free(didata);
SDL_SetError("GF: Display query failed"); SDL_SetError("GF: Display query failed");
return -1; return -1;
} }
/* Attach GF to selected display */ /* Attach GF to selected display */
status=gf_display_attach(&didata->display, gfdata->gfdev, it, NULL); status = gf_display_attach(&didata->display, gfdata->gfdev, it, NULL);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
/* video initialization problem */ /* video initialization problem */
SDL_free((void*)didata->cursor.cursor.bitmap.image0); SDL_free((void *) didata->cursor.cursor.bitmap.image0);
SDL_free((void*)didata->cursor.cursor.bitmap.image1); SDL_free((void *) didata->cursor.cursor.bitmap.image1);
SDL_free(didata); SDL_free(didata);
SDL_SetError("GF: Couldn't attach to display"); SDL_SetError("GF: Couldn't attach to display");
return -1; return -1;
} }
/* Initialize status variables */ /* Initialize status variables */
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
/* Attach to main display layer */ /* Attach to main display layer */
status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0); status =
if (status!=GF_ERR_OK) gf_layer_attach(&didata->layer, didata->display,
{ didata->display_info.main_layer_index, 0);
if (status != GF_ERR_OK) {
/* Failed to attach to main layer */ /* Failed to attach to main layer */
SDL_free((void*)didata->cursor.cursor.bitmap.image0); SDL_free((void *) didata->cursor.cursor.bitmap.image0);
SDL_free((void*)didata->cursor.cursor.bitmap.image1); SDL_free((void *) didata->cursor.cursor.bitmap.image1);
SDL_free(didata); SDL_free(didata);
SDL_SetError("GF: Couldn't attach to main layer, it could be busy"); SDL_SetError
("GF: Couldn't attach to main layer, it could be busy");
return -1; return -1;
} }
/* Mark main display layer is attached */ /* Mark main display layer is attached */
didata->layer_attached=SDL_TRUE; didata->layer_attached = SDL_TRUE;
/* Set layer source and destination viewport */ /* Set layer source and destination viewport */
gf_layer_set_src_viewport(didata->layer, 0, 0, current_mode.w-1, current_mode.h-1); gf_layer_set_src_viewport(didata->layer, 0, 0, current_mode.w - 1,
gf_layer_set_dst_viewport(didata->layer, 0, 0, current_mode.w-1, current_mode.h-1); current_mode.h - 1);
gf_layer_set_dst_viewport(didata->layer, 0, 0, current_mode.w - 1,
current_mode.h - 1);
/* Create main visible on display surface */ /* Create main visible on display surface */
status=gf_surface_create_layer(&didata->surface[0], &didata->layer, status = gf_surface_create_layer(&didata->surface[0], &didata->layer,
1, 0, current_mode.w, current_mode.h, 1, 0, current_mode.w, current_mode.h,
qnxgf_sdl_to_gf_pixelformat(current_mode.format), qnxgf_sdl_to_gf_pixelformat
NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE | (current_mode.format), NULL,
GF_SURFACE_CREATE_2D_ACCESSIBLE |
GF_SURFACE_CREATE_3D_ACCESSIBLE |
GF_SURFACE_CREATE_SHAREABLE); GF_SURFACE_CREATE_SHAREABLE);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
SDL_free((void*)didata->cursor.cursor.bitmap.image0); SDL_free((void *) didata->cursor.cursor.bitmap.image0);
SDL_free((void*)didata->cursor.cursor.bitmap.image1); SDL_free((void *) didata->cursor.cursor.bitmap.image1);
SDL_free(didata); SDL_free(didata);
SDL_SetError("GF: Can't create main layer surface at init (%d)\n", status); SDL_SetError("GF: Can't create main layer surface at init (%d)\n",
status);
return -1; return -1;
} }
...@@ -462,19 +463,18 @@ int qnxgf_videoinit(_THIS) ...@@ -462,19 +463,18 @@ int qnxgf_videoinit(_THIS)
// gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1); // gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
/* Update layer parameters */ /* Update layer parameters */
status=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE); status = gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
/* Free allocated surface */ /* Free allocated surface */
gf_surface_free(didata->surface[0]); gf_surface_free(didata->surface[0]);
didata->surface[0]=NULL; didata->surface[0] = NULL;
/* Disable and detach from layer */ /* Disable and detach from layer */
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
SDL_free((void*)didata->cursor.cursor.bitmap.image0); SDL_free((void *) didata->cursor.cursor.bitmap.image0);
SDL_free((void*)didata->cursor.cursor.bitmap.image1); SDL_free((void *) didata->cursor.cursor.bitmap.image1);
SDL_free(didata); SDL_free(didata);
SDL_SetError("GF: Can't update layer parameters\n"); SDL_SetError("GF: Can't update layer parameters\n");
return -1; return -1;
...@@ -484,56 +484,54 @@ int qnxgf_videoinit(_THIS) ...@@ -484,56 +484,54 @@ int qnxgf_videoinit(_THIS)
gf_layer_enable(didata->layer); gf_layer_enable(didata->layer);
/* Copy device name for each display */ /* Copy device name for each display */
SDL_strlcpy(didata->description, gfdata->gfdev_info.description, SDL_VIDEO_GF_DEVICENAME_MAX-1); SDL_strlcpy(didata->description, gfdata->gfdev_info.description,
SDL_VIDEO_GF_DEVICENAME_MAX - 1);
/* Search device capabilities and possible workarounds */ /* Search device capabilities and possible workarounds */
jt=0; jt = 0;
do { do {
if (gf_devicename[jt].name==NULL) if (gf_devicename[jt].name == NULL) {
{
break; break;
} }
if (SDL_strncmp(gf_devicename[jt].name, didata->description, SDL_strlen(gf_devicename[jt].name))==0) if (SDL_strncmp
{ (gf_devicename[jt].name, didata->description,
didata->caps=gf_devicename[jt].caps; SDL_strlen(gf_devicename[jt].name)) == 0) {
didata->caps = gf_devicename[jt].caps;
} }
jt++; jt++;
} while(1); } while (1);
/* Initialize display structure */ /* Initialize display structure */
SDL_zero(display); SDL_zero(display);
display.desktop_mode=current_mode; display.desktop_mode = current_mode;
display.current_mode=current_mode; display.current_mode = current_mode;
display.driverdata=didata; display.driverdata = didata;
didata->current_mode=current_mode; didata->current_mode = current_mode;
SDL_AddVideoDisplay(&display); SDL_AddVideoDisplay(&display);
/* Check for environment variables which could override some SDL settings */ /* Check for environment variables which could override some SDL settings */
didata->custom_refresh=0; didata->custom_refresh = 0;
override = SDL_getenv("SDL_VIDEO_GF_REFRESH_RATE"); override = SDL_getenv("SDL_VIDEO_GF_REFRESH_RATE");
if (override!=NULL) if (override != NULL) {
{ if (SDL_sscanf(override, "%u", &didata->custom_refresh) != 1) {
if (SDL_sscanf(override, "%u", &didata->custom_refresh)!=1) didata->custom_refresh = 0;
{
didata->custom_refresh=0;
} }
} }
/* Get all display modes for this display */ /* Get all display modes for this display */
_this->current_display=it; _this->current_display = it;
qnxgf_getdisplaymodes(_this); qnxgf_getdisplaymodes(_this);
} }
/* Restore default display */ /* Restore default display */
_this->current_display=0; _this->current_display = 0;
/* Add GF renderer to SDL */ /* Add GF renderer to SDL */
gf_addrenderdriver(_this); gf_addrenderdriver(_this);
/* Add GF input devices */ /* Add GF input devices */
status=gf_addinputdevices(_this); status = gf_addinputdevices(_this);
if (status!=0) if (status != 0) {
{
/* SDL error is set by gf_addinputdevices() function */ /* SDL error is set by gf_addinputdevices() function */
return -1; return -1;
} }
...@@ -542,9 +540,10 @@ int qnxgf_videoinit(_THIS) ...@@ -542,9 +540,10 @@ int qnxgf_videoinit(_THIS)
return 1; return 1;
} }
void qnxgf_videoquit(_THIS) void
qnxgf_videoquit(_THIS)
{ {
SDL_DisplayData* didata=NULL; SDL_DisplayData *didata = NULL;
uint32_t it; uint32_t it;
/* Stop collecting mouse events */ /* Stop collecting mouse events */
...@@ -553,136 +552,122 @@ void qnxgf_videoquit(_THIS) ...@@ -553,136 +552,122 @@ void qnxgf_videoquit(_THIS)
gf_delinputdevices(_this); gf_delinputdevices(_this);
/* SDL will restore old desktop mode on exit */ /* SDL will restore old desktop mode on exit */
for(it=0; it<_this->num_displays; it++) for (it = 0; it < _this->num_displays; it++) {
{ didata = _this->displays[it].driverdata;
didata=_this->displays[it].driverdata;
/* Free cursor image */ /* Free cursor image */
if (didata->cursor.cursor.bitmap.image0!=NULL) if (didata->cursor.cursor.bitmap.image0 != NULL) {
{ SDL_free((void *) didata->cursor.cursor.bitmap.image0);
SDL_free((void*)didata->cursor.cursor.bitmap.image0); didata->cursor.cursor.bitmap.image0 = NULL;
didata->cursor.cursor.bitmap.image0=NULL;
} }
if (didata->cursor.cursor.bitmap.image1!=NULL) if (didata->cursor.cursor.bitmap.image1 != NULL) {
{ SDL_free((void *) didata->cursor.cursor.bitmap.image1);
SDL_free((void*)didata->cursor.cursor.bitmap.image1); didata->cursor.cursor.bitmap.image1 = NULL;
didata->cursor.cursor.bitmap.image1=NULL;
} }
/* Free main surface */ /* Free main surface */
if (didata->surface[0]!=NULL) if (didata->surface[0] != NULL) {
{
gf_surface_free(didata->surface[0]); gf_surface_free(didata->surface[0]);
didata->surface[0]=NULL; didata->surface[0] = NULL;
} }
/* Free back surface */ /* Free back surface */
if (didata->surface[1]!=NULL) if (didata->surface[1] != NULL) {
{
gf_surface_free(didata->surface[1]); gf_surface_free(didata->surface[1]);
didata->surface[1]=NULL; didata->surface[1] = NULL;
} }
/* Free second back surface */ /* Free second back surface */
if (didata->surface[2]!=NULL) if (didata->surface[2] != NULL) {
{
gf_surface_free(didata->surface[2]); gf_surface_free(didata->surface[2]);
didata->surface[2]=NULL; didata->surface[2] = NULL;
} }
/* Detach layer before quit */ /* Detach layer before quit */
if (didata->layer_attached==SDL_TRUE) if (didata->layer_attached == SDL_TRUE) {
{
/* Disable layer if hardware supports this */ /* Disable layer if hardware supports this */
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
/* Detach from layer, free it for others */ /* Detach from layer, free it for others */
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer=NULL; didata->layer = NULL;
/* Mark it as detached */ /* Mark it as detached */
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
} }
/* Detach from selected display */ /* Detach from selected display */
gf_display_detach(didata->display); gf_display_detach(didata->display);
didata->display=NULL; didata->display = NULL;
} }
} }
void qnxgf_getdisplaymodes(_THIS) void
qnxgf_getdisplaymodes(_THIS)
{ {
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
(SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
SDL_DisplayMode mode; SDL_DisplayMode mode;
gf_modeinfo_t modeinfo; gf_modeinfo_t modeinfo;
uint32_t it=0; uint32_t it = 0;
uint32_t jt=0; uint32_t jt = 0;
uint32_t kt=0; uint32_t kt = 0;
int status; int status;
do { do {
status=gf_display_query_mode(didata->display, it, &modeinfo); status = gf_display_query_mode(didata->display, it, &modeinfo);
if (status==GF_ERR_OK) if (status == GF_ERR_OK) {
{
/* Parsing current mode */ /* Parsing current mode */
if ((modeinfo.flags & GF_MODE_GENERIC)==GF_MODE_GENERIC) if ((modeinfo.flags & GF_MODE_GENERIC) == GF_MODE_GENERIC) {
{
/* This mode is generic, so we can add to SDL our resolutions */ /* This mode is generic, so we can add to SDL our resolutions */
/* Only pixel format is fixed, refresh rate could be any */ /* Only pixel format is fixed, refresh rate could be any */
jt=0; jt = 0;
do { do {
if (generic_mode[jt].w==0) if (generic_mode[jt].w == 0) {
{
break; break;
} }
/* Check if driver do not supports doublescan video modes */ /* Check if driver do not supports doublescan video modes */
if ((didata->caps & SDL_GF_LOWRESOLUTION)!=SDL_GF_LOWRESOLUTION) if ((didata->caps & SDL_GF_LOWRESOLUTION) !=
{ SDL_GF_LOWRESOLUTION) {
if (generic_mode[jt].w<640) if (generic_mode[jt].w < 640) {
{
jt++; jt++;
continue; continue;
} }
} }
mode.w=generic_mode[jt].w; mode.w = generic_mode[jt].w;
mode.h=generic_mode[jt].h; mode.h = generic_mode[jt].h;
mode.refresh_rate=generic_mode[jt].refresh_rate; mode.refresh_rate = generic_mode[jt].refresh_rate;
mode.format=qnxgf_gf_to_sdl_pixelformat(modeinfo.primary_format); mode.format =
mode.driverdata=NULL; qnxgf_gf_to_sdl_pixelformat(modeinfo.primary_format);
mode.driverdata = NULL;
SDL_AddDisplayMode(_this->current_display, &mode); SDL_AddDisplayMode(_this->current_display, &mode);
jt++; jt++;
} while(1); } while (1);
} } else {
else
{
/* Add this display mode as is in case if it is non-generic */ /* Add this display mode as is in case if it is non-generic */
/* But go through the each refresh rate, supported by gf */ /* But go through the each refresh rate, supported by gf */
jt=0; jt = 0;
do { do {
if (modeinfo.refresh[jt]!=0) if (modeinfo.refresh[jt] != 0) {
{ mode.w = modeinfo.xres;
mode.w=modeinfo.xres; mode.h = modeinfo.yres;
mode.h=modeinfo.yres; mode.refresh_rate = modeinfo.refresh[jt];
mode.refresh_rate=modeinfo.refresh[jt]; mode.format =
mode.format=qnxgf_gf_to_sdl_pixelformat(modeinfo.primary_format); qnxgf_gf_to_sdl_pixelformat(modeinfo.
mode.driverdata=NULL; primary_format);
mode.driverdata = NULL;
SDL_AddDisplayMode(_this->current_display, &mode); SDL_AddDisplayMode(_this->current_display, &mode);
jt++; jt++;
} } else {
else
{
break; break;
} }
} while(1); } while (1);
} }
} } else {
else if (status == GF_ERR_PARM) {
{
if (status==GF_ERR_PARM)
{
/* out of available modes, all are listed */ /* out of available modes, all are listed */
break; break;
} }
...@@ -691,131 +676,116 @@ void qnxgf_getdisplaymodes(_THIS) ...@@ -691,131 +676,116 @@ void qnxgf_getdisplaymodes(_THIS)
break; break;
} }
it++; it++;
} while(1); } while (1);
} }
int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode) int
qnxgf_setdisplaymode(_THIS, SDL_DisplayMode * mode)
{ {
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
uint32_t refresh_rate=0; (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
uint32_t refresh_rate = 0;
int status; int status;
/* Current display dimensions and bpp are no more valid */ /* Current display dimensions and bpp are no more valid */
didata->current_mode.format=SDL_PIXELFORMAT_UNKNOWN; didata->current_mode.format = SDL_PIXELFORMAT_UNKNOWN;
didata->current_mode.w=0; didata->current_mode.w = 0;
didata->current_mode.h=0; didata->current_mode.h = 0;
/* Check if custom refresh rate requested */ /* Check if custom refresh rate requested */
if (didata->custom_refresh!=0) if (didata->custom_refresh != 0) {
{ refresh_rate = didata->custom_refresh;
refresh_rate=didata->custom_refresh; } else {
} refresh_rate = mode->refresh_rate;
else
{
refresh_rate=mode->refresh_rate;
} }
/* Check if SDL GF driver needs to find appropriate refresh rate itself */ /* Check if SDL GF driver needs to find appropriate refresh rate itself */
if (refresh_rate==0) if (refresh_rate == 0) {
{
uint32_t it; uint32_t it;
SDL_DisplayMode tempmode; SDL_DisplayMode tempmode;
/* Clear display mode structure */ /* Clear display mode structure */
SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode)); SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
tempmode.refresh_rate=0x0000FFFF; tempmode.refresh_rate = 0x0000FFFF;
/* Check if window width and height matches one of our modes */ /* Check if window width and height matches one of our modes */
for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++) for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
{ if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) && (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
(SDL_CurrentDisplay.display_modes[it].h==mode->h) && (SDL_CurrentDisplay.display_modes[it].format == mode->format))
(SDL_CurrentDisplay.display_modes[it].format==mode->format))
{ {
/* Find the lowest refresh rate available */ /* Find the lowest refresh rate available */
if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate) if (tempmode.refresh_rate >
{ SDL_CurrentDisplay.display_modes[it].refresh_rate) {
tempmode=SDL_CurrentDisplay.display_modes[it]; tempmode = SDL_CurrentDisplay.display_modes[it];
}
} }
} }
if (tempmode.refresh_rate!=0x0000FFFF)
{
refresh_rate=tempmode.refresh_rate;
} }
else if (tempmode.refresh_rate != 0x0000FFFF) {
{ refresh_rate = tempmode.refresh_rate;
} else {
/* Let video driver decide what to do with this */ /* Let video driver decide what to do with this */
refresh_rate=0; refresh_rate = 0;
} }
} }
/* Check if SDL GF driver needs to check custom refresh rate */ /* Check if SDL GF driver needs to check custom refresh rate */
if (didata->custom_refresh!=0) if (didata->custom_refresh != 0) {
{
uint32_t it; uint32_t it;
SDL_DisplayMode tempmode; SDL_DisplayMode tempmode;
/* Clear display mode structure */ /* Clear display mode structure */
SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode)); SDL_memset(&tempmode, 0x00, sizeof(SDL_DisplayMode));
tempmode.refresh_rate=0x0000FFFF; tempmode.refresh_rate = 0x0000FFFF;
/* Check if window width and height matches one of our modes */ /* Check if window width and height matches one of our modes */
for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++) for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
{ if ((SDL_CurrentDisplay.display_modes[it].w == mode->w) &&
if ((SDL_CurrentDisplay.display_modes[it].w==mode->w) && (SDL_CurrentDisplay.display_modes[it].h == mode->h) &&
(SDL_CurrentDisplay.display_modes[it].h==mode->h) && (SDL_CurrentDisplay.display_modes[it].format == mode->format))
(SDL_CurrentDisplay.display_modes[it].format==mode->format))
{ {
/* Find the lowest refresh rate available */ /* Find the lowest refresh rate available */
if (tempmode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate) if (tempmode.refresh_rate >
{ SDL_CurrentDisplay.display_modes[it].refresh_rate) {
tempmode=SDL_CurrentDisplay.display_modes[it]; tempmode = SDL_CurrentDisplay.display_modes[it];
} }
/* Check if requested refresh rate found */ /* Check if requested refresh rate found */
if (refresh_rate==SDL_CurrentDisplay.display_modes[it].refresh_rate) if (refresh_rate ==
{ SDL_CurrentDisplay.display_modes[it].refresh_rate) {
tempmode=SDL_CurrentDisplay.display_modes[it]; tempmode = SDL_CurrentDisplay.display_modes[it];
break; break;
} }
} }
} }
if (tempmode.refresh_rate!=0x0000FFFF) if (tempmode.refresh_rate != 0x0000FFFF) {
{ refresh_rate = tempmode.refresh_rate;
refresh_rate=tempmode.refresh_rate; } else {
}
else
{
/* Let video driver decide what to do with this */ /* Let video driver decide what to do with this */
refresh_rate=0; refresh_rate = 0;
} }
} }
/* Free main surface */ /* Free main surface */
if (didata->surface[0]!=NULL) if (didata->surface[0] != NULL) {
{
gf_surface_free(didata->surface[0]); gf_surface_free(didata->surface[0]);
didata->surface[0]=NULL; didata->surface[0] = NULL;
} }
/* Free back surface */ /* Free back surface */
if (didata->surface[1]!=NULL) if (didata->surface[1] != NULL) {
{
gf_surface_free(didata->surface[1]); gf_surface_free(didata->surface[1]);
didata->surface[1]=NULL; didata->surface[1] = NULL;
} }
/* Free second back surface */ /* Free second back surface */
if (didata->surface[2]!=NULL) if (didata->surface[2] != NULL) {
{
gf_surface_free(didata->surface[2]); gf_surface_free(didata->surface[2]);
didata->surface[2]=NULL; didata->surface[2] = NULL;
} }
/* Detach layer before switch to new graphics mode */ /* Detach layer before switch to new graphics mode */
if (didata->layer_attached==SDL_TRUE) if (didata->layer_attached == SDL_TRUE) {
{
/* Disable layer if hardware supports this */ /* Disable layer if hardware supports this */
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
...@@ -823,28 +793,27 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode) ...@@ -823,28 +793,27 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode)
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
/* Mark it as detached */ /* Mark it as detached */
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
} }
/* Set new display video mode */ /* Set new display video mode */
status=gf_display_set_mode(didata->display, mode->w, mode->h, refresh_rate, status =
gf_display_set_mode(didata->display, mode->w, mode->h, refresh_rate,
qnxgf_sdl_to_gf_pixelformat(mode->format), 0); qnxgf_sdl_to_gf_pixelformat(mode->format), 0);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
/* Display mode/resolution switch has been failed */ /* Display mode/resolution switch has been failed */
SDL_SetError("GF: Mode is not supported by graphics driver"); SDL_SetError("GF: Mode is not supported by graphics driver");
return -1; return -1;
} } else {
else didata->current_mode = *mode;
{ didata->current_mode.refresh_rate = refresh_rate;
didata->current_mode=*mode;
didata->current_mode.refresh_rate=refresh_rate;
} }
/* Attach to main display layer */ /* Attach to main display layer */
status=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0); status =
if (status!=GF_ERR_OK) gf_layer_attach(&didata->layer, didata->display,
{ didata->display_info.main_layer_index, 0);
if (status != GF_ERR_OK) {
SDL_SetError("GF: Couldn't attach to main layer, it could be busy"); SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
/* Failed to attach to main displayable layer */ /* Failed to attach to main displayable layer */
...@@ -852,23 +821,28 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode) ...@@ -852,23 +821,28 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode)
} }
/* Mark main display layer is attached */ /* Mark main display layer is attached */
didata->layer_attached=SDL_TRUE; didata->layer_attached = SDL_TRUE;
/* Set layer source and destination viewport */ /* Set layer source and destination viewport */
gf_layer_set_src_viewport(didata->layer, 0, 0, mode->w-1, mode->h-1); gf_layer_set_src_viewport(didata->layer, 0, 0, mode->w - 1, mode->h - 1);
gf_layer_set_dst_viewport(didata->layer, 0, 0, mode->w-1, mode->h-1); gf_layer_set_dst_viewport(didata->layer, 0, 0, mode->w - 1, mode->h - 1);
/* Create main visible on display surface */ /* Create main visible on display surface */
status=gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0, status =
mode->w, mode->h, qnxgf_sdl_to_gf_pixelformat(mode->format), gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0,
NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE | mode->w, mode->h,
qnxgf_sdl_to_gf_pixelformat(mode->format),
NULL,
GF_SURFACE_CREATE_2D_ACCESSIBLE |
GF_SURFACE_CREATE_3D_ACCESSIBLE |
GF_SURFACE_CREATE_SHAREABLE); GF_SURFACE_CREATE_SHAREABLE);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
SDL_SetError("GF: Can't create main layer surface at modeswitch (%d)\n", status); SDL_SetError
("GF: Can't create main layer surface at modeswitch (%d)\n",
status);
return -1; return -1;
} }
...@@ -876,24 +850,22 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode) ...@@ -876,24 +850,22 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode)
gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1); gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
/* Update layer parameters */ /* Update layer parameters */
status=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE); status = gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
if (status!=GF_ERR_OK) if (status != GF_ERR_OK) {
{
/* Free main surface */ /* Free main surface */
gf_surface_free(didata->surface[0]); gf_surface_free(didata->surface[0]);
didata->surface[0]=NULL; didata->surface[0] = NULL;
/* Detach layer */ /* Detach layer */
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
SDL_SetError("GF: Can't update layer parameters\n"); SDL_SetError("GF: Can't update layer parameters\n");
return -1; return -1;
} }
/* Restore cursor if it was visible */ /* Restore cursor if it was visible */
if (didata->cursor_visible==SDL_TRUE) if (didata->cursor_visible == SDL_TRUE) {
{
gf_cursor_set(didata->display, 0, &didata->cursor); gf_cursor_set(didata->display, 0, &didata->cursor);
gf_cursor_enable(didata->display, 0); gf_cursor_enable(didata->display, 0);
} }
...@@ -904,9 +876,11 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode) ...@@ -904,9 +876,11 @@ int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode)
return 0; return 0;
} }
int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette) int
qnxgf_setdisplaypalette(_THIS, SDL_Palette * palette)
{ {
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
(SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
/* QNX GF doesn't have support for global palette changing, but we */ /* QNX GF doesn't have support for global palette changing, but we */
/* could store it for usage in future */ /* could store it for usage in future */
...@@ -915,9 +889,11 @@ int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette) ...@@ -915,9 +889,11 @@ int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette)
return -1; return -1;
} }
int qnxgf_getdisplaypalette(_THIS, SDL_Palette* palette) int
qnxgf_getdisplaypalette(_THIS, SDL_Palette * palette)
{ {
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
(SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
/* We can't provide current palette settings and looks like SDL */ /* We can't provide current palette settings and looks like SDL */
/* do not call this function also, in such case this function returns -1 */ /* do not call this function also, in such case this function returns -1 */
...@@ -926,15 +902,19 @@ int qnxgf_getdisplaypalette(_THIS, SDL_Palette* palette) ...@@ -926,15 +902,19 @@ int qnxgf_getdisplaypalette(_THIS, SDL_Palette* palette)
return -1; return -1;
} }
int qnxgf_setdisplaygammaramp(_THIS, Uint16* ramp) int
qnxgf_setdisplaygammaramp(_THIS, Uint16 * ramp)
{ {
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
(SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
int status; int status;
/* Setup gamma ramp, for each color channel */ /* Setup gamma ramp, for each color channel */
status=gf_display_set_color_lut16(didata->display, (uint16_t*)ramp, (uint16_t*)ramp+256, (uint16_t*)ramp+512); status =
if (status!=GF_ERR_OK) gf_display_set_color_lut16(didata->display, (uint16_t *) ramp,
{ (uint16_t *) ramp + 256,
(uint16_t *) ramp + 512);
if (status != GF_ERR_OK) {
/* Setting display gamma ramp operation has been failed */ /* Setting display gamma ramp operation has been failed */
return -1; return -1;
} }
...@@ -942,7 +922,8 @@ int qnxgf_setdisplaygammaramp(_THIS, Uint16* ramp) ...@@ -942,7 +922,8 @@ int qnxgf_setdisplaygammaramp(_THIS, Uint16* ramp)
return 0; return 0;
} }
int qnxgf_getdisplaygammaramp(_THIS, Uint16* ramp) int
qnxgf_getdisplaygammaramp(_THIS, Uint16 * ramp)
{ {
/* TODO: We need to return previous gamma set */ /* TODO: We need to return previous gamma set */
/* Also we need some initial fake gamma to return */ /* Also we need some initial fake gamma to return */
...@@ -951,55 +932,51 @@ int qnxgf_getdisplaygammaramp(_THIS, Uint16* ramp) ...@@ -951,55 +932,51 @@ int qnxgf_getdisplaygammaramp(_THIS, Uint16* ramp)
return -1; return -1;
} }
int qnxgf_createwindow(_THIS, SDL_Window* window) int
qnxgf_createwindow(_THIS, SDL_Window * window)
{ {
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
SDL_WindowData* wdata; (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
SDL_WindowData *wdata;
int32_t status; int32_t status;
/* QNX GF supports fullscreen window modes only */ /* QNX GF supports fullscreen window modes only */
if ((window->flags & SDL_WINDOW_FULLSCREEN)!=SDL_WINDOW_FULLSCREEN) if ((window->flags & SDL_WINDOW_FULLSCREEN) != SDL_WINDOW_FULLSCREEN) {
{
uint32_t it; uint32_t it;
SDL_DisplayMode mode; SDL_DisplayMode mode;
/* Clear display mode structure */ /* Clear display mode structure */
SDL_memset(&mode, 0x00, sizeof(SDL_DisplayMode)); SDL_memset(&mode, 0x00, sizeof(SDL_DisplayMode));
mode.refresh_rate=0x0000FFFF; mode.refresh_rate = 0x0000FFFF;
/* Check if window width and height matches one of our modes */ /* Check if window width and height matches one of our modes */
for (it=0; it<SDL_CurrentDisplay.num_display_modes; it++) for (it = 0; it < SDL_CurrentDisplay.num_display_modes; it++) {
{ if ((SDL_CurrentDisplay.display_modes[it].w == window->w) &&
if ((SDL_CurrentDisplay.display_modes[it].w==window->w) && (SDL_CurrentDisplay.display_modes[it].h == window->h) &&
(SDL_CurrentDisplay.display_modes[it].h==window->h) && (SDL_CurrentDisplay.display_modes[it].format ==
(SDL_CurrentDisplay.display_modes[it].format==SDL_CurrentDisplay.desktop_mode.format)) SDL_CurrentDisplay.desktop_mode.format)) {
{
/* Find the lowest refresh rate available */ /* Find the lowest refresh rate available */
if (mode.refresh_rate>SDL_CurrentDisplay.display_modes[it].refresh_rate) if (mode.refresh_rate >
{ SDL_CurrentDisplay.display_modes[it].refresh_rate) {
mode=SDL_CurrentDisplay.display_modes[it]; mode = SDL_CurrentDisplay.display_modes[it];
} }
} }
} }
/* Check if end of display list has been reached */ /* Check if end of display list has been reached */
if (mode.refresh_rate==0x0000FFFF) if (mode.refresh_rate == 0x0000FFFF) {
{
SDL_SetError("GF: Desired video mode is not supported"); SDL_SetError("GF: Desired video mode is not supported");
/* Failed to create new window */ /* Failed to create new window */
return -1; return -1;
} } else {
else
{
/* Tell to the caller that mode will be fullscreen */ /* Tell to the caller that mode will be fullscreen */
window->flags|=SDL_WINDOW_FULLSCREEN; window->flags |= SDL_WINDOW_FULLSCREEN;
/* Setup fullscreen mode, bpp used from desktop mode in this case */ /* Setup fullscreen mode, bpp used from desktop mode in this case */
status=qnxgf_setdisplaymode(_this, &mode); status = qnxgf_setdisplaymode(_this, &mode);
if (status!=0) if (status != 0) {
{
/* Failed to swith fullscreen video mode */ /* Failed to swith fullscreen video mode */
return -1; return -1;
} }
...@@ -1007,49 +984,44 @@ int qnxgf_createwindow(_THIS, SDL_Window* window) ...@@ -1007,49 +984,44 @@ int qnxgf_createwindow(_THIS, SDL_Window* window)
} }
/* Setup our own window decorations and states, which are depend on fullscreen mode */ /* Setup our own window decorations and states, which are depend on fullscreen mode */
window->flags|=SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS | window->flags |= SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS |
SDL_WINDOW_MAXIMIZED | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_MAXIMIZED | SDL_WINDOW_INPUT_GRABBED |
SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS; SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS;
window->flags&=~(SDL_WINDOW_RESIZABLE | SDL_WINDOW_MINIMIZED); window->flags &= ~(SDL_WINDOW_RESIZABLE | SDL_WINDOW_MINIMIZED);
/* Ignore any window position settings */ /* Ignore any window position settings */
window->x=SDL_WINDOWPOS_UNDEFINED; window->x = SDL_WINDOWPOS_UNDEFINED;
window->y=SDL_WINDOWPOS_UNDEFINED; window->y = SDL_WINDOWPOS_UNDEFINED;
/* Allocate window internal data */ /* Allocate window internal data */
wdata=(SDL_WindowData*)SDL_calloc(1, sizeof(SDL_WindowData)); wdata = (SDL_WindowData *) SDL_calloc(1, sizeof(SDL_WindowData));
if (wdata==NULL) if (wdata == NULL) {
{
SDL_OutOfMemory(); SDL_OutOfMemory();
return -1; return -1;
} }
/* Setup driver data for this window */ /* Setup driver data for this window */
window->driverdata=wdata; window->driverdata = wdata;
/* Check if window must support OpenGL ES rendering */ /* Check if window must support OpenGL ES rendering */
if ((window->flags & SDL_WINDOW_OPENGL)==SDL_WINDOW_OPENGL) if ((window->flags & SDL_WINDOW_OPENGL) == SDL_WINDOW_OPENGL) {
{ #if defined(SDL_VIDEO_OPENGL_ES)
#if defined(SDL_VIDEO_OPENGL_ES)
EGLBoolean initstatus; EGLBoolean initstatus;
/* Mark this window as OpenGL ES compatible */ /* Mark this window as OpenGL ES compatible */
wdata->uses_gles=SDL_TRUE; wdata->uses_gles = SDL_TRUE;
/* Create connection to OpenGL ES */ /* Create connection to OpenGL ES */
if (gfdata->egldisplay==EGL_NO_DISPLAY) if (gfdata->egldisplay == EGL_NO_DISPLAY) {
{ gfdata->egldisplay = eglGetDisplay(gfdata->gfdev);
gfdata->egldisplay=eglGetDisplay(gfdata->gfdev); if (gfdata->egldisplay == EGL_NO_DISPLAY) {
if (gfdata->egldisplay==EGL_NO_DISPLAY)
{
SDL_SetError("GF: Can't get connection to OpenGL ES"); SDL_SetError("GF: Can't get connection to OpenGL ES");
return -1; return -1;
} }
/* Initialize OpenGL ES library, ignore EGL version */ /* Initialize OpenGL ES library, ignore EGL version */
initstatus=eglInitialize(gfdata->egldisplay, NULL, NULL); initstatus = eglInitialize(gfdata->egldisplay, NULL, NULL);
if (initstatus!=EGL_TRUE) if (initstatus != EGL_TRUE) {
{
SDL_SetError("GF: Can't init OpenGL ES library"); SDL_SetError("GF: Can't init OpenGL ES library");
return -1; return -1;
} }
...@@ -1057,10 +1029,10 @@ int qnxgf_createwindow(_THIS, SDL_Window* window) ...@@ -1057,10 +1029,10 @@ int qnxgf_createwindow(_THIS, SDL_Window* window)
/* Increment GL ES reference count usage */ /* Increment GL ES reference count usage */
gfdata->egl_refcount++; gfdata->egl_refcount++;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return -1; return -1;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
/* Enable mouse event collecting */ /* Enable mouse event collecting */
...@@ -1074,107 +1046,115 @@ int qnxgf_createwindow(_THIS, SDL_Window* window) ...@@ -1074,107 +1046,115 @@ int qnxgf_createwindow(_THIS, SDL_Window* window)
return 0; return 0;
} }
int qnxgf_createwindowfrom(_THIS, SDL_Window* window, const void* data) int
qnxgf_createwindowfrom(_THIS, SDL_Window * window, const void *data)
{ {
/* Failed to create window from another window */ /* Failed to create window from another window */
return -1; return -1;
} }
void qnxgf_setwindowtitle(_THIS, SDL_Window* window) void
qnxgf_setwindowtitle(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon) void
qnxgf_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon)
{ {
} }
void qnxgf_setwindowposition(_THIS, SDL_Window* window) void
qnxgf_setwindowposition(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_setwindowsize(_THIS, SDL_Window* window) void
qnxgf_setwindowsize(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_showwindow(_THIS, SDL_Window* window) void
qnxgf_showwindow(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_hidewindow(_THIS, SDL_Window* window) void
qnxgf_hidewindow(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_raisewindow(_THIS, SDL_Window* window) void
qnxgf_raisewindow(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_maximizewindow(_THIS, SDL_Window* window) void
qnxgf_maximizewindow(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_minimizewindow(_THIS, SDL_Window* window) void
qnxgf_minimizewindow(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_restorewindow(_THIS, SDL_Window* window) void
qnxgf_restorewindow(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_setwindowgrab(_THIS, SDL_Window* window) void
qnxgf_setwindowgrab(_THIS, SDL_Window * window)
{ {
} }
void qnxgf_destroywindow(_THIS, SDL_Window* window) void
qnxgf_destroywindow(_THIS, SDL_Window * window)
{ {
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata; (SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
if (wdata!=NULL) if (wdata != NULL) {
{ #if defined(SDL_VIDEO_OPENGL_ES)
#if defined(SDL_VIDEO_OPENGL_ES)
/* Destroy OpenGL ES surface if it was created */ /* Destroy OpenGL ES surface if it was created */
if (wdata->gles_surface!=EGL_NO_SURFACE) if (wdata->gles_surface != EGL_NO_SURFACE) {
{
eglDestroySurface(gfdata->egldisplay, wdata->gles_surface); eglDestroySurface(gfdata->egldisplay, wdata->gles_surface);
} }
/* Free any 3D target if it was created before */ /* Free any 3D target if it was created before */
if (wdata->target_created==SDL_TRUE) if (wdata->target_created == SDL_TRUE) {
{
gf_3d_target_free(wdata->target); gf_3d_target_free(wdata->target);
wdata->target_created==SDL_FALSE; wdata->target_created == SDL_FALSE;
} }
gfdata->egl_refcount--; gfdata->egl_refcount--;
if (gfdata->egl_refcount==0) if (gfdata->egl_refcount == 0) {
{
/* Terminate connection to OpenGL ES */ /* Terminate connection to OpenGL ES */
if (gfdata->egldisplay!=EGL_NO_DISPLAY) if (gfdata->egldisplay != EGL_NO_DISPLAY) {
{
eglTerminate(gfdata->egldisplay); eglTerminate(gfdata->egldisplay);
gfdata->egldisplay=EGL_NO_DISPLAY; gfdata->egldisplay = EGL_NO_DISPLAY;
} }
} }
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
} }
/*****************************************************************************/ /*****************************************************************************/
/* SDL Window Manager function */ /* SDL Window Manager function */
/*****************************************************************************/ /*****************************************************************************/
SDL_bool qnxgf_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info) SDL_bool
qnxgf_getwindowwminfo(_THIS, SDL_Window * window, struct SDL_SysWMinfo *info)
{ {
/* QNX GF do not operates at window level, this means we are have no */ /* QNX GF do not operates at window level, this means we are have no */
/* Window Manager available, no specific data in SDL_SysWMinfo too */ /* Window Manager available, no specific data in SDL_SysWMinfo too */
if (info->version.major<=SDL_MAJOR_VERSION) if (info->version.major <= SDL_MAJOR_VERSION) {
{
return SDL_TRUE; return SDL_TRUE;
} } else {
else SDL_SetError("Application not compiled with SDL %d.%d\n",
{ SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
SDL_SetError("Application not compiled with SDL %d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION);
return SDL_FALSE; return SDL_FALSE;
} }
...@@ -1185,113 +1165,109 @@ SDL_bool qnxgf_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* ...@@ -1185,113 +1165,109 @@ SDL_bool qnxgf_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo*
/*****************************************************************************/ /*****************************************************************************/
/* SDL OpenGL/OpenGL ES functions */ /* SDL OpenGL/OpenGL ES functions */
/*****************************************************************************/ /*****************************************************************************/
int qnxgf_gl_loadlibrary(_THIS, const char* path) int
qnxgf_gl_loadlibrary(_THIS, const char *path)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
/* Check if OpenGL ES library is specified for GF driver */ /* Check if OpenGL ES library is specified for GF driver */
if (path==NULL) if (path == NULL) {
{ path = SDL_getenv("SDL_OPENGL_LIBRARY");
path=SDL_getenv("SDL_OPENGL_LIBRARY"); if (path == NULL) {
if (path==NULL) path = SDL_getenv("SDL_OPENGLES_LIBRARY");
{
path=SDL_getenv("SDL_OPENGLES_LIBRARY");
} }
} }
/* Check if default library loading requested */ /* Check if default library loading requested */
if (path==NULL) if (path == NULL) {
{
/* Already linked with GF library which provides egl* subset of */ /* Already linked with GF library which provides egl* subset of */
/* functions, use Common profile of OpenGL ES library by default */ /* functions, use Common profile of OpenGL ES library by default */
path="/usr/lib/libGLES_CM.so.1"; path = "/usr/lib/libGLES_CM.so.1";
} }
/* Load dynamic library */ /* Load dynamic library */
_this->gl_config.dll_handle=SDL_LoadObject(path); _this->gl_config.dll_handle = SDL_LoadObject(path);
if (!_this->gl_config.dll_handle) if (!_this->gl_config.dll_handle) {
{
/* Failed to load new GL ES library */ /* Failed to load new GL ES library */
SDL_SetError("GF: Failed to locate OpenGL ES library"); SDL_SetError("GF: Failed to locate OpenGL ES library");
return -1; return -1;
} }
/* Store OpenGL ES library path and name */ /* Store OpenGL ES library path and name */
SDL_strlcpy(_this->gl_config.driver_path, path, SDL_arraysize(_this->gl_config.driver_path)); SDL_strlcpy(_this->gl_config.driver_path, path,
SDL_arraysize(_this->gl_config.driver_path));
/* New OpenGL ES library is loaded */ /* New OpenGL ES library is loaded */
return 0; return 0;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return -1; return -1;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
void* qnxgf_gl_getprocaddres(_THIS, const char* proc) void *
qnxgf_gl_getprocaddres(_THIS, const char *proc)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
void* function_address; void *function_address;
/* Try to get function address through the egl interface */ /* Try to get function address through the egl interface */
function_address=eglGetProcAddress(proc); function_address = eglGetProcAddress(proc);
if (function_address!=NULL) if (function_address != NULL) {
{
return function_address; return function_address;
} }
/* Then try to get function in the OpenGL ES library */ /* Then try to get function in the OpenGL ES library */
if (_this->gl_config.dll_handle) if (_this->gl_config.dll_handle) {
{ function_address =
function_address=SDL_LoadFunction(_this->gl_config.dll_handle, proc); SDL_LoadFunction(_this->gl_config.dll_handle, proc);
if (function_address!=NULL) if (function_address != NULL) {
{
return function_address; return function_address;
} }
} }
/* Add emulated OpenGL ES 1.1 functions */ /* Add emulated OpenGL ES 1.1 functions */
if (SDL_strcmp(proc, "glTexParameteri")==0) if (SDL_strcmp(proc, "glTexParameteri") == 0) {
{
return glTexParameteri; return glTexParameteri;
} }
if (SDL_strcmp(proc, "glTexParameteriv")==0) if (SDL_strcmp(proc, "glTexParameteriv") == 0) {
{
return glTexParameteriv; return glTexParameteriv;
} }
if (SDL_strcmp(proc, "glColor4ub")==0) if (SDL_strcmp(proc, "glColor4ub") == 0) {
{
return glColor4ub; return glColor4ub;
} }
/* Failed to get GL ES function address pointer */ /* Failed to get GL ES function address pointer */
SDL_SetError("GF: Cannot locate OpenGL ES function name"); SDL_SetError("GF: Cannot locate OpenGL ES function name");
return NULL; return NULL;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return NULL; return NULL;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
void qnxgf_gl_unloadlibrary(_THIS) void
qnxgf_gl_unloadlibrary(_THIS)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
/* Unload OpenGL ES library */ /* Unload OpenGL ES library */
if (_this->gl_config.dll_handle) if (_this->gl_config.dll_handle) {
{
SDL_UnloadObject(_this->gl_config.dll_handle); SDL_UnloadObject(_this->gl_config.dll_handle);
_this->gl_config.dll_handle=NULL; _this->gl_config.dll_handle = NULL;
} }
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return; return;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window) SDL_GLContext
qnxgf_gl_createcontext(_THIS, SDL_Window * window)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata; SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
SDL_DisplayData* didata=(SDL_DisplayData*)SDL_CurrentDisplay.driverdata; SDL_DisplayData *didata =
(SDL_DisplayData *) SDL_CurrentDisplay.driverdata;
EGLBoolean status; EGLBoolean status;
int32_t gfstatus; int32_t gfstatus;
EGLint configs; EGLint configs;
...@@ -1301,46 +1277,38 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window) ...@@ -1301,46 +1277,38 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window)
EGLint cit; EGLint cit;
/* Choose buffeingr scheme */ /* Choose buffeingr scheme */
if (!_this->gl_config.double_buffer) if (!_this->gl_config.double_buffer) {
{ surfaces = 1;
surfaces=1; } else {
} surfaces = 2;
else
{
surfaces=2;
} }
/* If driver has no support of video memory allocation, then */ /* If driver has no support of video memory allocation, then */
/* disable double buffering, use single buffer present copy */ /* disable double buffering, use single buffer present copy */
if ((didata->caps & SDL_GF_VIDEOMEMORY)!=SDL_GF_VIDEOMEMORY) if ((didata->caps & SDL_GF_VIDEOMEMORY) != SDL_GF_VIDEOMEMORY) {
{ surfaces = 1;
surfaces=1;
} }
/* Free main surface */ /* Free main surface */
if (didata->surface[0]!=NULL) if (didata->surface[0] != NULL) {
{
gf_surface_free(didata->surface[0]); gf_surface_free(didata->surface[0]);
didata->surface[0]=NULL; didata->surface[0] = NULL;
} }
/* Free back surface */ /* Free back surface */
if (didata->surface[1]!=NULL) if (didata->surface[1] != NULL) {
{
gf_surface_free(didata->surface[1]); gf_surface_free(didata->surface[1]);
didata->surface[1]=NULL; didata->surface[1] = NULL;
} }
/* Free second back surface */ /* Free second back surface */
if (didata->surface[2]!=NULL) if (didata->surface[2] != NULL) {
{
gf_surface_free(didata->surface[2]); gf_surface_free(didata->surface[2]);
didata->surface[2]=NULL; didata->surface[2] = NULL;
} }
/* Detach layer before switch to new graphics mode */ /* Detach layer before switch to new graphics mode */
if (didata->layer_attached==SDL_TRUE) if (didata->layer_attached == SDL_TRUE) {
{
/* Disable layer if hardware supports this */ /* Disable layer if hardware supports this */
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
...@@ -1348,13 +1316,14 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window) ...@@ -1348,13 +1316,14 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window)
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
/* Mark it as detached */ /* Mark it as detached */
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
} }
/* Attach to main display layer */ /* Attach to main display layer */
gfstatus=gf_layer_attach(&didata->layer, didata->display, didata->display_info.main_layer_index, 0); gfstatus =
if (gfstatus!=GF_ERR_OK) gf_layer_attach(&didata->layer, didata->display,
{ didata->display_info.main_layer_index, 0);
if (gfstatus != GF_ERR_OK) {
SDL_SetError("GF: Couldn't attach to main layer, it could be busy"); SDL_SetError("GF: Couldn't attach to main layer, it could be busy");
/* Failed to attach to main displayable layer */ /* Failed to attach to main displayable layer */
...@@ -1362,61 +1331,74 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window) ...@@ -1362,61 +1331,74 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window)
} }
/* Mark main display layer is attached */ /* Mark main display layer is attached */
didata->layer_attached=SDL_TRUE; didata->layer_attached = SDL_TRUE;
/* Set layer source and destination viewport */ /* Set layer source and destination viewport */
gf_layer_set_src_viewport(didata->layer, 0, 0, didata->current_mode.w-1, didata->current_mode.h-1); gf_layer_set_src_viewport(didata->layer, 0, 0, didata->current_mode.w - 1,
gf_layer_set_dst_viewport(didata->layer, 0, 0, didata->current_mode.w-1, didata->current_mode.h-1); didata->current_mode.h - 1);
gf_layer_set_dst_viewport(didata->layer, 0, 0, didata->current_mode.w - 1,
didata->current_mode.h - 1);
/* Create main visible on display surface */ /* Create main visible on display surface */
gfstatus=gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0, gfstatus =
didata->current_mode.w, didata->current_mode.h, qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), gf_surface_create_layer(&didata->surface[0], &didata->layer, 1, 0,
NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE | didata->current_mode.w,
didata->current_mode.h,
qnxgf_sdl_to_gf_pixelformat(didata->
current_mode.
format), NULL,
GF_SURFACE_CREATE_2D_ACCESSIBLE |
GF_SURFACE_CREATE_3D_ACCESSIBLE |
GF_SURFACE_CREATE_SHAREABLE); GF_SURFACE_CREATE_SHAREABLE);
if (gfstatus!=GF_ERR_OK) if (gfstatus != GF_ERR_OK) {
{
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
SDL_SetError("GF: Can't create main layer surface at glctx (%d)\n", gfstatus); SDL_SetError("GF: Can't create main layer surface at glctx (%d)\n",
gfstatus);
return NULL; return NULL;
} }
/* Set just created surface as main visible on the layer */ /* Set just created surface as main visible on the layer */
// gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1); // gf_layer_set_surfaces(didata->layer, &didata->surface[0], 1);
if (surfaces>1) if (surfaces > 1) {
{
/* Create back display surface */ /* Create back display surface */
gfstatus=gf_surface_create_layer(&didata->surface[1], &didata->layer, 1, 0, gfstatus =
didata->current_mode.w, didata->current_mode.h, qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format), gf_surface_create_layer(&didata->surface[1], &didata->layer, 1, 0,
NULL, GF_SURFACE_CREATE_2D_ACCESSIBLE | GF_SURFACE_CREATE_3D_ACCESSIBLE | didata->current_mode.w,
didata->current_mode.h,
qnxgf_sdl_to_gf_pixelformat(didata->
current_mode.
format), NULL,
GF_SURFACE_CREATE_2D_ACCESSIBLE |
GF_SURFACE_CREATE_3D_ACCESSIBLE |
GF_SURFACE_CREATE_SHAREABLE); GF_SURFACE_CREATE_SHAREABLE);
if (gfstatus!=GF_ERR_OK) if (gfstatus != GF_ERR_OK) {
{
gf_surface_free(didata->surface[0]); gf_surface_free(didata->surface[0]);
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
SDL_SetError("GF: Can't create main layer surface at glctx (%d)\n", gfstatus); SDL_SetError
("GF: Can't create main layer surface at glctx (%d)\n",
gfstatus);
return NULL; return NULL;
} }
} }
/* Update layer parameters */ /* Update layer parameters */
gfstatus=gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE); gfstatus = gf_layer_update(didata->layer, GF_LAYER_UPDATE_NO_WAIT_IDLE);
if (gfstatus!=GF_ERR_OK) if (gfstatus != GF_ERR_OK) {
{
/* Free main and back surfaces */ /* Free main and back surfaces */
gf_surface_free(didata->surface[1]); gf_surface_free(didata->surface[1]);
didata->surface[1]=NULL; didata->surface[1] = NULL;
gf_surface_free(didata->surface[0]); gf_surface_free(didata->surface[0]);
didata->surface[0]=NULL; didata->surface[0] = NULL;
/* Detach layer */ /* Detach layer */
gf_layer_disable(didata->layer); gf_layer_disable(didata->layer);
gf_layer_detach(didata->layer); gf_layer_detach(didata->layer);
didata->layer_attached=SDL_FALSE; didata->layer_attached = SDL_FALSE;
SDL_SetError("GF: Can't update layer parameters\n"); SDL_SetError("GF: Can't update layer parameters\n");
return NULL; return NULL;
} }
...@@ -1425,273 +1407,259 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window) ...@@ -1425,273 +1407,259 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window)
gf_layer_enable(didata->layer); gf_layer_enable(didata->layer);
/* Prepare attributes list to pass them to OpenGL ES */ /* Prepare attributes list to pass them to OpenGL ES */
attr_pos=0; attr_pos = 0;
wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID; wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); wdata->gles_attributes[attr_pos++] =
wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE; qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
wdata->gles_attributes[attr_pos++]=_this->gl_config.red_size; wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.red_size;
wdata->gles_attributes[attr_pos++]=_this->gl_config.green_size; wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.green_size;
wdata->gles_attributes[attr_pos++]=_this->gl_config.blue_size; wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE; wdata->gles_attributes[attr_pos++] = _this->gl_config.blue_size;
if (_this->gl_config.alpha_size) wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
{ if (_this->gl_config.alpha_size) {
wdata->gles_attributes[attr_pos++]=_this->gl_config.alpha_size; wdata->gles_attributes[attr_pos++] = _this->gl_config.alpha_size;
} } else {
else wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
{ }
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
} wdata->gles_attributes[attr_pos++] = _this->gl_config.depth_size;
wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE; if (_this->gl_config.buffer_size) {
wdata->gles_attributes[attr_pos++]=_this->gl_config.depth_size; wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
if (_this->gl_config.buffer_size) wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
{ }
wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE; if (_this->gl_config.stencil_size) {
wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size; wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
} wdata->gles_attributes[attr_pos++] = _this->gl_config.buffer_size;
if (_this->gl_config.stencil_size)
{
wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
wdata->gles_attributes[attr_pos++]=_this->gl_config.buffer_size;
} }
/* Set number of samples in multisampling */ /* Set number of samples in multisampling */
if (_this->gl_config.multisamplesamples) if (_this->gl_config.multisamplesamples) {
{ wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
wdata->gles_attributes[attr_pos++]=EGL_SAMPLES; wdata->gles_attributes[attr_pos++] =
wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplesamples; _this->gl_config.multisamplesamples;
} }
/* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */ /* Multisample buffers, OpenGL ES 1.0 spec defines 0 or 1 buffer */
if (_this->gl_config.multisamplebuffers) if (_this->gl_config.multisamplebuffers) {
{ wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS; wdata->gles_attributes[attr_pos++] =
wdata->gles_attributes[attr_pos++]=_this->gl_config.multisamplebuffers; _this->gl_config.multisamplebuffers;
} }
/* Finish attributes list */ /* Finish attributes list */
wdata->gles_attributes[attr_pos]=EGL_NONE; wdata->gles_attributes[attr_pos] = EGL_NONE;
/* Request first suitable framebuffer configuration */ /* Request first suitable framebuffer configuration */
status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes, status = eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes,
wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs); wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS,
if (status!=EGL_TRUE) &configs);
{ if (status != EGL_TRUE) {
SDL_SetError("GF: Can't find closest configuration for OpenGL ES"); SDL_SetError("GF: Can't find closest configuration for OpenGL ES");
return NULL; return NULL;
} }
/* Check if nothing has been found, try "don't care" settings */ /* Check if nothing has been found, try "don't care" settings */
if (configs==0) if (configs == 0) {
{
int32_t it; int32_t it;
int32_t jt; int32_t jt;
GLint depthbits[4]={32, 24, 16, EGL_DONT_CARE}; GLint depthbits[4] = { 32, 24, 16, EGL_DONT_CARE };
for (it=0; it<4; it++) for (it = 0; it < 4; it++) {
{ for (jt = 16; jt >= 0; jt--) {
for (jt=16; jt>=0; jt--)
{
/* Don't care about color buffer bits, use what exist */ /* Don't care about color buffer bits, use what exist */
/* Replace previous data set with EGL_DONT_CARE */ /* Replace previous data set with EGL_DONT_CARE */
attr_pos=0; attr_pos = 0;
wdata->gles_attributes[attr_pos++]=EGL_NATIVE_VISUAL_ID; wdata->gles_attributes[attr_pos++] = EGL_NATIVE_VISUAL_ID;
wdata->gles_attributes[attr_pos++]=qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format); wdata->gles_attributes[attr_pos++] =
wdata->gles_attributes[attr_pos++]=EGL_RED_SIZE; qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format);
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_RED_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_GREEN_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_GREEN_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_BLUE_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_BLUE_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_ALPHA_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_ALPHA_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_BUFFER_SIZE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_BUFFER_SIZE;
wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
/* Try to find requested or smallest depth */ /* Try to find requested or smallest depth */
if (_this->gl_config.depth_size) if (_this->gl_config.depth_size) {
{ wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE; wdata->gles_attributes[attr_pos++] = depthbits[it];
wdata->gles_attributes[attr_pos++]=depthbits[it]; } else {
} wdata->gles_attributes[attr_pos++] = EGL_DEPTH_SIZE;
else wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
{
wdata->gles_attributes[attr_pos++]=EGL_DEPTH_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
} }
if (_this->gl_config.stencil_size) if (_this->gl_config.stencil_size) {
{ wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE; wdata->gles_attributes[attr_pos++] = jt;
wdata->gles_attributes[attr_pos++]=jt; } else {
} wdata->gles_attributes[attr_pos++] = EGL_STENCIL_SIZE;
else wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
{
wdata->gles_attributes[attr_pos++]=EGL_STENCIL_SIZE;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE;
/* exit from stencil loop */ /* exit from stencil loop */
jt=0; jt = 0;
} }
/* Don't care about antialiasing */ /* Don't care about antialiasing */
wdata->gles_attributes[attr_pos++]=EGL_SAMPLES; wdata->gles_attributes[attr_pos++] = EGL_SAMPLES;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
wdata->gles_attributes[attr_pos++]=EGL_SAMPLE_BUFFERS; wdata->gles_attributes[attr_pos++] = EGL_SAMPLE_BUFFERS;
wdata->gles_attributes[attr_pos++]=EGL_DONT_CARE; wdata->gles_attributes[attr_pos++] = EGL_DONT_CARE;
wdata->gles_attributes[attr_pos]=EGL_NONE; wdata->gles_attributes[attr_pos] = EGL_NONE;
/* Request first suitable framebuffer configuration */ /* Request first suitable framebuffer configuration */
status=eglChooseConfig(gfdata->egldisplay, wdata->gles_attributes, status =
wdata->gles_configs, SDL_VIDEO_GF_OPENGLES_CONFS, &configs); eglChooseConfig(gfdata->egldisplay,
if (status!=EGL_TRUE) wdata->gles_attributes,
{ wdata->gles_configs,
SDL_SetError("Photon: Can't find closest configuration for OpenGL ES"); SDL_VIDEO_GF_OPENGLES_CONFS, &configs);
if (status != EGL_TRUE) {
SDL_SetError
("Photon: Can't find closest configuration for OpenGL ES");
return NULL; return NULL;
} }
if (configs!=0) if (configs != 0) {
{
break; break;
} }
} }
if (configs!=0) if (configs != 0) {
{
break; break;
} }
} }
/* No available configs */ /* No available configs */
if (configs==0) if (configs == 0) {
{ SDL_SetError
SDL_SetError("Photon: Can't find any configuration for OpenGL ES"); ("Photon: Can't find any configuration for OpenGL ES");
return NULL; return NULL;
} }
} }
/* Initialize config index */ /* Initialize config index */
wdata->gles_config=0; wdata->gles_config = 0;
/* Now check each configuration to find out the best */ /* Now check each configuration to find out the best */
for (cit=0; cit<configs; cit++) for (cit = 0; cit < configs; cit++) {
{
uint32_t stencil_found; uint32_t stencil_found;
uint32_t depth_found; uint32_t depth_found;
stencil_found=0; stencil_found = 0;
depth_found=0; depth_found = 0;
if (_this->gl_config.stencil_size) if (_this->gl_config.stencil_size) {
{ status =
status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[cit], EGL_STENCIL_SIZE, &attr_value); eglGetConfigAttrib(gfdata->egldisplay,
if (status==EGL_TRUE) wdata->gles_configs[cit], EGL_STENCIL_SIZE,
{ &attr_value);
if (attr_value!=0) if (status == EGL_TRUE) {
{ if (attr_value != 0) {
stencil_found=1; stencil_found = 1;
} }
} }
} } else {
else stencil_found = 1;
{
stencil_found=1;
} }
if (_this->gl_config.depth_size) if (_this->gl_config.depth_size) {
{ status =
status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[cit], EGL_DEPTH_SIZE, &attr_value); eglGetConfigAttrib(gfdata->egldisplay,
if (status==EGL_TRUE) wdata->gles_configs[cit], EGL_DEPTH_SIZE,
{ &attr_value);
if (attr_value!=0) if (status == EGL_TRUE) {
{ if (attr_value != 0) {
depth_found=1; depth_found = 1;
}
} }
} }
else } else {
{ depth_found = 1;
depth_found=1;
} }
/* Exit from loop if found appropriate configuration */ /* Exit from loop if found appropriate configuration */
if ((depth_found!=0) && (stencil_found!=0)) if ((depth_found != 0) && (stencil_found != 0)) {
{
break; break;
} }
} }
/* If best could not be found, use first */ /* If best could not be found, use first */
if (cit==configs) if (cit == configs) {
{ cit = 0;
cit=0;
} }
wdata->gles_config=cit; wdata->gles_config = cit;
/* Create OpenGL ES context */ /* Create OpenGL ES context */
wdata->gles_context=eglCreateContext(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_NO_CONTEXT, NULL); wdata->gles_context =
if (wdata->gles_context==EGL_NO_CONTEXT) eglCreateContext(gfdata->egldisplay,
{ wdata->gles_configs[wdata->gles_config],
EGL_NO_CONTEXT, NULL);
if (wdata->gles_context == EGL_NO_CONTEXT) {
SDL_SetError("GF: OpenGL ES context creation has been failed"); SDL_SetError("GF: OpenGL ES context creation has been failed");
return NULL; return NULL;
} }
/* Free any 3D target if it was created before */ /* Free any 3D target if it was created before */
if (wdata->target_created==SDL_TRUE) if (wdata->target_created == SDL_TRUE) {
{
gf_3d_target_free(wdata->target); gf_3d_target_free(wdata->target);
wdata->target_created==SDL_FALSE; wdata->target_created == SDL_FALSE;
} }
/* Create surface(s) target for OpenGL ES */ /* Create surface(s) target for OpenGL ES */
gfstatus=gf_3d_target_create(&wdata->target, didata->layer, &didata->surface[0], gfstatus =
surfaces, didata->current_mode.w, didata->current_mode.h, gf_3d_target_create(&wdata->target, didata->layer,
qnxgf_sdl_to_gf_pixelformat(didata->current_mode.format)); &didata->surface[0], surfaces,
if (gfstatus!=GF_ERR_OK) didata->current_mode.w, didata->current_mode.h,
{ qnxgf_sdl_to_gf_pixelformat(didata->current_mode.
format));
if (gfstatus != GF_ERR_OK) {
/* Destroy just created context */ /* Destroy just created context */
eglDestroyContext(gfdata->egldisplay, wdata->gles_context); eglDestroyContext(gfdata->egldisplay, wdata->gles_context);
wdata->gles_context=EGL_NO_CONTEXT; wdata->gles_context = EGL_NO_CONTEXT;
/* Mark 3D target as unallocated */ /* Mark 3D target as unallocated */
wdata->target_created=SDL_FALSE; wdata->target_created = SDL_FALSE;
SDL_SetError("GF: OpenGL ES target could not be created"); SDL_SetError("GF: OpenGL ES target could not be created");
return NULL; return NULL;
} } else {
else wdata->target_created = SDL_TRUE;
{
wdata->target_created=SDL_TRUE;
} }
/* Create target rendering surface on whole screen */ /* Create target rendering surface on whole screen */
wdata->gles_surface=eglCreateWindowSurface(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], wdata->target, NULL); wdata->gles_surface =
if (wdata->gles_surface==EGL_NO_SURFACE) eglCreateWindowSurface(gfdata->egldisplay,
{ wdata->gles_configs[wdata->gles_config],
wdata->target, NULL);
if (wdata->gles_surface == EGL_NO_SURFACE) {
/* Destroy 3d target */ /* Destroy 3d target */
gf_3d_target_free(wdata->target); gf_3d_target_free(wdata->target);
wdata->target_created=SDL_FALSE; wdata->target_created = SDL_FALSE;
/* Destroy OpenGL ES context */ /* Destroy OpenGL ES context */
eglDestroyContext(gfdata->egldisplay, wdata->gles_context); eglDestroyContext(gfdata->egldisplay, wdata->gles_context);
wdata->gles_context=EGL_NO_CONTEXT; wdata->gles_context = EGL_NO_CONTEXT;
SDL_SetError("GF: OpenGL ES surface could not be created"); SDL_SetError("GF: OpenGL ES surface could not be created");
return NULL; return NULL;
} }
/* Make just created context current */ /* Make just created context current */
status=eglMakeCurrent(gfdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context); status =
if (status!=EGL_TRUE) eglMakeCurrent(gfdata->egldisplay, wdata->gles_surface,
{ wdata->gles_surface, wdata->gles_context);
if (status != EGL_TRUE) {
/* Destroy OpenGL ES surface */ /* Destroy OpenGL ES surface */
eglDestroySurface(gfdata->egldisplay, wdata->gles_surface); eglDestroySurface(gfdata->egldisplay, wdata->gles_surface);
/* Destroy 3d target */ /* Destroy 3d target */
gf_3d_target_free(wdata->target); gf_3d_target_free(wdata->target);
wdata->target_created=SDL_FALSE; wdata->target_created = SDL_FALSE;
/* Destroy OpenGL ES context */ /* Destroy OpenGL ES context */
eglDestroyContext(gfdata->egldisplay, wdata->gles_context); eglDestroyContext(gfdata->egldisplay, wdata->gles_context);
wdata->gles_context=EGL_NO_CONTEXT; wdata->gles_context = EGL_NO_CONTEXT;
/* Failed to set current GL ES context */ /* Failed to set current GL ES context */
SDL_SetError("GF: Can't set OpenGL ES context on creation"); SDL_SetError("GF: Can't set OpenGL ES context on creation");
...@@ -1700,81 +1668,85 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window) ...@@ -1700,81 +1668,85 @@ SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window)
/* Setup into SDL internals state of OpenGL ES: */ /* Setup into SDL internals state of OpenGL ES: */
/* it is accelerated or not */ /* it is accelerated or not */
if ((didata->caps & SDL_GF_ACCELERATED_3D)==SDL_GF_ACCELERATED_3D) if ((didata->caps & SDL_GF_ACCELERATED_3D) == SDL_GF_ACCELERATED_3D) {
{ _this->gl_config.accelerated = 1;
_this->gl_config.accelerated=1; } else {
} _this->gl_config.accelerated = 0;
else
{
_this->gl_config.accelerated=0;
} }
/* Always clear stereo enable, since OpenGL ES do not supports stereo */ /* Always clear stereo enable, since OpenGL ES do not supports stereo */
_this->gl_config.stereo=0; _this->gl_config.stereo = 0;
/* Get back samples and samplebuffers configurations. Rest framebuffer */ /* Get back samples and samplebuffers configurations. Rest framebuffer */
/* parameters could be obtained through the OpenGL ES API */ /* parameters could be obtained through the OpenGL ES API */
status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLES, &attr_value); status =
if (status==EGL_TRUE) eglGetConfigAttrib(gfdata->egldisplay,
{ wdata->gles_configs[wdata->gles_config],
_this->gl_config.multisamplesamples=attr_value; EGL_SAMPLES, &attr_value);
if (status == EGL_TRUE) {
_this->gl_config.multisamplesamples = attr_value;
} }
status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_SAMPLE_BUFFERS, &attr_value); status =
if (status==EGL_TRUE) eglGetConfigAttrib(gfdata->egldisplay,
{ wdata->gles_configs[wdata->gles_config],
_this->gl_config.multisamplebuffers=attr_value; EGL_SAMPLE_BUFFERS, &attr_value);
if (status == EGL_TRUE) {
_this->gl_config.multisamplebuffers = attr_value;
} }
/* Get back stencil and depth buffer sizes */ /* Get back stencil and depth buffer sizes */
status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_DEPTH_SIZE, &attr_value); status =
if (status==EGL_TRUE) eglGetConfigAttrib(gfdata->egldisplay,
{ wdata->gles_configs[wdata->gles_config],
_this->gl_config.depth_size=attr_value; EGL_DEPTH_SIZE, &attr_value);
if (status == EGL_TRUE) {
_this->gl_config.depth_size = attr_value;
} }
status=eglGetConfigAttrib(gfdata->egldisplay, wdata->gles_configs[wdata->gles_config], EGL_STENCIL_SIZE, &attr_value); status =
if (status==EGL_TRUE) eglGetConfigAttrib(gfdata->egldisplay,
{ wdata->gles_configs[wdata->gles_config],
_this->gl_config.stencil_size=attr_value; EGL_STENCIL_SIZE, &attr_value);
if (status == EGL_TRUE) {
_this->gl_config.stencil_size = attr_value;
} }
/* Restore cursor if it was visible */ /* Restore cursor if it was visible */
if (didata->cursor_visible==SDL_TRUE) if (didata->cursor_visible == SDL_TRUE) {
{
gf_cursor_set(didata->display, 0, &didata->cursor); gf_cursor_set(didata->display, 0, &didata->cursor);
gf_cursor_enable(didata->display, 0); gf_cursor_enable(didata->display, 0);
} }
/* GL ES context was successfully created */ /* GL ES context was successfully created */
return wdata->gles_context; return wdata->gles_context;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return NULL; return NULL;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
int qnxgf_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context) int
qnxgf_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData* wdata; SDL_WindowData *wdata;
EGLBoolean status; EGLBoolean status;
if ((window==NULL) && (context==NULL)) if ((window == NULL) && (context == NULL)) {
{ status =
status=eglMakeCurrent(gfdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglMakeCurrent(gfdata->egldisplay, EGL_NO_SURFACE, EGL_NO_SURFACE,
if (status!=EGL_TRUE) EGL_NO_CONTEXT);
{ if (status != EGL_TRUE) {
/* Failed to set current GL ES context */ /* Failed to set current GL ES context */
SDL_SetError("GF: Can't set OpenGL ES context"); SDL_SetError("GF: Can't set OpenGL ES context");
return -1; return -1;
} }
} } else {
else wdata = (SDL_WindowData *) window->driverdata;
{ status =
wdata=(SDL_WindowData*)window->driverdata; eglMakeCurrent(gfdata->egldisplay, wdata->gles_surface,
status=eglMakeCurrent(gfdata->egldisplay, wdata->gles_surface, wdata->gles_surface, wdata->gles_context); wdata->gles_surface, wdata->gles_context);
if (status!=EGL_TRUE) if (status != EGL_TRUE) {
{
/* Failed to set current GL ES context */ /* Failed to set current GL ES context */
SDL_SetError("GF: Can't set OpenGL ES context"); SDL_SetError("GF: Can't set OpenGL ES context");
return -1; return -1;
...@@ -1782,27 +1754,26 @@ int qnxgf_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context) ...@@ -1782,27 +1754,26 @@ int qnxgf_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context)
} }
return 0; return 0;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return -1; return -1;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
int qnxgf_gl_setswapinterval(_THIS, int interval) int
qnxgf_gl_setswapinterval(_THIS, int interval)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
EGLBoolean status; EGLBoolean status;
/* Check if OpenGL ES connection has been initialized */ /* Check if OpenGL ES connection has been initialized */
if (gfdata->egldisplay!=EGL_NO_DISPLAY) if (gfdata->egldisplay != EGL_NO_DISPLAY) {
{
/* Set swap OpenGL ES interval */ /* Set swap OpenGL ES interval */
status=eglSwapInterval(gfdata->egldisplay, interval); status = eglSwapInterval(gfdata->egldisplay, interval);
if (status==EGL_TRUE) if (status == EGL_TRUE) {
{
/* Return success to upper level */ /* Return success to upper level */
gfdata->swapinterval=interval; gfdata->swapinterval = interval;
return 0; return 0;
} }
} }
...@@ -1810,56 +1781,56 @@ int qnxgf_gl_setswapinterval(_THIS, int interval) ...@@ -1810,56 +1781,56 @@ int qnxgf_gl_setswapinterval(_THIS, int interval)
/* Failed to set swap interval */ /* Failed to set swap interval */
SDL_SetError("GF: Cannot set swap interval"); SDL_SetError("GF: Cannot set swap interval");
return -1; return -1;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return -1; return -1;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
int qnxgf_gl_getswapinterval(_THIS) int
qnxgf_gl_getswapinterval(_THIS)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
/* Return default swap interval value */ /* Return default swap interval value */
return gfdata->swapinterval; return gfdata->swapinterval;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return -1; return -1;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
void qnxgf_gl_swapwindow(_THIS, SDL_Window* window) void
qnxgf_gl_swapwindow(_THIS, SDL_Window * window)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
SDL_WindowData* wdata=(SDL_WindowData*)window->driverdata; SDL_WindowData *wdata = (SDL_WindowData *) window->driverdata;
/* Finish all drawings */ /* Finish all drawings */
glFinish(); glFinish();
/* Swap buffers */ /* Swap buffers */
eglSwapBuffers(gfdata->egldisplay, wdata->gles_surface); eglSwapBuffers(gfdata->egldisplay, wdata->gles_surface);
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return; return;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
void qnxgf_gl_deletecontext(_THIS, SDL_GLContext context) void
qnxgf_gl_deletecontext(_THIS, SDL_GLContext context)
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
SDL_VideoData* gfdata=(SDL_VideoData*)_this->driverdata; SDL_VideoData *gfdata = (SDL_VideoData *) _this->driverdata;
EGLBoolean status; EGLBoolean status;
/* Check if OpenGL ES connection has been initialized */ /* Check if OpenGL ES connection has been initialized */
if (gfdata->egldisplay!=EGL_NO_DISPLAY) if (gfdata->egldisplay != EGL_NO_DISPLAY) {
{ if (context != EGL_NO_CONTEXT) {
if (context!=EGL_NO_CONTEXT) status = eglDestroyContext(gfdata->egldisplay, context);
{ if (status != EGL_TRUE) {
status=eglDestroyContext(gfdata->egldisplay, context);
if (status!=EGL_TRUE)
{
/* Error during OpenGL ES context destroying */ /* Error during OpenGL ES context destroying */
SDL_SetError("GF: OpenGL ES context destroy error"); SDL_SetError("GF: OpenGL ES context destroy error");
return; return;
...@@ -1868,23 +1839,25 @@ void qnxgf_gl_deletecontext(_THIS, SDL_GLContext context) ...@@ -1868,23 +1839,25 @@ void qnxgf_gl_deletecontext(_THIS, SDL_GLContext context)
} }
return; return;
#else #else
SDL_SetError("GF: OpenGL ES support is not compiled in"); SDL_SetError("GF: OpenGL ES support is not compiled in");
return; return;
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} }
/*****************************************************************************/ /*****************************************************************************/
/* SDL Event handling function */ /* SDL Event handling function */
/*****************************************************************************/ /*****************************************************************************/
void qnxgf_pumpevents(_THIS) void
qnxgf_pumpevents(_THIS)
{ {
} }
/*****************************************************************************/ /*****************************************************************************/
/* SDL screen saver related functions */ /* SDL screen saver related functions */
/*****************************************************************************/ /*****************************************************************************/
void qnxgf_suspendscreensaver(_THIS) void
qnxgf_suspendscreensaver(_THIS)
{ {
/* There is no screensaver in pure console, it may exist when running */ /* There is no screensaver in pure console, it may exist when running */
/* GF under Photon, but I do not know, how to disable screensaver */ /* GF under Photon, but I do not know, how to disable screensaver */
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include <gf/gf3d.h> #include <gf/gf3d.h>
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
#include <GLES/egl.h> #include <GLES/egl.h>
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
typedef struct SDL_VideoData typedef struct SDL_VideoData
...@@ -41,11 +41,11 @@ typedef struct SDL_VideoData ...@@ -41,11 +41,11 @@ typedef struct SDL_VideoData
gf_dev_t gfdev; /* GF device handle */ gf_dev_t gfdev; /* GF device handle */
gf_dev_info_t gfdev_info; /* GF device information */ gf_dev_info_t gfdev_info; /* GF device information */
SDL_bool gfinitialized; /* GF device initialization status */ SDL_bool gfinitialized; /* GF device initialization status */
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
EGLDisplay egldisplay; /* OpenGL ES display connection */ EGLDisplay egldisplay; /* OpenGL ES display connection */
uint32_t egl_refcount; /* OpenGL ES reference count */ uint32_t egl_refcount; /* OpenGL ES reference count */
uint32_t swapinterval; /* OpenGL ES default swap interval */ uint32_t swapinterval; /* OpenGL ES default swap interval */
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} SDL_VideoData; } SDL_VideoData;
#define SDL_VIDEO_GF_DEVICENAME_MAX 257 #define SDL_VIDEO_GF_DEVICENAME_MAX 257
...@@ -73,7 +73,7 @@ typedef struct SDL_DisplayData ...@@ -73,7 +73,7 @@ typedef struct SDL_DisplayData
typedef struct SDL_WindowData typedef struct SDL_WindowData
{ {
SDL_bool uses_gles; /* true if window support OpenGL ES */ SDL_bool uses_gles; /* true if window support OpenGL ES */
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
gf_3d_target_t target; /* OpenGL ES window target */ gf_3d_target_t target; /* OpenGL ES window target */
SDL_bool target_created; /* GF 3D target is created if true */ SDL_bool target_created; /* GF 3D target is created if true */
EGLConfig gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS]; EGLConfig gles_configs[SDL_VIDEO_GF_OPENGLES_CONFS];
...@@ -82,13 +82,13 @@ typedef struct SDL_WindowData ...@@ -82,13 +82,13 @@ typedef struct SDL_WindowData
EGLContext gles_context; /* OpenGL ES context */ EGLContext gles_context; /* OpenGL ES context */
EGLint gles_attributes[256]; /* OpenGL ES attributes for context */ EGLint gles_attributes[256]; /* OpenGL ES attributes for context */
EGLSurface gles_surface; /* OpenGL ES target rendering surface */ EGLSurface gles_surface; /* OpenGL ES target rendering surface */
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} SDL_WindowData; } SDL_WindowData;
typedef struct SDL_GLDriverData typedef struct SDL_GLDriverData
{ {
#if defined(SDL_VIDEO_OPENGL_ES) #if defined(SDL_VIDEO_OPENGL_ES)
#endif /* SDL_VIDEO_OPENGL_ES */ #endif /* SDL_VIDEO_OPENGL_ES */
} SDL_GLDriverData; } SDL_GLDriverData;
/****************************************************************************/ /****************************************************************************/
...@@ -96,7 +96,7 @@ typedef struct SDL_GLDriverData ...@@ -96,7 +96,7 @@ typedef struct SDL_GLDriverData
/****************************************************************************/ /****************************************************************************/
typedef struct GF_DeviceCaps typedef struct GF_DeviceCaps
{ {
uint8_t* name; uint8_t *name;
uint32_t caps; uint32_t caps;
} GF_DeviceCaps; } GF_DeviceCaps;
...@@ -117,38 +117,39 @@ typedef struct GF_DeviceCaps ...@@ -117,38 +117,39 @@ typedef struct GF_DeviceCaps
int qnxgf_videoinit(_THIS); int qnxgf_videoinit(_THIS);
void qnxgf_videoquit(_THIS); void qnxgf_videoquit(_THIS);
void qnxgf_getdisplaymodes(_THIS); void qnxgf_getdisplaymodes(_THIS);
int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode* mode); int qnxgf_setdisplaymode(_THIS, SDL_DisplayMode * mode);
int qnxgf_setdisplaypalette(_THIS, SDL_Palette* palette); int qnxgf_setdisplaypalette(_THIS, SDL_Palette * palette);
int qnxgf_getdisplaypalette(_THIS, SDL_Palette* palette); int qnxgf_getdisplaypalette(_THIS, SDL_Palette * palette);
int qnxgf_setdisplaygammaramp(_THIS, Uint16* ramp); int qnxgf_setdisplaygammaramp(_THIS, Uint16 * ramp);
int qnxgf_getdisplaygammaramp(_THIS, Uint16* ramp); int qnxgf_getdisplaygammaramp(_THIS, Uint16 * ramp);
int qnxgf_createwindow(_THIS, SDL_Window* window); int qnxgf_createwindow(_THIS, SDL_Window * window);
int qnxgf_createwindowfrom(_THIS, SDL_Window* window, const void* data); int qnxgf_createwindowfrom(_THIS, SDL_Window * window, const void *data);
void qnxgf_setwindowtitle(_THIS, SDL_Window* window); void qnxgf_setwindowtitle(_THIS, SDL_Window * window);
void qnxgf_setwindowicon(_THIS, SDL_Window* window, SDL_Surface* icon); void qnxgf_setwindowicon(_THIS, SDL_Window * window, SDL_Surface * icon);
void qnxgf_setwindowposition(_THIS, SDL_Window* window); void qnxgf_setwindowposition(_THIS, SDL_Window * window);
void qnxgf_setwindowsize(_THIS, SDL_Window* window); void qnxgf_setwindowsize(_THIS, SDL_Window * window);
void qnxgf_showwindow(_THIS, SDL_Window* window); void qnxgf_showwindow(_THIS, SDL_Window * window);
void qnxgf_hidewindow(_THIS, SDL_Window* window); void qnxgf_hidewindow(_THIS, SDL_Window * window);
void qnxgf_raisewindow(_THIS, SDL_Window* window); void qnxgf_raisewindow(_THIS, SDL_Window * window);
void qnxgf_maximizewindow(_THIS, SDL_Window* window); void qnxgf_maximizewindow(_THIS, SDL_Window * window);
void qnxgf_minimizewindow(_THIS, SDL_Window* window); void qnxgf_minimizewindow(_THIS, SDL_Window * window);
void qnxgf_restorewindow(_THIS, SDL_Window* window); void qnxgf_restorewindow(_THIS, SDL_Window * window);
void qnxgf_setwindowgrab(_THIS, SDL_Window* window); void qnxgf_setwindowgrab(_THIS, SDL_Window * window);
void qnxgf_destroywindow(_THIS, SDL_Window* window); void qnxgf_destroywindow(_THIS, SDL_Window * window);
/* Window manager function */ /* Window manager function */
SDL_bool qnxgf_getwindowwminfo(_THIS, SDL_Window* window, struct SDL_SysWMinfo* info); SDL_bool qnxgf_getwindowwminfo(_THIS, SDL_Window * window,
struct SDL_SysWMinfo *info);
/* OpenGL/OpenGL ES functions */ /* OpenGL/OpenGL ES functions */
int qnxgf_gl_loadlibrary(_THIS, const char* path); int qnxgf_gl_loadlibrary(_THIS, const char *path);
void* qnxgf_gl_getprocaddres(_THIS, const char* proc); void *qnxgf_gl_getprocaddres(_THIS, const char *proc);
void qnxgf_gl_unloadlibrary(_THIS); void qnxgf_gl_unloadlibrary(_THIS);
SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window* window); SDL_GLContext qnxgf_gl_createcontext(_THIS, SDL_Window * window);
int qnxgf_gl_makecurrent(_THIS, SDL_Window* window, SDL_GLContext context); int qnxgf_gl_makecurrent(_THIS, SDL_Window * window, SDL_GLContext context);
int qnxgf_gl_setswapinterval(_THIS, int interval); int qnxgf_gl_setswapinterval(_THIS, int interval);
int qnxgf_gl_getswapinterval(_THIS); int qnxgf_gl_getswapinterval(_THIS);
void qnxgf_gl_swapwindow(_THIS, SDL_Window* window); void qnxgf_gl_swapwindow(_THIS, SDL_Window * window);
void qnxgf_gl_deletecontext(_THIS, SDL_GLContext context); void qnxgf_gl_deletecontext(_THIS, SDL_GLContext context);
/* Event handling function */ /* Event handling function */
......
...@@ -598,7 +598,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) ...@@ -598,7 +598,7 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_NCPAINT: case WM_NCPAINT:
{ {
if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_FOREIGN) { if (SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_FOREIGN) {
return(0); return (0);
} }
break; break;
} }
......
...@@ -56,7 +56,7 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode) ...@@ -56,7 +56,7 @@ WIN_GetDisplayMode(LPCTSTR deviceName, DWORD index, SDL_DisplayMode * mode)
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
/* In WinCE EnumDisplaySettings(ENUM_CURRENT_SETTINGS) doesn't take the user defined orientation /* In WinCE EnumDisplaySettings(ENUM_CURRENT_SETTINGS) doesn't take the user defined orientation
into account but GetSystemMetrixs does. */ into account but GetSystemMetrixs does. */
if(index == ENUM_CURRENT_SETTINGS) { if (index == ENUM_CURRENT_SETTINGS) {
mode->w = GetSystemMetrics(SM_CXSCREEN); mode->w = GetSystemMetrics(SM_CXSCREEN);
mode->h = GetSystemMetrics(SM_CYSCREEN); mode->h = GetSystemMetrics(SM_CYSCREEN);
} }
...@@ -216,7 +216,7 @@ WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode) ...@@ -216,7 +216,7 @@ WIN_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
/* TODO: implement correctly. /* TODO: implement correctly.
On my Asus MyPAL, if I execute the code below On my Asus MyPAL, if I execute the code below
I get DISP_CHANGE_BADFLAGS and the Titlebar of the fullscreen window stays I get DISP_CHANGE_BADFLAGS and the Titlebar of the fullscreen window stays
visible ... (SDL_RaiseWindow() would fix that one)*/ visible ... (SDL_RaiseWindow() would fix that one) */
return 0; return 0;
#endif #endif
......
...@@ -40,7 +40,11 @@ ...@@ -40,7 +40,11 @@
#define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002 #define WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x0002
#endif #endif
typedef HGLRC (APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC, HGLRC hShareContext, const int * attribList); typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC) (HDC hDC,
HGLRC
hShareContext,
const int
*attribList);
int int
WIN_GL_LoadLibrary(_THIS, const char *path) WIN_GL_LoadLibrary(_THIS, const char *path)
...@@ -512,7 +516,9 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -512,7 +516,9 @@ WIN_GL_CreateContext(_THIS, SDL_Window * window)
return NULL; return NULL;
} }
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->wglGetProcAddress("wglCreateContextAttribsARB"); wglCreateContextAttribsARB =
(PFNWGLCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
wglGetProcAddress("wglCreateContextAttribsARB");
if (!wglCreateContextAttribsARB) { if (!wglCreateContextAttribsARB) {
SDL_SetError("GL 3.x is not supported"); SDL_SetError("GL 3.x is not supported");
context = temp_context; context = temp_context;
......
...@@ -242,7 +242,6 @@ WIN_CreateWindow(_THIS, SDL_Window * window) ...@@ -242,7 +242,6 @@ WIN_CreateWindow(_THIS, SDL_Window * window)
} }
g_hCtx[window->id] = videodata->WTOpenA(hwnd, &lc, TRUE); g_hCtx[window->id] = videodata->WTOpenA(hwnd, &lc, TRUE);
} }
#ifndef _WIN32_WCE /* has no RawInput */ #ifndef _WIN32_WCE /* has no RawInput */
/* we're telling the window, we want it to report raw input events from mice */ /* we're telling the window, we want it to report raw input events from mice */
Rid.usUsagePage = 0x01; Rid.usUsagePage = 0x01;
......
...@@ -77,7 +77,13 @@ ...@@ -77,7 +77,13 @@
static void X11_GL_InitExtensions(_THIS); static void X11_GL_InitExtensions(_THIS);
/* Typedef for the GL 3.0 context creation function */ /* Typedef for the GL 3.0 context creation function */
typedef GLXContext ( * PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display *dpy, GLXFBConfig config, GLXContext share_context, Bool direct, const int *attrib_list); typedef GLXContext(*PFNGLXCREATECONTEXTATTRIBSARBPROC) (Display * dpy,
GLXFBConfig config,
GLXContext
share_context,
Bool direct,
const int
*attrib_list);
int int
X11_GL_LoadLibrary(_THIS, const char *path) X11_GL_LoadLibrary(_THIS, const char *path)
...@@ -401,19 +407,25 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -401,19 +407,25 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
} else { } else {
/* If we want a GL 3.0 context or later we need to get a temporary /* If we want a GL 3.0 context or later we need to get a temporary
context to grab the new context creation function */ context to grab the new context creation function */
GLXContext temp_context = _this->gl_data->glXCreateContext(display, vinfo, NULL, True); GLXContext temp_context =
_this->gl_data->glXCreateContext(display, vinfo, NULL, True);
if (!temp_context) { if (!temp_context) {
SDL_SetError("Could not create GL context"); SDL_SetError("Could not create GL context");
return NULL; return NULL;
} else { } else {
int attribs[] = { int attribs[] = {
GLX_CONTEXT_MAJOR_VERSION_ARB, _this->gl_config.major_version, GLX_CONTEXT_MAJOR_VERSION_ARB,
GLX_CONTEXT_MINOR_VERSION_ARB, _this->gl_config.minor_version, _this->gl_config.major_version,
GLX_CONTEXT_MINOR_VERSION_ARB,
_this->gl_config.minor_version,
0 0
}; };
/* Get a pointer to the context creation function for GL 3.0 */ /* Get a pointer to the context creation function for GL 3.0 */
PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs = (PFNGLXCREATECONTEXTATTRIBSARBPROC)_this->gl_data->glXGetProcAddress((GLubyte*)"glXCreateContextAttribsARB"); PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribs =
(PFNGLXCREATECONTEXTATTRIBSARBPROC) _this->gl_data->
glXGetProcAddress((GLubyte *)
"glXCreateContextAttribsARB");
if (!glXCreateContextAttribs) { if (!glXCreateContextAttribs) {
SDL_SetError("GL 3.x is not supported"); SDL_SetError("GL 3.x is not supported");
context = temp_context; context = temp_context;
...@@ -421,16 +433,32 @@ X11_GL_CreateContext(_THIS, SDL_Window * window) ...@@ -421,16 +433,32 @@ X11_GL_CreateContext(_THIS, SDL_Window * window)
/* Create a GL 3.x context */ /* Create a GL 3.x context */
GLXFBConfig *framebuffer_config = NULL; GLXFBConfig *framebuffer_config = NULL;
int fbcount = 0; int fbcount = 0;
GLXFBConfig* (*glXChooseFBConfig)(Display* disp, int screen, const int* attrib_list, int* nelements); GLXFBConfig *(*glXChooseFBConfig) (Display * disp,
int screen,
glXChooseFBConfig = (GLXFBConfig* (*)(Display*, int, const int*, int*))_this->gl_data->glXGetProcAddress((GLubyte*)"glXChooseFBConfig"); const int *attrib_list,
int *nelements);
if (!glXChooseFBConfig || !(framebuffer_config = glXChooseFBConfig(display, DefaultScreen(display), NULL, &fbcount))) {
SDL_SetError("No good framebuffers found. GL 3.x disabled"); glXChooseFBConfig =
(GLXFBConfig *
(*)(Display *, int, const int *,
int *)) _this->gl_data->
glXGetProcAddress((GLubyte *) "glXChooseFBConfig");
if (!glXChooseFBConfig
|| !(framebuffer_config =
glXChooseFBConfig(display,
DefaultScreen(display), NULL,
&fbcount))) {
SDL_SetError
("No good framebuffers found. GL 3.x disabled");
context = temp_context; context = temp_context;
} else { } else {
context = glXCreateContextAttribs(display, framebuffer_config[0], NULL, True, attribs); context =
_this->gl_data->glXDestroyContext(display, temp_context); glXCreateContextAttribs(display,
framebuffer_config[0],
NULL, True, attribs);
_this->gl_data->glXDestroyContext(display,
temp_context);
} }
} }
} }
......
...@@ -118,10 +118,10 @@ main(int argc, char *argv[]) ...@@ -118,10 +118,10 @@ main(int argc, char *argv[])
/* you may want to change these according to the platform */ /* you may want to change these according to the platform */
video_w = 320; video_w = 320;
video_h = 480; video_h = 480;
#ifdef __QNXNTO__ #ifdef __QNXNTO__
video_h = 640; video_h = 640;
video_w = 480; video_w = 480;
#endif /* __QNXNTO__ */ #endif /* __QNXNTO__ */
if (argv[1]) { if (argv[1]) {
gl_library = argv[1]; gl_library = argv[1];
...@@ -153,11 +153,11 @@ main(int argc, char *argv[]) ...@@ -153,11 +153,11 @@ main(int argc, char *argv[])
pixels[3 * i + 2] = rand() % 250 - 125; pixels[3 * i + 2] = rand() % 250 - 125;
} }
#ifdef __QNXNTO__ #ifdef __QNXNTO__
f.glViewport(0, 0, video_h, video_w); f.glViewport(0, 0, video_h, video_w);
#else #else
f.glViewport(0, 0, video_w, video_h); f.glViewport(0, 0, video_w, video_h);
#endif /* __QNXNTO__ */ #endif /* __QNXNTO__ */
f.glMatrixMode(GL_PROJECTION); f.glMatrixMode(GL_PROJECTION);
f.glLoadIdentity(); f.glLoadIdentity();
......
...@@ -242,51 +242,54 @@ main(int argc, char *argv[]) ...@@ -242,51 +242,54 @@ main(int argc, char *argv[])
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n"); printf("\n");
status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); printf("Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); printf("Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); printf("Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
} else { } else {
printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); printf("Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError());
} }
if (fsaa) { if (fsaa) {
status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else { } else {
printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); printf("Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
} else { } else {
printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); printf("Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
} }
} }
if (accel) { if (accel) {
status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
if (!status) if (!status) {
{
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else { } else {
printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); printf("Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
} }
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "SDL_opengles.h" #include "SDL_opengles.h"
static CommonState *state; static CommonState *state;
static SDL_GLContext *context=NULL; static SDL_GLContext *context = NULL;
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
static void static void
...@@ -22,10 +22,8 @@ quit(int rc) ...@@ -22,10 +22,8 @@ quit(int rc)
{ {
int i; int i;
if (context!=NULL) if (context != NULL) {
{ for (i = 0; i < state->num_windows; i++) {
for (i=0; i<state->num_windows; i++)
{
if (context[i]) { if (context[i]) {
SDL_GL_DeleteContext(context[i]); SDL_GL_DeleteContext(context[i]);
} }
...@@ -149,16 +147,14 @@ main(int argc, char *argv[]) ...@@ -149,16 +147,14 @@ main(int argc, char *argv[])
quit(2); quit(2);
} }
context=SDL_calloc(state->num_windows, sizeof(SDL_GLContext)); context = SDL_calloc(state->num_windows, sizeof(SDL_GLContext));
if (context==NULL) if (context == NULL) {
{
fprintf(stderr, "Out of memory!\n"); fprintf(stderr, "Out of memory!\n");
quit(2); quit(2);
} }
/* Create OpenGL ES contexts */ /* Create OpenGL ES contexts */
for (i=0; i<state->num_windows; i++) for (i = 0; i < state->num_windows; i++) {
{
context[i] = SDL_GL_CreateContext(state->windows[i]); context[i] = SDL_GL_CreateContext(state->windows[i]);
if (!context[i]) { if (!context[i]) {
fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError()); fprintf(stderr, "SDL_GL_CreateContext(): %s\n", SDL_GetError());
...@@ -181,59 +177,65 @@ main(int argc, char *argv[]) ...@@ -181,59 +177,65 @@ main(int argc, char *argv[])
printf("Extensions : %s\n", glGetString(GL_EXTENSIONS)); printf("Extensions : %s\n", glGetString(GL_EXTENSIONS));
printf("\n"); printf("\n");
status=SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_RED_SIZE: %s\n",
SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_GREEN_SIZE: %s\n",
SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value); printf("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_BLUE_SIZE: %s\n",
SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value); status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
if (!status) { if (!status) {
printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value); printf("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", 16, value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
SDL_GetError());
} }
if (fsaa) { if (fsaa) {
status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value); printf("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
SDL_GetError());
} }
status=SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value); status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
if (!status) { if (!status) {
printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa, value); printf("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
SDL_GetError());
} }
} }
if (accel) { if (accel) {
status=SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value); status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
if (!status) if (!status) {
{
printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value); printf("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
} else { } else {
fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n", SDL_GetError()); fprintf(stderr, "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
SDL_GetError());
} }
} }
/* Set rendering settings for each context */ /* Set rendering settings for each context */
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
status=SDL_GL_MakeCurrent(state->windows[i], context[i]); status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) if (status) {
{
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */ /* Continue for next window */
...@@ -262,9 +264,8 @@ main(int argc, char *argv[]) ...@@ -262,9 +264,8 @@ main(int argc, char *argv[])
} }
for (i = 0; i < state->num_windows; ++i) { for (i = 0; i < state->num_windows; ++i) {
int w, h; int w, h;
status=SDL_GL_MakeCurrent(state->windows[i], context[i]); status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
if (status) if (status) {
{
printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError()); printf("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
/* Continue for next window */ /* Continue for next window */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment