Moved image scaling to DCQ thread; fixes scale-out-of-sync problem in
melee. Also reduced number of scaling steps. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@861 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
Changes towards version 0.3:
|
||||
- Moved image scaling to DCQ thread; fixes scale-out-of-sync problem
|
||||
in melee -Mika
|
||||
- Fix lockup in cyborg melee (fixes 204 and 218) from chmmravatar
|
||||
- Added -g option to control gamma correction, from chmmravatar
|
||||
- Restored the CondBank to actually use condition variables properly
|
||||
|
||||
@@ -53,6 +53,7 @@ void DrawFromExtraScreen (PRECT r);
|
||||
void SetGraphicGrabOther (int grab_other);
|
||||
void SetGraphicScale (int scale);
|
||||
int GetGraphicScale (void);
|
||||
int GetGraphicScaleIdentity (void);
|
||||
void SetGraphicUseOtherExtra (int other);
|
||||
void ScreenTransition (int transition, PRECT pRect);
|
||||
|
||||
|
||||
@@ -22,12 +22,17 @@
|
||||
#include "rotozoom.h"
|
||||
#include "graphics/tfb_draw.h"
|
||||
|
||||
static int gscale;
|
||||
#define GSCALE_SHIFT 2 // controls the number of scale steps
|
||||
#define GSCALE_IDENTITY (256 >> GSCALE_SHIFT) // 'identity scale'
|
||||
|
||||
static int gscale = GSCALE_IDENTITY;
|
||||
|
||||
void
|
||||
SetGraphicScale (int scale)
|
||||
{
|
||||
gscale = scale;
|
||||
gscale = scale >> GSCALE_SHIFT;
|
||||
if (gscale == 0)
|
||||
gscale = GSCALE_IDENTITY;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -36,6 +41,12 @@ GetGraphicScale ()
|
||||
return gscale;
|
||||
}
|
||||
|
||||
int
|
||||
GetGraphicScaleIdentity (void)
|
||||
{
|
||||
return GSCALE_IDENTITY;
|
||||
}
|
||||
|
||||
static void
|
||||
read_screen (PRECT lpRect, FRAMEPTR DstFramePtr)
|
||||
{
|
||||
|
||||
@@ -49,9 +49,9 @@ TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale, TFB_Palette *pale
|
||||
targetRect.x = x;
|
||||
targetRect.y = y;
|
||||
|
||||
if (scale != 0 && scale != 256)
|
||||
if (scale != 0 && scale != GetGraphicScaleIdentity ())
|
||||
{
|
||||
// TFB_DrawImage_FixScaling (img, scale);
|
||||
TFB_DrawImage_FixScaling (img, scale);
|
||||
surf = img->ScaledImg;
|
||||
}
|
||||
else
|
||||
@@ -92,9 +92,9 @@ TFB_DrawCanvas_FilledImage (TFB_Image *img, int x, int y, int scale, int r, int
|
||||
targetRect.x = x;
|
||||
targetRect.y = y;
|
||||
|
||||
if (scale != 0 && scale != 256)
|
||||
if (scale != 0 && scale != GetGraphicScaleIdentity ())
|
||||
{
|
||||
// TFB_DrawImage_FixScaling (img, scale);
|
||||
TFB_DrawImage_FixScaling (img, scale);
|
||||
surf = img->ScaledImg;
|
||||
}
|
||||
else
|
||||
@@ -206,9 +206,9 @@ TFB_DrawCanvas_New_Scaled (TFB_Canvas src, int scale)
|
||||
{
|
||||
SDL_Surface *new_surf;
|
||||
|
||||
new_surf = zoomSurface ((SDL_Surface *)src, scale / 256.0f,
|
||||
scale / 256.0f, SMOOTHING_OFF);
|
||||
|
||||
new_surf = zoomSurface ((SDL_Surface *)src, scale / (float)GetGraphicScaleIdentity (),
|
||||
scale / (float)GetGraphicScaleIdentity (), SMOOTHING_OFF);
|
||||
|
||||
if (new_surf)
|
||||
{
|
||||
if (!TFB_DrawCanvas_IsPaletted (new_surf))
|
||||
|
||||
@@ -510,11 +510,6 @@ TFB_FlushGraphics () // Only call from main thread!!
|
||||
int y = DC.data.image.y;
|
||||
|
||||
LockMutex (DC_image->mutex);
|
||||
if (DC.data.image.scale)
|
||||
TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y);
|
||||
else
|
||||
TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y);
|
||||
|
||||
if (DC.data.image.UsePalette)
|
||||
{
|
||||
pal = palette;
|
||||
@@ -529,6 +524,13 @@ TFB_FlushGraphics () // Only call from main thread!!
|
||||
DC.data.image.scale, pal,
|
||||
SDL_Screens[DC.data.image.destBuffer]);
|
||||
|
||||
LockMutex (DC_image->mutex);
|
||||
if (DC.data.image.scale)
|
||||
TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y);
|
||||
else
|
||||
TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y);
|
||||
UnlockMutex (DC_image->mutex);
|
||||
|
||||
break;
|
||||
}
|
||||
case TFB_DRAWCOMMANDTYPE_FILLEDIMAGE:
|
||||
@@ -537,14 +539,17 @@ TFB_FlushGraphics () // Only call from main thread!!
|
||||
int x = DC.data.filledimage.x;
|
||||
int y = DC.data.filledimage.y;
|
||||
|
||||
TFB_DrawCanvas_FilledImage (DC.data.filledimage.image, DC.data.filledimage.x, DC.data.filledimage.y,
|
||||
DC.data.filledimage.scale, DC.data.filledimage.r, DC.data.filledimage.g,
|
||||
DC.data.filledimage.b, SDL_Screens[DC.data.filledimage.destBuffer]);
|
||||
|
||||
LockMutex (DC_image->mutex);
|
||||
if (DC.data.filledimage.scale)
|
||||
TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y);
|
||||
else
|
||||
TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y);
|
||||
UnlockMutex (DC_image->mutex);
|
||||
|
||||
TFB_DrawCanvas_FilledImage (DC.data.filledimage.image, DC.data.filledimage.x, DC.data.filledimage.y,
|
||||
DC.data.filledimage.scale, DC.data.filledimage.r, DC.data.filledimage.g,
|
||||
DC.data.filledimage.b, SDL_Screens[DC.data.filledimage.destBuffer]);
|
||||
break;
|
||||
}
|
||||
case TFB_DRAWCOMMANDTYPE_LINE:
|
||||
@@ -616,8 +621,7 @@ TFB_FlushGraphics () // Only call from main thread!!
|
||||
|
||||
TFB_BBox_RegisterPoint (src.x, src.y);
|
||||
TFB_BBox_RegisterPoint (src.x + src.w, src.y + src.h);
|
||||
|
||||
|
||||
|
||||
SDL_BlitSurface(SDL_Screens[DC.data.copy.srcBuffer], &src, SDL_Screens[DC.data.copy.destBuffer], &dest);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ TFB_DrawScreen_Image (TFB_Image *img, int x, int y, int scale, TFB_Palette *pale
|
||||
DC.data.image.image = img;
|
||||
DC.data.image.x = x;
|
||||
DC.data.image.y = y;
|
||||
DC.data.image.scale = (scale == 256) ? 0 : scale;
|
||||
DC.data.image.scale = (scale == GetGraphicScaleIdentity ()) ? 0 : scale;
|
||||
|
||||
if (palette != NULL)
|
||||
{
|
||||
@@ -129,7 +129,7 @@ TFB_DrawScreen_FilledImage (TFB_Image *img, int x, int y, int scale, int r, int
|
||||
DC.data.filledimage.image = img;
|
||||
DC.data.filledimage.x = x;
|
||||
DC.data.filledimage.y = y;
|
||||
DC.data.filledimage.scale = (scale == 256) ? 0 : scale;
|
||||
DC.data.filledimage.scale = (scale == GetGraphicScaleIdentity ()) ? 0 : scale;
|
||||
DC.data.filledimage.r = r;
|
||||
DC.data.filledimage.g = g;
|
||||
DC.data.filledimage.b = b;
|
||||
|
||||
@@ -46,10 +46,9 @@ void
|
||||
TFB_Prim_Rect (PRECT r, TFB_Palette *color)
|
||||
{
|
||||
RECT arm;
|
||||
int gscale;
|
||||
int gscale, gscale_identity;
|
||||
gscale = GetGraphicScale ();
|
||||
if (!gscale)
|
||||
gscale = 256;
|
||||
gscale_identity = GetGraphicScaleIdentity ();
|
||||
arm = *r;
|
||||
arm.extent.width = r->extent.width;
|
||||
arm.extent.height = 1;
|
||||
@@ -57,10 +56,10 @@ TFB_Prim_Rect (PRECT r, TFB_Palette *color)
|
||||
arm.extent.height = r->extent.height;
|
||||
arm.extent.width = 1;
|
||||
TFB_Prim_FillRect (&arm, color);
|
||||
arm.corner.x += ((r->extent.width * gscale) >> 8) - 1;
|
||||
arm.corner.x += ((r->extent.width * gscale) / gscale_identity) - 1;
|
||||
TFB_Prim_FillRect (&arm, color);
|
||||
arm.corner.x = r->corner.x;
|
||||
arm.corner.y += ((r->extent.height * gscale) >> 8) - 1;
|
||||
arm.corner.y += ((r->extent.height * gscale) / gscale_identity) - 1;
|
||||
arm.extent.width = r->extent.width;
|
||||
arm.extent.height = 1;
|
||||
TFB_Prim_FillRect (&arm, color);
|
||||
@@ -70,7 +69,7 @@ void
|
||||
TFB_Prim_FillRect (PRECT r, TFB_Palette *color)
|
||||
{
|
||||
RECT rect;
|
||||
int gscale;
|
||||
int gscale, gscale_identity;
|
||||
|
||||
rect.corner.x = r->corner.x - _CurFramePtr->HotSpot.x;
|
||||
rect.corner.y = r->corner.y - _CurFramePtr->HotSpot.y;
|
||||
@@ -78,10 +77,11 @@ TFB_Prim_FillRect (PRECT r, TFB_Palette *color)
|
||||
rect.extent.height = r->extent.height;
|
||||
|
||||
gscale = GetGraphicScale ();
|
||||
if (gscale)
|
||||
gscale_identity = GetGraphicScaleIdentity ();
|
||||
if (gscale != gscale_identity)
|
||||
{
|
||||
rect.extent.width = (rect.extent.width * gscale) >> 8;
|
||||
rect.extent.height = (rect.extent.height * gscale) >> 8;
|
||||
rect.extent.width = (rect.extent.width * gscale) / gscale_identity;
|
||||
rect.extent.height = (rect.extent.height * gscale) / gscale_identity;
|
||||
rect.corner.x += (r->extent.width -
|
||||
rect.extent.width) >> 1;
|
||||
rect.corner.y += (r->extent.height -
|
||||
@@ -118,7 +118,7 @@ TFB_Prim_Stamp (PSTAMP stmp)
|
||||
TFB_Image *img;
|
||||
BOOLEAN paletted;
|
||||
TFB_Palette palette[256];
|
||||
int gscale;
|
||||
int gscale, gscale_identity;
|
||||
|
||||
SrcFramePtr = (PFRAME_DESC)stmp->frame;
|
||||
if (!SrcFramePtr)
|
||||
@@ -128,6 +128,7 @@ TFB_Prim_Stamp (PSTAMP stmp)
|
||||
}
|
||||
img = SrcFramePtr->image;
|
||||
gscale = GetGraphicScale ();
|
||||
gscale_identity = GetGraphicScaleIdentity ();
|
||||
|
||||
if (!img)
|
||||
{
|
||||
@@ -141,13 +142,12 @@ TFB_Prim_Stamp (PSTAMP stmp)
|
||||
y = stmp->origin.y - _CurFramePtr->HotSpot.y - SrcFramePtr->HotSpot.y;
|
||||
paletted = FALSE;
|
||||
|
||||
if (gscale != 0 && gscale != 256)
|
||||
if (gscale != GetGraphicScaleIdentity ())
|
||||
{
|
||||
TFB_DrawImage_FixScaling (img, gscale);
|
||||
x += (SrcFramePtr->HotSpot.x *
|
||||
((1 << 8) - gscale)) >> 8;
|
||||
(gscale_identity - gscale)) / gscale_identity;
|
||||
y += (SrcFramePtr->HotSpot.y *
|
||||
((1 << 8) - gscale)) >> 8;
|
||||
(gscale_identity - gscale)) / gscale_identity;
|
||||
}
|
||||
|
||||
if (TFB_DrawCanvas_IsPaletted(img->NormalImg) && img->colormap_index != -1)
|
||||
@@ -177,7 +177,7 @@ TFB_Prim_StampFill (PSTAMP stmp, TFB_Palette *color)
|
||||
PFRAME_DESC SrcFramePtr;
|
||||
TFB_Image *img;
|
||||
int r, g, b;
|
||||
int gscale;
|
||||
int gscale, gscale_identity;
|
||||
|
||||
SrcFramePtr = (PFRAME_DESC)stmp->frame;
|
||||
if (!SrcFramePtr)
|
||||
@@ -187,6 +187,7 @@ TFB_Prim_StampFill (PSTAMP stmp, TFB_Palette *color)
|
||||
}
|
||||
img = SrcFramePtr->image;
|
||||
gscale = GetGraphicScale ();
|
||||
gscale_identity = GetGraphicScaleIdentity ();
|
||||
|
||||
if (!img)
|
||||
{
|
||||
@@ -202,13 +203,12 @@ TFB_Prim_StampFill (PSTAMP stmp, TFB_Palette *color)
|
||||
g = color->g;
|
||||
b = color->b;
|
||||
|
||||
if (gscale != 0 && gscale != 256)
|
||||
if (gscale != gscale_identity)
|
||||
{
|
||||
TFB_DrawImage_FixScaling (img, gscale);
|
||||
x += (SrcFramePtr->HotSpot.x *
|
||||
((1 << 8) - gscale)) >> 8;
|
||||
(gscale_identity - gscale)) / gscale_identity;
|
||||
y += (SrcFramePtr->HotSpot.y *
|
||||
((1 << 8) - gscale)) >> 8;
|
||||
(gscale_identity - gscale)) / gscale_identity;
|
||||
}
|
||||
|
||||
UnlockMutex (img->mutex);
|
||||
|
||||
Reference in New Issue
Block a user