From: <mcm...@us...> - 2003-01-30 21:24:55
|
Update of /cvsroot/sc2/sc2/src/sc2code/libs/graphics/sdl In directory sc8-pr-cvs1:/tmp/cvs-serv574/src/sc2code/libs/graphics/sdl Modified Files: Makeinfo pure.c sdl_common.c Added Files: bbox.c bbox.h Log Message: TFB_FlushGraphics tracks smallest required rectangle to update or rescale A partial version of only updating the smallest rectangle possible has been implemented for no scaling and for ScaleNearest. --- NEW FILE: bbox.c --- #include "SDL.h" #include "bbox.h" TFB_BoundingBox TFB_BBox; void TFB_BBox_Reset () { TFB_BBox.valid = 0; TFB_BBox.clip.corner.x = 0; TFB_BBox.clip.corner.y = 0; TFB_BBox.clip.extent.width = ScreenWidth; TFB_BBox.clip.extent.height = ScreenHeight; } void TFB_BBox_GetClipRect (TFB_Canvas c) { SDL_Rect r; SDL_GetClipRect ((SDL_Surface *)c, &r); TFB_BBox.clip.corner.x = r.x; TFB_BBox.clip.corner.y = r.y; TFB_BBox.clip.extent.width = r.w; TFB_BBox.clip.extent.height = r.h; } void TFB_BBox_RegisterPoint (int x, int y) { int x1 = TFB_BBox.clip.corner.x; int y1 = TFB_BBox.clip.corner.y; int x2 = TFB_BBox.clip.corner.x + TFB_BBox.clip.extent.width - 1; int y2 = TFB_BBox.clip.corner.y + TFB_BBox.clip.extent.height - 1; /* Make sure the cliprect is sane */ if (x1 < 0) x1 = TFB_BBox.clip.corner.x = 0; if (y1 < 0) y1 = TFB_BBox.clip.corner.y = 0; if (x2 >= ScreenWidth) { TFB_BBox.clip.extent.width = ScreenWidth - x1; x2 = ScreenWidth - 1; } if (y2 >= ScreenHeight) { TFB_BBox.clip.extent.height = ScreenHeight - y1; y2 = ScreenHeight - 1; } /* Constrain coordinates */ if (x < x1) x = x1; if (x >= x2) x = x2; if (y < y1) y = y1; if (y >= y2) y = y2; /* Is this the first point? If so, set a pixel-region and return. */ if (!TFB_BBox.valid) { TFB_BBox.valid = 1; TFB_BBox.region.corner.x = x; TFB_BBox.region.corner.y = y; TFB_BBox.region.extent.width = 1; TFB_BBox.region.extent.height = 1; return; } /* Otherwise expand the rectangle if necessary. */ x1 = TFB_BBox.region.corner.x; y1 = TFB_BBox.region.corner.y; x2 = TFB_BBox.region.corner.x + TFB_BBox.region.extent.width - 1; y2 = TFB_BBox.region.corner.y + TFB_BBox.region.extent.height - 1; if (x < x1) { TFB_BBox.region.corner.x = x; TFB_BBox.region.extent.width += x1 - x; } if (y < y1) { TFB_BBox.region.corner.y = y; TFB_BBox.region.extent.height += y1 - y; } if (x > x2) { TFB_BBox.region.extent.width += x - x2; } if (y > y2) { TFB_BBox.region.extent.height += y - y2; } } void TFB_BBox_RegisterRect (PRECT r) { TFB_BBox_RegisterPoint (r->corner.x, r->corner.y); TFB_BBox_RegisterPoint (r->corner.x + r->extent.width, r->corner.y + r->extent.height); } void TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y) { SDL_Surface *s = (SDL_Surface *)c; TFB_BBox_RegisterPoint (x, y); TFB_BBox_RegisterPoint (x + s->w, y + s->h); } --- NEW FILE: bbox.h --- #include "gfxlib.h" #include "graphics/tfb_draw.h" #include "graphics/gfx_common.h" #ifndef _BBOX_H_ #define _BBOX_H_ /* Bounding Box operations. These operations are NOT synchronized. * However, they should only be accessed by TFB_FlushGraphics and * TFB_SwapBuffers, or the routines that they exclusively call -- all * of which are only callable by the thread that is permitted to touch * the screen. No explicit locks should therefore be required. */ typedef struct { int valid; // If zero, the next point registered becomes the region RECT region; // The actual modified rectangle RECT clip; // Points outside of this rectangle are pushed to // the closest border point } TFB_BoundingBox; extern TFB_BoundingBox TFB_BBox; void TFB_BBox_RegisterPoint (int x, int y); void TFB_BBox_RegisterRect (PRECT r); void TFB_BBox_RegisterCanvas (TFB_Canvas c, int x, int y); void TFB_BBox_Reset (); void TFB_BBox_GetClipRect (TFB_Canvas c); #endif Index: Makeinfo =================================================================== RCS file: /cvsroot/sc2/sc2/src/sc2code/libs/graphics/sdl/Makeinfo,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makeinfo 30 Jan 2003 07:47:41 -0000 1.5 --- Makeinfo 30 Jan 2003 21:24:51 -0000 1.6 *************** *** 1,3 **** uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c primitives.c pure.c rndzoom.c rotozoom.c sdl_common.c oscilloscope.c ! canvas.c" --- 1,3 ---- uqm_CFILES="3do_blt.c 3do_funcs.c 3do_getbody.c dcqueue.c opengl.c primitives.c pure.c rndzoom.c rotozoom.c sdl_common.c oscilloscope.c ! canvas.c bbox.c" Index: pure.c =================================================================== RCS file: /cvsroot/sc2/sc2/src/sc2code/libs/graphics/sdl/pure.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** pure.c 12 Jan 2003 18:50:41 -0000 1.22 --- pure.c 30 Jan 2003 21:24:51 -0000 1.23 *************** *** 21,24 **** --- 21,25 ---- #include "pure.h" #include "primitives.h" + #include "bbox.h" static SDL_Surface *fade_black; *************** *** 832,839 **** // nearest neighbor scaling to 2x ! static void Scale_Nearest (SDL_Surface *src, SDL_Surface *dst) { int x, y; const int w = src->w, h = src->h, dw = dst->w; switch (dst->format->BytesPerPixel) --- 833,842 ---- // nearest neighbor scaling to 2x ! static void Scale_Nearest (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) { int x, y; const int w = src->w, h = src->h, dw = dst->w; + const int x0 = r->x, y0 = r->y, rw = r->w, rh = r->h; + const int ds = w-rw, dd = (dw-rw) * 2; switch (dst->format->BytesPerPixel) *************** *** 843,849 **** Uint16 *src_p = (Uint16 *)src->pixels, *dst_p = (Uint16 *)dst->pixels; Uint16 pixval_16; ! for (y = 0; y < h; ++y) { ! for (x = 0; x < w; ++x) { pixval_16 = *src_p++; --- 846,854 ---- Uint16 *src_p = (Uint16 *)src->pixels, *dst_p = (Uint16 *)dst->pixels; Uint16 pixval_16; ! src_p += w*y0 + x0; ! dst_p += (dw*y0 + x0) * 2; ! for (y = 0; y < rh; ++y) { ! for (x = 0; x < rw; ++x) { pixval_16 = *src_p++; *************** *** 853,857 **** *dst_p++ = pixval_16; } ! dst_p += dw; } break; --- 858,863 ---- *dst_p++ = pixval_16; } ! dst_p += dd; ! src_p += ds; } break; *************** *** 890,896 **** Uint32 *src_p = (Uint32 *)src->pixels, *dst_p = (Uint32 *)dst->pixels; Uint32 pixval_32; ! for (y = 0; y < h; ++y) { ! for (x = 0; x < w; ++x) { pixval_32 = *src_p++; --- 896,904 ---- Uint32 *src_p = (Uint32 *)src->pixels, *dst_p = (Uint32 *)dst->pixels; Uint32 pixval_32; ! src_p += w*y0 + x0; ! dst_p += (dw*y0 + x0) * 2; ! for (y = 0; y < rh; ++y) { ! for (x = 0; x < rw; ++x) { pixval_32 = *src_p++; *************** *** 900,904 **** *dst_p++ = pixval_32; } ! dst_p += dw; } break; --- 908,913 ---- *dst_p++ = pixval_32; } ! dst_p += dd; ! src_p += ds; } break; *************** *** 908,912 **** // bilinear scaling to 2x ! static void Scale_BilinearFilter (SDL_Surface *src, SDL_Surface *dst) { int x, y, i = 0, j, fa, fb, fc, fd; --- 917,921 ---- // bilinear scaling to 2x ! static void Scale_BilinearFilter (SDL_Surface *src, SDL_Surface *dst, SDL_Rect *r) { int x, y, i = 0, j, fa, fb, fc, fd; *************** *** 1003,1007 **** // 24bpp mode bilinear scaling isn't implemented currently // it would probably be too slow to be useful anyway ! Scale_Nearest (src, dst); break; } --- 1012,1016 ---- // 24bpp mode bilinear scaling isn't implemented currently // it would probably be too slow to be useful anyway ! Scale_Nearest (src, dst, r); break; } *************** *** 1170,1173 **** --- 1179,1195 ---- int fade_amount = FadeAmount; int transition_amount = TransitionAmount; + SDL_Rect updated; + + 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 ((transition_amount != 255) || (fade_amount != 255)) + { + updated.x = updated.y = 0; + updated.w = ScreenWidth; + updated.h = ScreenHeight; + } if (ScreenWidth == 320 && ScreenHeight == 240 && *************** *** 1211,1219 **** if (gfx_flags & TFB_GFXFLAGS_SCALE_BILINEAR) ! Scale_BilinearFilter (backbuffer, SDL_Video); else if (gfx_flags & TFB_GFXFLAGS_SCALE_BIADAPT) Scale_BiAdaptFilter (backbuffer, SDL_Video); else ! Scale_Nearest (backbuffer, SDL_Video); if (gfx_flags & TFB_GFXFLAGS_SCANLINES) --- 1233,1241 ---- if (gfx_flags & TFB_GFXFLAGS_SCALE_BILINEAR) ! Scale_BilinearFilter (backbuffer, SDL_Video, &updated); else if (gfx_flags & TFB_GFXFLAGS_SCALE_BIADAPT) Scale_BiAdaptFilter (backbuffer, SDL_Video); else ! Scale_Nearest (backbuffer, SDL_Video, &updated); if (gfx_flags & TFB_GFXFLAGS_SCANLINES) *************** *** 1227,1231 **** // resolution is 320x240 so we can blit directly ! SDL_BlitSurface (SDL_Screen, NULL, SDL_Video, NULL); if (transition_amount != 255) --- 1249,1253 ---- // resolution is 320x240 so we can blit directly ! SDL_BlitSurface (SDL_Screen, &updated, SDL_Video, &updated); if (transition_amount != 255) Index: sdl_common.c =================================================================== RCS file: /cvsroot/sc2/sc2/src/sc2code/libs/graphics/sdl/sdl_common.c,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** sdl_common.c 30 Jan 2003 07:47:41 -0000 1.39 --- sdl_common.c 30 Jan 2003 21:24:51 -0000 1.40 *************** *** 28,31 **** --- 28,32 ---- #include "SDL_thread.h" #include "libs/graphics/drawcmd.h" + #include "bbox.h" SDL_Surface *SDL_Video; *************** *** 522,525 **** --- 523,529 ---- } + TFB_BBox_Reset (); + TFB_BBox_GetClipRect (SDL_Screens[0]); + done = FALSE; while (!done) *************** *** 561,566 **** case TFB_DRAWCOMMANDTYPE_IMAGE: { ! TFB_Image *DC_image = (TFB_Image *)DC.data.image.image; TFB_Palette *pal; if (DC.data.image.UsePalette) --- 565,577 ---- case TFB_DRAWCOMMANDTYPE_IMAGE: { ! TFB_Image *DC_image = DC.data.image.image; TFB_Palette *pal; + int x = DC.data.image.x; + int y = DC.data.image.y; + + if (DC.data.image.UseScaling) + TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y); + else + TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y); if (DC.data.image.UsePalette) *************** *** 573,577 **** } ! TFB_DrawCanvas_Image (DC_image, DC.data.image.x, DC.data.image.y, DC.data.image.UseScaling, pal, SDL_Screens[DC.data.image.destBuffer], --- 584,588 ---- } ! TFB_DrawCanvas_Image (DC_image, x, y, DC.data.image.UseScaling, pal, SDL_Screens[DC.data.image.destBuffer], *************** *** 582,585 **** --- 593,605 ---- case TFB_DRAWCOMMANDTYPE_FILLEDIMAGE: { + TFB_Image *DC_image = DC.data.filledimage.image; + int x = DC.data.filledimage.x; + int y = DC.data.filledimage.y; + + if (DC.data.filledimage.UseScaling) + TFB_BBox_RegisterCanvas (DC_image->ScaledImg, x, y); + else + TFB_BBox_RegisterCanvas (DC_image->NormalImg, x, y); + TFB_DrawCanvas_FilledImage (DC.data.filledimage.image, DC.data.filledimage.x, DC.data.filledimage.y, DC.data.filledimage.UseScaling, DC.data.filledimage.r, DC.data.filledimage.g, *************** *** 590,593 **** --- 610,615 ---- 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); TFB_DrawCanvas_Line (DC.data.line.x1, DC.data.line.y1, DC.data.line.x2, DC.data.line.y2, *************** *** 598,601 **** --- 620,624 ---- case TFB_DRAWCOMMANDTYPE_RECTANGLE: { + 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, *************** *** 607,615 **** { SDL_Rect r; ! r.x = DC.data.scissor.x; ! r.y = DC.data.scissor.y; ! r.w = DC.data.scissor.w; ! r.h = DC.data.scissor.h; ! SDL_SetClipRect(SDL_Screens[0], &r); break; --- 630,637 ---- { SDL_Rect r; ! r.x = TFB_BBox.clip.corner.x = DC.data.scissor.x; ! r.y = TFB_BBox.clip.corner.y = DC.data.scissor.y; ! r.w = TFB_BBox.clip.extent.width = DC.data.scissor.w; ! r.h = TFB_BBox.clip.extent.height = DC.data.scissor.h; SDL_SetClipRect(SDL_Screens[0], &r); break; *************** *** 617,625 **** case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE: SDL_SetClipRect(SDL_Screens[0], NULL); break; case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE: { SDL_Rect src, dest; ! TFB_Image *DC_image = (TFB_Image *)DC.data.copytoimage.image; if (DC_image == 0) --- 639,651 ---- case TFB_DRAWCOMMANDTYPE_SCISSORDISABLE: SDL_SetClipRect(SDL_Screens[0], NULL); + TFB_BBox.clip.corner.x = 0; + TFB_BBox.clip.corner.y = 0; + TFB_BBox.clip.extent.width = ScreenWidth; + TFB_BBox.clip.extent.height = ScreenHeight; break; case TFB_DRAWCOMMANDTYPE_COPYTOIMAGE: { SDL_Rect src, dest; ! TFB_Image *DC_image = DC.data.copytoimage.image; if (DC_image == 0) *************** *** 648,651 **** --- 674,681 ---- 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); + TFB_BlitSurface(SDL_Screens[DC.data.copy.srcBuffer], &src, SDL_Screens[DC.data.copy.destBuffer], &dest, DC.data.copy.BlendNumerator, DC.data.copy.BlendDenominator); |