src/video/photon/SDL_ph_video.c
author Sam Lantinga <slouken@libsdl.org>
Sat, 02 Mar 2002 16:50:35 +0000
changeset 291 68a8a8237c09
parent 283 3d8b6b9f1e18
child 297 f6ffac90895c
permissions -rw-r--r--
Date: Thu, 21 Feb 2002 09:18:24 +0200
From: "Mike Gorchak" <mike@malva.ua>
Subject: Re: Patches for QNX RtP again.

SDL_ph_image.c - Added OpenGL update functions - fixed some application
crashes.
Some dead code removed, reformatting some functions.
SDL_ph_image_c.h - Added OpenGL update function prototype.
SDL_ph_video.c - Added GL_GetAttribute and GL_SetAttribute functions
with next supported flags: SDL_GL_DOUBLEBUFFER,
SDL_GL_STENCIL_SIZE, SDL_GL_DEPTH_SIZE
GetWMInfo function (stub) has been implemented by me,
but not listed in device structure - fixed.
SDL_ph_wm.c - fixed warning 'no return in non-void function'.
README.QNX - Updating readme. Some spellcheck. ;-)
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@0
     3
    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
#include <stdlib.h>
slouken@0
    29
#include <stdio.h>
slouken@0
    30
#include <unistd.h>
slouken@0
    31
#include <string.h>
slouken@0
    32
#include <sys/ioctl.h>
slouken@0
    33
slouken@0
    34
#include "SDL.h"
slouken@0
    35
#include "SDL_error.h"
slouken@0
    36
#include "SDL_timer.h"
slouken@0
    37
#include "SDL_thread.h"
slouken@0
    38
#include "SDL_video.h"
slouken@0
    39
#include "SDL_mouse.h"
slouken@0
    40
#include "SDL_endian.h"
slouken@0
    41
#include "SDL_sysvideo.h"
slouken@0
    42
#include "SDL_pixels_c.h"
slouken@0
    43
#include "SDL_events_c.h"
slouken@0
    44
#include "SDL_ph_video.h"
slouken@0
    45
#include "SDL_ph_modes_c.h"
slouken@0
    46
#include "SDL_ph_image_c.h"
slouken@0
    47
#include "SDL_ph_events_c.h"
slouken@0
    48
#include "SDL_ph_mouse_c.h"
slouken@19
    49
#include "SDL_ph_wm_c.h"
slouken@0
    50
#include "SDL_phyuv_c.h"
slouken@0
    51
#include "blank_cursor.h"
slouken@0
    52
slouken@0
    53
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat);
slouken@0
    54
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
slouken@0
    55
                int width, int height, int bpp, Uint32 flags);
slouken@0
    56
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors);
slouken@0
    57
static void ph_VideoQuit(_THIS);
slouken@0
    58
static void ph_DeleteDevice(SDL_VideoDevice *device);
slouken@291
    59
slouken@291
    60
#ifdef HAVE_OPENGL
slouken@266
    61
static void ph_GL_SwapBuffers(_THIS);
slouken@291
    62
static int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value);
slouken@291
    63
#endif /* HAVE_OPENGL */
slouken@266
    64
slouken@279
    65
#ifdef HAVE_OPENGL
slouken@266
    66
PdOpenGLContext_t* OGLContext=NULL;
slouken@279
    67
#endif /* HAVE_OPENGL */
slouken@0
    68
slouken@0
    69
static int ph_Available(void)
slouken@0
    70
{
slouken@291
    71
    return 1;
slouken@0
    72
}
slouken@0
    73
slouken@0
    74
