[Scummvm-git-logs] scummvm master -> 2c0e9555deab7a5892e8e268e7959551fd29e456

sev- noreply at scummvm.org
Sat Feb 25 13:22:13 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
2c0e9555de GRAPHICS: Refactor Surface::copyFrom() & Surface::copyRectToSurface (#4727)


Commit: 2c0e9555deab7a5892e8e268e7959551fd29e456
    https://github.com/scummvm/scummvm/commit/2c0e9555deab7a5892e8e268e7959551fd29e456
Author: Miro Kropáček (miro.kropacek at gmail.com)
Date: 2023-02-25T14:22:08+01:00

Commit Message:
GRAPHICS: Refactor Surface::copyFrom() & Surface::copyRectToSurface (#4727)

GRAPHICS: Refactor Surface::copyFrom() & Surface::copyRectToSurface()

This change makes Surface::copyFrom() slightly slower but
Surface::copyRectToSurface() performs better for rectangles with the
same width as the surface.

And of course we avoid unnecessary code duplication.

Co-authored-by: Cameron Cawley <ccawley2011 at gmail.com>

Changed paths:
    graphics/surface.cpp


diff --git a/graphics/surface.cpp b/graphics/surface.cpp
index 7fcf5e51fc9..7f8c52d8d08 100644
--- a/graphics/surface.cpp
+++ b/graphics/surface.cpp
@@ -24,10 +24,10 @@
 #include "common/util.h"
 #include "common/rect.h"
 #include "common/textconsole.h"
+#include "graphics/blit.h"
 #include "graphics/palette.h"
 #include "graphics/primitives.h"
 #include "graphics/surface.h"
-#include "graphics/blit.h"
 #include "graphics/transform_tools.h"
 
 namespace Graphics {
@@ -95,17 +95,7 @@ void Surface::init(int16 width, int16 height, int16 newPitch, void *newPixels, c
 
 void Surface::copyFrom(const Surface &surf) {
 	create(surf.w, surf.h, surf.format);
-	if (surf.pitch == pitch) {
-		memcpy(pixels, surf.pixels, h * pitch);
-	} else {
-		const byte *src = (const byte *)surf.pixels;
-		byte *dst = (byte *)pixels;
-		for (int y = h; y > 0; --y) {
-			memcpy(dst, src, w * format.bytesPerPixel);
-			src += surf.pitch;
-			dst += pitch;
-		}
-	}
+	copyBlit((byte *)pixels, (const byte *)surf.pixels, pitch, surf.pitch, w, h, format.bytesPerPixel);
 }
 
 Surface Surface::getSubArea(const Common::Rect &area) {
@@ -176,11 +166,7 @@ void Surface::copyRectToSurface(const void *buffer, int srcPitch, int destX, int
 	// Copy buffer data to internal buffer
 	const byte *src = (const byte *)buffer;
 	byte *dst = (byte *)getBasePtr(destX, destY);
-	for (int i = 0; i < height; i++) {
-		memcpy(dst, src, width * format.bytesPerPixel);
-		src += srcPitch;
-		dst += pitch;
-	}
+	copyBlit(dst, src, pitch, srcPitch, width, height, format.bytesPerPixel);
 }
 
 void Surface::copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) {




More information about the Scummvm-git-logs mailing list