[Scummvm-git-logs] scummvm master -> 1cffb9c86ad56379d08acdd6231824187684eb68

sev- noreply at scummvm.org
Mon Jun 26 12:25:34 UTC 2023


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

Summary:
c04313ba9f ANDROID: Fix overlay background capture
75b3be75b3 ANDROID: Don't improve score when bits is not enough
14d57b2b61 ANDROID: Don't use a framebuffer when it's not needed
560793e571 ANDROID: Don't warp mouse when showing overlay in game
bc438d078a ANDROID: When resizing don't reset everything
33b09af3b2 ANDROID: Allow screen rotation
7af3a4571e ANDROID: Allow resizable activities
8e731782cc ANDROID: Fix ifdef
79da015e8f ANDROID: Various fixes to textures
1cffb9c86a ANDROID: Don't make GL calls when there is not context


Commit: c04313ba9f0e5c220ad81d35f6eda0c29d270157
    https://github.com/scummvm/scummvm/commit/c04313ba9f0e5c220ad81d35f6eda0c29d270157
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Fix overlay background capture

In GLES2, only RGBA8888 support is guaranteed.
Texture needs to be recreated on GPU before use and is already flipped.

Changed paths:
    backends/graphics3d/android/android-graphics3d.cpp


diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index a48630a7f91..7d777c47b20 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -106,7 +106,7 @@ AndroidGraphics3dManager::AndroidGraphics3dManager() :
 		// If not 16, this must be 24 or 32 bpp so make use of them
 		_game_texture = new GLES888Texture();
 		_overlay_texture = new GLES8888Texture();
-		_overlay_background = new GLES888Texture();
+		_overlay_background = new GLES8888Texture();
 		_mouse_texture_palette = new GLESFakePalette8888Texture();
 	}
 	_mouse_texture = _mouse_texture_palette;
@@ -526,10 +526,12 @@ void AndroidGraphics3dManager::showOverlay(bool inGUI) {
 			}
 
 			GLCALL(glViewport(0, 0, JNI::egl_surface_width, JNI::egl_surface_height));
+			_overlay_background->reinit();
 			_overlay_background->allocBuffer(_overlay_texture->width(), _overlay_texture->height());
 			_overlay_background->setDrawRect(0, 0,
 			                                 JNI::egl_surface_width, JNI::egl_surface_height);
 			_overlay_background->readPixels();
+			_overlay_background->setGameTexture();
 
 			// Restore game viewport
 			GLCALL(glViewport(savedViewport[0], savedViewport[1], savedViewport[2], savedViewport[3]));


Commit: 75b3be75b37825b65abb5f5a91ce92a3fb7c9f5d
    https://github.com/scummvm/scummvm/commit/75b3be75b37825b65abb5f5a91ce92a3fb7c9f5d
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Don't improve score when bits is not enough

Changed paths:
    backends/platform/android/org/scummvm/scummvm/ScummVM.java


diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
index d166fd7ba22..6bd5b1f0c5a 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
@@ -413,7 +413,8 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
 				score += 10;
 
 			// penalize for wasted bits
-			score -= value - size;
+			if (value > size)
+				score -= value - size;
 
 			return score;
 		}


Commit: 14d57b2b6146ea13c104ea8d11d50482d24e5705
    https://github.com/scummvm/scummvm/commit/14d57b2b6146ea13c104ea8d11d50482d24e5705
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Don't use a framebuffer when it's not needed

This also fixes a bug in frame buffer placement in vertical aspect ratio

Changed paths:
    backends/graphics3d/android/android-graphics3d.cpp
    backends/platform/android/org/scummvm/scummvm/ScummVM.java


diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index 7d777c47b20..219744c9c94 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -315,17 +315,22 @@ void AndroidGraphics3dManager::updateScreen() {
 	CONTEXT_SET_DISABLE(GL_SCISSOR_TEST);
 	CONTEXT_SET_DISABLE(GL_STENCIL_TEST);
 
-	glViewport(0, 0, JNI::egl_surface_width, JNI::egl_surface_height);
+	GLCALL(glViewport(0, 0, JNI::egl_surface_width, JNI::egl_surface_height));
 
-	// clear pointer leftovers in dead areas
-	clearScreen(kClear);
+	if (_frame_buffer) {
+		// clear pointer leftovers in dead areas
+		clearScreen(kClear);
 
-	_game_texture->drawTextureRect();
+		_game_texture->drawTextureRect();
+	}
 
 	if (_show_overlay) {
 		// If the overlay is in game we expect the game to continue drawing
-		if (_overlay_in_gui && _overlay_background && _overlay_background->getTextureName() != 0) {
-			GLCALL(_overlay_background->drawTextureRect());
+		if (_overlay_in_gui) {
+			clearScreen(kClear);
+			if (_overlay_background && _overlay_background->getTextureName() != 0) {
+				GLCALL(_overlay_background->drawTextureRect());
+			}
 		}
 		GLCALL(_overlay_texture->drawTextureRect());
 
@@ -616,11 +621,17 @@ Graphics::PixelFormat AndroidGraphics3dManager::getOverlayFormat() const {
 }
 
 int16 AndroidGraphics3dManager::getHeight() const {
-	return _game_texture->height();
+	if (_frame_buffer)
+		return _frame_buffer->getHeight();
+	else
+		return _overlay_texture->height();
 }
 
 int16 AndroidGraphics3dManager::getWidth() const {
-	return _game_texture->width();
+	if (_frame_buffer)
+		return _frame_buffer->getWidth();
+	else
+		return _overlay_texture->width();
 }
 
 void AndroidGraphics3dManager::setPalette(const byte *colors, uint start, uint num) {
@@ -674,12 +685,16 @@ void AndroidGraphics3dManager::initSize(uint width, uint height,
 	GLTHREADCHECK;
 
 	_game_texture->allocBuffer(width, height);
+	_game_texture->setGameTexture();
 
 	delete _frame_buffer;
-	_frame_buffer = new OpenGL::FrameBuffer(_game_texture->getTextureName(),
-	                                        _game_texture->width(), _game_texture->height(),
-	                                        _game_texture->texWidth(), _game_texture->texHeight());
-	_frame_buffer->attach();
+
+	if (!engineSupportsArbitraryResolutions) {
+		_frame_buffer = new OpenGL::FrameBuffer(_game_texture->getTextureName(),
+		                                        _game_texture->width(), _game_texture->height(),
+		                                        _game_texture->texWidth(), _game_texture->texHeight());
+		_frame_buffer->attach();
+	}
 
 	// Don't know mouse size yet - it gets reallocated in
 	// setMouseCursor.  We need the palette allocated before
@@ -690,8 +705,6 @@ void AndroidGraphics3dManager::initSize(uint width, uint height,
 	updateScreenRect();
 
 	clearScreen(kClear);
-
-	_game_texture->setGameTexture();
 }
 
 int AndroidGraphics3dManager::getScreenChangeID() const {
@@ -743,8 +756,8 @@ void AndroidGraphics3dManager::updateCursorScaling() {
 
 	// In case scaling is actually enabled we will scale the cursor according
 	// to the game screen.
-	uint16 w = _game_texture->width();
-	uint16 h = _game_texture->height();
+	uint16 w = getWidth();
+	uint16 h = getHeight();
 
 	if (!_mouse_dont_scale && w && h) {
 		const frac_t screen_scale_factor_x = intToFrac(_game_texture->getDrawRect().width()) / w;
@@ -906,8 +919,8 @@ void AndroidGraphics3dManager::updateScreenRect() {
 	// Clear the overlay background so it is not displayed distorted while resizing
 	_overlay_background->release();
 
-	uint16 w = _game_texture->width();
-	uint16 h = _game_texture->height();
+	uint16 w = getWidth();
+	uint16 h = getHeight();
 
 	if (w && h && _ar_correction) {
 
@@ -930,7 +943,7 @@ void AndroidGraphics3dManager::updateScreenRect() {
 			rect.moveTo((JNI::egl_surface_width - rect.width()) / 2, 0);
 		} else {
 			rect.setHeight(round(JNI::egl_surface_width / game_ar));
-			rect.moveTo((JNI::egl_surface_height - rect.height()) / 2, 0);
+			rect.moveTo(0, (JNI::egl_surface_height - rect.height()) / 2);
 		}
 	}
 
@@ -940,7 +953,7 @@ void AndroidGraphics3dManager::updateScreenRect() {
 }
 
 const GLESBaseTexture *AndroidGraphics3dManager::getActiveTexture() const {
-	if (_show_overlay) {
+	if (!_frame_buffer || _show_overlay) {
 		return _overlay_texture;
 	} else {
 		return _game_texture;
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
index 6bd5b1f0c5a..cba72338059 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
@@ -438,8 +438,9 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
 			score += weightBits(EGL10.EGL_GREEN_SIZE, 6);
 			score += weightBits(EGL10.EGL_BLUE_SIZE, 5);
 			score += weightBits(EGL10.EGL_ALPHA_SIZE, 0);
-			score += weightBits(EGL10.EGL_DEPTH_SIZE, 0);
-			score += weightBits(EGL10.EGL_STENCIL_SIZE, 0);
+			// Prefer 24 bits depth
+			score += weightBits(EGL10.EGL_DEPTH_SIZE, 24);
+			score += weightBits(EGL10.EGL_STENCIL_SIZE, 8);
 
 			return score;
 		}
@@ -537,6 +538,10 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
 				if (attr.get(EGL10.EGL_BUFFER_SIZE) < bitsPerPixel)
 					good = false;
 
+				// Force a config with a depth buffer and a stencil buffer when rendering directly on backbuffer
+				if ((attr.get(EGL10.EGL_DEPTH_SIZE) == 0) || (attr.get(EGL10.EGL_STENCIL_SIZE) == 0))
+					good = false;
+
 				int score = attr.weight();
 
 				Log.d(LOG_TAG, String.format(Locale.ROOT, "%s (%d, %s)", attr.toString(), score, good ? "OK" : "NOK"));


Commit: 560793e571571cbe1e89a2b8bb6d2ffbe66dcf64
    https://github.com/scummvm/scummvm/commit/560793e571571cbe1e89a2b8bb6d2ffbe66dcf64
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Don't warp mouse when showing overlay in game

Changed paths:
    backends/graphics3d/android/android-graphics3d.cpp


diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index 219744c9c94..57c8e893f48 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -547,7 +547,9 @@ void AndroidGraphics3dManager::showOverlay(bool inGUI) {
 		}
 	}
 
-	warpMouse(_overlay_texture->width() / 2, _overlay_texture->height() / 2);
+	if (inGUI) {
+		warpMouse(_overlay_texture->width() / 2, _overlay_texture->height() / 2);
+	}
 }
 
 void AndroidGraphics3dManager::hideOverlay() {


Commit: bc438d078af300f735692a9bcbd3538de05d3375
    https://github.com/scummvm/scummvm/commit/bc438d078af300f735692a9bcbd3538de05d3375
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: When resizing don't reset everything

Only reinitialize the needed bits.
EGLSurface needs to be reset to take the new size into account.
GLSurfaceView in AOSP does the same thing.

Changed paths:
    backends/graphics/android/android-graphics.cpp
    backends/graphics/android/android-graphics.h
    backends/graphics3d/android/android-graphics3d.cpp
    backends/graphics3d/android/android-graphics3d.h
    backends/platform/android/events.cpp


diff --git a/backends/graphics/android/android-graphics.cpp b/backends/graphics/android/android-graphics.cpp
index ebdf4f3b858..2803eb44ed3 100644
--- a/backends/graphics/android/android-graphics.cpp
+++ b/backends/graphics/android/android-graphics.cpp
@@ -138,6 +138,25 @@ void AndroidGraphicsManager::deinitSurface() {
 	JNI::deinitSurface();
 }
 
+void AndroidGraphicsManager::resizeSurface() {
+
+	// If we had lost surface just init it again
+	if (!JNI::haveSurface()) {
+		initSurface();
+		return;
+	}
+
+	// Recreate the EGL surface, context is preserved
+	JNI::deinitSurface();
+	JNI::initSurface();
+
+	dynamic_cast<OSystem_Android *>(g_system)->getTouchControls().init(
+	    this, JNI::egl_surface_width, JNI::egl_surface_height);
+
+	handleResize(JNI::egl_surface_width, JNI::egl_surface_height);
+}
+
+
 void AndroidGraphicsManager::updateScreen() {
 	//ENTER();
 
diff --git a/backends/graphics/android/android-graphics.h b/backends/graphics/android/android-graphics.h
index 4c084731076..2043e5e6353 100644
--- a/backends/graphics/android/android-graphics.h
+++ b/backends/graphics/android/android-graphics.h
@@ -33,6 +33,7 @@ public:
 
 	virtual void initSurface() = 0;
 	virtual void deinitSurface() = 0;
+	virtual void resizeSurface() = 0;
 
 	virtual Common::Point getMousePosition() = 0;
 	virtual bool notifyMousePosition(Common::Point &mouse) = 0;
@@ -71,6 +72,7 @@ public:
 
 	virtual void initSurface() override;
 	virtual void deinitSurface() override;
+	virtual void resizeSurface() override;
 
 	virtual AndroidCommonGraphics::State getState() const override;
 	virtual bool setState(const AndroidCommonGraphics::State &state) override;
diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index 57c8e893f48..2e4ea44e100 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -250,6 +250,31 @@ void AndroidGraphics3dManager::deinitSurface() {
 	JNI::deinitSurface();
 }
 
+void AndroidGraphics3dManager::resizeSurface() {
+	LOGD("resizing 3D surface");
+
+	if (!JNI::haveSurface()) {
+		initSurface();
+		return;
+	}
+
+	JNI::deinitSurface();
+	JNI::initSurface();
+
+	_screenChangeID = JNI::surface_changeid;
+
+	if (_overlay_texture) {
+		initOverlay();
+	}
+
+	dynamic_cast<OSystem_Android *>(g_system)->getTouchControls().init(
+	    this, JNI::egl_surface_width, JNI::egl_surface_height);
+
+	updateScreenRect();
+	// double buffered, flip twice
+	clearScreen(kClearUpdate, 2);
+}
+
 void AndroidGraphics3dManager::updateScreen() {
 	//ENTER();
 
diff --git a/backends/graphics3d/android/android-graphics3d.h b/backends/graphics3d/android/android-graphics3d.h
index 37241e1df2a..a5cd2741c06 100644
--- a/backends/graphics3d/android/android-graphics3d.h
+++ b/backends/graphics3d/android/android-graphics3d.h
@@ -39,6 +39,7 @@ public:
 
 	virtual void initSurface() override;
 	virtual void deinitSurface() override;
+	virtual void resizeSurface() override;
 
 	virtual AndroidCommonGraphics::State getState() const override;
 	virtual bool setState(const AndroidCommonGraphics::State &state) override;
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 38079a61537..23309197fd4 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -1420,8 +1420,7 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
 
 			if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) {
 				// surface changed
-				dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->deinitSurface();
-				dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->initSurface();
+				dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->resizeSurface();
 
 				event.type = Common::EVENT_SCREEN_CHANGED;
 


Commit: 33b09af3b2fcc93c43350e22a5f1c0f97cbf15c0
    https://github.com/scummvm/scummvm/commit/33b09af3b2fcc93c43350e22a5f1c0f97cbf15c0
Author: Cameron Cawley (ccawley2011 at gmail.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Allow screen rotation

Changed paths:
    backends/platform/android/org/scummvm/scummvm/ScummVM.java
    dists/android/AndroidManifest.xml


diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
index cba72338059..15ec35218cf 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
@@ -109,13 +109,6 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
 	// SurfaceHolder callback
 	final public void surfaceChanged(SurfaceHolder holder, int format,
 										int width, int height) {
-		// the orientation may reset on standby mode and the theme manager
-		// could assert when using a portrait resolution. so lets not do that.
-		if (height > width) {
-			Log.d(LOG_TAG, String.format(Locale.ROOT, "Ignoring surfaceChanged: %dx%d (%d)",
-											width, height, format));
-			return;
-		}
 
 		PixelFormat pixelFormat = new PixelFormat();
 		PixelFormat.getPixelFormatInfo(format, pixelFormat);
diff --git a/dists/android/AndroidManifest.xml b/dists/android/AndroidManifest.xml
index df8683f6233..8927ef8234e 100644
--- a/dists/android/AndroidManifest.xml
+++ b/dists/android/AndroidManifest.xml
@@ -17,9 +17,6 @@
 	<uses-feature
 		android:name="android.hardware.wifi"
 		android:required="false" />
-	<uses-feature
-		android:name="android.hardware.screen.landscape"
-		android:required="false" />
 	<uses-feature
 		android:name="android.hardware.touchscreen"
 		android:required="false" />
@@ -50,7 +47,6 @@
 			android:exported="true"
 			android:banner="@drawable/leanback_icon"
 			android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
-			android:screenOrientation="landscape"
 			android:theme="@style/SplashTheme"
 			android:windowSoftInputMode="adjustResize">
 			<intent-filter>
@@ -67,7 +63,6 @@
 			android:banner="@drawable/leanback_icon"
 			android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
 			android:launchMode="singleInstance"
-			android:screenOrientation="landscape"
 			android:theme="@style/AppTheme"
 			android:windowSoftInputMode="adjustResize">
 		</activity>


Commit: 7af3a4571eb3d2c2e71328e63d775ed3613605bc
    https://github.com/scummvm/scummvm/commit/7af3a4571eb3d2c2e71328e63d775ed3613605bc
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Allow resizable activities

Changed paths:
    dists/android/AndroidManifest.xml


diff --git a/dists/android/AndroidManifest.xml b/dists/android/AndroidManifest.xml
index 8927ef8234e..f2085c01b0b 100644
--- a/dists/android/AndroidManifest.xml
+++ b/dists/android/AndroidManifest.xml
@@ -46,7 +46,8 @@
 			android:name=".SplashActivity"
 			android:exported="true"
 			android:banner="@drawable/leanback_icon"
-			android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
+			android:configChanges="orientation|keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
+			android:resizeableActivity="true"
 			android:theme="@style/SplashTheme"
 			android:windowSoftInputMode="adjustResize">
 			<intent-filter>
@@ -61,7 +62,8 @@
 			android:name=".ScummVMActivity"
 			android:exported="false"
 			android:banner="@drawable/leanback_icon"
-			android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
+			android:configChanges="orientation|keyboard|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
+			android:resizeableActivity="true"
 			android:launchMode="singleInstance"
 			android:theme="@style/AppTheme"
 			android:windowSoftInputMode="adjustResize">


Commit: 8e731782cc301ce75d355fcc9144a73f880e18f1
    https://github.com/scummvm/scummvm/commit/8e731782cc301ce75d355fcc9144a73f880e18f1
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Fix ifdef

isRunningInMainThread is used by GLTHREADCHECK when ANDROID_DEBUG_GL is
defined

Changed paths:
    backends/platform/android/android.h


diff --git a/backends/platform/android/android.h b/backends/platform/android/android.h
index d7ea089e9b3..99308fe1f26 100644
--- a/backends/platform/android/android.h
+++ b/backends/platform/android/android.h
@@ -223,7 +223,7 @@ public:
 	void *getOpenGLProcAddress(const char *name) const override;
 #endif
 
-#ifdef ANDROID_DEBUG_GL_CALLS
+#ifdef ANDROID_DEBUG_GL
 	bool isRunningInMainThread() { return pthread_self() == _main_thread; }
 #endif
 


Commit: 79da015e8ffbc155d04ec95eca3504ca0dd4dfba
    https://github.com/scummvm/scummvm/commit/79da015e8ffbc155d04ec95eca3504ca0dd4dfba
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Various fixes to textures

- Don't create texture in constructor: it's called before the context is
  created
- Don't leak texture names when calling reinit()
- Fix allocBuffer return condition
- Don't call GL if there is no texture object
- Make sure all textures are released and inited

Changed paths:
    backends/graphics3d/android/android-graphics3d.cpp
    backends/graphics3d/android/texture.cpp


diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index 2e4ea44e100..739b88bd47e 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -202,6 +202,10 @@ void AndroidGraphics3dManager::initSurface() {
 		_mouse_texture->reinit();
 	}
 
+	if (_mouse_texture_palette && _mouse_texture != _mouse_texture_palette) {
+		_mouse_texture_palette->reinit();
+	}
+
 	if (_touchcontrols_texture) {
 		_touchcontrols_texture->reinit();
 	}
@@ -239,6 +243,10 @@ void AndroidGraphics3dManager::deinitSurface() {
 		_mouse_texture->release();
 	}
 
+	if (_mouse_texture_palette && _mouse_texture != _mouse_texture_palette) {
+		_mouse_texture_palette->release();
+	}
+
 	dynamic_cast<OSystem_Android *>(g_system)->getTouchControls().init(
 	    nullptr, 0, 0);
 	if (_touchcontrols_texture) {
@@ -823,6 +831,7 @@ void AndroidGraphics3dManager::setMouseCursor(const void *buf, uint w, uint h,
 				_mouse_texture_rgb = new GLES8888Texture();
 			}
 			_mouse_texture_rgb->setLinearFilter(_graphicsMode == 1);
+			_mouse_texture_rgb->reinit();
 		}
 
 		_mouse_texture = _mouse_texture_rgb;
diff --git a/backends/graphics3d/android/texture.cpp b/backends/graphics3d/android/texture.cpp
index 7ae71ac930e..c1243978525 100644
--- a/backends/graphics3d/android/texture.cpp
+++ b/backends/graphics3d/android/texture.cpp
@@ -141,7 +141,6 @@ GLESBaseTexture::GLESBaseTexture(GLenum glFormat, GLenum glType,
 	_pixelFormat(pixelFormat),
 	_palettePixelFormat(),
 	_is_game_texture(false) {
-	GLCALL(glGenTextures(1, &_texture_name));
 }
 
 GLESBaseTexture::~GLESBaseTexture() {
@@ -156,6 +155,10 @@ void GLESBaseTexture::release() {
 }
 
 void GLESBaseTexture::reinit() {
+	if (_texture_name) {
+		release();
+	}
+
 	GLCALL(glGenTextures(1, &_texture_name));
 
 	initSize();
@@ -164,6 +167,10 @@ void GLESBaseTexture::reinit() {
 }
 
 void GLESBaseTexture::initSize() {
+	if (!_texture_name) {
+		return;
+	}
+
 	// Allocate room for the texture now, but pixel data gets uploaded
 	// later (perhaps with multiple TexSubImage2D operations).
 	GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
@@ -184,6 +191,10 @@ void GLESBaseTexture::setLinearFilter(bool value) {
 		_glFilter = GL_NEAREST;
 	}
 
+	if (!_texture_name) {
+		return;
+	}
+
 	GLCALL(glBindTexture(GL_TEXTURE_2D, _texture_name));
 
 	GLCALL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _glFilter));
@@ -191,14 +202,14 @@ void GLESBaseTexture::setLinearFilter(bool value) {
 }
 
 void GLESBaseTexture::allocBuffer(GLuint w, GLuint h) {
+	if (w == _surface.w && h == _surface.h) {
+		return;
+	}
+
 	_surface.w = w;
 	_surface.h = h;
 	_surface.format = _pixelFormat;
 
-	if (w == _texture_width && h == _texture_height) {
-		return;
-	}
-
 	if (_npot_supported) {
 		_texture_width = _surface.w;
 		_texture_height = _surface.h;
@@ -212,6 +223,10 @@ void GLESBaseTexture::allocBuffer(GLuint w, GLuint h) {
 
 void GLESBaseTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h,
                                   const Common::Rect &clip) {
+	if (!_texture_name) {
+		return;
+	}
+
 	if (_all_dirty) {
 		_dirty_rect.top = 0;
 		_dirty_rect.left = 0;
@@ -230,7 +245,7 @@ void GLESBaseTexture::drawTexture(GLshort x, GLshort y, GLshort w, GLshort h,
 		GLCALL(glTexSubImage2D(GL_TEXTURE_2D, 0,
 		                       _dirty_rect.left, _dirty_rect.top,
 		                       _dirty_rect.width(), _dirty_rect.height(),
-				       _glFormat, _glType, tex));
+		                       _glFormat, _glType, tex));
 	}
 
 


Commit: 1cffb9c86ad56379d08acdd6231824187684eb68
    https://github.com/scummvm/scummvm/commit/1cffb9c86ad56379d08acdd6231824187684eb68
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-06-26T15:25:27+03:00

Commit Message:
ANDROID: Don't make GL calls when there is not context

This is forbidden by EGL specification

Changed paths:
    backends/graphics3d/android/android-graphics3d.cpp
    backends/platform/android/android.cpp
    backends/platform/android/events.cpp
    backends/platform/android/org/scummvm/scummvm/ScummVM.java


diff --git a/backends/graphics3d/android/android-graphics3d.cpp b/backends/graphics3d/android/android-graphics3d.cpp
index 739b88bd47e..32e8db790eb 100644
--- a/backends/graphics3d/android/android-graphics3d.cpp
+++ b/backends/graphics3d/android/android-graphics3d.cpp
@@ -127,9 +127,14 @@ AndroidGraphics3dManager::~AndroidGraphics3dManager() {
 	glBindRenderbuffer(GL_RENDERBUFFER, 0);
 	glUseProgram(0);
 
+	// Cleanup framebuffer before destroying context
+	delete _frame_buffer;
+	_frame_buffer = nullptr;
+
 	deinitSurface();
 
-	delete _frame_buffer;
+	// These textures have been cleaned in deinitSurface
+	// Deleting them now without a context is harmless
 	delete _game_texture;
 	delete _overlay_texture;
 	delete _overlay_background;
diff --git a/backends/platform/android/android.cpp b/backends/platform/android/android.cpp
index abfa957af7f..c07a719bb0a 100644
--- a/backends/platform/android/android.cpp
+++ b/backends/platform/android/android.cpp
@@ -246,8 +246,9 @@ OSystem_Android::~OSystem_Android() {
 	delete _savefileManager;
 	_savefileManager = 0;
 
-	// Uninitialize surface now to avoid it to be done later when touch controls are destroyed
-	dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->deinitSurface();
+	// Uninitialize graphics manager now to avoid it to be done later when touch controls are destroyed
+	delete _graphicsManager;
+	_graphicsManager = 0;
 
 	delete _logger;
 	_logger = nullptr;
diff --git a/backends/platform/android/events.cpp b/backends/platform/android/events.cpp
index 23309197fd4..95c42d45328 100644
--- a/backends/platform/android/events.cpp
+++ b/backends/platform/android/events.cpp
@@ -1417,7 +1417,8 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
 	if (pthread_self() == _main_thread) {
 		if (_screen_changeid != JNI::surface_changeid) {
 			_screen_changeid = JNI::surface_changeid;
-
+			// If we loose the surface, don't deinit as we loose the EGL context and this may lead to crashes
+			// Keep a dangling surface until we get a resize
 			if (JNI::egl_surface_width > 0 && JNI::egl_surface_height > 0) {
 				// surface changed
 				dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->resizeSurface();
@@ -1425,9 +1426,6 @@ bool OSystem_Android::pollEvent(Common::Event &event) {
 				event.type = Common::EVENT_SCREEN_CHANGED;
 
 				return true;
-			} else {
-				// surface lost
-				dynamic_cast<AndroidCommonGraphics *>(_graphicsManager)->deinitSurface();
 			}
 		}
 
diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
index 15ec35218cf..1f2ad20c702 100644
--- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java
+++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java
@@ -167,11 +167,11 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable {
 
 		int res = main(_args);
 
+		destroy();
+
 		deinitEGL();
 		deinitAudio();
 
-		destroy();
-
 		// Don't exit force-ably here!
 		if (_svm_destroyed_callback != null) {
 			_svm_destroyed_callback.handle(res);




More information about the Scummvm-git-logs mailing list