[Scummvm-git-logs] scummvm master -> 77fce6614e2e2f2f04d32c63443752538c5b22cc

sev- noreply at scummvm.org
Sun Nov 20 16:18:45 UTC 2022


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

Summary:
30743f4a5e VIDEO: Optimize subtitles rendering
220eed50e9 VIDEO: Add a close method for subtitles
54ec6bdea0 MOHWAK: Adapt to subtitles changes and optimize
08b91ceb08 AGOS: Adapt to subtitles changes and optimize
50ca8969bf GROOVIE: Adapt to subtitles changes and optimize
fd6c95c35b VIDEO: Cleanup subtitles dev mode
17fc926291 GROOVIE: Disable overlay when skipping video
db1d834729 VIDEO: Handle screen size change in subtitles
77fce6614e BACKENDS: OPENGL: Disable scissor test when overlay is for games


Commit: 30743f4a5e2f4554992ae3dd3cd4aeafa2efea4b
    https://github.com/scummvm/scummvm/commit/30743f4a5e2f4554992ae3dd3cd4aeafa2efea4b
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
VIDEO: Optimize subtitles rendering

Subtitle text is only rendered while necessary.
Overlay management is done in the class instead of expecting engine to
handle it.
Overlay is not cleared when there is alpha support. This avoids useless
memory operations while the overlay being transparent, game screen is
rendered below it.

Changed paths:
    video/subtitles.cpp
    video/subtitles.h


diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 777ce2c25d2..beef25b4e2a 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -231,7 +231,7 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
 
 #define SHADOW 1
 