static SDL_VideoDevice *ph_CreateDevice(int devindex)
slouken@0
    75
{
slouken@0
    76
    SDL_VideoDevice *device;
slouken@0
    77
slouken@0
    78
    /* Initialize all variables that we clean on shutdown */
slouken@0
    79
    device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
slouken@0
    80
    if ( device ) {
slouken@0
    81
        memset(device, 0, (sizeof *device));
slouken@0
    82
        device->hidden = (struct SDL_PrivateVideoData *)
slouken@0
    83
                malloc((sizeof *device->hidden));
slouken@0
    84
        device->gl_data = NULL;
slouken@0
    85
    }
slouken@0
    86
    if ( (device == NULL) || (device->hidden == NULL) ) {
slouken@0
    87
        SDL_OutOfMemory();
slouken@0
    88
        ph_DeleteDevice(device);
slouken@0
    89
        return(0);
slouken@0
    90
    }
slouken@0
    91
    memset(device->hidden, 0, (sizeof *device->hidden));
slouken@0
    92
slouken@0
    93
    /* Set the driver flags */
slouken@279
    94
    device->handles_any_size = 1; /* JB not true for fullscreen */
slouken@0
    95
slouken@0
    96
    /* Set the function pointers */
slouken@266
    97
    device->CreateYUVOverlay = ph_CreateYUVOverlay;
slouken@0
    98
    device->VideoInit = ph_VideoInit;
slouken@0
    99
    device->ListModes = ph_ListModes;
slouken@0
   100
    device->SetVideoMode = ph_SetVideoMode;
slouken@0
   101
    device->ToggleFullScreen =  ph_ToggleFullScreen;
slouken@0
   102
    device->UpdateMouse = NULL;	
slouken@0
   103
    device->SetColors = ph_SetColors;
slouken@279
   104
    device->UpdateRects = NULL; /* ph_ResizeImage; */
slouken@0
   105
    device->VideoQuit = ph_VideoQuit;
slouken@0
   106
    device->AllocHWSurface = ph_AllocHWSurface;
slouken@0
   107
    device->CheckHWBlit = NULL;
slouken@0
   108
    device->FillHWRect = NULL;
slouken@0
   109
    device->SetHWColorKey = NULL;
slouken@0
   110
    device->SetHWAlpha = NULL;
slouken@0
   111
    device->LockHWSurface = ph_LockHWSurface;
slouken@0
   112
    device->UnlockHWSurface = ph_UnlockHWSurface;
slouken@0
   113
    device->FlipHWSurface = ph_FlipHWSurface;
slouken@0
   114
    device->FreeHWSurface = ph_FreeHWSurface;
slouken@19
   115
    device->SetCaption = ph_SetCaption;
slouken@0
   116
    device->SetIcon = NULL;
slouken@19
   117
    device->IconifyWindow = ph_IconifyWindow;
slouken@283
   118
    device->GrabInput = ph_GrabInput;
slouken@291
   119
    device->GetWMInfo = ph_GetWMInfo;
slouken@0
   120
    device->FreeWMCursor = ph_FreeWMCursor;
slouken@0
   121
    device->CreateWMCursor = ph_CreateWMCursor;
slouken@0
   122
    device->ShowWMCursor = ph_ShowWMCursor;
slouken@0
   123
    device->WarpWMCursor = ph_WarpWMCursor;
slouken@0
   124
    device->CheckMouseMode = ph_CheckMouseMode;
slouken@0
   125
    device->InitOSKeymap = ph_InitOSKeymap;
slouken@0
   126
    device->PumpEvents = ph_PumpEvents;
slouken@0
   127
slouken@279
   128
    /* OpenGL support. */
slouken@266
   129
    device->GL_LoadLibrary = NULL;
slouken@266
   130
    device->GL_GetProcAddress = NULL;
slouken@266
   131
    device->GL_MakeCurrent = NULL;
slouken@279
   132
#ifdef HAVE_OPENGL
slouken@266
   133
    device->GL_SwapBuffers = ph_GL_SwapBuffers;
slouken@291
   134
    device->GL_GetAttribute = ph_GL_GetAttribute;
slouken@279
   135
#else
slouken@279
   136
    device->GL_SwapBuffers = NULL;
slouken@291
   137
    device->GL_GetAttribute = NULL;
slouken@279
   138
#endif /* HAVE_OPENGL */
slouken@266
   139
slouken@0
   140
    device->free = ph_DeleteDevice;
slouken@0
   141
slouken@0
   142
    return device;
slouken@0
   143
}
slouken@0
   144
slouken@19
   145
