From 7089b278350dff3ef5faaa6dfe938c0f10f7a1ab Mon Sep 17 00:00:00 2001 From: avolkov Date: Sat, 3 Dec 2005 09:53:02 +0000 Subject: [PATCH] Trilinear scaler overhaul: moving image hotspot processing to tfb_draw/DCQ git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@2028 8092fc87-c524-0410-9efc-e669fe64eaf9 --- sc2/src/sc2code/libs/graphics/drawcmd.h | 1 + .../sc2code/libs/graphics/sdl/sdl_common.c | 18 ++++++++++--- sc2/src/sc2code/libs/graphics/tfb_draw.c | 17 +++++++++--- sc2/src/sc2code/libs/graphics/tfb_draw.h | 7 ++++- sc2/src/sc2code/libs/graphics/tfb_prim.c | 27 +++++-------------- sc2/src/sc2code/process.c | 2 ++ 6 files changed, 44 insertions(+), 28 deletions(-) diff --git a/sc2/src/sc2code/libs/graphics/drawcmd.h b/sc2/src/sc2code/libs/graphics/drawcmd.h index 47295fe7d..9a6962713 100644 --- a/sc2/src/sc2code/libs/graphics/drawcmd.h +++ b/sc2/src/sc2code/libs/graphics/drawcmd.h @@ -101,6 +101,7 @@ typedef struct tfb_dc_setmip { TFB_Image *image; TFB_Canvas mipmap; + int hotx, hoty; } TFB_DrawCommand_SetMipmap; typedef struct tfb_dc_delimg diff --git a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c index 18c294f2c..4301df2c2 100644 --- a/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c +++ b/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c @@ -607,6 +607,8 @@ TFB_FlushGraphics () // Only call from main thread!! case TFB_DRAWCOMMANDTYPE_SETMIPMAP: LockMutex (DC.data.setmipmap.image->mutex); DC.data.setmipmap.image->MipmapImg = DC.data.setmipmap.mipmap; + DC.data.setmipmap.image->MipmapHs.x = DC.data.setmipmap.hotx; + DC.data.setmipmap.image->MipmapHs.y = DC.data.setmipmap.hoty; UnlockMutex (DC.data.setmipmap.image->mutex); break; case TFB_DRAWCOMMANDTYPE_IMAGE: @@ -629,9 +631,13 @@ TFB_FlushGraphics () // Only call from main thread!! { LockMutex (DC_image->mutex); if (DC.data.image.scale) - TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y); + TFB_BBox_RegisterCanvas (DC_image->ScaledImg, + x - DC_image->last_scale_hs.x, + y - DC_image->last_scale_hs.y); else - TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y); + TFB_BBox_RegisterCanvas (DC_image->NormalImg, + x - DC_image->NormalHs.x, + y - DC_image->NormalHs.y); UnlockMutex (DC_image->mutex); } @@ -653,9 +659,13 @@ TFB_FlushGraphics () // Only call from main thread!! { LockMutex (DC_image->mutex); if (DC.data.filledimage.scale) - TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y); + TFB_BBox_RegisterCanvas (DC_image->ScaledImg, + x - DC_image->last_scale_hs.x, + y - DC_image->last_scale_hs.y); else - TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y); + TFB_BBox_RegisterCanvas (DC_image->NormalImg, + x - DC_image->NormalHs.x, + y - DC_image->NormalHs.y); UnlockMutex (DC_image->mutex); } diff --git a/sc2/src/sc2code/libs/graphics/tfb_draw.c b/sc2/src/sc2code/libs/graphics/tfb_draw.c index 07017ebff..786674e11 100644 --- a/sc2/src/sc2code/libs/graphics/tfb_draw.c +++ b/sc2/src/sc2code/libs/graphics/tfb_draw.c @@ -19,6 +19,7 @@ #include "drawcmd.h" #include "units.h" +static const HOT_SPOT NullHs = {0, 0}; void TFB_DrawScreen_Line (int x1, int y1, int x2, int y2, int r, int g, int b, @@ -291,6 +292,9 @@ TFB_DrawImage_New (TFB_Canvas canvas) img->MipmapImg = NULL; img->FilledImg = NULL; img->colormap_index = -1; + img->NormalHs = NullHs; + img->MipmapHs = NullHs; + img->last_scale_hs = NullHs; img->last_scale_type = -1; TFB_DrawCanvas_GetExtent (canvas, &img->extent); @@ -317,6 +321,9 @@ TFB_DrawImage_CreateForScreen (int w, int h, BOOLEAN withalpha) img->MipmapImg = NULL; img->FilledImg = NULL; img->colormap_index = -1; + img->NormalHs = NullHs; + img->MipmapHs = NullHs; + img->last_scale_hs = NullHs; img->last_scale_type = -1; img->Palette = NULL; img->extent.width = w; @@ -386,12 +393,16 @@ void TFB_DrawImage_FixScaling (TFB_Image *image, int target, int type) { EXTENT old = image->extent; - TFB_DrawCanvas_GetScaledExtent (image->NormalImg, image->MipmapImg, - target, &image->extent); + HOT_SPOT oldhs = image->last_scale_hs; + TFB_DrawCanvas_GetScaledExtent (image->NormalImg, image->NormalHs, + image->MipmapImg, image->MipmapHs, target, + &image->extent, &image->last_scale_hs); if ((old.width != image->extent.width) || (old.height != image->extent.height) || image->dirty || - !image->ScaledImg || type != image->last_scale_type) + !image->ScaledImg || type != image->last_scale_type || + (oldhs.x != image->last_scale_hs.x) || + (oldhs.y != image->last_scale_hs.y)) { image->dirty = FALSE; image->ScaledImg = TFB_DrawCanvas_New_ScaleTarget (image->NormalImg, diff --git a/sc2/src/sc2code/libs/graphics/tfb_draw.h b/sc2/src/sc2code/libs/graphics/tfb_draw.h index 2d82bdcc0..307e7741c 100644 --- a/sc2/src/sc2code/libs/graphics/tfb_draw.h +++ b/sc2/src/sc2code/libs/graphics/tfb_draw.h @@ -56,6 +56,9 @@ typedef struct tfb_image TFB_Canvas FilledImg; TFB_Palette *Palette; int colormap_index; + HOT_SPOT NormalHs; + HOT_SPOT MipmapHs; + HOT_SPOT last_scale_hs; int last_scale_type; TFB_Palette last_fill; EXTENT extent; @@ -107,7 +110,9 @@ TFB_Canvas TFB_DrawCanvas_ToScreenFormat (TFB_Canvas canvas); BOOLEAN TFB_DrawCanvas_IsPaletted (TFB_Canvas canvas); void TFB_DrawCanvas_Rescale_Nearest (TFB_Canvas src, TFB_Canvas dst, EXTENT size); void TFB_DrawCanvas_Rescale_Trilinear (TFB_Canvas src, TFB_Canvas dst, TFB_Canvas mipmap, EXTENT size); -void TFB_DrawCanvas_GetScaledExtent (TFB_Canvas src_canvas, TFB_Canvas src_mipmap, int scale, PEXTENT size); +void TFB_DrawCanvas_GetScaledExtent (TFB_Canvas src_canvas, HOT_SPOT src_hs, + TFB_Canvas src_mipmap, HOT_SPOT mm_hs, + int scale, PEXTENT size, HOT_SPOT *hs); void TFB_DrawCanvas_Rotate (TFB_Canvas src, TFB_Canvas dst, int angle, EXTENT size); void TFB_DrawCanvas_GetRotatedExtent (TFB_Canvas src, int angle, PEXTENT size); void TFB_DrawCanvas_GetExtent (TFB_Canvas canvas, PEXTENT size); diff --git a/sc2/src/sc2code/libs/graphics/tfb_prim.c b/sc2/src/sc2code/libs/graphics/tfb_prim.c index 0eef41250..8af304de4 100644 --- a/sc2/src/sc2code/libs/graphics/tfb_prim.c +++ b/sc2/src/sc2code/libs/graphics/tfb_prim.c @@ -140,18 +140,11 @@ TFB_Prim_Stamp (PSTAMP stmp) LockMutex (img->mutex); - x = stmp->origin.x - _CurFramePtr->HotSpot.x - SrcFramePtr->HotSpot.x; - y = stmp->origin.y - _CurFramePtr->HotSpot.y - SrcFramePtr->HotSpot.y; + img->NormalHs = SrcFramePtr->HotSpot; + x = stmp->origin.x - _CurFramePtr->HotSpot.x; + y = stmp->origin.y - _CurFramePtr->HotSpot.y; paletted = FALSE; - if (gscale != GSCALE_IDENTITY) - { // rounding error correction here - x += (SrcFramePtr->HotSpot.x * (GSCALE_IDENTITY - gscale) - + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; - y += (SrcFramePtr->HotSpot.y * (GSCALE_IDENTITY - gscale) - + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; - } - if (TFB_DrawCanvas_IsPaletted(img->NormalImg) && img->colormap_index != -1) { TFB_ColorMapToRGB (palette, img->colormap_index); @@ -198,20 +191,14 @@ TFB_Prim_StampFill (PSTAMP stmp, TFB_Palette *color) LockMutex (img->mutex); - x = stmp->origin.x - _CurFramePtr->HotSpot.x - SrcFramePtr->HotSpot.x; - y = stmp->origin.y - _CurFramePtr->HotSpot.y - SrcFramePtr->HotSpot.y; + img->NormalHs = SrcFramePtr->HotSpot; + x = stmp->origin.x - _CurFramePtr->HotSpot.x; + y = stmp->origin.y - _CurFramePtr->HotSpot.y; + r = color->r; g = color->g; b = color->b; - if (gscale != GSCALE_IDENTITY) - { // rounding error correction here - x += (SrcFramePtr->HotSpot.x * (GSCALE_IDENTITY - gscale) - + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; - y += (SrcFramePtr->HotSpot.y * (GSCALE_IDENTITY - gscale) - + (GSCALE_IDENTITY >> 1)) / GSCALE_IDENTITY; - } - UnlockMutex (img->mutex); if (TYPE_GET (_CurFramePtr->TypeIndexAndFlags) == SCREEN_DRAWABLE) diff --git a/sc2/src/sc2code/process.c b/sc2/src/sc2code/process.c index e652f3a30..c3714321f 100644 --- a/sc2/src/sc2code/process.c +++ b/sc2/src/sc2code/process.c @@ -947,6 +947,8 @@ PostProcessQueue (VIEW_STATE view_state, SIZE scroll_x, TFB_Image *mmimg = frame->image; DC.Type = TFB_DRAWCOMMANDTYPE_SETMIPMAP; DC.data.setmipmap.image = ((PFRAME_DESC)ElementPtr->next.image.frame)->image; + DC.data.setmipmap.hotx = frame->HotSpot.x; + DC.data.setmipmap.hoty = frame->HotSpot.y; LockMutex (mmimg->mutex); DC.data.setmipmap.mipmap = mmimg->NormalImg; UnlockMutex (mmimg->mutex);