Some optimizations: bbox is updated only if destbuffer is screen

surface; if bbox isn't valid, swapbuffer does nothing; better locking of
imgmutex


git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@1082 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
gewlitys
2003-07-22 23:50:13 +00:00
parent d60c03e7b6
commit ad23c55afa
4 changed files with 92 additions and 88 deletions
+8 -17
View File
@@ -60,19 +60,19 @@ TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale, TFB_Palette *pale
targetRect.x = x;
targetRect.y = y;
if (palette == 0)
palette = img->Palette;
if (scale != 0 && scale != GSCALE_IDENTITY)
{
int type;
if (optMeleeScale == TFB_SCALE_TRILINEAR && img->MipmapImg)
{
type = TFB_SCALE_TRILINEAR;
if (palette)
{
if (((SDL_Surface *)img->NormalImg)->format->palette)
SDL_SetColors (img->NormalImg, (SDL_Color*)palette, 0, 256);
if (((SDL_Surface *)img->MipmapImg)->format->palette)
SDL_SetColors (img->MipmapImg, (SDL_Color*)palette, 0, 256);
}
if (((SDL_Surface *)img->NormalImg)->format->palette)
SDL_SetColors (img->NormalImg, (SDL_Color*)palette, 0, 256);
if (((SDL_Surface *)img->MipmapImg)->format->palette)
SDL_SetColors (img->MipmapImg, (SDL_Color*)palette, 0, 256);
}
else
{
@@ -94,16 +94,7 @@ TFB_DrawCanvas_Image (TFB_Image *img, int x, int y, int scale, TFB_Palette *pale
}
if (surf->format->palette)
{
if (palette)
{
SDL_SetColors (surf, (SDL_Color*)palette, 0, 256);
}
else
{
SDL_SetColors (surf, (SDL_Color*)img->Palette, 0, 256);
}
}
SDL_SetColors (surf, (SDL_Color*)palette, 0, 256);
SDL_BlitSurface(surf, pSrcRect, (NativeCanvas) target, &targetRect);
UnlockMutex (img->mutex);
+38 -32
View File
@@ -271,14 +271,12 @@ TFB_GL_DrawQuad (void)
void
TFB_GL_SwapBuffers (int force_full_redraw)
{
int fade_amount;
int transition_amount;
SDL_Rect updated;
int fade_amount = FadeAmount;
int transition_amount = TransitionAmount;
updated.x = TFB_BBox.region.corner.x;
updated.y = TFB_BBox.region.corner.y;
updated.w = TFB_BBox.region.extent.width;
updated.h = TFB_BBox.region.extent.height;
if (!force_full_redraw && !TFB_BBox.valid &&
fade_amount == 255 && transition_amount == 255)
return;
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
@@ -293,36 +291,45 @@ TFB_GL_SwapBuffers (int force_full_redraw)
glDisable (GL_BLEND);
glColor4f (1, 1, 1, 1);
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT ||
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
if (TFB_BBox.valid)
{
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT)
Scale_BiAdaptFilter (SDL_Screen, scaled_display, &updated);
else if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
Scale_BiAdaptAdvFilter (SDL_Screen, scaled_display, &updated);
SDL_Rect updated;
glPixelStorei (GL_UNPACK_ROW_LENGTH, ScreenWidth * 2);
glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y * 2);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x * 2);
SDL_LockSurface (scaled_display);
glTexSubImage2D (GL_TEXTURE_2D, 0, updated.x * 2, updated.y * 2, updated.w * 2, updated.h * 2,
GL_RGBA, GL_UNSIGNED_BYTE, scaled_display->pixels);
SDL_UnlockSurface (scaled_display);
}
else
{
glPixelStorei (GL_UNPACK_ROW_LENGTH, ScreenWidth);
glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x);
SDL_LockSurface (SDL_Screen);
glTexSubImage2D (GL_TEXTURE_2D, 0, updated.x, updated.y, updated.w, updated.h,
GL_RGBA, GL_UNSIGNED_BYTE, SDL_Screen->pixels);
SDL_UnlockSurface (SDL_Screen);
updated.x = TFB_BBox.region.corner.x;
updated.y = TFB_BBox.region.corner.y;
updated.w = TFB_BBox.region.extent.width;
updated.h = TFB_BBox.region.extent.height;
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT ||
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
{
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT)
Scale_BiAdaptFilter (SDL_Screen, scaled_display, &updated);
else if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
Scale_BiAdaptAdvFilter (SDL_Screen, scaled_display, &updated);
glPixelStorei (GL_UNPACK_ROW_LENGTH, ScreenWidth * 2);
glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y * 2);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x * 2);
SDL_LockSurface (scaled_display);
glTexSubImage2D (GL_TEXTURE_2D, 0, updated.x * 2, updated.y * 2, updated.w * 2, updated.h * 2,
GL_RGBA, GL_UNSIGNED_BYTE, scaled_display->pixels);
SDL_UnlockSurface (scaled_display);
}
else
{
glPixelStorei (GL_UNPACK_ROW_LENGTH, ScreenWidth);
glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x);
SDL_LockSurface (SDL_Screen);
glTexSubImage2D (GL_TEXTURE_2D, 0, updated.x, updated.y, updated.w, updated.h,
GL_RGBA, GL_UNSIGNED_BYTE, SDL_Screen->pixels);
SDL_UnlockSurface (SDL_Screen);
}
}
TFB_GL_DrawQuad ();
transition_amount = TransitionAmount;
if (transition_amount != 255)
{
float scale_x = (ScreenWidthActual / (float)ScreenWidth);
@@ -382,7 +389,6 @@ TFB_GL_SwapBuffers (int force_full_redraw)
glDisable (GL_SCISSOR_TEST);
}
fade_amount = FadeAmount;
if (fade_amount != 255)
{
float c;
+14 -14
View File
@@ -231,26 +231,26 @@ TFB_Pure_SwapBuffers (int force_full_redraw)
int transition_amount = TransitionAmount;
SDL_Rect updated;
if (fade_amount != 255 || transition_amount != 255 ||
if (force_full_redraw ||
fade_amount != 255 || transition_amount != 255 ||
last_fade_amount != 255 || last_transition_amount != 255)
force_full_redraw = 1;
last_fade_amount = fade_amount;
last_transition_amount = transition_amount;
if (!force_full_redraw)
{
updated.x = TFB_BBox.region.corner.x;
updated.y = TFB_BBox.region.corner.y;
updated.w = TFB_BBox.region.extent.width;
updated.h = TFB_BBox.region.extent.height;
}
else
{
updated.x = updated.y = 0;
updated.w = ScreenWidth;
updated.h = ScreenHeight;
}
else
{
if (!TFB_BBox.valid)
return;
updated.x = TFB_BBox.region.corner.x;
updated.y = TFB_BBox.region.corner.y;
updated.w = TFB_BBox.region.extent.width;
updated.h = TFB_BBox.region.extent.height;
}
last_fade_amount = fade_amount;
last_transition_amount = transition_amount;
if (ScreenWidth == 320 && ScreenHeight == 240 &&
ScreenWidthActual == 640 && ScreenHeightActual == 480)
+31 -24
View File
@@ -525,27 +525,24 @@ TFB_FlushGraphics () // Only call from main thread!!
int x = DC.data.image.x;
int y = DC.data.image.y;
LockMutex (DC_image->mutex);
if (DC.data.image.UsePalette)
{
pal = palette;
}
else
{
pal = DC_image->Palette;
}
UnlockMutex (DC_image->mutex);
pal = 0;
TFB_DrawCanvas_Image (DC_image, x, y,
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);
if (DC.data.image.destBuffer == 0)
{
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;
}
@@ -559,19 +556,25 @@ TFB_FlushGraphics () // Only call from main thread!!
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);
if (DC.data.filledimage.destBuffer == 0)
{
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);
}
break;
}
case TFB_DRAWCOMMANDTYPE_LINE:
{
TFB_BBox_RegisterPoint (DC.data.line.x1, DC.data.line.y1);
TFB_BBox_RegisterPoint (DC.data.line.x2, DC.data.line.y2);
if (DC.data.line.destBuffer == 0)
{
TFB_BBox_RegisterPoint (DC.data.line.x1, DC.data.line.y1);
TFB_BBox_RegisterPoint (DC.data.line.x2, DC.data.line.y2);
}
TFB_DrawCanvas_Line (DC.data.line.x1, DC.data.line.y1,
DC.data.line.x2, DC.data.line.y2,
DC.data.line.r, DC.data.line.g, DC.data.line.b,
@@ -580,7 +583,8 @@ TFB_FlushGraphics () // Only call from main thread!!
}
case TFB_DRAWCOMMANDTYPE_RECTANGLE:
{
TFB_BBox_RegisterRect (&DC.data.rect.rect);
if (DC.data.rect.destBuffer == 0)
TFB_BBox_RegisterRect (&DC.data.rect.rect);
TFB_DrawCanvas_Rect (&DC.data.rect.rect, DC.data.rect.r,
DC.data.rect.g, DC.data.rect.b,
SDL_Screens[DC.data.rect.destBuffer]);
@@ -635,8 +639,11 @@ TFB_FlushGraphics () // Only call from main thread!!
src.w = DC.data.copy.w;
src.h = DC.data.copy.h;
TFB_BBox_RegisterPoint (src.x, src.y);
TFB_BBox_RegisterPoint (src.x + src.w, src.y + src.h);
if (DC.data.copy.destBuffer == 0)
{
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;