VideoBootStrap ph_bootstrap = {
slouken@0
   146
        "photon", "QNX Photon video output",
slouken@0
   147
	ph_Available, ph_CreateDevice
slouken@0
   148
};
slouken@0
   149
slouken@0
   150
static void ph_DeleteDevice(SDL_VideoDevice *device)
slouken@0
   151
{
slouken@0
   152
slouken@0
   153
    if ( device ) {
slouken@0
   154
        if ( device->hidden ) {
slouken@0
   155
            free(device->hidden);
slouken@0
   156
            device->hidden = NULL;
slouken@0
   157
        }
slouken@0
   158
        if ( device->gl_data ) {
slouken@0
   159
            free(device->gl_data);
slouken@0
   160
            device->gl_data = NULL;
slouken@0
   161
        }
slouken@0
   162
        free(device);
slouken@0
   163
        device = NULL;
slouken@0
   164
    }
slouken@0
   165
}
slouken@0
   166
slouken@0
   167
static int ph_VideoInit(_THIS, SDL_PixelFormat *vformat)
slouken@0
   168
{
slouken@0
   169
	PtArg_t arg[1];
slouken@266
   170
	PhDim_t dim;
slouken@0
   171
	PgColor_t ph_palette[_Pg_MAX_PALETTE];
slouken@0
   172
	int i;
slouken@0
   173
	unsigned long *tempptr;
slouken@0
   174
	int rtnval;
slouken@266
   175
//	PgDisplaySettings_t mysettings;
slouken@0
   176
	PgVideoModeInfo_t my_mode_info;
slouken@204
   177
	PgHWCaps_t my_hwcaps;
slouken@0
   178
	
slouken@266
   179
	if( NULL == ( event = malloc( EVENT_SIZE ) ) )
slouken@266
   180
	   exit( EXIT_FAILURE );
slouken@0
   181
slouken@0
   182
	/* Create a widget 'window' to capture events */
slouken@0
   183
    dim.w=0; //JB test320;
slouken@0
   184
    dim.h=0; //JB test240;
slouken@0
   185
    //We need to return BytesPerPixel as it in used by CreateRGBsurface
slouken@0
   186
	
slouken@0
   187
    PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
slouken@0
   188
    
slouken@0
   189
/*    
slouken@0
   190
    PtSetArg(&arg[1], Pt_ARG_RESIZE_FLAGS, Pt_TRUE, Pt_RESIZE_XY_AS_REQUIRED);
slouken@0
   191
    PtSetArg(&arg[2], Pt_ARG_WINDOW_STATE, Pt_TRUE, Ph_WM_STATE_ISFRONT |
slouken@0
   192
                        Ph_WM_STATE_ISMAX |
slouken@0
   193
                        Ph_WM_STATE_ISFOCUS);
slouken@0
   194
slouken@0
   195
    PtSetArg(&arg[3], Pt_ARG_WINDOW_RENDER_FLAGS,Pt_FALSE,~0);
slouken@0
   196
    PtSetArg(&arg[4], Pt_ARG_WINDOW_MANAGED_FLAGS,Pt_TRUE,
slouken@0
   197
                        Ph_WM_FFRONT |
slouken@0
   198
                        Ph_WM_CLOSE |
slouken@0
   199
                        Ph_WM_TOFRONT |
slouken@0
   200
                        Ph_WM_CONSWITCH);
slouken@0
   201
*/    
slouken@0
   202
    
slouken@0
   203
    
slouken@0
   204
	window=PtAppInit(NULL, NULL, NULL, 1, arg);
slouken@0
   205
slouken@0
   206
  	if(window == NULL)
slouken@0
   207
  	{
slouken@19
   208
  		printf("Photon application init failed, probably Photon is not running.\n");
slouken@19
   209
        	exit( EXIT_FAILURE );
slouken@0
   210
  	}
slouken@0
   211
slouken@266
   212
	//PgSetDrawBufferSize(16 *1024);
slouken@266
   213
	PgSetRegion(PtWidgetRid(window));
slouken@266
   214
	PgSetClipping(0,NULL);
slouken@266
   215
	PtRealizeWidget(window);
slouken@0
   216
slouken@0
   217
slouken@0
   218
    /* Get the available video modes */
slouken@0
   219
//    if(ph_GetVideoModes(this) < 0)
slouken@0
   220
//        return -1;
slouken@0
   221
slouken@0
   222
	/* Create the blank cursor */
slouken@0
   223
	SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
slouken@0
   224
                (int)BLANK_CWIDTH, (int)BLANK_CHEIGHT,
slouken@0
   225
                   (int)BLANK_CHOTX, (int)BLANK_CHOTY);
