From 8bed92098b94ebe14dfd9d622585fbfc150a8757 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 9 Apr 2011 04:03:48 +0300 Subject: Improve SDL gui draw speed. --- src/graphics.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/graphics.h | 3 ++ 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index c1d96acdd..1e2fc0fb4 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -438,7 +438,8 @@ void Graphics::drawImagePattern2(GraphicsVertexes *vert, Image *img) std::list::iterator it; for (it = arr->begin(); it != arr->end(); ++it) - SDL_BlitSurface(img->mSDLSurface, &(*it)->src, mTarget, &(*it)->dst); + SDL_LowerBlit(img->mSDLSurface, &(*it)->src, mTarget, &(*it)->dst); +// SDL_BlitSurface(img->mSDLSurface, &(*it)->src, mTarget, &(*it)->dst); } bool Graphics::calcImageRect(GraphicsVertexes* vert, @@ -540,7 +541,11 @@ void Graphics::calcImagePattern(GraphicsVertexes* vert, srcRect.w = static_cast(dw); srcRect.h = static_cast(dh); - vert->pushSDL(srcRect, dstRect); + if (SDL_FakeUpperBlit(image->mSDLSurface, &srcRect, + mTarget, &dstRect) == 1) + { + vert->pushSDL(srcRect, dstRect); + } } } vert->incPtr(1); @@ -593,3 +598,101 @@ bool Graphics::calcWindow(GraphicsVertexes* vert, imgRect.grid[1], imgRect.grid[5], imgRect.grid[7], imgRect.grid[3], imgRect.grid[4]); } + +int Graphics::SDL_FakeUpperBlit (SDL_Surface *src, SDL_Rect *srcrect, + SDL_Surface *dst, SDL_Rect *dstrect) +{ + SDL_Rect fulldst; + int srcx, srcy, w, h; + + /* Make sure the surfaces aren't locked */ + if (!src || !dst) + return(-1); + + if (src->locked || dst->locked) + return(-1); + + /* If the destination rectangle is NULL, use the entire dest surface */ + if (dstrect == NULL) + { + fulldst.x = fulldst.y = 0; + dstrect = &fulldst; + } + + /* clip the source rectangle to the source surface */ + if(srcrect) + { + int maxw, maxh; + + srcx = srcrect->x; + w = srcrect->w; + if (srcx < 0) + { + w += srcx; + dstrect->x -= srcx; + srcx = 0; + } + maxw = src->w - srcx; + if (maxw < w) + w = maxw; + + srcy = srcrect->y; + h = srcrect->h; + if (srcy < 0) + { + h += srcy; + dstrect->y -= srcy; + srcy = 0; + } + maxh = src->h - srcy; + if (maxh < h) + h = maxh; + } + else + { + srcx = srcy = 0; + w = src->w; + h = src->h; + } + + /* clip the destination rectangle against the clip rectangle */ + { + SDL_Rect *clip = &dst->clip_rect; + int dx, dy; + + dx = clip->x - dstrect->x; + if(dx > 0) + { + w -= dx; + dstrect->x += dx; + srcx += dx; + } + dx = dstrect->x + w - clip->x - clip->w; + if(dx > 0) + w -= dx; + + dy = clip->y - dstrect->y; + if(dy > 0) + { + h -= dy; + dstrect->y += dy; + srcy += dy; + } + dy = dstrect->y + h - clip->y - clip->h; + if(dy > 0) + h -= dy; + } + + if(w > 0 && h > 0) + { + srcrect->x = srcx; + srcrect->y = srcy; + srcrect->w = dstrect->w = w; + srcrect->h = dstrect->h = h; + + return 1; +// return SDL_LowerBlit(src, &sr, dst, dstrect); + } + dstrect->w = dstrect->h = 0; + return 0; +} diff --git a/src/graphics.h b/src/graphics.h index 817249c60..c1d5aa501 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -256,6 +256,9 @@ class Graphics : public gcn::SDLGraphics { return mClipStack.top(); } protected: + int SDL_FakeUpperBlit (SDL_Surface *src, SDL_Rect *srcrect, + SDL_Surface *dst, SDL_Rect *dstrect); + int mWidth; int mHeight; int mBpp; -- cgit v1.2.3-70-g09d2