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.x = x;
targetRect.y = y; targetRect.y = y;
if (palette == 0)
palette = img->Palette;
if (scale != 0 && scale != GSCALE_IDENTITY) if (scale != 0 && scale != GSCALE_IDENTITY)
{ {
int type; int type;
if (optMeleeScale == TFB_SCALE_TRILINEAR && img->MipmapImg) if (optMeleeScale == TFB_SCALE_TRILINEAR && img->MipmapImg)
{ {
type = TFB_SCALE_TRILINEAR; 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->NormalImg)->format->palette) if (((SDL_Surface *)img->MipmapImg)->format->palette)
SDL_SetColors (img->NormalImg, (SDL_Color*)palette, 0, 256); SDL_SetColors (img->MipmapImg, (SDL_Color*)palette, 0, 256);
if (((SDL_Surface *)img->MipmapImg)->format->palette)
SDL_SetColors (img->MipmapImg, (SDL_Color*)palette, 0, 256);
}
} }
else 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 (surf->format->palette)
{ SDL_SetColors (surf, (SDL_Color*)palette, 0, 256);
if (palette)
{
SDL_SetColors (surf, (SDL_Color*)palette, 0, 256);
}
else
{
SDL_SetColors (surf, (SDL_Color*)img->Palette, 0, 256);
}
}
SDL_BlitSurface(surf, pSrcRect, (NativeCanvas) target, &targetRect); SDL_BlitSurface(surf, pSrcRect, (NativeCanvas) target, &targetRect);
UnlockMutex (img->mutex); UnlockMutex (img->mutex);
+38 -32
View File
@@ -271,14 +271,12 @@ TFB_GL_DrawQuad (void)
void void
TFB_GL_SwapBuffers (int force_full_redraw) TFB_GL_SwapBuffers (int force_full_redraw)
{ {
int fade_amount; int fade_amount = FadeAmount;
int transition_amount; int transition_amount = TransitionAmount;
SDL_Rect updated;
updated.x = TFB_BBox.region.corner.x; if (!force_full_redraw && !TFB_BBox.valid &&
updated.y = TFB_BBox.region.corner.y; fade_amount == 255 && transition_amount == 255)
updated.w = TFB_BBox.region.extent.width; return;
updated.h = TFB_BBox.region.extent.height;
glMatrixMode (GL_PROJECTION); glMatrixMode (GL_PROJECTION);
glLoadIdentity (); glLoadIdentity ();
@@ -293,36 +291,45 @@ TFB_GL_SwapBuffers (int force_full_redraw)
glDisable (GL_BLEND); glDisable (GL_BLEND);
glColor4f (1, 1, 1, 1); glColor4f (1, 1, 1, 1);
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT || if (TFB_BBox.valid)
GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
{ {
if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT) SDL_Rect updated;
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); updated.x = TFB_BBox.region.corner.x;
glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y * 2); updated.y = TFB_BBox.region.corner.y;
glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x * 2); updated.w = TFB_BBox.region.extent.width;
SDL_LockSurface (scaled_display); updated.h = TFB_BBox.region.extent.height;
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); if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT ||
SDL_UnlockSurface (scaled_display); GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
} {
else if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPT)
{ Scale_BiAdaptFilter (SDL_Screen, scaled_display, &updated);
glPixelStorei (GL_UNPACK_ROW_LENGTH, ScreenWidth); else if (GfxFlags & TFB_GFXFLAGS_SCALE_BIADAPTADV)
glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y); Scale_BiAdaptAdvFilter (SDL_Screen, scaled_display, &updated);
glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x);
SDL_LockSurface (SDL_Screen); glPixelStorei (GL_UNPACK_ROW_LENGTH, ScreenWidth * 2);
glTexSubImage2D (GL_TEXTURE_2D, 0, updated.x, updated.y, updated.w, updated.h, glPixelStorei (GL_UNPACK_SKIP_ROWS, updated.y * 2);
GL_RGBA, GL_UNSIGNED_BYTE, SDL_Screen->pixels); glPixelStorei (GL_UNPACK_SKIP_PIXELS, updated.x * 2);
SDL_UnlockSurface (SDL_Screen); 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 (); TFB_GL_DrawQuad ();
transition_amount = TransitionAmount;
if (transition_amount != 255) if (transition_amount != 255)
{ {
float scale_x = (ScreenWidthActual / (float)ScreenWidth); float scale_x = (ScreenWidthActual / (float)ScreenWidth);
@@ -382,7 +389,6 @@ TFB_GL_SwapBuffers (int force_full_redraw)
glDisable (GL_SCISSOR_TEST); glDisable (GL_SCISSOR_TEST);
} }
fade_amount = FadeAmount;
if (fade_amount != 255) if (fade_amount != 255)
{ {
float c; float c;
+14 -14
View File
@@ -231,26 +231,26 @@ TFB_Pure_SwapBuffers (int force_full_redraw)
int transition_amount = TransitionAmount; int transition_amount = TransitionAmount;
SDL_Rect updated; 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) 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.x = updated.y = 0;
updated.w = ScreenWidth; updated.w = ScreenWidth;
updated.h = ScreenHeight; 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 && if (ScreenWidth == 320 && ScreenHeight == 240 &&
ScreenWidthActual == 640 && ScreenHeightActual == 480) 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 x = DC.data.image.x;
int y = DC.data.image.y; int y = DC.data.image.y;
LockMutex (DC_image->mutex);
if (DC.data.image.UsePalette) if (DC.data.image.UsePalette)
{
pal = palette; pal = palette;
}
else else
{ pal = 0;
pal = DC_image->Palette;
}
UnlockMutex (DC_image->mutex);
TFB_DrawCanvas_Image (DC_image, x, y, TFB_DrawCanvas_Image (DC_image, x, y,
DC.data.image.scale, pal, DC.data.image.scale, pal,
SDL_Screens[DC.data.image.destBuffer]); SDL_Screens[DC.data.image.destBuffer]);
LockMutex (DC_image->mutex); if (DC.data.image.destBuffer == 0)
if (DC.data.image.scale) {
TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y); LockMutex (DC_image->mutex);
else if (DC.data.image.scale)
TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y); TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y);
UnlockMutex (DC_image->mutex); else
TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y);
UnlockMutex (DC_image->mutex);
}
break; 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.scale, DC.data.filledimage.r, DC.data.filledimage.g,
DC.data.filledimage.b, SDL_Screens[DC.data.filledimage.destBuffer]); DC.data.filledimage.b, SDL_Screens[DC.data.filledimage.destBuffer]);
LockMutex (DC_image->mutex); if (DC.data.filledimage.destBuffer == 0)
if (DC.data.filledimage.scale) {
TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y); LockMutex (DC_image->mutex);
else if (DC.data.filledimage.scale)
TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y); TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y);
UnlockMutex (DC_image->mutex); else
TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y);
UnlockMutex (DC_image->mutex);
}
break; break;
} }
case TFB_DRAWCOMMANDTYPE_LINE: case TFB_DRAWCOMMANDTYPE_LINE:
{ {
TFB_BBox_RegisterPoint (DC.data.line.x1, DC.data.line.y1); if (DC.data.line.destBuffer == 0)
TFB_BBox_RegisterPoint (DC.data.line.x2, DC.data.line.y2); {
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, TFB_DrawCanvas_Line (DC.data.line.x1, DC.data.line.y1,
DC.data.line.x2, DC.data.line.y2, DC.data.line.x2, DC.data.line.y2,
DC.data.line.r, DC.data.line.g, DC.data.line.b, 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: 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, TFB_DrawCanvas_Rect (&DC.data.rect.rect, DC.data.rect.r,
DC.data.rect.g, DC.data.rect.b, DC.data.rect.g, DC.data.rect.b,
SDL_Screens[DC.data.rect.destBuffer]); SDL_Screens[DC.data.rect.destBuffer]);
@@ -635,8 +639,11 @@ TFB_FlushGraphics () // Only call from main thread!!
src.w = DC.data.copy.w; src.w = DC.data.copy.w;
src.h = DC.data.copy.h; src.h = DC.data.copy.h;
TFB_BBox_RegisterPoint (src.x, src.y); if (DC.data.copy.destBuffer == 0)
TFB_BBox_RegisterPoint (src.x + src.w, src.y + src.h); {
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); SDL_BlitSurface(SDL_Screens[DC.data.copy.srcBuffer], &src, SDL_Screens[DC.data.copy.destBuffer], &dest);
break; break;