slouken@0
   226
slouken@0
   227
	if(SDL_BlankCursor == NULL)
slouken@0
   228
	  printf("could not create blank cursor\n");
slouken@279
   229
slouken@204
   230
         if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
slouken@266
   231
         {
slouken@204
   232
                fprintf(stderr,"ph_VideoInit:  GetGraphicsHWCaps failed!! \n");
slouken@266
   233
         }
slouken@204
   234
         if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
slouken@266
   235
         {
slouken@0
   236
                fprintf(stderr,"ph_VideoInit:  PgGetVideoModeInfo failed\n");
slouken@266
   237
         }
slouken@266
   238
slouken@279
   239
         //We need to return BytesPerPixel as it in used by CreateRGBsurface
slouken@279
   240
         vformat->BitsPerPixel = my_mode_info.bits_per_pixel;
slouken@279
   241
         vformat->BytesPerPixel = my_mode_info.bytes_per_scanline/my_mode_info.width;
slouken@279
   242
         
slouken@279
   243
         //return a palette if we are in 256 color mode           
slouken@0
   244
		if(vformat->BitsPerPixel == 8)
slouken@0
   245
		{
slouken@0
   246
			vformat->palette = malloc(sizeof(SDL_Palette));
slouken@0
   247
			memset(vformat->palette, 0, sizeof(SDL_Palette));
slouken@0
   248
			vformat->palette->ncolors = 256;
slouken@0
   249
			vformat->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
slouken@0
   250
			
slouken@0
   251
			//fill the palette
slouken@0
   252
			rtnval = PgGetPalette(ph_palette);
slouken@0
   253
			if(rtnval < 0)
slouken@0
   254
			   printf("ph_VideoInit:  PgGetPalette failed\n");
slouken@0
   255
			   
slouken@279
   256
                        tempptr = (unsigned long *)vformat->palette->colors;
slouken@0
   257
slouken@0
   258
			for(i=0;i<256; i++)
slouken@0
   259
			{
slouken@0
   260
  				*tempptr = (((unsigned long)ph_palette[i]) << 8);
slouken@0
   261
  				tempptr++;
slouken@0
   262
slouken@0
   263
			}		
slouken@0
   264
		
slouken@0
   265
		}
slouken@0
   266
slouken@0
   267
slouken@19
   268
    currently_fullscreen = 0;
slouken@19
   269
    
slouken@19
   270
    this->info.wm_available = 1;
slouken@19
   271
    
slouken@0
   272
    return 0;
slouken@0
   273
}
slouken@0
   274
slouken@0
   275
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current,
slouken@0
   276
                int width, int height, int bpp, Uint32 flags)
slouken@0
   277
{
slouken@0
   278
    PgDisplaySettings_t settings;
slouken@0
   279
    int mode, actual_width, actual_height;
slouken@266
   280
    PtArg_t arg[5];
slouken@266
   281
    PhDim_t dim;	
slouken@266
   282
    int rtnval;
slouken@266
   283
    PgColor_t ph_palette[_Pg_MAX_PALETTE];
slouken@266
   284
    int i;
slouken@266
   285
    unsigned long *tempptr;
slouken@279
   286
slouken@279
   287
#ifdef HAVE_OPENGL
slouken@266
   288
    uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS];
slouken@291
   289
    int OGLargc;
slouken@291
   290
#endif /* HAVE_OPENGL */
slouken@0
   291
slouken@266
   292
    actual_width = width;
slouken@266
   293
    actual_height = height;
slouken@0
   294
slouken@266
   295
    dim.w=width;
slouken@266
   296
    dim.h=height;
slouken@0
   297
slouken@0
   298
    /* Lock the event thread, in multi-threading environments */
slouken@0
   299
    SDL_Lock_EventThread();
slouken@0
   300
slouken@0
   301
     /* Initialize the window */
slouken@279
   302
    if (flags & SDL_FULLSCREEN) /* Direct Context , assume SDL_HWSURFACE also set */
slouken@0
   303
    {
slouken@0
   304
        /* Get the video mode and set it */
slouken@0
   305
        if (flags & SDL_ANYFORMAT)
slouken@0
   306
        {
slouken@0
   307
            if ((mode = get_mode_any_format(width, height, bpp)) == 0)
slouken@0
   308
            {
slouken@0
   309
                fprintf(stderr,"error: get_mode_any_format failed\n");
slouken@0
   310
                exit(1);
slouken@0
   311
            }
slouken@0
   312
        }
slouken@0
   313
        else
slouken@0
   314
        {
slouken@0
   315
            if ((mode = get_mode(width, height, bpp)) == 0)
slouken@0
   316
            {
slouken@291
   317
                fprintf(stderr,"error: get_mode failed\n");
slouken@291
   318
                exit(1);
slouken@0
   319
            }
slouken@0
   320
        }
slouken@0
   321
        settings.mode = mode;
slouken@0
   322
        settings.refresh = 0;
slouken@0
   323
        settings.flags  = 0;       
slouken@266
   324
slouken@0
   325
        if (PgSetVideoMode( &settings ) < 0)
slouken@0
   326
        {
slouken@0
   327
            fprintf(stderr,"error: PgSetVideoMode failed\n");
slouken@0
   328
        }
slouken@0
   329
slouken@291
   330
        /* Get the true height and width */
slouken@0
   331
slouken@291
   332
        current->flags = (flags & (~SDL_RESIZABLE)); /* no resize for Direct Context */
slouken@0
   333
slouken@291
   334
        /* Begin direct mode */
slouken@291
   335
slouken@291
   336
        ph_EnterFullScreen(this);
slouken@0
   337
slouken@279
   338
    } /* end fullscreen flag */
slouken@266
   339
    else
slouken@0
   340
    {
slouken@266
   341
       if (flags & SDL_HWSURFACE)  /* Use offscreen memory iff SDL_HWSURFACE flag is set */
slouken@266
   342
       {
slouken@279
   343
         /* Hardware surface is Offsceen Context.  ph_ResizeImage handles the switch */
slouken@283
   344
         current->flags = (flags & (~SDL_RESIZABLE)); /* no stretch blit in offscreen context */
slouken@266
   345
       }
slouken@279
   346
       else /* must be SDL_SWSURFACE */
slouken@266
   347
       {
slouken@283
   348
          current->flags = (flags | SDL_RESIZABLE); /* yes we can resize as this is a software surface */
slouken@266
   349
       }
slouken@279
   350
slouken@279
   351
#ifdef HAVE_OPENGL       
slouken@279
   352
       if (flags & SDL_OPENGL) /* for now support OpenGL in window mode only */
slouken@266
   353
       {
slouken@291
   354
          OGLargc=0;
slouken@291
   355
          if (this->gl_config.depth_size)
slouken@291
   356
          {
slouken@291
   357
             OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS;
slouken@291
   358
             OGLAttrib[OGLargc++]=this->gl_config.depth_size;
slouken@291
   359
          }
slouken@291
   360
          if (this->gl_config.stencil_size)
slouken@291
   361
          {
slouken@291
   362
             OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS;
slouken@291
   363
             OGLAttrib[OGLargc++]=this->gl_config.stencil_size;
slouken@291
   364
          }
slouken@291
   365
          OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE;
slouken@291
   366
          if (this->gl_config.double_buffer)
slouken@291
   367
          {
slouken@291
   368
             OGLContext=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib);
slouken@291
   369
          }
slouken@291
   370
          else
slouken@291
   371
          {
slouken@291
   372
             OGLContext=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib);
slouken@291
   373
          }
slouken@266
   374
          if (OGLContext==NULL)
