From 05bb27d9ae610d26f124ca28ce82028ec11a8579 Mon Sep 17 00:00:00 2001 From: avolkov Date: Tue, 29 Dec 2009 15:27:22 +0000 Subject: [PATCH] Add CopyContextRect() gfxlib call, which should eventually replace direct LoadDisplayPixmap() calls; this also scratches off a FlashContext to-do git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3488 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/libs/gfxlib.h | 3 +++ sc2/src/libs/graphics/context.c | 32 ++++++++++++++++++++++++++++++++ sc2/src/uqm/flash.c | 19 +++---------------- sc2/src/uqm/flash.h | 5 ----- sc2/src/uqm/util.c | 10 ++-------- sc2/src/uqm/util.h | 2 +- 6 files changed, 41 insertions(+), 30 deletions(-) diff --git a/sc2/src/libs/gfxlib.h b/sc2/src/libs/gfxlib.h index 48455dbb9..346030357 100644 --- a/sc2/src/libs/gfxlib.h +++ b/sc2/src/libs/gfxlib.h @@ -345,6 +345,9 @@ extern BOOLEAN GetContextClipRect (RECT *pRect); extern POINT SetContextOrigin (POINT orgOffset); extern DrawMode SetContextDrawMode (DrawMode); extern DrawMode GetContextDrawMode (void); +// 'area' may be NULL to copy the entire CONTEXT cliprect +// 'area' is relative to the CONTEXT cliprect +extern DRAWABLE CopyContextRect (const RECT* area); extern TIME_VALUE DrawablesIntersect (INTERSECT_CONTROL *pControl0, INTERSECT_CONTROL *pControl1, TIME_VALUE max_time_val); diff --git a/sc2/src/libs/graphics/context.c b/sc2/src/libs/graphics/context.c index 9a9a70426..009fe121b 100644 --- a/sc2/src/libs/graphics/context.c +++ b/sc2/src/libs/graphics/context.c @@ -344,6 +344,38 @@ FixContextFontEffect (void) UnsetContextFBkFlags (FBK_DIRTY); } +// 'area' may be NULL to copy the entire CONTEXT cliprect +// 'area' is relative to the CONTEXT cliprect +DRAWABLE +CopyContextRect (const RECT* area) +{ + RECT clipRect; + RECT fgRect; + RECT r; + + if (!ContextActive () || !_CurFramePtr) + return NULL; + + fgRect = _get_context_fg_rect (); + GetContextClipRect (&clipRect); + r = clipRect; + if (area) + { // a portion of the context + r.corner.x += area->corner.x; + r.corner.y += area->corner.y; + r.extent = area->extent; + } + // TODO: Should this take CONTEXT origin into account too? + // validate the rect + if (!BoxIntersect (&r, &fgRect, &r)) + return NULL; + + if (_CurFramePtr->Type == SCREEN_DRAWABLE) + return LoadDisplayPixmap (&r, NULL); + else + return CopyFrameRect (_CurFramePtr, &r); +} + #ifdef DEBUG const char * GetContextName (CONTEXT context) diff --git a/sc2/src/uqm/flash.c b/sc2/src/uqm/flash.c index d0e918471..cececaa74 100644 --- a/sc2/src/uqm/flash.c +++ b/sc2/src/uqm/flash.c @@ -533,32 +533,19 @@ static void Flash_grabOriginal (FlashContext *context) { CONTEXT oldGfxContext; - RECT clipRect; - RECT grabRect; if (context->original != (FRAME) 0) DestroyDrawable (ReleaseDrawable (context->original)); - // XXX: This assumes that FlashContext.gfxContext is an on-screen CONTEXT - // (i.e. it's foreground frame is Screen). LoadDisplayPixmap() would - // not work with an off-screen context. - // TODO: Get rid of LoadDisplayPixmap(). It does not take CONTEXT - // clip-rect into account. LockMutex (GraphicsLock); oldGfxContext = SetContext (context->gfxContext); - // FlashContext.rect is relative to the CONTEXT clip-rect - grabRect = context->rect; - GetContextClipRect (&clipRect); - grabRect.corner.x += clipRect.corner.x; - grabRect.corner.y += clipRect.corner.y; - context->original = CaptureDrawable (LoadDisplayPixmap ( - &grabRect, (FRAME) 0)); + context->original = CaptureDrawable (CopyContextRect (&context->rect)); SetContext (oldGfxContext); - UnlockMutex (GraphicsLock); FlushGraphics (); - // LoadDisplayPixmap only queues the command to read + // CopyContextRect() may have queued the command to read // a rectangle from the screen; a FlushGraphics() // is necessary to ensure that it can actually be used. + UnlockMutex (GraphicsLock); } static inline void diff --git a/sc2/src/uqm/flash.h b/sc2/src/uqm/flash.h index 7f992b5f7..d3c7bb568 100644 --- a/sc2/src/uqm/flash.h +++ b/sc2/src/uqm/flash.h @@ -78,11 +78,6 @@ * * Limitations: * - * 1) Highlight and overlay flashing modes read the original gfxContext - * contents, but they do so with LoadDisplayPixmap(). This means that these - * modes can currently only be used with on-screen CONTEXTs (i.e. CONTEXTs - * that have Screen as foreground FRAME); - * * 2) Functions that draw to the gfxContext or read the original gfxContext * contents, which is most of them, must be called with gfxContext having * the same clip-rect as it did when other drawing functions were called. diff --git a/sc2/src/uqm/util.c b/sc2/src/uqm/util.c index b6d74d4e9..8b264069a 100644 --- a/sc2/src/uqm/util.c +++ b/sc2/src/uqm/util.c @@ -112,18 +112,12 @@ SeedRandomNumbers (void) } STAMP -SaveContextFrame (RECT *saveRect) +SaveContextFrame (const RECT *saveRect) { STAMP s; - RECT r; - GetContextClipRect (&r); if (saveRect) { // a portion of the context - r.corner.x += saveRect->corner.x; - r.corner.y += saveRect->corner.y; - r.extent = saveRect->extent; - s.origin = saveRect->corner; } else @@ -132,7 +126,7 @@ SaveContextFrame (RECT *saveRect) s.origin.y = 0; } - s.frame = CaptureDrawable (LoadDisplayPixmap (&r, NULL)); + s.frame = CaptureDrawable (CopyContextRect (saveRect)); return s; } diff --git a/sc2/src/uqm/util.h b/sc2/src/uqm/util.h index 0e52415de..2add76ec3 100644 --- a/sc2/src/uqm/util.h +++ b/sc2/src/uqm/util.h @@ -26,7 +26,7 @@ extern void DrawStarConBox (RECT *pRect, SIZE BorderWidth, extern DWORD SeedRandomNumbers (void); // saveRect can be NULL to save the entire context frame -extern STAMP SaveContextFrame (RECT *saveRect); +extern STAMP SaveContextFrame (const RECT *saveRect); #endif /* _UTIL_H */