Date: Wed, 22 May 2002 22:30:58 +0300
authorSam Lantinga <slouken@libsdl.org>
Tue, 28 May 2002 19:31:32 +0000
changeset 380bce7171e7a85
parent 379 11c8a7684f74
child 381 bc1401311390
Date: Wed, 22 May 2002 22:30:58 +0300
From: "Mike Gorchak" <mike@malva.com.ua>
Subject: One more QNX patch

Hi !

- Fixed graywin test application. Added properly support for
window size not equal to 640x480.
- Added support for not aligned pitch of image in SDL_SWSURFACE
and SDL_HWSURFACE. Using Photon builtin alignes.
- Added memory clear after each malloc to avoid problems in the
future :)
- Removed unused variables and static variables, fixed some warnings.
- Updated readme.QNX file.
README.QNX
src/video/photon/SDL_ph_image.c
src/video/photon/SDL_ph_mouse.c
src/video/photon/SDL_ph_video.c
src/video/photon/SDL_ph_video.h
src/video/photon/SDL_phyuv.c
test/graywin.c
     1.1 --- a/README.QNX	Tue May 28 19:24:11 2002 +0000
     1.2 +++ b/README.QNX	Tue May 28 19:31:32 2002 +0000
     1.3 @@ -1,4 +1,4 @@
     1.4 -README by Mike Gorchak <mike@malva.ua>
     1.5 +README by Mike Gorchak <mike@malva.ua>, <lestat@i.com.ua>
     1.6  
     1.7      OpenGL in window mode  works well  and  stable, in fullscreen
     1.8  mode too, but fullscreen mode has not been heavily tested.
     1.9 @@ -16,6 +16,9 @@
    1.10     videomode has.
    1.11  3. No  shared  libraries  yet.  We  need  manually  set  flag  to
    1.12     'configure' --disable-shared.
    1.13 +4. Due to Photon API limitation, flag SDL_HWSURFACE supported on-
    1.14 +   ly in case of desktop bpp is equal requested bpp in window mo-
    1.15 +   de.
    1.16  
    1.17  Some building issues:
    1.18  
     2.1 --- a/src/video/photon/SDL_ph_image.c	Tue May 28 19:24:11 2002 +0000
     2.2 +++ b/src/video/photon/SDL_ph_image.c	Tue May 28 19:31:32 2002 +0000
     2.3 @@ -38,11 +38,14 @@
     2.4  
     2.5  int ph_SetupImage(_THIS, SDL_Surface *screen)
     2.6  {
     2.7 +    PgColor_t* palette=NULL;
     2.8      int type=0;
     2.9 -    PgColor_t* palette=NULL;
    2.10 +    int bpp;
    2.11 +    
    2.12 +    bpp=screen->format->BitsPerPixel;
    2.13  
    2.14      /* Determine image type */
    2.15 -    switch(screen->format->BitsPerPixel)
    2.16 +    switch(bpp)
    2.17      {
    2.18          case 8:{
    2.19              type = Pg_IMAGE_PALETTE_BYTE;
    2.20 @@ -65,14 +68,14 @@
    2.21          }
    2.22          break;
    2.23          default:{
    2.24 -            fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", screen->format->BitsPerPixel);
    2.25 +            fprintf(stderr,"ph_SetupImage(): unsupported bbp = %d\n", bpp);
    2.26              return -1;
    2.27          }
    2.28          break;
    2.29      }
    2.30  
    2.31      /* palette emulation code */
    2.32 -    if ((screen->format->BitsPerPixel==8) && (desktoppal==SDLPH_PAL_EMULATE))
    2.33 +    if ((bpp==8) && (desktoppal==SDLPH_PAL_EMULATE))
    2.34      {
    2.35          /* creating image palette */
    2.36          palette=malloc(_Pg_MAX_PALETTE*sizeof(PgColor_t));
    2.37 @@ -81,7 +84,7 @@
    2.38          /* using shared memory for speed (set last param to 1) */
    2.39          if ((SDL_Image = PhCreateImage(NULL, screen->w, screen->h, type, palette, _Pg_MAX_PALETTE, 1)) == NULL)
    2.40          {
    2.41 -            fprintf(stderr,"ph_SetupImage: PhCreateImage failed for bpp=8.\n");
    2.42 +            fprintf(stderr,"ph_SetupImage(): PhCreateImage failed for bpp=8.\n");
    2.43              return -1;
    2.44          }
    2.45      }
    2.46 @@ -94,8 +97,9 @@
    2.47              return -1;
    2.48          }
    2.49      }
    2.50 -
    2.51 +    
    2.52      screen->pixels = SDL_Image->image;
    2.53 +    screen->pitch = SDL_Image->bpl; /* Recalculated pitch, created by PhCreateImage */
    2.54  
    2.55      this->UpdateRects = ph_NormalUpdate;
    2.56  
    2.57 @@ -105,9 +109,12 @@
    2.58  int ph_SetupOCImage(_THIS, SDL_Surface *screen)
    2.59  {
    2.60      int type = 0;
    2.61 +    int bpp;
    2.62 +    
    2.63 +    bpp=screen->format->BitsPerPixel;
    2.64  
    2.65      /* Determine image type */
    2.66 -    switch(screen->format->BitsPerPixel)
    2.67 +    switch(bpp)
    2.68      {
    2.69          case 8: {
    2.70                      type = Pg_IMAGE_PALETTE_BYTE;
    2.71 @@ -130,7 +137,7 @@
    2.72                  }
    2.73                  break;
    2.74          default:{
    2.75 -                    fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", screen->format->BitsPerPixel);
    2.76 +                    fprintf(stderr,"ph_SetupOCImage(): unsupported bpp = %d\n", bpp);
    2.77                      return -1;
    2.78                  }
    2.79                  break;
    2.80 @@ -138,6 +145,8 @@
    2.81  
    2.82      OCImage.FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
    2.83      OCImage.FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
    2.84 +    memset(OCImage.FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
    2.85 +    memset(OCImage.FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
    2.86  
    2.87      if(OCImage.direct_context == NULL)
    2.88      {
    2.89 @@ -152,7 +161,7 @@
    2.90          return -1;
    2.91      }
    2.92  
    2.93 -    OCImage.Stride = OCImage.offscreen_context->pitch;	
    2.94 +    screen->pitch = OCImage.offscreen_context->pitch; /* Recalculated pitch */
    2.95  
    2.96      if (OCImage.flags & SDL_DOUBLEBUF)
    2.97      {
    2.98 @@ -269,10 +278,6 @@
    2.99      return;
   2.100  }
   2.101  
   2.102 -static PhPoint_t ph_pos;
   2.103 -static PhRect_t ph_rect;
   2.104 -static int i;
   2.105 -
   2.106  void ph_OpenGLUpdate(_THIS, int numrects, SDL_Rect* rects)
   2.107  {
   2.108     this->GL_SwapBuffers(this);
   2.109 @@ -282,7 +287,11 @@
   2.110  
   2.111  void ph_NormalUpdate(_THIS, int numrects, SDL_Rect *rects)
   2.112  {
   2.113 -    for ( i=0; i<numrects; ++i ) 
   2.114 +    PhPoint_t ph_pos;
   2.115 +    PhRect_t ph_rect;
   2.116 +    int i;
   2.117 +
   2.118 +    for (i=0; i<numrects; ++i) 
   2.119      {
   2.120      	if (rects[i].w==0) /* Clipped? */
   2.121          { 
   2.122 @@ -310,6 +319,8 @@
   2.123  
   2.124  void ph_OCUpdate(_THIS, int numrects, SDL_Rect *rects)
   2.125  {
   2.126 +    int i;
   2.127 +
   2.128      PhPoint_t zero = {0};
   2.129      PhArea_t src_rect;
   2.130      PhArea_t dest_rect;
     3.1 --- a/src/video/photon/SDL_ph_mouse.c	Tue May 28 19:24:11 2002 +0000
     3.2 +++ b/src/video/photon/SDL_ph_mouse.c	Tue May 28 19:31:32 2002 +0000
     3.3 @@ -67,8 +67,8 @@
     3.4  	/* Allocate and initialize the cursor memory */
     3.5  	if ((cursor = (WMcursor*)malloc(sizeof(WMcursor))) == NULL)
     3.6  	{
     3.7 -        SDL_OutOfMemory();
     3.8 -        return(NULL);
     3.9 +            SDL_OutOfMemory();
    3.10 +            return(NULL);
    3.11  	}
    3.12  	memset(cursor,0,sizeof(WMcursor));
    3.13  
     4.1 --- a/src/video/photon/SDL_ph_video.c	Tue May 28 19:24:11 2002 +0000
     4.2 +++ b/src/video/photon/SDL_ph_video.c	Tue May 28 19:31:32 2002 +0000
     4.3 @@ -192,6 +192,7 @@
     4.4      {
     4.5          exit(EXIT_FAILURE);
     4.6      }
     4.7 +    memset(event, 0x00, EVENT_SIZE);
     4.8  
     4.9      /* Create the blank cursor */
    4.10      SDL_BlankCursor = this->CreateWMCursor(this, blank_cdata, blank_cmask,
    4.11 @@ -200,17 +201,17 @@
    4.12  
    4.13      if (SDL_BlankCursor == NULL)
    4.14      {
    4.15 -        printf("ph_VideoInit: could not create blank cursor\n");
    4.16 +        printf("ph_VideoInit(): could not create blank cursor !\n");
    4.17      }
    4.18  
    4.19      if (PgGetGraphicsHWCaps(&my_hwcaps) < 0)
    4.20      {
    4.21 -        fprintf(stderr,"ph_VideoInit: GetGraphicsHWCaps failed!! \n");
    4.22 +        fprintf(stderr,"ph_VideoInit(): GetGraphicsHWCaps failed !\n");
    4.23      }
    4.24  
    4.25      if (PgGetVideoModeInfo(my_hwcaps.current_video_mode, &my_mode_info) < 0)
    4.26      {
    4.27 -        fprintf(stderr,"ph_VideoInit:  PgGetVideoModeInfo failed\n");
    4.28 +        fprintf(stderr,"ph_VideoInit(): PgGetVideoModeInfo failed !\n");
    4.29      }
    4.30  
    4.31      /* We need to return BytesPerPixel as it in used by CreateRGBsurface */
     5.1 --- a/src/video/photon/SDL_ph_video.h	Tue May 28 19:24:11 2002 +0000
     5.2 +++ b/src/video/photon/SDL_ph_video.h	Tue May 28 19:31:32 2002 +0000
     5.3 @@ -75,7 +75,6 @@
     5.4          FRAMEDATA *FrameData0;
     5.5          FRAMEDATA *FrameData1;
     5.6          int current;
     5.7 -        long Stride;
     5.8          long flags;
     5.9      } ocimage;
    5.10  
     6.1 --- a/src/video/photon/SDL_phyuv.c	Tue May 28 19:24:11 2002 +0000
     6.2 +++ b/src/video/photon/SDL_phyuv.c	Tue May 28 19:31:32 2002 +0000
     6.3 @@ -210,8 +210,10 @@
     6.4      overlay->hwdata->screen_width = 1024;
     6.5      overlay->hwdata->screen_height  = 768;
     6.6  
     6.7 -    overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
     6.8 -    overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof( FRAMEDATA)));
     6.9 +    overlay->hwdata->FrameData0 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
    6.10 +    overlay->hwdata->FrameData1 = (FRAMEDATA *) malloc((size_t)(sizeof(FRAMEDATA)));
    6.11 +    memset(overlay->hwdata->FrameData0, 0x00, (size_t)(sizeof(FRAMEDATA)));
    6.12 +    memset(overlay->hwdata->FrameData1, 0x00, (size_t)(sizeof(FRAMEDATA)));
    6.13  
    6.14      overlay->hwdata->caps.size = sizeof(overlay->hwdata->caps);
    6.15  
    6.16 @@ -493,7 +495,7 @@
    6.17  	//Lock gets the pointer and passes it to the app. The app writes all yuv data into overlay->pixels
    6.18  //Note this is defined as Uint8 **pixels;				/* Read-write */	
    6.19  	overlay->pixels = &overlay->hwdata->CurrentFrameData->Y; 
    6.20 -	overlay->pitches  = &overlay->hwdata->YStride;
    6.21 +	overlay->pitches = (Uint16*) &(overlay->hwdata->YStride);
    6.22  		
    6.23  	return(0);
    6.24  }
     7.1 --- a/test/graywin.c	Tue May 28 19:24:11 2002 +0000
     7.2 +++ b/test/graywin.c	Tue May 28 19:31:32 2002 +0000
     7.3 @@ -15,7 +15,7 @@
     7.4  #endif
     7.5  
     7.6  /* Draw a randomly sized and colored box centered about (X,Y) */
     7.7 -void DrawBox(SDL_Surface *screen, int X, int Y)
     7.8 +void DrawBox(SDL_Surface *screen, int X, int Y, int width, int height)
     7.9  {
    7.10  	static unsigned int seeded = 0;
    7.11  	SDL_Rect area;
    7.12 @@ -28,8 +28,8 @@
    7.13  	}
    7.14  
    7.15  	/* Get the bounds of the rectangle */
    7.16 -	area.w = (rand()%640);
    7.17 -	area.h = (rand()%480);
    7.18 +	area.w = (rand()%width);
    7.19 +	area.h = (rand()%height);
    7.20  	area.x = X-(area.w/2);
    7.21  	area.y = Y-(area.h/2);
    7.22  	color = (rand()%NUM_COLORS);
    7.23 @@ -72,7 +72,7 @@
    7.24  	}
    7.25  	buffer = (Uint8 *)screen->pixels;
    7.26  	for ( i=0; i<screen->h; ++i ) {
    7.27 -		memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w);
    7.28 +		memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
    7.29  		buffer += screen->pitch;
    7.30  	}
    7.31  	SDL_UnlockSurface(screen);
    7.32 @@ -126,7 +126,7 @@
    7.33  		if ( argv[argc] && (strcmp(argv[argc], "-fullscreen") == 0) ) {
    7.34  			videoflags |= SDL_FULLSCREEN;
    7.35  		} else {
    7.36 -			fprintf(stderr, "Usage: %s [-warp] [-fullscreen]\n",
    7.37 +			fprintf(stderr, "Usage: %s [-width] [-height] [-bpp] [-hw] [-hwpalette] [-noframe] [-fullscreen]\n",
    7.38  								argv[0]);
    7.39  			exit(1);
    7.40  		}
    7.41 @@ -143,7 +143,7 @@
    7.42  	while ( !done && SDL_WaitEvent(&event) ) {
    7.43  		switch (event.type) {
    7.44  			case SDL_MOUSEBUTTONDOWN:
    7.45 -				DrawBox(screen, event.button.x, event.button.y);
    7.46 +				DrawBox(screen, event.button.x, event.button.y, width, height);
    7.47  				break;
    7.48  			case SDL_KEYDOWN:
    7.49  				/* Ignore ALT-TAB for windows */
    7.50 @@ -153,7 +153,7 @@
    7.51  				}
    7.52  				/* Center the mouse on <SPACE> */
    7.53  				if ( event.key.keysym.sym == SDLK_SPACE ) {
    7.54 -					SDL_WarpMouse(640/2, 480/2);
    7.55 +					SDL_WarpMouse(width/2, height/2);
    7.56  					break;
    7.57  				}
    7.58  				/* Toggle fullscreen mode on <RETURN> */