|
@@ -36,12 +36,13 @@ static bool _draw_threaded;
|
|
|
/** Thread used to 'draw' to the screen, i.e. push data to the screen. */
|
|
|
static ThreadObject *_draw_thread = NULL;
|
|
|
/** Mutex to keep the access to the shared memory controlled. */
|
|
|
static ThreadMutex *_draw_mutex = NULL;
|
|
|
/** Should we keep continue drawing? */
|
|
|
static volatile bool _draw_continue;
|
|
|
static Palette _local_palette;
|
|
|
|
|
|
#define MAX_DIRTY_RECTS 100
|
|
|
static SDL_Rect _dirty_rects[MAX_DIRTY_RECTS];
|
|
|
static int _num_dirty_rects;
|
|
|
|
|
|
void VideoDriver_SDL::MakeDirty(int left, int top, int width, int height)
|
|
@@ -52,43 +53,46 @@ void VideoDriver_SDL::MakeDirty(int left
|
|
|
_dirty_rects[_num_dirty_rects].w = width;
|
|
|
_dirty_rects[_num_dirty_rects].h = height;
|
|
|
}
|
|
|
_num_dirty_rects++;
|
|
|
}
|
|
|
|
|
|
static void UpdatePalette(uint start, uint count)
|
|
|
static void UpdatePalette()
|
|
|
{
|
|
|
SDL_Color pal[256];
|
|
|
|
|
|
for (uint i = 0; i != count; i++) {
|
|
|
pal[i].r = _cur_palette.palette[start + i].r;
|
|
|
pal[i].g = _cur_palette.palette[start + i].g;
|
|
|
pal[i].b = _cur_palette.palette[start + i].b;
|
|
|
for (int i = 0; i != _local_palette.count_dirty; i++) {
|
|
|
pal[i].r = _local_palette.palette[_local_palette.first_dirty + i].r;
|
|
|
pal[i].g = _local_palette.palette[_local_palette.first_dirty + i].g;
|
|
|
pal[i].b = _local_palette.palette[_local_palette.first_dirty + i].b;
|
|
|
pal[i].unused = 0;
|
|
|
}
|
|
|
|
|
|
SDL_CALL SDL_SetColors(_sdl_screen, pal, start, count);
|
|
|
SDL_CALL SDL_SetColors(_sdl_screen, pal, _local_palette.first_dirty, _local_palette.count_dirty);
|
|
|
}
|
|
|
|
|
|
static void InitPalette()
|
|
|
{
|
|
|
UpdatePalette(0, 256);
|
|
|
_local_palette = _cur_palette;
|
|
|
_local_palette.first_dirty = 0;
|
|
|
_local_palette.count_dirty = 256;
|
|
|
UpdatePalette();
|
|
|
}
|
|
|
|
|
|
static void CheckPaletteAnim()
|
|
|
{
|
|
|
if (_cur_palette.count_dirty != 0) {
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
|
|
|
|
|
switch (blitter->UsePaletteAnimation()) {
|
|
|
case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND:
|
|
|
UpdatePalette(_cur_palette.first_dirty, _cur_palette.count_dirty);
|
|
|
UpdatePalette();
|
|
|
break;
|
|
|
|
|
|
case Blitter::PALETTE_ANIMATION_BLITTER:
|
|
|
blitter->PaletteAnimate(_cur_palette);
|
|
|
blitter->PaletteAnimate(_local_palette);
|
|
|
break;
|
|
|
|
|
|
case Blitter::PALETTE_ANIMATION_NONE:
|
|
|
break;
|
|
|
|
|
|
default:
|
|
@@ -118,12 +122,13 @@ static void DrawSurfaceToScreenThread(vo
|
|
|
_draw_mutex->SendSignal();
|
|
|
|
|
|
/* Now wait for the first thing to draw! */
|
|
|
_draw_mutex->WaitForSignal();
|
|
|
|
|
|
while (_draw_continue) {
|
|
|
CheckPaletteAnim();
|
|
|
/* Then just draw and wait till we stop */
|
|
|
DrawSurfaceToScreen();
|
|
|
_draw_mutex->WaitForSignal();
|
|
|
}
|
|
|
|
|
|
_draw_mutex->EndCritical();
|
|
@@ -582,13 +587,13 @@ void VideoDriver_SDL::MainLoop()
|
|
|
|
|
|
GameLoop();
|
|
|
|
|
|
if (_draw_threaded) _draw_mutex->BeginCritical();
|
|
|
|
|
|
UpdateWindows();
|
|
|
CheckPaletteAnim();
|
|
|
_local_palette = _cur_palette;
|
|
|
} else {
|
|
|
/* Release the thread while sleeping */
|
|
|
if (_draw_threaded) _draw_mutex->EndCritical();
|
|
|
CSleep(1);
|
|
|
if (_draw_threaded) _draw_mutex->BeginCritical();
|
|
|
|
|
@@ -598,12 +603,13 @@ void VideoDriver_SDL::MainLoop()
|
|
|
|
|
|
/* End of the critical part. */
|
|
|
if (_draw_threaded && !HasModalProgress()) {
|
|
|
_draw_mutex->SendSignal();
|
|
|
} else {
|
|
|
/* Oh, we didn't have threads, then just draw unthreaded */
|
|
|
CheckPaletteAnim();
|
|
|
DrawSurfaceToScreen();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (_draw_threaded) {
|
|
|
_draw_continue = false;
|