From ff7267d04424c9d438e2e1814a6dfc8dddee9cff Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Tue, 3 Jul 2018 20:54:05 +0200 Subject: [PATCH] try to use a single memcpy if possible - adds stretching support (not used in C&C games though) --- ddraw.rc | 2 +- src/surface.c | 66 ++++++++++++++++++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/ddraw.rc b/ddraw.rc index f2c85fb..e09f1eb 100644 --- a/ddraw.rc +++ b/ddraw.rc @@ -2,7 +2,7 @@ #define vxstr(a,b,c,d) str(a##.##b##.##c##.##d) #define str(s) #s -#define VERSION 1,1,7,3 +#define VERSION 1,1,7,4 1 VERSIONINFO FILEVERSION VERSION diff --git a/src/surface.c b/src/surface.c index 2a65289..2600fbb 100644 --- a/src/surface.c +++ b/src/surface.c @@ -104,29 +104,51 @@ HRESULT __stdcall ddraw_surface_Blt(IDirectDrawSurfaceImpl *This, LPRECT lpDestR if(Source) { - int dx=0,dy=0; - if (lpDestRect) - { - dx=lpDestRect->left; - dy=lpDestRect->top; - } - int x0=0,y0=0,x1=Source->width,y1=Source->height; - if (lpSrcRect) - { - x0 = max(x0, lpSrcRect->left); - x1 = min(x1, lpSrcRect->right); - y0 = max(y0, lpSrcRect->top); - y1 = min(y1, lpSrcRect->bottom); - } - unsigned char* to = (unsigned char *)This->surface + dy*This->width + dx; - unsigned char* from = (unsigned char *)Source->surface + y0*Source->width + x0; - int s = x1-x0; + //BitBlt(This->hDC, lpDestRect->left, lpDestRect->top, lpDestRect->right, lpDestRect->bottom, + // Source->hDC, lpSrcRect->left, lpSrcRect->top, SRCCOPY); + + int dst_w = lpDestRect->right - lpDestRect->left; + int dst_h = lpDestRect->bottom - lpDestRect->top; + int src_w = lpSrcRect->right - lpSrcRect->left; + int src_h = lpSrcRect->bottom - lpSrcRect->top; + + if (dst_w != src_w || dst_h != src_h) + { + StretchBlt(This->hDC, lpDestRect->left, lpDestRect->top, lpDestRect->right, lpDestRect->bottom, + Source->hDC, lpSrcRect->left, lpSrcRect->top, lpSrcRect->right, lpSrcRect->bottom, SRCCOPY); + } + else if (dst_w == This->width && dst_h == This->height && + src_w == Source->width && src_h == Source->height) + { + memcpy(This->surface, Source->surface, This->width * This->height * This->lXPitch); + } + else + { + int dx=0,dy=0; + if (lpDestRect) + { + dx=lpDestRect->left; + dy=lpDestRect->top; + } + int x0=0,y0=0,x1=Source->width,y1=Source->height; + if (lpSrcRect) + { + x0 = max(x0, lpSrcRect->left); + x1 = min(x1, lpSrcRect->right); + y0 = max(y0, lpSrcRect->top); + y1 = min(y1, lpSrcRect->bottom); + } + unsigned char* to = (unsigned char *)This->surface + dy*This->width + dx; + unsigned char* from = (unsigned char *)Source->surface + y0*Source->width + x0; + int s = x1-x0; + + int y; + for(y=y0; ywidth, from+=Source->width) + { + memcpy(to, from, s); + } + } - int y; - for(y=y0; ywidth, from+=Source->width) - { - memcpy(to, from, s); - } } if(This->caps & DDSCAPS_PRIMARYSURFACE && !(This->flags & DDSD_BACKBUFFERCOUNT) && ddraw->render.run)