finish cacheing code for flash. Build rect in memory, then Stamp to screen

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@625 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
ghaushe
2003-02-01 05:13:58 +00:00
parent b57dfabfcd
commit 366c385cb0
+68 -47
View File
@@ -1123,8 +1123,11 @@ CountSISPieces (BYTE piece_type)
Task flash_task = 0; Task flash_task = 0;
RECT flash_rect; RECT flash_rect;
static FRAME flash_frame; static FRAME flash_frame;
static FRAME flash_screen_frame = 0;
static int flash_changed; static int flash_changed;
Mutex flash_mutex = 0; Mutex flash_mutex = 0;
void arith_frame_blit (FRAME srcFrame, RECT *rsrc, FRAME dstFrame,
RECT *rdst, int num,int denom);
int flash_rect_func(void *data) int flash_rect_func(void *data)
{ {
@@ -1134,7 +1137,7 @@ int flash_rect_func(void *data)
DWORD TimeIn, WaitTime; DWORD TimeIn, WaitTime;
SIZE strength, fstrength, incr; SIZE strength, fstrength, incr;
RECT cached_rect, framesize_rect; RECT cached_rect, framesize_rect;
FRAME cached_frame; FRAME cached_frame, cached_screen_frame;
Task task = (Task)data; Task task = (Task)data;
int cached[CACHE_SIZE]; int cached[CACHE_SIZE];
STAMP cached_stamp[CACHE_SIZE]; STAMP cached_stamp[CACHE_SIZE];
@@ -1159,9 +1162,10 @@ int flash_rect_func(void *data)
{ {
cached_rect = flash_rect; cached_rect = flash_rect;
cached_frame = flash_frame; cached_frame = flash_frame;
cached_screen_frame = flash_screen_frame;
flash_changed = 0; flash_changed = 0;
UnlockMutex (flash_mutex); UnlockMutex (flash_mutex);
// Wait for the ExtraScreen to get initialized // Wait for the flash_screen_frame to get initialized
FlushGraphics (); FlushGraphics ();
if (cached_frame) if (cached_frame)
GetFrameRect (cached_frame, &framesize_rect); GetFrameRect (cached_frame, &framesize_rect);
@@ -1175,17 +1179,16 @@ int flash_rect_func(void *data)
} }
else else
UnlockMutex (flash_mutex); UnlockMutex (flash_mutex);
SetSemaphore (GraphicsSem);
OldContext = SetContext (ScreenContext);
if (cached_rect.extent.width) if (cached_rect.extent.width)
{ {
BatchGraphics (); STAMP *pStamp;
SetContextClipRect (&cached_rect);
if (cached_frame) if (cached_frame)
{ {
#define MIN_F_STRENGTH -3 #define MIN_F_STRENGTH -3
#define MAX_F_STRENGTH 3 #define MAX_F_STRENGTH 3
int num = 0, denom = 0;
if ((fstrength += incr) > MAX_F_STRENGTH) if ((fstrength += incr) > MAX_F_STRENGTH)
{ {
fstrength = MAX_F_STRENGTH - 1; fstrength = MAX_F_STRENGTH - 1;
@@ -1197,37 +1200,38 @@ int flash_rect_func(void *data)
incr = 1; incr = 1;
} }
if (cached[fstrength - MIN_F_STRENGTH]) if (cached[fstrength - MIN_F_STRENGTH])
DrawStamp (&cached_stamp[fstrength - MIN_F_STRENGTH]); pStamp = &cached_stamp[fstrength - MIN_F_STRENGTH];
else else
{ {
RECT tmp_rect = framesize_rect;
pStamp = &cached_stamp[fstrength - MIN_F_STRENGTH];
cached[fstrength - MIN_F_STRENGTH] = 1;
pStamp->frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP,
framesize_rect.extent.width, framesize_rect.extent.height, 1));
pStamp->origin.x = framesize_rect.corner.x;
pStamp->origin.y = framesize_rect.corner.y;
tmp_rect.corner.x = 0;
tmp_rect.corner.y = 0;
if (fstrength != NORMAL_F_STRENGTH) if (fstrength != NORMAL_F_STRENGTH)
{ {
STAMP s; arith_frame_blit (cached_frame, &tmp_rect, pStamp->frame, NULL,
fstrength > 0 ? fstrength : -fstrength, 16);
ClearBackGround (&framesize_rect);
SetGraphicStrength (fstrength > 0 ? fstrength : -fstrength, 16);
s.origin.x = s.origin.y = 0;
s.frame = cached_frame;
DrawStamp (&s);
if (fstrength < 0) if (fstrength < 0)
SetGraphicStrength (-8, 8); // add to -(partial mask) {
num = -8;
denom = 8;
}
else else
SetGraphicStrength (8, -8); // add to (partial mask) {
num = 8;
denom = -8;
}
} }
DrawFromExtraScreen (&framesize_rect); arith_frame_blit (cached_screen_frame, &framesize_rect, pStamp->frame,
SetGraphicStrength (4, 4); &tmp_rect, num, denom);
{
STAMP *pStamp;
pStamp = &cached_stamp[fstrength - MIN_F_STRENGTH];
cached[fstrength - MIN_F_STRENGTH] = 1;
pStamp->origin.x = framesize_rect.corner.x;
pStamp->origin.y = framesize_rect.corner.y;
pStamp->frame = CaptureDrawable (LoadDisplayPixmap (&framesize_rect, (FRAME)0));
}
} }
} }
else else
@@ -1237,30 +1241,34 @@ int flash_rect_func(void *data)
if ((strength += 2) > MAX_STRENGTH) if ((strength += 2) > MAX_STRENGTH)
strength = MIN_STRENGTH; strength = MIN_STRENGTH;
if (cached[strength - MIN_STRENGTH]) if (cached[strength - MIN_STRENGTH])
DrawStamp (&cached_stamp[strength - MIN_STRENGTH]); pStamp = &cached_stamp[strength - MIN_STRENGTH];
else else
{ {
SetGraphicStrength (strength, 4); RECT tmp_rect = cached_rect;
DrawFromExtraScreen (&cached_rect); pStamp = &cached_stamp[strength - MIN_STRENGTH];
SetGraphicStrength (4, 4); cached[strength - MIN_STRENGTH] = 1;
pStamp->frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP,
cached_rect.extent.width, cached_rect.extent.height, 1));
pStamp->origin.x = 0;
pStamp->origin.y = 0;
tmp_rect.corner.x = 0;
tmp_rect.corner.y = 0;
{ arith_frame_blit (cached_screen_frame, &tmp_rect, pStamp->frame,
STAMP *pStamp; &tmp_rect, 4, 4);
pStamp = &cached_stamp[strength - MIN_STRENGTH]; if (strength != 4)
cached[strength - MIN_STRENGTH] = 1; arith_frame_blit (cached_screen_frame, &tmp_rect, pStamp->frame,
pStamp->origin.x = 0; &tmp_rect, strength, 4);
pStamp->origin.y = 0;
pStamp->frame = CaptureDrawable (LoadDisplayPixmap (&cached_rect, (FRAME)0));
}
} }
} }
SetSemaphore (GraphicsSem);
OldContext = SetContext (ScreenContext);
SetContextClipRect (&cached_rect);
DrawStamp (pStamp);
SetContextClipRect (NULL_PTR); // this will flush whatever SetContextClipRect (NULL_PTR); // this will flush whatever
SetContext (OldContext);
UnbatchGraphics (); ClearSemaphore (GraphicsSem);
} }
SetContext (OldContext);
ClearSemaphore (GraphicsSem);
FlushGraphics (); FlushGraphics ();
SleepThreadUntil (TimeIn + WaitTime); SleepThreadUntil (TimeIn + WaitTime);
TimeIn = GetTimeCounter (); TimeIn = GetTimeCounter ();
@@ -1340,12 +1348,25 @@ SetFlashRect (PRECT pRect, FRAME f)
|| old_r.corner.y != flash_rect.corner.y || old_r.corner.y != flash_rect.corner.y
|| old_f != flash_frame)) || old_f != flash_frame))
{ {
DrawFromExtraScreen (&old_r); if (flash_screen_frame)
{
STAMP old_s;
old_s.origin.x = old_r.corner.x;
old_s.origin.y = old_r.corner.y;
old_s.frame = flash_screen_frame;
DrawStamp (&old_s);
DestroyDrawable (ReleaseDrawable (flash_screen_frame));
flash_screen_frame = 0;
}
else
fprintf (stderr, "couldn't locate flash_screen_rect\n");
} }
if (flash_rect.extent.width) if (flash_rect.extent.width)
{ {
LoadIntoExtraScreen (&flash_rect); if (flash_screen_frame)
DestroyDrawable (ReleaseDrawable (flash_screen_frame));
flash_screen_frame = CaptureDrawable (LoadDisplayPixmap (&flash_rect, (FRAME)0));
} }
LockMutex (flash_mutex); LockMutex (flash_mutex);
flash_changed = 1; flash_changed = 1;