From edcccdb75fd48540d43058d0e6ac7f218d6f80b4 Mon Sep 17 00:00:00 2001 From: avolkov Date: Sun, 27 Dec 2009 08:59:47 +0000 Subject: [PATCH] Migrate flash-rect task to new drawing modes git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3478 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/libs/gfxlib.h | 1 + sc2/src/libs/graphics/drawable.c | 70 ++++++++++++++++++++++++++------ sc2/src/uqm/sis.c | 53 +++++++++++++----------- 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/sc2/src/libs/gfxlib.h b/sc2/src/libs/gfxlib.h index b99032016..ef1130f03 100644 --- a/sc2/src/libs/gfxlib.h +++ b/sc2/src/libs/gfxlib.h @@ -404,6 +404,7 @@ extern FRAME SetRelFrameIndex (FRAME Frame, SIZE FrameOffs); extern FRAME SetEquFrameIndex (FRAME DstFrame, FRAME SrcFrame); extern FRAME IncFrameIndex (FRAME Frame); extern FRAME DecFrameIndex (FRAME Frame); +extern DRAWABLE CloneFrame (FRAME Frame); extern DRAWABLE RotateFrame (FRAME Frame, int angle_deg); extern DRAWABLE RescaleFrame (FRAME, int width, int height); // This pair works for both paletted and trucolor frames diff --git a/sc2/src/libs/graphics/drawable.c b/sc2/src/libs/graphics/drawable.c index 747b778f6..8499583a4 100644 --- a/sc2/src/libs/graphics/drawable.c +++ b/sc2/src/libs/graphics/drawable.c @@ -296,19 +296,12 @@ GetFramePixel (FRAME frame, POINT pixelPt) pixelPt.x, pixelPt.y); } -// Creates a new DRAWABLE of specified size and scales the passed -// frame onto it. The aspect ratio is not preserved. -DRAWABLE -RescaleFrame (FRAME frame, int width, int height) +static FRAME +makeMatchingFrame (FRAME frame, int width, int height) { DRAWABLE drawable; FRAME newFrame; CREATE_FLAGS flags; - TFB_Image *img; - TFB_Canvas src, dst; - - if (!frame) - return NULL; flags = GetFrameParentDrawable (frame)->Flags; drawable = CreateDrawable (flags, width, height, 1); @@ -321,6 +314,61 @@ RescaleFrame (FRAME frame, int width, int height) return NULL; } + return newFrame; +} + +// Creates an new DRAWABLE mostly identical to specified FRAME +DRAWABLE +CloneFrame (FRAME frame) +{ + FRAME newFrame; + TFB_Image *img; + TFB_Canvas src, dst; + RECT r; + + if (!frame) + return NULL; + + GetFrameRect (frame, &r); + r.corner.x = 0; + r.corner.y = 0; + + newFrame = makeMatchingFrame (frame, r.extent.width, r.extent.height); + if (!newFrame) + return NULL; + + // copy the hot-spot + newFrame->HotSpot = frame->HotSpot; + + img = frame->image; + LockMutex (img->mutex); + + // copy the pixels + src = img->NormalImg; + dst = newFrame->image->NormalImg; + TFB_DrawCanvas_CopyRect (src, &r, dst, MAKE_POINT (0, 0)); + + UnlockMutex (img->mutex); + + return ReleaseDrawable (newFrame); +} + +// Creates a new DRAWABLE of specified size and scales the passed +// frame onto it. The aspect ratio is not preserved. +DRAWABLE +RescaleFrame (FRAME frame, int width, int height) +{ + FRAME newFrame; + TFB_Image *img; + TFB_Canvas src, dst; + + if (!frame) + return NULL; + + newFrame = makeMatchingFrame (frame, width, height); + if (!newFrame) + return NULL; + // scale the hot-spot newFrame->HotSpot.x = frame->HotSpot.x * width / frame->Bounds.width; newFrame->HotSpot.y = frame->HotSpot.y * height / frame->Bounds.height; @@ -334,9 +382,7 @@ RescaleFrame (FRAME frame, int width, int height) UnlockMutex (img->mutex); - ReleaseDrawable (newFrame); - - return drawable; + return ReleaseDrawable (newFrame); } BOOLEAN diff --git a/sc2/src/uqm/sis.c b/sc2/src/uqm/sis.c index 213882f20..b0ad311fd 100644 --- a/sc2/src/uqm/sis.c +++ b/sc2/src/uqm/sis.c @@ -1583,10 +1583,6 @@ static FRAME flash_screen_frame = 0; // The original contents of the flash rectangle. static int flash_changed; Mutex flash_mutex = 0; -// XXX: these are currently defined in libs/graphics/sdl/3do_getbody.c -// they should be sorted out and cleaned up at some point -extern void arith_frame_blit (FRAME srcFrame, const RECT *rsrc, - FRAME dstFrame, const RECT *rdst, int num, int denom); static int flash_rect_func (void *data) @@ -1620,21 +1616,14 @@ flash_rect_func (void *data) LockMutex (flash_mutex); if (flash_changed) { - RECT screen_rect; cached_rect = flash_rect; if (cached_screen_frame) DestroyDrawable (ReleaseDrawable (cached_screen_frame)); flash_changed = 0; // Wait for the flash_screen_frame to get initialized FlushGraphics (); - GetFrameRect (flash_screen_frame, &screen_rect); - cached_screen_frame = CaptureDrawable (CreateDrawable ( - WANT_PIXMAP, screen_rect.extent.width, - screen_rect.extent.height, 1)); - screen_rect.corner.x = 0; - screen_rect.corner.y = 0; - arith_frame_blit (flash_screen_frame, &screen_rect, - cached_screen_frame, NULL, 0, 0); + cached_screen_frame = CaptureDrawable ( + CloneFrame (flash_screen_frame)); UnlockMutex (flash_mutex); // Clear the cache. @@ -1652,6 +1641,7 @@ flash_rect_func (void *data) if (cached_rect.extent.width) { STAMP *pStamp; + #define MIN_STRENGTH 4 #define MAX_STRENGTH 6 strength += 2; @@ -1661,22 +1651,36 @@ flash_rect_func (void *data) pStamp = &cached_stamp[strength - MIN_STRENGTH]; else { - RECT tmp_rect = cached_rect; pStamp = &cached_stamp[strength - MIN_STRENGTH]; cached[strength - MIN_STRENGTH] = true; - pStamp->frame = CaptureDrawable (CreateDrawable (WANT_PIXMAP, - cached_rect.extent.width, cached_rect.extent.height, - 1)); + pStamp->frame = CaptureDrawable ( + CloneFrame (cached_screen_frame)); 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, &tmp_rect, 4, 4); if (strength != 4) - arith_frame_blit (cached_screen_frame, &tmp_rect, - pStamp->frame, &tmp_rect, strength, 4); + { // brighten the frame with an additive + DrawMode oldMode; + STAMP s; + int factor; + + s.origin.x = 0; + s.origin.y = 0; + s.frame = cached_screen_frame; + + factor = (strength - MIN_STRENGTH) * DRAW_FACTOR_1 / 4; + + LockMutex (GraphicsLock); + OldContext = SetContext (OffScreenContext); + SetContextFGFrame (pStamp->frame); + SetContextClipRect (NULL); + oldMode = SetContextDrawMode (MAKE_DRAW_MODE ( + DRAW_ADDITIVE, factor)); + DrawStamp (&s); + SetContextDrawMode (oldMode); + SetContext (OldContext); + UnlockMutex (GraphicsLock); + } } LockMutex (GraphicsLock); @@ -1685,7 +1689,8 @@ flash_rect_func (void *data) // flash changed_can't be modified while GraphicSem is held if (!flash_changed) DrawStamp (pStamp); - SetContextClipRect (NULL); // this will flush whatever + // XXX: Shouldn't we save and restore the original cliprect? + SetContextClipRect (NULL); SetContext (OldContext); UnlockMutex (GraphicsLock); }