slouken@266
   375
          {
slouken@291
   376
             fprintf(stderr,"error: cannot create OpenGL context.\n");
slouken@266
   377
             exit(1);
slouken@266
   378
          }
slouken@266
   379
          PhDCSetCurrent(OGLContext);
slouken@266
   380
       }
slouken@291
   381
#else
slouken@291
   382
       if (flags & SDL_OPENGL) /* if no OpenGL support */
slouken@291
   383
       {
slouken@291
   384
          fprintf(stderr, "error: no OpenGL support, try to recompile library.\n");
slouken@291
   385
          exit(1);
slouken@291
   386
       }
slouken@291
   387
slouken@279
   388
#endif /* HAVE_OPENGL */
slouken@266
   389
       
slouken@0
   390
    }
slouken@0
   391
slouken@279
   392
	/* If we are setting video to use the palette make sure we have allocated memory for it */
slouken@0
   393
	if(bpp == 8)
slouken@0
   394
	{
slouken@0
   395
		current->format->palette = malloc(sizeof(SDL_Palette));
slouken@0
   396
		memset(current->format->palette, 0, sizeof(SDL_Palette));
slouken@0
   397
		current->format->palette->ncolors = 256;
slouken@0
   398
		current->format->palette->colors = (SDL_Color *)malloc(256 *sizeof(SDL_Color));
slouken@279
   399
		/* fill the palette */
slouken@0
   400
		rtnval = PgGetPalette(ph_palette);
slouken@0
   401
slouken@266
   402
                tempptr = (unsigned long *)current->format->palette->colors;
slouken@0
   403
slouken@0
   404
		for(i=0;i<256; i++)
slouken@0
   405
		{
slouken@0
   406
  			*tempptr = (((unsigned long)ph_palette[i]) << 8);
slouken@0
   407
  			tempptr++;
slouken@0
   408
slouken@0
   409
		}
slouken@0
   410
	}
slouken@0
   411
slouken@0
   412
slouken@279
   413
	/* Current window dimensions */
slouken@0
   414
	PtGetResource( window, Pt_ARG_DIM, &dim, 0 );
slouken@279
   415
slouken@279
   416
	/* If we need to resize the window */
slouken@0
   417
	if((dim.w != width)||(dim.h != height))
slouken@0
   418
	{
slouken@0
   419
	    dim.w=width;
slouken@266
   420
	    dim.h=height; 
slouken@266
   421
	    PtSetArg(&arg[0], Pt_ARG_DIM, &dim,0);
slouken@266
   422
	    PtSetResources( window, 1, arg ); 	
slouken@266
   423
            current->w = width;
slouken@266
   424
            current->h = height;
slouken@266
   425
            current->format->BitsPerPixel = bpp;
slouken@279
   426
            current->format->BytesPerPixel = (bpp+7)/8;
slouken@266
   427
            current->pitch = SDL_CalculatePitch(current);
slouken@279
   428
            /* Must call at least once it setup image planes */
slouken@266
   429
            ph_ResizeImage(this, current, flags);
slouken@266
   430
        }
slouken@0
   431
slouken@0
   432
    SDL_Unlock_EventThread();
slouken@0
   433
slouken@0
   434
    /* We're done! */
slouken@0
   435
    return(current);
slouken@0
   436
}
slouken@0
   437
slouken@0
   438
static void ph_VideoQuit(_THIS)
slouken@0
   439
{
slouken@283
   440
    ph_DestroyImage(this, SDL_VideoSurface); 
slouken@0
   441
slouken@279
   442
    if (currently_fullscreen)
slouken@279
   443
    {
slouken@279
   444
        PdDirectStop( directContext );
slouken@279
   445
        PdReleaseDirectContext( directContext );
slouken@279
   446
        directContext=0;	
slouken@279
   447
        currently_fullscreen = 0;
slouken@279
   448
    }
slouken@0
   449
}
slouken@0
   450
slouken@0
   451
slouken@0
   452
