summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-04-09 04:03:48 +0300
committerAndrei Karas <akaras@inbox.ru>2011-04-09 04:03:48 +0300
commit8bed92098b94ebe14dfd9d622585fbfc150a8757 (patch)
tree2211bd2c0c6db311915b5181dcc77cfee5fdc3cb /src
parent3968453eb82521f6ab3966ff1dc08cd0c803d359 (diff)
downloadmanaplus-8bed92098b94ebe14dfd9d622585fbfc150a8757.tar.gz
manaplus-8bed92098b94ebe14dfd9d622585fbfc150a8757.tar.bz2
manaplus-8bed92098b94ebe14dfd9d622585fbfc150a8757.tar.xz
manaplus-8bed92098b94ebe14dfd9d622585fbfc150a8757.zip
Improve SDL gui draw speed.
Diffstat (limited to 'src')
-rw-r--r--src/graphics.cpp107
-rw-r--r--src/graphics.h3
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<DoubleRect*>::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<Uint16>(dw);
srcRect.h = static_cast<Uint16>(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;