src/video/windx5/SDL_dx5video.c
changeset 292 eadc0746dfaf
parent 252 e8157fcb3114
child 296 fab1ddc4d7bf
     1.1 --- a/src/video/windx5/SDL_dx5video.c	Sat Mar 02 16:50:35 2002 +0000
     1.2 +++ b/src/video/windx5/SDL_dx5video.c	Tue Mar 05 19:55:32 2002 +0000
     1.3 @@ -421,6 +421,7 @@
     1.4  static int DX5_SetHWColorKey(_THIS, SDL_Surface *surface, Uint32 key);
     1.5  static int DX5_SetHWAlpha(_THIS, SDL_Surface *surface, Uint8 alpha);
     1.6  static int DX5_LockHWSurface(_THIS, SDL_Surface *surface);
     1.7 +static int DX5_LockHWSurfaceRect(_THIS, SDL_Surface *surface, SDL_Rect *rect, void **pixels, int *pitch);
     1.8  static void DX5_UnlockHWSurface(_THIS, SDL_Surface *surface);
     1.9  static int DX5_FlipHWSurface(_THIS, SDL_Surface *surface);
    1.10  static void DX5_FreeHWSurface(_THIS, SDL_Surface *surface);
    1.11 @@ -591,7 +592,9 @@
    1.12  	device->SetHWColorKey = DX5_SetHWColorKey;
    1.13  	device->SetHWAlpha = DX5_SetHWAlpha;
    1.14  	device->LockHWSurface = DX5_LockHWSurface;
    1.15 +	device->LockHWSurfaceRect = DX5_LockHWSurfaceRect;
    1.16  	device->UnlockHWSurface = DX5_UnlockHWSurface;
    1.17 +	device->UnlockHWSurfaceRect = DX5_UnlockHWSurface;
    1.18  	device->FlipHWSurface = DX5_FlipHWSurface;
    1.19  	device->FreeHWSurface = DX5_FreeHWSurface;
    1.20  #ifdef IID_IDirectDrawGammaControl
    1.21 @@ -1910,6 +1913,43 @@
    1.22  	surface->pixels = ddsd.lpSurface;
    1.23  	return(0);
    1.24  }
    1.25 +static int DX5_LockHWSurfaceRect(_THIS, SDL_Surface *surface, SDL_Rect *rect, void **pixels, int *pitch)
    1.26 +{
    1.27 +	HRESULT result;
    1.28 +	LPDIRECTDRAWSURFACE3 dd_surface;
    1.29 +	DDSURFACEDESC ddsd;
    1.30 +	RECT ddrect;
    1.31 +
    1.32 +	/* Calculate the lock rectangle */
    1.33 +	ddrect.top    = rect->y;
    1.34 +	ddrect.bottom = rect->y+rect->h;
    1.35 +	ddrect.left   = rect->x;
    1.36 +	ddrect.right  = rect->x+rect->w;
    1.37 +
    1.38 +	/* Lock and load! */
    1.39 +	dd_surface = surface->hwdata->dd_writebuf;
    1.40 +	memset(&ddsd, 0, sizeof(ddsd));
    1.41 +	ddsd.dwSize = sizeof(ddsd);
    1.42 +	result = IDirectDrawSurface3_Lock(dd_surface, &ddrect, &ddsd,
    1.43 +					(DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
    1.44 +	if ( result == DDERR_SURFACELOST ) {
    1.45 +		result = IDirectDrawSurface3_Restore(
    1.46 +						surface->hwdata->dd_surface);
    1.47 +		result = IDirectDrawSurface3_Lock(dd_surface, &ddrect, &ddsd, 
    1.48 +					(DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL);
    1.49 +	}
    1.50 +	if ( result != DD_OK ) {
    1.51 +		SetDDerror("DirectDrawSurface3::Lock", result);
    1.52 +		return(-1);
    1.53 +	}
    1.54 +	*pixels = ddsd.lpSurface;
    1.55 +#if defined(NONAMELESSUNION)
    1.56 +	*pitch = ddsd.u1.lPitch;
    1.57 +#else
    1.58 +	*pitch = (Uint16)ddsd.lPitch;
    1.59 +#endif
    1.60 +	return(0);
    1.61 +}
    1.62  
    1.63  static void DX5_UnlockHWSurface(_THIS, SDL_Surface *surface)
    1.64  {