static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
slouken@0
   453
{
slouken@0
   454
	PgColor_t *in, *out;
slouken@0
   455
	int i, j;
slouken@0
   456
	int alloct_all = 1;
slouken@0
   457
slouken@0
   458
    	colors = this->screen->format->palette->colors;
slouken@0
   459
slouken@0
   460
	in = alloca( ncolors*sizeof(PgColor_t)  );
slouken@0
   461
	if ( in == NULL  ) {
slouken@0
   462
		return 0;
slouken@0
   463
	}
slouken@0
   464
	memset(in,0,ncolors*sizeof(PgColor_t));
slouken@0
   465
slouken@0
   466
    out = alloca( ncolors*sizeof(PgColor_t)  );
slouken@0
   467
    if ( out == NULL  ) {
slouken@0
   468
		return 0;
slouken@0
   469
    }
slouken@0
   470
	
slouken@0
   471
	for (i=0,j=firstcolor;i<ncolors;i++,j++)
slouken@0
   472
	{
slouken@0
   473
		in[i] |= colors[j].r<<16 ;
slouken@0
   474
		in[i] |= colors[j].g<<8 ;
slouken@0
   475
		in[i] |= colors[j].b ; 
slouken@0
   476
	}
slouken@0
   477
slouken@0
   478
	if ( (this->screen->flags & SDL_HWPALETTE) == SDL_HWPALETTE ) 
slouken@0
   479
	{
slouken@0
   480
		if( PgSetPalette( in, 0, 0, ncolors, Pg_PALSET_HARD, 0) < 0 )
slouken@0
   481
		{
slouken@0
   482
			fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_HARD)  failed\n");
slouken@0
   483
			return 0;
slouken@0
   484
		}  
slouken@0
   485
	}
slouken@0
   486
	else 
slouken@0
   487
	{
slouken@0
   488
		if ( PgColorMatch(ncolors, in, out) < 0 )
slouken@0
   489
        {
slouken@0
   490
            fprintf(stderr,"error: PgColorMatch failed\n");
slouken@0
   491
            return 0;
slouken@0
   492
        }
slouken@0
   493
		for (i=0;i<ncolors;i++)
slouken@0
   494
		{
slouken@0
   495
			if (memcmp(&in[i],&out[i],sizeof(PgColor_t)))
slouken@0
   496
			{
slouken@0
   497
				alloct_all = 0;
slouken@0
   498
				break;
slouken@0
   499
			}
slouken@0
   500
		}
slouken@0
   501
        if( PgSetPalette( out, 0, 0, ncolors, Pg_PALSET_SOFT, 0) < 0 )
slouken@0
   502
        {
slouken@0
   503
            fprintf(stderr,"error: PgSetPalette(..,Pg_PALSET_SOFT) failed\n");
slouken@0
   504
            return 0;
slouken@0
   505
        }
slouken@0
   506
	}
slouken@0
   507
	return alloct_all;
slouken@0
   508
}
slouken@0
   509
slouken@279
   510
#ifdef HAVE_OPENGL
slouken@266
   511
void ph_GL_SwapBuffers(_THIS)
slouken@266
   512
{
slouken@291
   513
    PgSetRegion(PtWidgetRid(window));
slouken@291
   514
    PdOpenGLContextSwapBuffers(OGLContext);
slouken@266
   515
}
slouken@266
   516
slouken@291
   517
int ph_GL_GetAttribute(_THIS, SDL_GLattr attrib, int* value)
slouken@0
   518
{
slouken@291
   519
    switch (attrib)
slouken@291
   520
    {
slouken@291
   521
        case SDL_GL_DOUBLEBUFFER:
slouken@291
   522
             *value=this->gl_config.double_buffer;
slouken@291
   523
             break;
slouken@291
   524
        case SDL_GL_STENCIL_SIZE:
slouken@291
   525
             *value=this->gl_config.stencil_size;
slouken@291
   526
             break;
slouken@291
   527
        case SDL_GL_DEPTH_SIZE:
slouken@291
   528
             *value=this->gl_config.depth_size;
slouken@291
   529
             break;
slouken@291
   530
        default:
slouken@291
   531
             *value=0;
slouken@291
   532
             return(-1);
slouken@291
   533
    }
slouken@291
   534
    return 0;
slouken@291
   535
}
slouken@0
   536
slouken@291
   537
#endif /* HAVE_OPENGL */