-Subtitles::Subtitles() : _loaded(false), _font(nullptr), _hPad(0), _vPad(0) {
+Subtitles::Subtitles() : _loaded(false), _font(nullptr), _hPad(0), _vPad(0), _overlayHasAlpha(true) {
 	_surface = new Graphics::Surface();
 	_subtitleDev = ConfMan.getBool("subtitle_dev");
 }
@@ -273,7 +273,9 @@ void Subtitles::loadSRTFile(const char *fname) {
 void Subtitles::setBBox(const Common::Rect bbox) {
 	_bbox = bbox;
 
-	_surface->create(_bbox.width() + SHADOW * 2, _bbox.height() + SHADOW * 2, g_system->getOverlayFormat());
+	Graphics::PixelFormat overlayFormat = g_system->getOverlayFormat();
+	_overlayHasAlpha = overlayFormat.aBits() != 0;
+	_surface->create(_bbox.width() + SHADOW * 2, _bbox.height() + SHADOW * 2, overlayFormat);
 }
 
 void Subtitles::setColor(byte r, byte g, byte b) {
@@ -287,12 +289,12 @@ void Subtitles::setPadding(uint16 horizontal, uint16 vertical) {
 	_vPad = vertical;
 }
 
-void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
+bool Subtitles::drawSubtitle(uint32 timestamp, bool force) {
 	Common::String subtitle = _srtParser.getSubtitle(timestamp);
 	
 	if (!_loaded) {
 		if (!_subtitleDev)
-			return;
+			return false;
 		uint32 hours, mins, secs, msecs;
 		secs = timestamp / 1000;
 		hours = secs / 3600;
@@ -302,21 +304,46 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
 		subtitle += " " + Common::String::format("%u:%u:%u,%u", hours, mins, secs, msecs);
 	}
 
-	if (!force && subtitle == _prevSubtitle)
-		return;
+	if (!force && _overlayHasAlpha && subtitle == _subtitle)
+		return false;
 
-	debug(1, "%d: %s", timestamp, subtitle.c_str());
+	if (force || subtitle != _subtitle) {
+		debug(1, "%d: %s", timestamp, subtitle.c_str());
 
-	_surface->fillRect(Common::Rect(0, 0, _surface->w, _surface->h), _transparentColor);
+		_subtitle = subtitle;
+		renderSubtitle();
+	}
 
-	_prevSubtitle = subtitle;
+	if (_overlayHasAlpha) {
+		// When we have alpha, draw the whole surface without thinking it more
+		g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left, _bbox.top, _surface->w, _surface->h);
+	} else {
+		// When overlay doesn't have alpha, showing it hides the underlying game screen
+		// We force a copy of the game screen to the overlay by clearing it
+		// We then draw the smallest possible surface to minimize black rectangle behind text
+		g_system->clearOverlay();
+		g_system->copyRectToOverlay((byte *)_surface->getPixels() + _drawRect.top * _surface->pitch + _drawRect.left * _surface->format.bytesPerPixel, _surface->pitch,
+				_bbox.left + _drawRect.left, _bbox.top + _drawRect.top, _drawRect.width(), _drawRect.height());
+	}
+
+	return true;
+}
+
+void Subtitles::renderSubtitle() {
+	_surface->fillRect(Common::Rect(0, 0, _surface->w, _surface->h), _transparentColor);
 
 	Common::Array<Common::U32String> lines;
 
-	_font->wordWrapText(convertUtf8ToUtf32(subtitle), _bbox.width(), lines);
+	_font->wordWrapText(convertUtf8ToUtf32(_subtitle), _bbox.width(), lines);
+
+	if (lines.empty()) {
+		_drawRect.left = 0;
+		_drawRect.top = 0;
+		_drawRect.right = 0;
+		_drawRect.bottom = 0;
 
-	if (lines.empty())
 		return;
+	}
 
 	int height = _vPad;
 
@@ -325,15 +352,17 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
 		width = MAX(_font->getStringWidth(lines[i]), width);
 	width = MIN(width + 2 * _hPad, (int)_bbox.width());
 
+	int originX = (_bbox.width() - width) / 2;
+
 	for (uint i = 0; i < lines.size(); i++) {
 		Common::U32String line = convertBiDiU32String(lines[i]).visual;
 
-		_font->drawString(_surface, line, 0, height, width, _blackColor, Graphics::kTextAlignCenter);
-		_font->drawString(_surface, line, SHADOW * 2, height, width, _blackColor, Graphics::kTextAlignCenter);
-		_font->drawString(_surface, line, 0, height + SHADOW * 2, width, _blackColor, Graphics::kTextAlignCenter);
-		_font->drawString(_surface, line, SHADOW * 2, height + SHADOW * 2, width, _blackColor, Graphics::kTextAlignCenter);
+		_font->drawString(_surface, line, originX, height, width, _blackColor, Graphics::kTextAlignCenter);
+		_font->drawString(_surface, line, originX + SHADOW * 2, height, width, _blackColor, Graphics::kTextAlignCenter);
+		_font->drawString(_surface, line, originX, height + SHADOW * 2, width, _blackColor, Graphics::kTextAlignCenter);
+		_font->drawString(_surface, line, originX + SHADOW * 2, height + SHADOW * 2, width, _blackColor, Graphics::kTextAlignCenter);
 
-		_font->drawString(_surface, line, SHADOW, height + SHADOW, width, _color, Graphics::kTextAlignCenter);
+		_font->drawString(_surface, line, originX + SHADOW, height + SHADOW, width, _color, Graphics::kTextAlignCenter);
 
 		height += _font->getFontHeight();
 
@@ -343,8 +372,10 @@ void Subtitles::drawSubtitle(uint32 timestamp, bool force) {
 
 	height += _vPad;
 
-	g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left + (_bbox.width() - width) / 2, _bbox.top, width + SHADOW * 2, height + SHADOW * 2);
-	g_system->updateScreen();
+	_drawRect.left = originX;
+	_drawRect.top = 0;
+	_drawRect.setWidth(width + SHADOW * 2);
+	_drawRect.setHeight(height + SHADOW * 2);
 }
 
 } // End of namespace Video
diff --git a/video/subtitles.h b/video/subtitles.h
index 364c4c9f89b..07a1154e74f 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -68,12 +68,16 @@ public:
 	void setBBox(const Common::Rect bbox);
 	void setColor(byte r, byte g, byte b);
 	void setPadding(uint16 horizontal, uint16 vertical);
-	void drawSubtitle(uint32 timestamp, bool force = false);
+	bool drawSubtitle(uint32 timestamp, bool force = false);
+	bool isLoaded() const { return _loaded || _subtitleDev; }
 
 private:
+	void renderSubtitle();
+
 	SRTParser _srtParser;
 	bool _loaded;
 	bool _subtitleDev;
+	bool _overlayHasAlpha;
 
 	const Graphics::Font *_font;
 	int _fontHeight;
@@ -81,9 +85,9 @@ private:
 	Graphics::Surface *_surface;
 
 	Common::Rect _bbox;
-	Common::Rect _dirtyRect;
+	Common::Rect _drawRect;
 
-	Common::String _prevSubtitle;
+	Common::String _subtitle;
 	uint32 _color;
 	uint32 _blackColor;
 	uint32 _transparentColor;


Commit: 220eed50e9ef8a5e2ae1bd526c581d54267539b0
    https://github.com/scummvm/scummvm/commit/220eed50e9ef8a5e2ae1bd526c581d54267539b0
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
VIDEO: Add a close method for subtitles

Changed paths:
    video/subtitles.h


diff --git a/video/subtitles.h b/video/subtitles.h
index 07a1154e74f..9273c2c0fab 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -64,6 +64,7 @@ public:
 	~Subtitles();
 
 	void loadSRTFile(const char *fname);
+	void close() { _loaded = false; _srtParser.cleanup(); }
 	void setFont(const char *fontname, int height = 18);
 	void setBBox(const Common::Rect bbox);
 	void setColor(byte r, byte g, byte b);


Commit: 54ec6bdea08d4c014e02f28d69f32cf2fc3b3b10
    https://github.com/scummvm/scummvm/commit/54ec6bdea08d4c014e02f28d69f32cf2fc3b3b10
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
MOHWAK: Adapt to subtitles changes and optimize

Subtitles are now tied to VideoEntry instead of the VideoManager this
allows to load different videos while having a subtitle for each.
Screen update is done only when necessary and overlay is cleared at
specific points.

Changed paths:
    engines/mohawk/video.cpp
    engines/mohawk/video.h


diff --git a/engines/mohawk/video.cpp b/engines/mohawk/video.cpp
index 13716f9f69c..704e6897e1e 100644
--- a/engines/mohawk/video.cpp
+++ b/engines/mohawk/video.cpp
@@ -51,9 +51,12 @@ VideoEntry::~VideoEntry() {
 }
 
 void VideoEntry::close() {
-	g_system->hideOverlay();
 	delete _video;
 	_video = nullptr;
+
+	if (_subtitles.isLoaded()) {
+		g_system->hideOverlay();
+	}
 }
 
 bool VideoEntry::endOfVideo() const {
@@ -111,16 +114,41 @@ void VideoEntry::setRate(const Common::Rational &rate) {
 void VideoEntry::pause(bool isPaused) {
 	assert(_video);
 	_video->pauseVideo(isPaused);
+
+	if (_subtitles.isLoaded()) {
+		if (isPaused) {
+			g_system->hideOverlay();
+		} else {
+			g_system->showOverlay(false);
+			g_system->clearOverlay();
+			_subtitles.drawSubtitle(_video->getTime(), true);
+		}
+	}
 }
 
 void VideoEntry::start() {
 	assert(_video);
 	_video->start();
+
+	if (_subtitles.isLoaded()) {
+		const int16 h = g_system->getOverlayHeight(),
+			        w = g_system->getOverlayWidth();
+		_subtitles.setBBox(Common::Rect(20, h - 120, w - 20, h - 20));
+		_subtitles.setColor(0xff, 0xff, 0xff);
+		_subtitles.setFont("FreeSans.ttf");
+
+		g_system->showOverlay(false);
+		g_system->clearOverlay();
+	}
 }
 
 void VideoEntry::stop() {
 	assert(_video);
 	_video->stop();
+
+	if (_subtitles.isLoaded()) {
+		g_system->hideOverlay();
+	}
 }
 
 bool VideoEntry::isPlaying() const {
@@ -141,12 +169,6 @@ void VideoEntry::setVolume(int volume) {
 VideoManager::VideoManager(MohawkEngine *vm) : _vm(vm) {
 	// Set dithering enabled, if required
 	_enableDither = (_vm->getGameType() == GType_MYST || _vm->getGameType() == GType_MAKINGOF) && !_vm->isGameVariant(GF_ME);
-
-	int16 h = g_system->getOverlayHeight();
-
-	_subtitles.setBBox(Common::Rect(20, h - 120, g_system->getOverlayWidth() - 20, h - 20));
-	_subtitles.setColor(0xff, 0xff, 0xff);
-	_subtitles.setFont("FreeSans.ttf");
 }
 
 VideoManager::~VideoManager() {
@@ -177,7 +199,7 @@ VideoEntryPtr VideoManager::playMovie(const Common::String &fileName, Audio::Mix
 
 
 	Common::String subtitlesName = Common::String::format("%s.srt", fileName.substr(0, fileName.size() - 4).c_str());
-	loadSubtitles(subtitlesName.c_str());
+	ptr->loadSubtitles(subtitlesName.c_str());
 
 	ptr->start();
 	return ptr;
@@ -196,9 +218,6 @@ bool VideoManager::updateMovies() {
 	bool updateScreen = false;
 
 	for (VideoList::iterator it = _videos.begin(); it != _videos.end(); ) {
-		g_system->showOverlay(false);
-		g_system->clearOverlay();
-
 		// Check of the video has reached the end
 		if ((*it)->endOfVideo()) {
 			if ((*it)->isLooping()) {
@@ -220,13 +239,13 @@ bool VideoManager::updateMovies() {
 			continue;
 		}
 
-		_subtitles.drawSubtitle(video->getTime(), true);
-
 		// Check if we need to draw a frame
 		if (video->needsUpdate()) {
 			if (drawNextFrame(*it)) {
 				updateScreen = true;
 			}
+
+			updateScreen |= (*it)->_subtitles.drawSubtitle(video->getTime(), false);
 		}
 
 		// Remember to increase the iterator
diff --git a/engines/mohawk/video.h b/engines/mohawk/video.h
index 2f3e8c31774..6dd6ced4a3d 100644
--- a/engines/mohawk/video.h
+++ b/engines/mohawk/video.h
@@ -219,6 +219,10 @@ public:
 	 */
 	void setVolume(int volume);
 
+	/**
+	 * Load the subtitles
+	 */
+	void loadSubtitles(const char *fname) { _subtitles.loadSRTFile(fname); }
 private:
 	// Non-changing variables
 	Video::VideoDecoder *_video;
@@ -231,6 +235,8 @@ private:
 	bool _loop;
 	bool _enabled;
 	Audio::Timestamp _start;
+
+	Video::Subtitles _subtitles;
 };
 
 typedef Common::SharedPtr<VideoEntry> VideoEntryPtr;
@@ -254,7 +260,6 @@ public:
 	VideoEntryPtr findVideo(const Common::String &fileName);
 	void drawVideoFrame(const VideoEntryPtr &video, const Audio::Timestamp &time);
 	void removeEntry(const VideoEntryPtr &video);
-	void loadSubtitles(const char *fname) { _subtitles.loadSRTFile(fname); }
 
 protected:
 	MohawkEngine *_vm;
@@ -274,8 +279,6 @@ protected:
 	// Dithering control
 	bool _enableDither;
 	void checkEnableDither(VideoEntryPtr &entry);
-
-	Video::Subtitles _subtitles;
 };
 
 } // End of namespace Mohawk


Commit: 08b91ceb0859fc7626b0b1d012a6c988cb58339e
    https://github.com/scummvm/scummvm/commit/08b91ceb0859fc7626b0b1d012a6c988cb58339e
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
AGOS: Adapt to subtitles changes and optimize

Overlay is not shown when there are no subtitles to show.
Subtitles are drawn at the correct frame and without forcing rendering.

Changed paths:
    engines/agos/animation.cpp
    engines/agos/animation.h


diff --git a/engines/agos/animation.cpp b/engines/agos/animation.cpp
index 42ebd50952b..8625fa6d606 100644
--- a/engines/agos/animation.cpp
+++ b/engines/agos/animation.cpp
@@ -438,7 +438,7 @@ bool MoviePlayerSMK::load() {
 	CursorMan.showMouse(false);
 
 	Common::String subtitlesName = Common::String::format("%s.srt", baseName);
-	loadSubtitles(subtitlesName.c_str());
+	_subtitles.loadSRTFile(subtitlesName.c_str());
 
 	return true;
 }
@@ -466,16 +466,19 @@ void MoviePlayerSMK::copyFrameToBuffer(byte *dst, uint x, uint y, uint pitch) {
 }
 
 void MoviePlayerSMK::playVideo() {
+	if (_subtitles.isLoaded()) {
+		g_system->clearOverlay();
+		g_system->showOverlay(false);
+	}
 	while (!endOfVideo() && !_skipMovie && !_vm->shouldQuit()) {
-		_subtitles.drawSubtitle(getTime(), true);
 		handleNextFrame();
-		g_system->showOverlay(false);
-		g_system->clearOverlay();
 	}
 }
 
 void MoviePlayerSMK::stopVideo() {
-	g_system->hideOverlay();
+	if (_subtitles.isLoaded()) {
+		g_system->hideOverlay();
+	}
 	close();
 }
 
@@ -519,6 +522,8 @@ bool MoviePlayerSMK::processFrame() {
 		return false;
 	}
 
+	_subtitles.drawSubtitle(getTime(), false);
+
 	_vm->_system->updateScreen();
 
 	// Wait before showing the next frame
diff --git a/engines/agos/animation.h b/engines/agos/animation.h
index 0c5e75558fc..8a403a6ce63 100644
--- a/engines/agos/animation.h
+++ b/engines/agos/animation.h
@@ -62,7 +62,6 @@ public:
 	virtual void playVideo() = 0;
 	virtual void nextFrame() = 0;
 	virtual void stopVideo() = 0;
-	void loadSubtitles(const char *fname) { _subtitles.loadSRTFile(fname); }
 
 protected:
 	virtual void handleNextFrame();


Commit: 50ca8969bfa1ee2ae61bcc466d17d9a6001d2da6
    https://github.com/scummvm/scummvm/commit/50ca8969bfa1ee2ae61bcc466d17d9a6001d2da6
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
GROOVIE: Adapt to subtitles changes and optimize

Close subtitles when they are not needed anymore.
Only show, clear and hide overlay when needed.
Draw the subtitle at the correct place using the real frame time.
Use srt files instead of txt ones.

Changed paths:
    engines/groovie/script.cpp
    engines/groovie/video/player.cpp


diff --git a/engines/groovie/script.cpp b/engines/groovie/script.cpp
index 797944ed030..3deecbf561c 100644
--- a/engines/groovie/script.cpp
+++ b/engines/groovie/script.cpp
@@ -959,8 +959,8 @@ bool Script::playvideofromref(uint32 fileref, bool loopUntilAudioDone) {
 			Common::String subtitleName = _vm->_resMan->getGjdName(info);
 			subtitleName = subtitleName.substr(0, subtitleName.size() - 4);
 			subtitleName.toUppercase();
-			// add the filename without the extension, then add the .txt extension
-			subtitleName += "-" + info.filename.substr(0, info.filename.size() - 3) + "txt";
+			// add the filename without the extension, then add the srt extension
+			subtitleName += "-" + info.filename.substr(0, info.filename.size() - 3) + "srt";
 
 			_vm->_videoPlayer->loadSubtitles(subtitleName.c_str());
 		} else {
diff --git a/engines/groovie/video/player.cpp b/engines/groovie/video/player.cpp
index 414ba6c51a9..7a1d5f84ded 100644
--- a/engines/groovie/video/player.cpp
+++ b/engines/groovie/video/player.cpp
@@ -87,10 +87,9 @@ bool VideoPlayer::playFrame() {
 	// Process the next frame while the file is open
 	if (_file) {
 		end = playFrameInternal();
-	}
 
-	uint32 currTime = _syst->getMillis();
-	_subtitles.drawSubtitle(currTime - _startTime);
+		_subtitles.drawSubtitle(_lastFrameTime - _startTime);
+	}
 
 	// The file has been completely processed
 	if (end) {
@@ -108,7 +107,10 @@ bool VideoPlayer::playFrame() {
 			}
 		}
 
-		g_system->hideOverlay();
+		if (_subtitles.isLoaded()) {
+			_subtitles.close();
+			g_system->hideOverlay();
+		}
 	}
 
 	return end;
@@ -124,8 +126,10 @@ void VideoPlayer::waitFrame() {
 		_lastFrameTime = currTime;
 		_frameTimeDrift = 0.0f;
 
-		g_system->showOverlay(false);
-		g_system->clearOverlay();
+		if (_subtitles.isLoaded()) {
+			g_system->showOverlay(false);
+			g_system->clearOverlay();
+		}
 	} else {
 		uint32 millisDiff = currTime - _lastFrameTime;
 		float fMillis = _millisBetweenFrames + _frameTimeDrift;


Commit: fd6c95c35bf6a208b23a3f4d05fd736627232fae
    https://github.com/scummvm/scummvm/commit/fd6c95c35bf6a208b23a3f4d05fd736627232fae
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
VIDEO: Cleanup subtitles dev mode

Changed paths:
    video/subtitles.cpp
    video/subtitles.h


diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index beef25b4e2a..38549f8b06b 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -120,7 +120,6 @@ bool SRTParser::parseFile(const char *fname) {
 	cleanup();
 
 	if (!f.open(fname)) {
-		_entries.push_back(new SRTEntry(0, 0, 99999999, fname));
 		return false;
 	}
 
@@ -267,6 +266,9 @@ void Subtitles::setFont(const char *fontname, int height) {
 void Subtitles::loadSRTFile(const char *fname) {
 	debug(1, "loadSRTFile('%s')", fname);
 
+	if (_subtitleDev) {
+		_fname = fname;
+	}
 	_loaded = _srtParser.parseFile(fname);
 }
 
@@ -290,18 +292,20 @@ void Subtitles::setPadding(uint16 horizontal, uint16 vertical) {
 }
 
 bool Subtitles::drawSubtitle(uint32 timestamp, bool force) {
-	Common::String subtitle = _srtParser.getSubtitle(timestamp);
-	
-	if (!_loaded) {
-		if (!_subtitleDev)
-			return false;
+	Common::String subtitle;
+	if (_loaded) {
+		subtitle = _srtParser.getSubtitle(timestamp);
+	} else if (_subtitleDev) {
+		subtitle = _fname;
 		uint32 hours, mins, secs, msecs;
 		secs = timestamp / 1000;
 		hours = secs / 3600;
 		mins = (secs / 60) % 60;
 		secs %= 60;
 		msecs = timestamp % 1000;
-		subtitle += " " + Common::String::format("%u:%u:%u,%u", hours, mins, secs, msecs);
+		subtitle += " " + Common::String::format("%02u:%02u:%02u,%03u", hours, mins, secs, msecs);
+	} else {
+		return false;
 	}
 
 	if (!force && _overlayHasAlpha && subtitle == _subtitle)
diff --git a/video/subtitles.h b/video/subtitles.h
index 9273c2c0fab..dcaa267c9b3 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -64,7 +64,7 @@ public:
 	~Subtitles();
 
 	void loadSRTFile(const char *fname);
-	void close() { _loaded = false; _srtParser.cleanup(); }
+	void close() { _loaded = false; _subtitle.clear(); _fname.clear(); _srtParser.cleanup(); }
 	void setFont(const char *fontname, int height = 18);
 	void setBBox(const Common::Rect bbox);
 	void setColor(byte r, byte g, byte b);
@@ -88,6 +88,7 @@ private:
 	Common::Rect _bbox;
 	Common::Rect _drawRect;
 
+	Common::String _fname;
 	Common::String _subtitle;
 	uint32 _color;
 	uint32 _blackColor;


Commit: 17fc9262910b8c7b5a7f0a90fb27297c34c303a9
    https://github.com/scummvm/scummvm/commit/17fc9262910b8c7b5a7f0a90fb27297c34c303a9
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
GROOVIE: Disable overlay when skipping video

Changed paths:
    engines/groovie/script.cpp
    engines/groovie/video/player.cpp
    engines/groovie/video/player.h


diff --git a/engines/groovie/script.cpp b/engines/groovie/script.cpp
index 3deecbf561c..eca7defb3e4 100644
--- a/engines/groovie/script.cpp
+++ b/engines/groovie/script.cpp
@@ -987,6 +987,8 @@ bool Script::playvideofromref(uint32 fileref, bool loopUntilAudioDone) {
 
 			_bitflags = 0;
 
+			_vm->_videoPlayer->unloadSubtitles();
+
 			// End the playback
 			return true;
 		}
diff --git a/engines/groovie/video/player.cpp b/engines/groovie/video/player.cpp
index 7a1d5f84ded..c15da648d12 100644
--- a/engines/groovie/video/player.cpp
+++ b/engines/groovie/video/player.cpp
@@ -107,15 +107,19 @@ bool VideoPlayer::playFrame() {
 			}
 		}
 
-		if (_subtitles.isLoaded()) {
-			_subtitles.close();
-			g_system->hideOverlay();
-		}
+		unloadSubtitles();
 	}
 
 	return end;
 }
 
+void VideoPlayer::unloadSubtitles() {
+	if (_subtitles.isLoaded()) {
+		_subtitles.close();
+		g_system->hideOverlay();
+	}
+}
+
 void VideoPlayer::waitFrame() {
 	if (isFastForwarding()) {
 		return;
diff --git a/engines/groovie/video/player.h b/engines/groovie/video/player.h
index 9a55a35808f..62d36767d3b 100644
--- a/engines/groovie/video/player.h
+++ b/engines/groovie/video/player.h
@@ -50,6 +50,7 @@ public:
 	void setOverrideSpeed(bool isOverride);
 
 	void loadSubtitles(const char *fname) { _subtitles.loadSRTFile(fname); }
+	void unloadSubtitles();
 
 protected:
 	// To be implemented by subclasses


Commit: db1d8347296265978b8b1bfd21b064e60ffec913
    https://github.com/scummvm/scummvm/commit/db1d8347296265978b8b1bfd21b064e60ffec913
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
VIDEO: Handle screen size change in subtitles

This avoids assertions failures when overlay is resized while displaying
subtitles

Changed paths:
    video/subtitles.cpp
    video/subtitles.h


diff --git a/video/subtitles.cpp b/video/subtitles.cpp
index 38549f8b06b..05bc780d44e 100644
--- a/video/subtitles.cpp
+++ b/video/subtitles.cpp
@@ -230,7 +230,8 @@ Common::String SRTParser::getSubtitle(uint32 timestamp) {
 
 #define SHADOW 1
 
-Subtitles::Subtitles() : _loaded(false), _font(nullptr), _hPad(0), _vPad(0), _overlayHasAlpha(true) {
+Subtitles::Subtitles() : _loaded(false), _font(nullptr), _hPad(0), _vPad(0), _overlayHasAlpha(true),
+	_lastOverlayWidth(-1), _lastOverlayHeight(-1) {
 	_surface = new Graphics::Surface();
 	_subtitleDev = ConfMan.getBool("subtitle_dev");
 }
@@ -273,11 +274,14 @@ void Subtitles::loadSRTFile(const char *fname) {
 }
 
 void Subtitles::setBBox(const Common::Rect bbox) {
-	_bbox = bbox;
+	_requestedBBox = bbox;
 
 	Graphics::PixelFormat overlayFormat = g_system->getOverlayFormat();
 	_overlayHasAlpha = overlayFormat.aBits() != 0;
-	_surface->create(_bbox.width() + SHADOW * 2, _bbox.height() + SHADOW * 2, overlayFormat);
+	_surface->create(_requestedBBox.width() + SHADOW * 2, _requestedBBox.height() + SHADOW * 2, overlayFormat);
+	// Force recalculation of real bounding box
+	_lastOverlayWidth = -1;
+	_lastOverlayHeight = -1;
 }
 
 void Subtitles::setColor(byte r, byte g, byte b) {
@@ -308,6 +312,40 @@ bool Subtitles::drawSubtitle(uint32 timestamp, bool force) {
 		return false;
 	}
 
+	int16 width = g_system->getOverlayWidth(),
+		  height = g_system->getOverlayHeight();
+
+	if (width != _lastOverlayWidth ||
+		height != _lastOverlayHeight) {
+		_lastOverlayWidth = width;
+		_lastOverlayHeight = height;
+
+		// Recalculate the real bounding box to use
+		_realBBox = _requestedBBox;
+
+		if (_realBBox.bottom > height) {
+			// First try to move the bounding box
+			_realBBox.top -= _realBBox.bottom - height;
+			_realBBox.bottom = height;
+		}
+		if (_realBBox.top < 0) {
+			// Not enough space
+			_realBBox.top = 0;
+		}
+
+		if (_realBBox.right > width) {
+			// First try to move the bounding box
+			_realBBox.left -= _realBBox.right - width;
+			_realBBox.right = width;
+		}
+		if (_realBBox.left < 0) {
+			// Not enough space
+			_realBBox.left = 0;
+		}
+
+		force = true;
+	}
+
 	if (!force && _overlayHasAlpha && subtitle == _subtitle)
 		return false;
 
@@ -320,14 +358,14 @@ bool Subtitles::drawSubtitle(uint32 timestamp, bool force) {
 
 	if (_overlayHasAlpha) {
 		// When we have alpha, draw the whole surface without thinking it more
-		g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _bbox.left, _bbox.top, _surface->w, _surface->h);
+		g_system->copyRectToOverlay(_surface->getPixels(), _surface->pitch, _realBBox.left, _realBBox.top, _realBBox.width(), _realBBox.height());
 	} else {
 		// When overlay doesn't have alpha, showing it hides the underlying game screen
 		// We force a copy of the game screen to the overlay by clearing it
 		// We then draw the smallest possible surface to minimize black rectangle behind text
 		g_system->clearOverlay();
 		g_system->copyRectToOverlay((byte *)_surface->getPixels() + _drawRect.top * _surface->pitch + _drawRect.left * _surface->format.bytesPerPixel, _surface->pitch,
-				_bbox.left + _drawRect.left, _bbox.top + _drawRect.top, _drawRect.width(), _drawRect.height());
+				_realBBox.left + _drawRect.left, _realBBox.top + _drawRect.top, _drawRect.width(), _drawRect.height());
 	}
 
 	return true;
@@ -338,7 +376,7 @@ void Subtitles::renderSubtitle() {
 
 	Common::Array<Common::U32String> lines;
 
-	_font->wordWrapText(convertUtf8ToUtf32(_subtitle), _bbox.width(), lines);
+	_font->wordWrapText(convertUtf8ToUtf32(_subtitle), _realBBox.width(), lines);
 
 	if (lines.empty()) {
 		_drawRect.left = 0;
@@ -354,9 +392,9 @@ void Subtitles::renderSubtitle() {
 	int width = 0;
 	for (uint i = 0; i < lines.size(); i++)
 		width = MAX(_font->getStringWidth(lines[i]), width);
-	width = MIN(width + 2 * _hPad, (int)_bbox.width());
+	width = MIN(width + 2 * _hPad, (int)_realBBox.width());
 
-	int originX = (_bbox.width() - width) / 2;
+	int originX = (_realBBox.width() - width) / 2;
 
 	for (uint i = 0; i < lines.size(); i++) {
 		Common::U32String line = convertBiDiU32String(lines[i]).visual;
@@ -370,7 +408,7 @@ void Subtitles::renderSubtitle() {
 
 		height += _font->getFontHeight();
 
-		if (height + _vPad > _bbox.bottom)
+		if (height + _vPad > _realBBox.bottom)
 			break;
 	}
 
diff --git a/video/subtitles.h b/video/subtitles.h
index dcaa267c9b3..f649921567b 100644
--- a/video/subtitles.h
+++ b/video/subtitles.h
@@ -85,8 +85,10 @@ private:
 
 	Graphics::Surface *_surface;
 
-	Common::Rect _bbox;
 	Common::Rect _drawRect;
+	Common::Rect _requestedBBox;
+	Common::Rect _realBBox;
+	int16 _lastOverlayWidth, _lastOverlayHeight;
 
 	Common::String _fname;
 	Common::String _subtitle;


Commit: 77fce6614e2e2f2f04d32c63443752538c5b22cc
    https://github.com/scummvm/scummvm/commit/77fce6614e2e2f2f04d32c63443752538c5b22cc
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-20T17:18:38+01:00

Commit Message:
BACKENDS: OPENGL: Disable scissor test when overlay is for games

WIthout this, the game cannot draw outside its area for subtitles.
This is exhibited when scaling is set to center.

Changed paths:
    backends/graphics/opengl/opengl-graphics.cpp


diff --git a/backends/graphics/opengl/opengl-graphics.cpp b/backends/graphics/opengl/opengl-graphics.cpp
index 81280f7fd28..92aff02465e 100644
--- a/backends/graphics/opengl/opengl-graphics.cpp
+++ b/backends/graphics/opengl/opengl-graphics.cpp
@@ -636,7 +636,7 @@ void OpenGLGraphicsManager::updateScreen() {
 	// Clear the screen buffer.
 	GL_CALL(glClear(GL_COLOR_BUFFER_BIT));
 
-	if (!_overlayInGUI) {
+	if (!_overlayVisible) {
 		// The scissor test is enabled to:
 		// - Clip the cursor to the game screen
 		// - Clip the game screen when the shake offset is non-zero
@@ -694,7 +694,7 @@ void OpenGLGraphicsManager::updateScreen() {
 		                         _cursorWidthScaled, _cursorHeightScaled);
 	}
 
-	if (!_overlayInGUI) {
+	if (!_overlayVisible) {
 		_backBuffer.enableScissorTest(false);
 	}
 




More information about the Scummvm-git-logs mailing list