[Scummvm-git-logs] scummvm master -> 116a2f89417feaa338d41e7434477073c9c0ad0a

dreammaster dreammaster at scummvm.org
Mon Jul 12 05:13:18 UTC 2021


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:
116a2f8941 AGS: Further improve rendering with a screen dirty rect area


Commit: 116a2f89417feaa338d41e7434477073c9c0ad0a
    https://github.com/scummvm/scummvm/commit/116a2f89417feaa338d41e7434477073c9c0ad0a
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-07-11T22:12:09-07:00

Commit Message:
AGS: Further improve rendering with a screen dirty rect area

When the screen format doesn't match the virtual screen, rather than
blitting the entire surface each frame, keep track of the largest
bounds of pixels that have been changed when writing to the temporary
intermediate screen, and only blit the resulting area.

Long term, though, it would be interesting to review to see if the
batch system the graphics driver uses for rendering can be used to
determine a list of rects in the screen that are affected. If so,
hopefully those can be used instead.

Changed paths:
    engines/ags/engine/gfx/ali_3d_scummvm.cpp
    engines/ags/engine/gfx/ali_3d_scummvm.h


diff --git a/engines/ags/engine/gfx/ali_3d_scummvm.cpp b/engines/ags/engine/gfx/ali_3d_scummvm.cpp
index 79d9b27db6..2030bad923 100644
--- a/engines/ags/engine/gfx/ali_3d_scummvm.cpp
+++ b/engines/ags/engine/gfx/ali_3d_scummvm.cpp
@@ -371,12 +371,41 @@ void ScummVMRendererGraphicsDriver::RenderSpriteBatch(const ALSpriteBatch &batch
 	}
 }
 
+void ScummVMRendererGraphicsDriver::copySurface(const Graphics::Surface &src, bool mode) {
+	assert(src.w == _screen->w && src.h == _screen->h && src.pitch == _screen->pitch);
+	const uint32 *srcP = (const uint32 *)src.getPixels();
+	uint32 *destP = (uint32 *)_screen->getPixels();
+	uint32 pixel;
+	int x1 = 9999, y1 = 9999, x2 = -1, y2 = -1;
+
+	for (int y = 0; y < src.h; ++y) {
+		for (int x = 0; x < src.w; ++x, ++srcP, ++destP) {
+			if (!mode) {
+				pixel = (*srcP & 0xff00ff00) |
+					((*srcP & 0xff) << 16) |
+					((*srcP >> 16) & 0xff);
+			} else {
+				pixel = ((*srcP & 0xffffff) << 8) |
+					((*srcP >> 24) & 0xff);
+			}
+
+			if (*destP != pixel) {
+				*destP = pixel;
+				x1 = MIN(x1, x);
+				y1 = MIN(y1, y);
+				x2 = MAX(x2, x);
+				y2 = MAX(y2, y);
+			}
+		}
+	}
+
+	if (x2 != -1)
+		_screen->addDirtyRect(Common::Rect(x1, y1, x2 + 1, y2 + 1));
+}
+
 void ScummVMRendererGraphicsDriver::BlitToScreen() {
 	const Graphics::Surface &src =
 		virtualScreen->GetAllegroBitmap()->getSurface();
-	int i;
-	const uint32 *srcP;
-	uint32 *destP;
 
 	enum {
 		kRenderInitial, kRenderDirect, kRenderToABGR, kRenderToRGBA,
@@ -408,25 +437,12 @@ void ScummVMRendererGraphicsDriver::BlitToScreen() {
 	switch (renderMode) {
 	case kRenderToABGR:
 		// ARGB to ABGR
-		assert(src.w == _screen->w && src.h == _screen->h);
-		srcP = (const uint32 *)src.getPixels();
-		destP = (uint32 *)_screen->getPixels();
-		for (i = 0; i < src.w * src.h; ++i, ++srcP, ++destP) {
-			*destP = (*srcP & 0xff00ff00) |
-				((*srcP & 0xff) << 16) |
-				((*srcP >> 16) & 0xff);
-		}
+		copySurface(src, false);
 		break;
 
 	case kRenderToRGBA:
 		// ARGB to RGBA
-		assert(src.w == _screen->w && src.h == _screen->h);
-		srcP = (const uint32 *)src.getPixels();
-		destP = (uint32 *)_screen->getPixels();
-		for (i = 0; i < src.w * src.h; ++i, ++srcP, ++destP) {
-			*destP = ((*srcP & 0xffffff) << 8) |
-				((*srcP >> 24) & 0xff);
-		}
+		copySurface(src, true);
 		break;
 
 	case kRenderOther: {
@@ -450,10 +466,8 @@ void ScummVMRendererGraphicsDriver::BlitToScreen() {
 		break;
 	}
 
-	if (_screen) {
-		_screen->addDirtyRect(Common::Rect(0, 0, src.w, src.h));
+	if (_screen)
 		_screen->update();
-	}
 }
 
 void ScummVMRendererGraphicsDriver::Render(int /*xoff*/, int /*yoff*/, GlobalFlipType flip) {
diff --git a/engines/ags/engine/gfx/ali_3d_scummvm.h b/engines/ags/engine/gfx/ali_3d_scummvm.h
index ab988382bb..8a5200668f 100644
--- a/engines/ags/engine/gfx/ali_3d_scummvm.h
+++ b/engines/ags/engine/gfx/ali_3d_scummvm.h
@@ -280,6 +280,7 @@ private:
 	void __fade_out_range(int speed, int from, int to, int targetColourRed, int targetColourGreen, int targetColourBlue);
 	// Copy raw screen bitmap pixels to the screen
 	void BlitToScreen();
+	void copySurface(const Graphics::Surface &src, bool mode);
 	// Render bitmap on screen
 	void Present() { BlitToScreen(); }
 };




More information about the Scummvm-git-logs mailing list