/*  $Id: pixel_buffer_sdl_frame.cpp,v 1.5 2003/10/12 14:44:22 sphair Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser General Public
**  License along with this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
*/

#include "Display/display_precomp.h"
#include "pixel_buffer_sdl_frame.h"
#include "Display/graphic_context_generic.h"
#include "API/Core/System/error.h"

#include <SDL/SDL.h>

/////////////////////////////////////////////////////////////////////////////
// CL_PixelBuffer_SDL_Frame construction:

CL_PixelBuffer_SDL_Frame::CL_PixelBuffer_SDL_Frame(int frame, CL_GraphicContext &gc)
: frame(frame), gc(gc)
{
	SDL_Surface *screen = SDL_GetVideoSurface();
	format.set_depth(screen->format->BitsPerPixel);
	format.set_red_mask  (screen->format->Rmask);
	format.set_green_mask(screen->format->Gmask);
	format.set_blue_mask (screen->format->Bmask);
	format.set_alpha_mask(screen->format->Amask);
	format.enable_colorkey(false);

	width = screen->w;
	height = screen->h;
	pitch = screen->pitch;
}

CL_PixelBuffer_SDL_Frame::~CL_PixelBuffer_SDL_Frame()
{
}

/////////////////////////////////////////////////////////////////////////////
// CL_PixelBuffer_SDL_Frame operations:

void *CL_PixelBuffer_SDL_Frame::get_data()
{
	return SDL_GetVideoSurface();
}

void CL_PixelBuffer_SDL_Frame::perform_lock()
{
	if(SDL_MUSTLOCK(SDL_GetVideoSurface()))
		if(SDL_LockSurface(SDL_GetVideoSurface()) < 0)
			throw CL_Error(SDL_GetError());
}

void CL_PixelBuffer_SDL_Frame::perform_unlock()
{
	if(SDL_MUSTLOCK(SDL_GetVideoSurface())){
		SDL_UnlockSurface(SDL_GetVideoSurface());
	}
}

/////////////////////////////////////////////////////////////////////////////
// CL_PixelBuffer_SDL_Frame implementation:
