SetFlashRect bugfixes and speed workarounds
git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@87 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -83,6 +83,8 @@ enum
|
|||||||
TFB_DRAWCOMMANDTYPE_SCISSORDISABLE,
|
TFB_DRAWCOMMANDTYPE_SCISSORDISABLE,
|
||||||
TFB_DRAWCOMMANDTYPE_COPYBACKBUFFERTOOTHERBUFFER,
|
TFB_DRAWCOMMANDTYPE_COPYBACKBUFFERTOOTHERBUFFER,
|
||||||
TFB_DRAWCOMMANDTYPE_DELETEIMAGE,
|
TFB_DRAWCOMMANDTYPE_DELETEIMAGE,
|
||||||
|
TFB_DRAWCOMMANDTYPE_FLUSHGRAPHICS,
|
||||||
|
TFB_DRAWCOMMANDTYPE_SKIPGRAPHICS
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct tfb_palette
|
typedef struct tfb_palette
|
||||||
@@ -136,6 +138,8 @@ void TFB_DrawCommandQueue_Push (TFB_DrawCommandQueue* myQueue,
|
|||||||
int TFB_DrawCommandQueue_Pop (TFB_DrawCommandQueue* myQueue,
|
int TFB_DrawCommandQueue_Pop (TFB_DrawCommandQueue* myQueue,
|
||||||
TFB_DrawCommand* Command);
|
TFB_DrawCommand* Command);
|
||||||
|
|
||||||
|
void TFB_DrawCommandQueue_Clear (TFB_DrawCommandQueue* myQueue);
|
||||||
|
|
||||||
extern TFB_DrawCommandQueue *DrawCommandQueue;
|
extern TFB_DrawCommandQueue *DrawCommandQueue;
|
||||||
|
|
||||||
// The TFB_Enqueue* functions are necessary, because only the
|
// The TFB_Enqueue* functions are necessary, because only the
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ InitGraphics (int argc, char* argv[], COUNT KbytesRequired)
|
|||||||
void
|
void
|
||||||
UninitGraphics () // Also probably empty
|
UninitGraphics () // Also probably empty
|
||||||
{
|
{
|
||||||
HFree (DrawCommandQueue);
|
// HFree (DrawCommandQueue); This is static now!
|
||||||
|
|
||||||
mem_uninit ();
|
mem_uninit ();
|
||||||
}
|
}
|
||||||
@@ -75,10 +75,22 @@ UnbatchGraphics (void)
|
|||||||
void
|
void
|
||||||
FlushGraphics (void)
|
FlushGraphics (void)
|
||||||
{
|
{
|
||||||
|
TFB_DrawCommand DrawCommand;
|
||||||
TFB_BatchReset ();
|
TFB_BatchReset ();
|
||||||
continuity_break = 1;
|
continuity_break = 1;
|
||||||
|
DrawCommand.Type = TFB_DRAWCOMMANDTYPE_FLUSHGRAPHICS;
|
||||||
|
DrawCommand.image = 0;
|
||||||
|
TFB_EnqueueDrawCommand(&DrawCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SkipGraphics (void)
|
||||||
|
{
|
||||||
|
TFB_DrawCommand DrawCommand;
|
||||||
|
DrawCommand.Type = TFB_DRAWCOMMANDTYPE_SKIPGRAPHICS;
|
||||||
|
DrawCommand.image = 0;
|
||||||
|
TFB_EnqueueDrawCommand(&DrawCommand);
|
||||||
|
}
|
||||||
// Status: Ignored (only used in fmv.c)
|
// Status: Ignored (only used in fmv.c)
|
||||||
void
|
void
|
||||||
SetGraphicUseOtherExtra (int other) //Could this possibly be more cryptic?!? :)
|
SetGraphicUseOtherExtra (int other) //Could this possibly be more cryptic?!? :)
|
||||||
|
|||||||
@@ -197,6 +197,19 @@ TFB_DrawCommandQueue_Pop (TFB_DrawCommandQueue *myQueue, TFB_DrawCommand *target
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TFB_DrawCommandQueue_Clear (TFB_DrawCommandQueue *myQueue)
|
||||||
|
{
|
||||||
|
Lock_DCQ ();
|
||||||
|
myQueue->Size = 0;
|
||||||
|
myQueue->Front = 0;
|
||||||
|
myQueue->Back = 0;
|
||||||
|
myQueue->Batching = 0;
|
||||||
|
myQueue->FullSize = 0;
|
||||||
|
myQueue->InsertionPoint = 0;
|
||||||
|
Unlock_DCQ ();
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
|
TFB_EnqueueDrawCommand (TFB_DrawCommand* DrawCommand)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
|
|||||||
{
|
{
|
||||||
// normal blit: dst = src
|
// normal blit: dst = src
|
||||||
|
|
||||||
//fprintf(stderr, "normal blit\n");
|
// fprintf(stderr, "normal blit\n");
|
||||||
SDL_BlitSurface (src, srcrect, dst, dstrect);
|
SDL_BlitSurface (src, srcrect, dst, dstrect);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -402,14 +402,34 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
|
|||||||
dst_getpix = getpixel_for (dst);
|
dst_getpix = getpixel_for (dst);
|
||||||
putpix = putpixel_for (dst);
|
putpix = putpixel_for (dst);
|
||||||
|
|
||||||
SDL_LockSurface (src);
|
if (SDL_MUSTLOCK(src))
|
||||||
SDL_LockSurface (dst);
|
{
|
||||||
|
if (SDL_LockSurface (src) == -1)
|
||||||
|
{
|
||||||
|
printf("Couldn't lock src!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Locked src.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK(dst))
|
||||||
|
{
|
||||||
|
if (SDL_LockSurface (dst) == -1)
|
||||||
|
{
|
||||||
|
printf("Couldn't lock dst!\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("Locked dst.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (blend_denom < 0)
|
if (blend_denom < 0)
|
||||||
{
|
{
|
||||||
// additive blit: dst = src + dst
|
// additive blit: dst = src + dst
|
||||||
|
|
||||||
//fprintf(stderr, "additive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel);
|
// fprintf(stderr, "additive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel);
|
||||||
|
|
||||||
for (y = y1; y < y2; ++y)
|
for (y = y1; y < y2; ++y)
|
||||||
{
|
{
|
||||||
@@ -446,7 +466,7 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
|
|||||||
{
|
{
|
||||||
// subtractive blit: dst = src - dst
|
// subtractive blit: dst = src - dst
|
||||||
|
|
||||||
//fprintf(stderr, "subtractive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel);
|
// fprintf(stderr, "subtractive blit %d %d, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel);
|
||||||
|
|
||||||
for (y = y1; y < y2; ++y)
|
for (y = y1; y < y2; ++y)
|
||||||
{
|
{
|
||||||
@@ -485,7 +505,7 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
|
|||||||
|
|
||||||
float f = blend_numer / (float)blend_denom;
|
float f = blend_numer / (float)blend_denom;
|
||||||
|
|
||||||
//fprintf(stderr, "modulated blit %d %d, f %f, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, f, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel);
|
// fprintf(stderr, "modulated blit %d %d, f %f, src %d %d %d %d dst %d %d, srcbpp %d\n",blend_numer, blend_denom, f, x1, y1, x2, y2, dstrect->x, dstrect->y, src->format->BitsPerPixel);
|
||||||
|
|
||||||
for (y = y1; y < y2; ++y)
|
for (y = y1; y < y2; ++y)
|
||||||
{
|
{
|
||||||
@@ -515,9 +535,14 @@ void TFB_BlitSurface (SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (SDL_MUSTLOCK(dst))
|
||||||
|
{
|
||||||
SDL_UnlockSurface (dst);
|
SDL_UnlockSurface (dst);
|
||||||
|
}
|
||||||
|
if (SDL_MUSTLOCK(src))
|
||||||
|
{
|
||||||
SDL_UnlockSurface (src);
|
SDL_UnlockSurface (src);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -562,6 +587,7 @@ TFB_FlushGraphics () // Only call from main thread!!
|
|||||||
int semval;
|
int semval;
|
||||||
int commands_handled;
|
int commands_handled;
|
||||||
BOOLEAN livelock_deterrence;
|
BOOLEAN livelock_deterrence;
|
||||||
|
BOOLEAN done;
|
||||||
|
|
||||||
// This is technically a locking violation on DrawCommandQueue->Size,
|
// This is technically a locking violation on DrawCommandQueue->Size,
|
||||||
// but it is likely to not be very destructive.
|
// but it is likely to not be very destructive.
|
||||||
@@ -619,7 +645,8 @@ TFB_FlushGraphics () // Only call from main thread!!
|
|||||||
livelock_deterrence = TRUE;
|
livelock_deterrence = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (TRUE)
|
done = FALSE;
|
||||||
|
while (!done)
|
||||||
{
|
{
|
||||||
TFB_DrawCommand DC;
|
TFB_DrawCommand DC;
|
||||||
TFB_Image *DC_image;
|
TFB_Image *DC_image;
|
||||||
@@ -799,8 +826,12 @@ TFB_FlushGraphics () // Only call from main thread!!
|
|||||||
HFree (DC_image);
|
HFree (DC_image);
|
||||||
DC_image = 0;
|
DC_image = 0;
|
||||||
break;
|
break;
|
||||||
|
case TFB_DRAWCOMMANDTYPE_FLUSHGRAPHICS:
|
||||||
|
done = TRUE;
|
||||||
|
break;
|
||||||
|
case TFB_DRAWCOMMANDTYPE_SKIPGRAPHICS:
|
||||||
|
TFB_DrawCommandQueue_Clear (DrawCommandQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DC_image)
|
if (DC_image)
|
||||||
UnlockMutex (DC_image->mutex);
|
UnlockMutex (DC_image->mutex);
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -932,7 +932,7 @@ int flash_rect_func(void *data)
|
|||||||
{
|
{
|
||||||
#define NORMAL_STRENGTH 4
|
#define NORMAL_STRENGTH 4
|
||||||
#define NORMAL_F_STRENGTH 0
|
#define NORMAL_F_STRENGTH 0
|
||||||
DWORD TimeIn;
|
DWORD TimeIn, WaitTime;
|
||||||
SIZE strength, fstrength, incr;
|
SIZE strength, fstrength, incr;
|
||||||
Task task = (Task)data;
|
Task task = (Task)data;
|
||||||
|
|
||||||
@@ -940,6 +940,7 @@ int flash_rect_func(void *data)
|
|||||||
incr = 1;
|
incr = 1;
|
||||||
strength = NORMAL_STRENGTH;
|
strength = NORMAL_STRENGTH;
|
||||||
TimeIn = GetTimeCounter ();
|
TimeIn = GetTimeCounter ();
|
||||||
|
WaitTime = ONE_SECOND / 16;
|
||||||
while (!Task_ReadState(task, TASK_EXIT))
|
while (!Task_ReadState(task, TASK_EXIT))
|
||||||
{
|
{
|
||||||
CONTEXT OldContext;
|
CONTEXT OldContext;
|
||||||
@@ -1002,10 +1003,16 @@ int flash_rect_func(void *data)
|
|||||||
SetGraphicStrength (4, 4);
|
SetGraphicStrength (4, 4);
|
||||||
|
|
||||||
UnbatchGraphics ();
|
UnbatchGraphics ();
|
||||||
|
FlushGraphics ();
|
||||||
|
/* ACK, cheap hack, oh well, blame Michael Martin until he fixes it */
|
||||||
|
if (flash_rect.extent.width > 250)
|
||||||
|
{
|
||||||
|
SkipGraphics ();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
SetContext (OldContext);
|
SetContext (OldContext);
|
||||||
ClearSemaphore (GraphicsSem);
|
ClearSemaphore (GraphicsSem);
|
||||||
SleepThreadUntil (TimeIn + (ONE_SECOND / 16));
|
SleepThreadUntil (TimeIn + WaitTime);
|
||||||
TimeIn = GetTimeCounter ();
|
TimeIn = GetTimeCounter ();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1045,7 +1052,7 @@ SetFlashRect (PRECT pRect, FRAME f)
|
|||||||
flash_rect.extent.width = 0;
|
flash_rect.extent.width = 0;
|
||||||
if (flash_task)
|
if (flash_task)
|
||||||
{
|
{
|
||||||
Task_SetState (flash_task, TASK_EXIT);
|
ConcludeTask (flash_task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user