[Scummvm-git-logs] scummvm master -> 133eea820cb2ce18dca5652f4ad0e1924bc01e62
spleen1981
noreply at scummvm.org
Tue Oct 22 17:40:44 UTC 2024
This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
a874244a6d LIBRETRO: rewrite surface graphics manager and split sources
79e0d08e91 LIBRETRO: JANITORIAL: cleanup
35f9f7eb71 LIBRETRO: handle resizing to native res in hw rendering
8dffadf672 LIBRETRO: BUILD: Allow fallback to curl if wget is missing (#68)
133eea820c LIBRETRO: fix pointer input coordinates
Commit: a874244a6d7fd3e1947f23a5748e430e3a76b16d
https://github.com/scummvm/scummvm/commit/a874244a6d7fd3e1947f23a5748e430e3a76b16d
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2024-10-22T19:38:50+02:00
Commit Message:
LIBRETRO: rewrite surface graphics manager and split sources
Changed paths:
A backends/platform/libretro/include/libretro-graphics-opengl.h
A backends/platform/libretro/include/libretro-graphics-surface.h
A backends/platform/libretro/src/libretro-graphics-opengl.cpp
A backends/platform/libretro/src/libretro-graphics-surface.cpp
R backends/platform/libretro/include/libretro-graphics.h
R backends/platform/libretro/src/libretro-graphics.cpp
backends/platform/libretro/Makefile.common
backends/platform/libretro/include/libretro-core.h
backends/platform/libretro/include/libretro-defs.h
backends/platform/libretro/include/libretro-os.h
backends/platform/libretro/src/libretro-core.cpp
backends/platform/libretro/src/libretro-os-base.cpp
backends/platform/libretro/src/libretro-os-events.cpp
backends/platform/libretro/src/libretro-os-inputs.cpp
diff --git a/backends/platform/libretro/Makefile.common b/backends/platform/libretro/Makefile.common
index f23f8d6c838..4c3bdfa6e0f 100644
--- a/backends/platform/libretro/Makefile.common
+++ b/backends/platform/libretro/Makefile.common
@@ -168,7 +168,11 @@ LIBRETRO_OBJS := $(CORE_PATH)/libretro-core.o \
$(CORE_PATH)/libretro-timer.o \
$(CORE_PATH)/libretro-mapper.o \
$(CORE_PATH)/libretro-options-widget.o \
- $(CORE_PATH)/libretro-graphics.o
+ $(CORE_PATH)/libretro-graphics-surface.o
+
+ifeq ($(or $(HAVE_OPENGL), $(HAVE_OPENGLES2)), 1)
+ LIBRETRO_OBJS += $(CORE_PATH)/libretro-graphics-opengl.o
+endif
OBJS += $(LIBRETRO_OBJS)
diff --git a/backends/platform/libretro/include/libretro-core.h b/backends/platform/libretro/include/libretro-core.h
index ece0aa3c6da..2597647286c 100644
--- a/backends/platform/libretro/include/libretro-core.h
+++ b/backends/platform/libretro/include/libretro-core.h
@@ -43,6 +43,8 @@ bool retro_setting_get_gamepad_cursor_only(void);
float retro_setting_get_gamepad_cursor_speed(void);
float retro_setting_get_gamepad_acceleration_time(void);
+void retro_set_size(unsigned width, unsigned height);
+
uint8 retro_get_video_hw_mode(void);
#ifdef USE_OPENGL
uintptr_t retro_get_hw_fb(void);
diff --git a/backends/platform/libretro/include/libretro-defs.h b/backends/platform/libretro/include/libretro-defs.h
index 5ef616999d5..63aa8e7f657 100644
--- a/backends/platform/libretro/include/libretro-defs.h
+++ b/backends/platform/libretro/include/libretro-defs.h
@@ -38,6 +38,8 @@
#define AUDIO_STATUS_BUFFER_UNDERRUN (1 << 3)
#define AUDIO_STATUS_UPDATE_LATENCY (1 << 4)
#define AUDIO_STATUS_UPDATE_AV_INFO (1 << 5)
+#define AUDIO_STATUS_RESET_PENDING (1 << 6)
+#define AUDIO_STATUS_UPDATE_GEOMETRY (1 << 7)
// Video status
#define VIDEO_GRAPHIC_MODE_REQUEST_SW (1 << 0)
diff --git a/backends/platform/libretro/include/libretro-graphics-opengl.h b/backends/platform/libretro/include/libretro-graphics-opengl.h
new file mode 100644
index 00000000000..380762bdacf
--- /dev/null
+++ b/backends/platform/libretro/include/libretro-graphics-opengl.h
@@ -0,0 +1,43 @@
+/* Copyright (C) 2024 Giovanni Cascione <ing.cascione at gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef BACKENDS_LIBRETRO_GRAPHICS_OPENGL_H
+#define BACKENDS_LIBRETRO_GRAPHICS_OPENGL_H
+
+#include "backends/graphics/opengl/opengl-graphics.h"
+
+class LibretroOpenGLGraphics : public OpenGL::OpenGLGraphicsManager {
+public:
+ LibretroOpenGLGraphics(OpenGL::ContextType contextType);
+ bool loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) override { return true; };
+ void refreshScreen() override;
+ void setSystemMousePosition(const int x, const int y) override {};
+ void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) override;
+
+ bool isOverlayInGUI(void){ return _overlayInGUI; }
+ void setMousePosition(int x, int y);
+ Common::Point convertWindowToVirtual(int x, int y) const;
+ void resetContext(OpenGL::ContextType contextType);
+};
+
+class LibretroHWFramebuffer : public OpenGL::Backbuffer {
+
+protected:
+ void activateInternal() override;
+};
+
+#endif //BACKENDS_LIBRETRO_GRAPHICS_OPENGL_H
diff --git a/backends/platform/libretro/include/libretro-graphics.h b/backends/platform/libretro/include/libretro-graphics-surface.h
similarity index 58%
rename from backends/platform/libretro/include/libretro-graphics.h
rename to backends/platform/libretro/include/libretro-graphics-surface.h
index 13db3146cf1..f5471892e61 100644
--- a/backends/platform/libretro/include/libretro-graphics.h
+++ b/backends/platform/libretro/include/libretro-graphics-surface.h
@@ -14,44 +14,26 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-#ifndef BACKENDS_LIBRETRO_GRAPHICS_H
-#define BACKENDS_LIBRETRO_GRAPHICS_H
+#ifndef BACKENDS_LIBRETRO_GRAPHICS_SURFACE_H
+#define BACKENDS_LIBRETRO_GRAPHICS_SURFACE_H
#include "common/system.h"
-#include "graphics/paletteman.h"
-#include "graphics/surface.h"
-#include "backends/graphics/graphics.h"
+#include "graphics/palette.h"
+#include "graphics/managed_surface.h"
+#include "backends/graphics/windowed.h"
-#ifdef USE_OPENGL
-#include "backends/graphics/opengl/opengl-graphics.h"
-#endif
+class LibretroGraphics : public WindowedGraphicsManager {
-class LibretroPalette {
public:
- const byte *_prevColorsSource;
- unsigned char _colors[256 * 3];
- LibretroPalette(void);
- ~LibretroPalette(void) {};
- void set(const byte *colors, uint start, uint num);
- void get(byte *colors, uint start, uint num) const;
- unsigned char *getColor(uint aIndex) const;
- void reset(void) {
- _prevColorsSource = NULL;
- }
-};
-
-class LibretroGraphics : public GraphicsManager {
-
-public:
- Graphics::Surface _screen;
+ Graphics::ManagedSurface _screen;
Graphics::Surface _gameScreen;
Graphics::Surface _overlay;
Graphics::Surface _mouseImage;
- LibretroPalette _mousePalette;
- LibretroPalette _gamePalette;
+ Graphics::Palette _mousePalette;
+ Graphics::Palette _gamePalette;
private:
- bool _overlayInGUI;
+ //bool _overlayInGUI;
bool _overlayVisible;
bool _mouseDontScale;
bool _mousePaletteEnabled;
@@ -60,6 +42,7 @@ private:
int _mouseHotspotX;
int _mouseHotspotY;
int _mouseKeyColor;
+ int _screenChangeID;
public:
LibretroGraphics();
@@ -72,15 +55,13 @@ public:
Graphics::PixelFormat getScreenFormat(void) const override;
void copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) override;
void updateScreen(void) override;
- void showOverlay(bool inGUI) override;
- void hideOverlay(void) override;
void clearOverlay(void) override;
void grabOverlay(Graphics::Surface &surface) const override;
void copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) override;
int16 getOverlayHeight(void) const override;
int16 getOverlayWidth(void) const override;
Graphics::PixelFormat getOverlayFormat() const override;
- const Graphics::Surface *getScreen(void);
+ const Graphics::ManagedSurface *getScreen(void);
bool showMouse(bool visible) override;
void warpMouse(int x, int y) override;
void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor = 255, bool dontScale = false, const Graphics::PixelFormat *format = NULL, const byte *mask = nullptr) override;
@@ -91,64 +72,31 @@ public:
void setFeatureState(OSystem::Feature f, bool enable) override;
bool getFeatureState(OSystem::Feature f) const override;
- int getDefaultGraphicsMode() const override {
- return 0;
- }
- bool isOverlayVisible() const override {
- return _overlayVisible;
- }
- bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override {
- return true;
- }
- int getGraphicsMode() const override {
- return 0;
- }
- Graphics::Surface *lockScreen() override {
- return &_gameScreen;
- }
+ int getDefaultGraphicsMode() const override { return 0; }
+ bool setGraphicsMode(int mode, uint flags = OSystem::kGfxModeNoFlags) override { return true; }
+ int getGraphicsMode() const override { return 0; }
+ Graphics::Surface *lockScreen() override { return &_gameScreen; }
void unlockScreen() override {}
- void setShakePos(int shakeXOffset, int shakeYOffset) override {}
- int getScreenChangeID() const override {
- return 0;
- }
+ int getScreenChangeID() const override;
void beginGFXTransaction() override {}
- OSystem::TransactionError endGFXTransaction() override {
- return OSystem::kTransactionSuccess;
- }
+ OSystem::TransactionError endGFXTransaction() override { return OSystem::kTransactionSuccess; }
void fillScreen(uint32 col) override {}
void fillScreen(const Common::Rect &r, uint32 col) override {}
void setFocusRectangle(const Common::Rect &rect) override {}
void clearFocusRectangle() override {}
- void displayMessageOnOSD(const Common::U32String &msg) override;
- void displayActivityIconOnOSD(const Graphics::Surface *icon) override {}
void realUpdateScreen(void);
-protected:
- void setPalette(const byte *colors, uint start, uint num) override;
- void grabPalette(byte *colors, uint start, uint num) const override;
-};
-
-#ifdef USE_OPENGL
-class LibretroOpenGLGraphics : public OpenGL::OpenGLGraphicsManager {
-public:
- LibretroOpenGLGraphics(OpenGL::ContextType contextType);
- bool loadVideoMode(uint requestedWidth, uint requestedHeight, const Graphics::PixelFormat &format) override { return true; };
- void refreshScreen() override;
- void setSystemMousePosition(const int x, const int y) override {};
- void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) override;
-
- bool isOverlayInGUI(void){ return _overlayInGUI; }
+ bool gameNeedsAspectRatioCorrection() const override { return false; }
+ void handleResizeImpl(const int width, const int height) override {};
+ void setSystemMousePosition(const int x, const int y) override {}
void setMousePosition(int x, int y);
- Common::Point convertWindowToVirtual(int x, int y) const;
- void resetContext(OpenGL::ContextType contextType);
-};
-class LibretroHWFramebuffer : public OpenGL::Backbuffer {
+ void displayMessageOnOSD(const Common::U32String &msg) override;
protected:
- void activateInternal() override;
+ void setPalette(const byte *colors, uint start, uint num) override;
+ void grabPalette(byte *colors, uint start, uint num) const override;
};
-#endif
-#endif //BACKENDS_LIBRETRO_GRAPHICS_H
+#endif //BACKENDS_LIBRETRO_GRAPHICS_SURFACE_H
diff --git a/backends/platform/libretro/include/libretro-os.h b/backends/platform/libretro/include/libretro-os.h
index 5d6248efc79..e1a3aca0045 100644
--- a/backends/platform/libretro/include/libretro-os.h
+++ b/backends/platform/libretro/include/libretro-os.h
@@ -19,12 +19,13 @@
#include "audio/mixer_intern.h"
#include "base/main.h"
-#include "backends/base-backend.h"
+//#include "backends/base-backend.h"
#include "common/system.h"
#include "common/mutex.h"
#include "common/list.h"
#include "common/events.h"
#include "backends/modular-backend.h"
+#include "graphics/managed_surface.h"
#define BASE_CURSOR_SPEED 4
#define CURSOR_STATUS_DOING_JOYSTICK (1 << 0)
@@ -87,15 +88,17 @@ public:
void quit() override {}
void resetGraphicsManager(void);
- void getScreen(const Graphics::Surface *&screen);
+ void getScreen(const Graphics::ManagedSurface *&screen);
int16 getScreenWidth(void);
int16 getScreenHeight(void);
bool isOverlayInGUI(void);
#ifdef USE_OPENGL
void resetGraphicsContext(void);
+#ifdef USE_GLAD
void *getOpenGLProcAddress(const char *name) const override;
#endif
+#endif
private:
bool checkPathSetting(const char *setting, Common::String const &defaultPath, bool isDirectory = true);
diff --git a/backends/platform/libretro/src/libretro-core.cpp b/backends/platform/libretro/src/libretro-core.cpp
index a6737ef2e01..4551d951ace 100644
--- a/backends/platform/libretro/src/libretro-core.cpp
+++ b/backends/platform/libretro/src/libretro-core.cpp
@@ -45,6 +45,8 @@
#define INCLUDED_FROM_BASE_VERSION_CPP
#include "base/internal_version.h"
+#include "graphics/managed_surface.h"
+
#include "backends/platform/libretro/include/libretro-defs.h"
#include "backends/platform/libretro/include/libretro-core.h"
#include "backends/platform/libretro/include/libretro-threads.h"
@@ -81,6 +83,11 @@ char cmd_params_num;
static uint8 video_hw_mode = 0;
+static unsigned base_width = RES_W;
+static unsigned base_height = RES_H;
+static unsigned max_width = RES_W;
+static unsigned max_height = RES_H;
+
static uint32 current_frame = 0;
static uint8 frameskip_no;
static uint8 frameskip_type;
@@ -556,7 +563,7 @@ static void update_variables(void) {
if (old_frame_rate != frame_rate || old_sample_rate != sample_rate) {
audio_buffer_init(sample_rate, (uint16) frame_rate);
if (g_system)
- audio_status |= AUDIO_STATUS_UPDATE_AV_INFO;
+ audio_status |= (AUDIO_STATUS_UPDATE_AV_INFO & AUDIO_STATUS_RESET_PENDING);
}
}
@@ -816,11 +823,25 @@ void retro_get_system_info(struct retro_system_info *info) {
info->block_extract = false;
}
+void retro_set_size(unsigned width, unsigned height) {
+ if (base_width == width && base_height == height) {
+ return;
+ } else if (width > max_width || height > max_height) {
+ max_width = width;
+ max_height = height;
+ audio_status |= AUDIO_STATUS_UPDATE_AV_INFO;
+ } else
+ audio_status |= AUDIO_STATUS_UPDATE_GEOMETRY;
+
+ base_width = width;
+ base_height = height;
+}
+
void retro_get_system_av_info(struct retro_system_av_info *info) {
- info->geometry.base_width = RES_W;
- info->geometry.base_height = RES_H;
- info->geometry.max_width = RES_W;
- info->geometry.max_height = RES_H;
+ info->geometry.base_width = base_width;
+ info->geometry.base_height = base_height;
+ info->geometry.max_width = max_width;
+ info->geometry.max_height = max_height;
info->geometry.aspect_ratio = 4.0f / 3.0f;
info->timing.fps = frame_rate;
info->timing.sample_rate = sample_rate;
@@ -1039,10 +1060,17 @@ void retro_run(void) {
except in case of core options reset to defaults, for which the following call is needed*/
retro_update_options_display();
- if (audio_status & AUDIO_STATUS_UPDATE_AV_INFO) {
+ if (audio_status & (AUDIO_STATUS_UPDATE_AV_INFO | AUDIO_STATUS_UPDATE_GEOMETRY)) {
struct retro_system_av_info info;
retro_get_system_av_info(&info);
- environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &info);
+ if (audio_status & AUDIO_STATUS_UPDATE_GEOMETRY) {
+ environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &info);
+ audio_status &= ~AUDIO_STATUS_UPDATE_GEOMETRY;
+ } else {
+ printf("\retro_run\n");
+ environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &info);
+ audio_status &= ~AUDIO_STATUS_UPDATE_AV_INFO;
+ }
}
if (audio_status & AUDIO_STATUS_UPDATE_LATENCY) {
@@ -1059,8 +1087,8 @@ void retro_run(void) {
audio_status &= ~AUDIO_STATUS_UPDATE_LATENCY;
}
- if (audio_status & AUDIO_STATUS_UPDATE_AV_INFO) {
- audio_status &= ~AUDIO_STATUS_UPDATE_AV_INFO;
+ if (audio_status & AUDIO_STATUS_RESET_PENDING) {
+ audio_status &= ~AUDIO_STATUS_RESET_PENDING;
retro_reset();
return;
}
@@ -1110,14 +1138,13 @@ void retro_run(void) {
/* Retrieve video */
if (!skip_frame && (audio_video_enable & 1)) {
if (video_hw_mode & VIDEO_GRAPHIC_MODE_REQUEST_SW) {
- const Graphics::Surface *screen;
+ const Graphics::ManagedSurface *screen;
LIBRETRO_G_SYSTEM->getScreen(screen);
video_cb(screen->getPixels(), screen->w, screen->h, screen->pitch);
} else
video_cb(RETRO_HW_FRAME_BUFFER_VALID, LIBRETRO_G_SYSTEM->getScreenWidth(), LIBRETRO_G_SYSTEM->getScreenHeight(), 0);
}
-
current_frame++;
poll_cb();
diff --git a/backends/platform/libretro/src/libretro-graphics-opengl.cpp b/backends/platform/libretro/src/libretro-graphics-opengl.cpp
new file mode 100644
index 00000000000..5613e2b2e68
--- /dev/null
+++ b/backends/platform/libretro/src/libretro-graphics-opengl.cpp
@@ -0,0 +1,67 @@
+/* Copyright (C) 2024 Giovanni Cascione <ing.cascione at gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "backends/graphics/opengl/opengl-graphics.h"
+#include "backends/graphics/opengl/framebuffer.h"
+#include "graphics/opengl/debug.h"
+
+#include "backends/platform/libretro/include/libretro-defs.h"
+#include "backends/platform/libretro/include/libretro-core.h"
+#include "backends/platform/libretro/include/libretro-os.h"
+#include "backends/platform/libretro/include/libretro-timer.h"
+#include "backends/platform/libretro/include/libretro-graphics-opengl.h"
+
+LibretroOpenGLGraphics::LibretroOpenGLGraphics(OpenGL::ContextType contextType) {
+ resetContext(contextType);
+}
+
+void LibretroOpenGLGraphics::refreshScreen(){
+ dynamic_cast<LibretroTimerManager *>(LIBRETRO_G_SYSTEM->getTimerManager())->checkThread(THREAD_SWITCH_UPDATE);
+}
+
+void LibretroOpenGLGraphics::setMousePosition(int x, int y){
+ OpenGL::OpenGLGraphicsManager::setMousePosition(x, y);
+}
+
+void LibretroOpenGLGraphics::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
+ /* Workaround to fix a cursor glich (e.g. GUI with Classic theme) occurring when any overlay is activated from retroarch (e.g. keyboard overlay).
+ Currently no feedback is available from frontend to detect if overlays are toggled to delete _cursor only if needed.
+ @TODO: root cause to be investigated. */
+ delete _cursor;
+ _cursor = nullptr;
+ OpenGL::OpenGLGraphicsManager::setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format, mask);
+}
+
+Common::Point LibretroOpenGLGraphics::convertWindowToVirtual(int x, int y) const {
+ return OpenGL::OpenGLGraphicsManager::convertWindowToVirtual(x, y);
+}
+
+void LibretroHWFramebuffer::activateInternal(){
+ GL_CALL(glBindFramebuffer(GL_FRAMEBUFFER, retro_get_hw_fb()));
+}
+
+void LibretroOpenGLGraphics::resetContext(OpenGL::ContextType contextType) {
+ const Graphics::PixelFormat rgba8888 =
+#ifdef SCUMM_LITTLE_ENDIAN
+ Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
+#else
+ Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
+#endif
+ notifyContextDestroy();
+ notifyContextCreate(contextType, new LibretroHWFramebuffer(), rgba8888, rgba8888);
+ handleResize(RES_W_OVERLAY, RES_H_OVERLAY);
+}
diff --git a/backends/platform/libretro/src/libretro-graphics-surface.cpp b/backends/platform/libretro/src/libretro-graphics-surface.cpp
new file mode 100644
index 00000000000..0285144f06d
--- /dev/null
+++ b/backends/platform/libretro/src/libretro-graphics-surface.cpp
@@ -0,0 +1,232 @@
+/* Copyright (C) 2023 Giovanni Cascione <ing.cascione at gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "graphics/colormasks.h"
+#include "graphics/palette.h"
+#include "graphics/managed_surface.h"
+
+#include "gui/message.h"
+
+#include "backends/platform/libretro/include/libretro-defs.h"
+#include "backends/platform/libretro/include/libretro-core.h"
+#include "backends/platform/libretro/include/libretro-os.h"
+#include "backends/platform/libretro/include/libretro-timer.h"
+#include "backends/platform/libretro/include/libretro-graphics-surface.h"
+
+LibretroGraphics::LibretroGraphics() : _mousePaletteEnabled(false),
+ _mouseVisible(false),
+ _mouseKeyColor(0),
+ _mouseDontScale(false),
+ _screenUpdatePending(false),
+ _gamePalette(256),
+ _mousePalette(256),
+ _screenChangeID(1 << (sizeof(int) * 8 - 2)){}
+
+LibretroGraphics::~LibretroGraphics() {
+ _gameScreen.free();
+ _overlay.free();
+ _mouseImage.free();
+ _screen.free();
+}
+
+Common::List<Graphics::PixelFormat> LibretroGraphics::getSupportedFormats() const {
+ Common::List<Graphics::PixelFormat> result;
+
+#ifdef SCUMM_LITTLE_ENDIAN
+ /* RGBA8888 */
+ result.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
+#else
+ /* ABGR8888 */
+ result.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
+#endif
+ /* RGB565 - overlay */
+ result.push_back(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
+
+ /* RGB555 - fmtowns */
+ result.push_back(Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15));
+
+ /* Palette - most games */
+ result.push_back(Graphics::PixelFormat::createFormatCLUT8());
+
+ return result;
+}
+
+const OSystem::GraphicsMode *LibretroGraphics::getSupportedGraphicsModes() const {
+ static const OSystem::GraphicsMode s_noGraphicsModes[] = {{0, 0, 0}};
+ return s_noGraphicsModes;
+}
+
+void LibretroGraphics::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
+ Graphics::PixelFormat actFormat = format ? *format : Graphics::PixelFormat::createFormatCLUT8();
+
+ /* Override for ScummVM Launcher */
+ if (nullptr == ConfMan.getActiveDomain()){
+ width = RES_W_OVERLAY;
+ height = RES_H_OVERLAY;
+ }
+
+ if (_gameScreen.w != width || _gameScreen.h != height || _gameScreen.format != actFormat)
+ _gameScreen.create(width, height, actFormat);
+
+ if (_overlay.w != width || _overlay.h != height)
+ _overlay.create(width, height, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
+
+ if (getWindowWidth() != width || getWindowHeight() != height) {
+ _screen.create(width, height, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
+ handleResize(width, height);
+ recalculateDisplayAreas();
+ retro_set_size(width, height);
+ LIBRETRO_G_SYSTEM->refreshRetroSettings();
+ ++_screenChangeID;
+ }
+}
+
+int16 LibretroGraphics::getHeight() const {
+ return _gameScreen.h;
+}
+
+int16 LibretroGraphics::getWidth() const {
+ return _gameScreen.w;
+}
+
+Graphics::PixelFormat LibretroGraphics::getScreenFormat() const {
+ return _gameScreen.format;
+}
+
+void LibretroGraphics::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {
+ _gameScreen.copyRectToSurface(buf, pitch, x, y, w, h);
+}
+
+void LibretroGraphics::updateScreen() {
+ _screenUpdatePending = true;
+ if (! retro_setting_get_timing_inaccuracies_enabled() && !_overlayInGUI)
+ dynamic_cast<LibretroTimerManager *>(LIBRETRO_G_SYSTEM->getTimerManager())->checkThread(THREAD_SWITCH_UPDATE);
+}
+
+void LibretroGraphics::realUpdateScreen(void) {
+ const Graphics::Surface &srcSurface = (_overlayInGUI) ? _overlay : _gameScreen;
+
+ if (srcSurface.w && srcSurface.h)
+ _screen.blitFrom(srcSurface, Common::Rect(srcSurface.w,srcSurface.h),Common::Rect(_screen.w,_screen.h),&_gamePalette);
+
+ if (_mouseVisible && _mouseImage.w && _mouseImage.h)
+ _screen.transBlitFrom(_mouseImage, Common::Point(_cursorX - _mouseHotspotX, _cursorY - _mouseHotspotY), _mouseKeyColor, false, 0, 0xff, _mousePaletteEnabled ? &_mousePalette : &_gamePalette);
+
+ _screenUpdatePending = false;
+}
+
+void LibretroGraphics::clearOverlay() {
+ _overlay.fillRect(Common::Rect(_overlay.w, _overlay.h), 0);
+}
+
+void LibretroGraphics::grabOverlay(Graphics::Surface &surface) const {
+ surface.copyFrom(_overlay);
+}
+
+void LibretroGraphics::copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {
+ _overlay.copyRectToSurface(buf, pitch, x, y, w, h);
+}
+
+int16 LibretroGraphics::getOverlayHeight() const {
+ return _overlay.h;
+}
+
+int16 LibretroGraphics::getOverlayWidth() const {
+ return _overlay.w;
+}
+
+Graphics::PixelFormat LibretroGraphics::getOverlayFormat() const {
+ return _overlay.format;
+}
+
+bool LibretroGraphics::showMouse(bool visible) {
+ const bool wasVisible = _mouseVisible;
+ _mouseVisible = visible;
+ return wasVisible;
+}
+
+void LibretroGraphics::warpMouse(int x, int y) {
+ LIBRETRO_G_SYSTEM->_mouseX = x;
+ LIBRETRO_G_SYSTEM->_mouseY = y;
+ WindowedGraphicsManager::warpMouse(x, y);
+}
+
+void LibretroGraphics::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
+ if (!buf || !w || !h)
+ return;
+
+ const Graphics::PixelFormat mformat = format ? *format : Graphics::PixelFormat::createFormatCLUT8();
+
+ if (_mouseImage.w != w || _mouseImage.h != h || _mouseImage.format != mformat){
+ _mouseImage.create(w, h, mformat);
+ }
+
+ _mouseImage.copyRectToSurface(buf, _mouseImage.pitch, 0, 0, w, h);
+
+ _mouseHotspotX = hotspotX;
+ _mouseHotspotY = hotspotY;
+ _mouseKeyColor = keycolor;
+ _mouseDontScale = dontScale;
+}
+
+void LibretroGraphics::setCursorPalette(const byte *colors, uint start, uint num) {
+ _mousePalette.set(colors, start, num);
+ _mousePaletteEnabled = true;
+}
+
+bool LibretroGraphics::isOverlayInGUI(void) {
+ return _overlayInGUI;
+}
+
+const Graphics::ManagedSurface *LibretroGraphics::getScreen() {
+ return &_screen;
+}
+
+void LibretroGraphics::setPalette(const byte *colors, uint start, uint num) {
+ _gamePalette.set(colors, start, num);
+}
+
+void LibretroGraphics::grabPalette(byte *colors, uint start, uint num) const {
+ _gamePalette.grab(colors, start, num);
+}
+
+bool LibretroGraphics::hasFeature(OSystem::Feature f) const {
+ return (f == OSystem::kFeatureCursorPalette) || (f == OSystem::kFeatureCursorAlpha);
+}
+
+void LibretroGraphics::setFeatureState(OSystem::Feature f, bool enable) {
+ if (f == OSystem::kFeatureCursorPalette)
+ _mousePaletteEnabled = enable;
+}
+
+bool LibretroGraphics::getFeatureState(OSystem::Feature f) const {
+ return (f == OSystem::kFeatureCursorPalette) ? _mousePaletteEnabled : false;
+}
+
+void LibretroGraphics::setMousePosition(int x, int y){
+ WindowedGraphicsManager::setMousePosition(x, y);
+}
+
+void LibretroGraphics::displayMessageOnOSD(const Common::U32String &msg) {
+ // Display the message for 3 seconds
+ GUI::TimedMessageDialog dialog(msg, 3000);
+ dialog.runModal();
+}
+
+int LibretroGraphics::getScreenChangeID() const {
+ return _screenChangeID;
+}
diff --git a/backends/platform/libretro/src/libretro-graphics.cpp b/backends/platform/libretro/src/libretro-graphics.cpp
deleted file mode 100644
index a6fd1aa7f7b..00000000000
--- a/backends/platform/libretro/src/libretro-graphics.cpp
+++ /dev/null
@@ -1,504 +0,0 @@
-/* Copyright (C) 2023 Giovanni Cascione <ing.cascione at gmail.com>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <retro_inline.h>
-
-#include "graphics/colormasks.h"
-#include "graphics/palette.h"
-#include "graphics/surface.h"
-
-#include "backends/platform/libretro/include/libretro-defs.h"
-#include "backends/platform/libretro/include/libretro-core.h"
-#include "backends/platform/libretro/include/libretro-os.h"
-#include "backends/platform/libretro/include/libretro-timer.h"
-#include "backends/platform/libretro/include/libretro-graphics.h"
-
-#include "gui/message.h"
-
-#ifdef USE_OPENGL
-#include "backends/graphics/opengl/opengl-graphics.h"
-#include "backends/graphics/opengl/framebuffer.h"
-#include "graphics/opengl/debug.h"
-#endif
-
-static INLINE void blit_uint8_uint16_fast(Graphics::Surface &aOut, const Graphics::Surface &aIn, const LibretroPalette &aColors) {
- for (int i = 0; i < aIn.h; i++) {
- if (i >= aOut.h)
- continue;
-
- uint8 *const in = (uint8 *)aIn.getPixels() + (i * aIn.w);
- uint16 *const out = (uint16 *)aOut.getPixels() + (i * aOut.w);
-
- for (int j = 0; j < aIn.w; j++) {
- if (j >= aOut.w)
- continue;
-
- uint8 r, g, b;
-
- const uint8 val = in[j];
- // if(val != 0xFFFFFFFF)
- {
- if (aIn.format.bytesPerPixel == 1) {
- unsigned char *col = aColors.getColor(val);
- r = *col++;
- g = *col++;
- b = *col++;
- } else
- aIn.format.colorToRGB(in[j], r, g, b);
-
- out[j] = aOut.format.RGBToColor(r, g, b);
- }
- }
- }
-}
-
-static INLINE void blit_uint32_uint16(Graphics::Surface &aOut, const Graphics::Surface &aIn, const LibretroPalette &aColors) {
- for (int i = 0; i < aIn.h; i++) {
- if (i >= aOut.h)
- continue;
-
- uint32 *const in = (uint32 *)aIn.getPixels() + (i * aIn.w);
- uint16 *const out = (uint16 *)aOut.getPixels() + (i * aOut.w);
-
- for (int j = 0; j < aIn.w; j++) {
- if (j >= aOut.w)
- continue;
-
- uint8 r, g, b;
-
- // const uint32 val = in[j];
- // if(val != 0xFFFFFFFF)
- {
- aIn.format.colorToRGB(in[j], r, g, b);
- out[j] = aOut.format.RGBToColor(r, g, b);
- }
- }
- }
-}
-
-static INLINE void blit_uint16_uint16(Graphics::Surface &aOut, const Graphics::Surface &aIn, const LibretroPalette &aColors) {
- for (int i = 0; i < aIn.h; i++) {
- if (i >= aOut.h)
- continue;
-
- uint16 *const in = (uint16 *)aIn.getPixels() + (i * aIn.w);
- uint16 *const out = (uint16 *)aOut.getPixels() + (i * aOut.w);
-
- for (int j = 0; j < aIn.w; j++) {
- if (j >= aOut.w)
- continue;
-
- uint8 r, g, b;
-
- // const uint16 val = in[j];
- // if(val != 0xFFFFFFFF)
- {
- aIn.format.colorToRGB(in[j], r, g, b);
- out[j] = aOut.format.RGBToColor(r, g, b);
- }
- }
- }
-}
-
-static void blit_uint8_uint16(Graphics::Surface &aOut, const Graphics::Surface &aIn, int aX, int aY, const LibretroPalette &aColors, uint32 aKeyColor) {
- for (int i = 0; i < aIn.h; i++) {
- if ((i + aY) < 0 || (i + aY) >= aOut.h)
- continue;
-
- uint8 *const in = (uint8 *)aIn.getPixels() + (i * aIn.w);
- uint16 *const out = (uint16 *)aOut.getPixels() + ((i + aY) * aOut.w);
-
- for (int j = 0; j < aIn.w; j++) {
- if ((j + aX) < 0 || (j + aX) >= aOut.w)
- continue;
-
- uint8 r, g, b;
-
- const uint8 val = in[j];
- if (val != aKeyColor) {
- unsigned char *col = aColors.getColor(val);
- r = *col++;
- g = *col++;
- b = *col++;
- out[j + aX] = aOut.format.RGBToColor(r, g, b);
- }
- }
- }
-}
-
-static void blit_uint16_uint16(Graphics::Surface &aOut, const Graphics::Surface &aIn, int aX, int aY, const LibretroPalette &aColors, uint32 aKeyColor) {
- for (int i = 0; i < aIn.h; i++) {
- if ((i + aY) < 0 || (i + aY) >= aOut.h)
- continue;
-
- uint16 *const in = (uint16 *)aIn.getPixels() + (i * aIn.w);
- uint16 *const out = (uint16 *)aOut.getPixels() + ((i + aY) * aOut.w);
-
- for (int j = 0; j < aIn.w; j++) {
- if ((j + aX) < 0 || (j + aX) >= aOut.w)
- continue;
-
- uint8 r, g, b;
-
- const uint16 val = in[j];
- if (val != aKeyColor) {
- aIn.format.colorToRGB(in[j], r, g, b);
- out[j + aX] = aOut.format.RGBToColor(r, g, b);
- }
- }
- }
-}
-
-static void blit_uint32_uint16(Graphics::Surface &aOut, const Graphics::Surface &aIn, int aX, int aY, const LibretroPalette &aColors, uint32 aKeyColor) {
- for (int i = 0; i < aIn.h; i++) {
- if ((i + aY) < 0 || (i + aY) >= aOut.h)
- continue;
-
- uint32 *const in = (uint32 *)aIn.getPixels() + (i * aIn.w);
- uint16 *const out = (uint16 *)aOut.getPixels() + ((i + aY) * aOut.w);
-
- for (int j = 0; j < aIn.w; j++) {
- if ((j + aX) < 0 || (j + aX) >= aOut.w)
- continue;
-
- uint8 in_a, in_r, in_g, in_b;
- uint8 out_r, out_g, out_b;
- uint32 blend_r, blend_g, blend_b;
-
- const uint32 val = in[j];
- if (val != aKeyColor) {
- aIn.format.colorToARGB(in[j], in_a, in_r, in_g, in_b);
-
- if (in_a) {
- aOut.format.colorToRGB(out[j + aX], out_r, out_g, out_b);
-
- blend_r = ((in_r * in_a) + (out_r * (255 - in_a))) / 255;
- blend_g = ((in_g * in_a) + (out_g * (255 - in_a))) / 255;
- blend_b = ((in_b * in_a) + (out_b * (255 - in_a))) / 255;
-
- out[j + aX] = aOut.format.RGBToColor(blend_r, blend_g, blend_b);
- }
- }
- }
- }
-}
-
-static INLINE void copyRectToSurface(uint8 *pixels, int out_pitch, const uint8 *src, int pitch, int x, int y, int w, int h, int out_bpp) {
- uint8 *dst = pixels + y * out_pitch + x * out_bpp;
-
- do {
- memcpy(dst, src, w * out_bpp);
- src += pitch;
- dst += out_pitch;
- } while (--h);
-}
-
-LibretroPalette::LibretroPalette() : _prevColorsSource(NULL) {
- memset(_colors, 0, sizeof(_colors));
-}
-
-void LibretroPalette::set(const byte *colors, uint start, uint num) {
- /* TODO: This check is a workaround to handle a SEGFAULT in iOS due to the call from SmushPlayer::play in scumm engine,
- caused by the corruption of start argument (and consequently colors ptr). Root cause to be investigated. */
- if (start > 255) {
- start = 0;
- colors = _prevColorsSource;
- } else
- _prevColorsSource = colors;
-
- if (num > 256)
- num = 256;
-
- if (colors)
- memcpy(_colors + start * 3, colors, num * 3);
- else
- LIBRETRO_G_SYSTEM->logMessage(LogMessageType::kError, "LibretroPalette colors ptr is NULL\n");
-}
-
-void LibretroPalette::get(byte *colors, uint start, uint num) const {
- memcpy(colors, _colors + start * 3, num * 3);
-}
-
-unsigned char *LibretroPalette::getColor(uint aIndex) const {
- return (unsigned char *)&_colors[aIndex * 3];
-}
-
-LibretroGraphics::LibretroGraphics() : _mousePaletteEnabled(false), _mouseVisible(false), _mouseKeyColor(0), _mouseDontScale(false), _screenUpdatePending(false) {
- _overlay.create(RES_W_OVERLAY, RES_H_OVERLAY, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
-}
-
-LibretroGraphics::~LibretroGraphics() {
- _gameScreen.free();
- _overlay.free();
- _mouseImage.free();
- _screen.free();
-}
-
-Common::List<Graphics::PixelFormat> LibretroGraphics::getSupportedFormats() const {
- Common::List<Graphics::PixelFormat> result;
-
-#ifdef SCUMM_LITTLE_ENDIAN
- /* RGBA8888 */
- result.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0));
-#else
- /* ABGR8888 */
- result.push_back(Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24));
-#endif
- /* RGB565 - overlay */
- result.push_back(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
-
- /* RGB555 - fmtowns */
- result.push_back(Graphics::PixelFormat(2, 5, 5, 5, 1, 10, 5, 0, 15));
-
- /* Palette - most games */
- result.push_back(Graphics::PixelFormat::createFormatCLUT8());
-
- return result;
-}
-
-const OSystem::GraphicsMode *LibretroGraphics::getSupportedGraphicsModes() const {
- static const OSystem::GraphicsMode s_noGraphicsModes[] = {{0, 0, 0}};
- return s_noGraphicsModes;
-}
-
-void LibretroGraphics::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
- _gameScreen.create(width, height, format ? *format : Graphics::PixelFormat::createFormatCLUT8());
- LIBRETRO_G_SYSTEM->refreshRetroSettings();
-}
-
-int16 LibretroGraphics::getHeight() const {
- return _gameScreen.h;
-}
-
-int16 LibretroGraphics::getWidth() const {
- return _gameScreen.w;
-}
-
-Graphics::PixelFormat LibretroGraphics::getScreenFormat() const {
- return _gameScreen.format;
-}
-
-void LibretroGraphics::copyRectToScreen(const void *buf, int pitch, int x, int y, int w, int h) {
- const uint8 *src = (const uint8 *)buf;
- uint8 *pix = (uint8 *)_gameScreen.getPixels();
- copyRectToSurface(pix, _gameScreen.pitch, src, pitch, x, y, w, h, _gameScreen.format.bytesPerPixel);
-}
-
-void LibretroGraphics::updateScreen() {
- _screenUpdatePending = true;
- if (! retro_setting_get_timing_inaccuracies_enabled() && !_overlayInGUI)
- dynamic_cast<LibretroTimerManager *>(LIBRETRO_G_SYSTEM->getTimerManager())->checkThread(THREAD_SWITCH_UPDATE);
-}
-
-void LibretroGraphics::realUpdateScreen(void) {
- const Graphics::Surface &srcSurface = (_overlayInGUI) ? _overlay : _gameScreen;
- if (srcSurface.w && srcSurface.h) {
- switch (srcSurface.format.bytesPerPixel) {
- case 1:
- case 3:
- blit_uint8_uint16_fast(_screen, srcSurface, _gamePalette);
- break;
- case 2:
- blit_uint16_uint16(_screen, srcSurface, _gamePalette);
- break;
- case 4:
- blit_uint32_uint16(_screen, srcSurface, _gamePalette);
- break;
- }
- }
-
- // Draw Mouse
- if (_mouseVisible && _mouseImage.w && _mouseImage.h) {
- const int x = LIBRETRO_G_SYSTEM->_mouseX - _mouseHotspotX;
- const int y = LIBRETRO_G_SYSTEM->_mouseY - _mouseHotspotY;
-
- switch (_mouseImage.format.bytesPerPixel) {
- case 1:
- case 3:
- blit_uint8_uint16(_screen, _mouseImage, x, y, _mousePaletteEnabled ? _mousePalette : _gamePalette, _mouseKeyColor);
- break;
- case 2:
- blit_uint16_uint16(_screen, _mouseImage, x, y, _mousePaletteEnabled ? _mousePalette : _gamePalette, _mouseKeyColor);
- break;
- case 4:
- blit_uint32_uint16(_screen, _mouseImage, x, y, _mousePaletteEnabled ? _mousePalette : _gamePalette, _mouseKeyColor);
- break;
- }
- }
- _screenUpdatePending = false;
-}
-
-void LibretroGraphics::showOverlay(bool inGUI) {
- _overlayVisible = true;
- _overlayInGUI = inGUI;
-}
-
-void LibretroGraphics::hideOverlay() {
- _overlayVisible = false;
- _overlayInGUI = false;
-}
-
-void LibretroGraphics::clearOverlay() {
- _overlay.fillRect(Common::Rect(_overlay.w, _overlay.h), 0);
-}
-
-void LibretroGraphics::grabOverlay(Graphics::Surface &surface) const {
- const unsigned char *src = (unsigned char *)_overlay.getPixels();
- unsigned char *dst = (byte *)surface.getPixels();
- ;
- unsigned i = RES_H_OVERLAY;
-
- do {
- memcpy(dst, src, RES_W_OVERLAY << 1);
- dst += surface.pitch;
- src += RES_W_OVERLAY << 1;
- } while (--i);
-}
-
-void LibretroGraphics::copyRectToOverlay(const void *buf, int pitch, int x, int y, int w, int h) {
- const uint8 *src = (const uint8 *)buf;
- uint8 *pix = (uint8 *)_overlay.getPixels();
- copyRectToSurface(pix, _overlay.pitch, src, pitch, x, y, w, h, _overlay.format.bytesPerPixel);
-}
-
-int16 LibretroGraphics::getOverlayHeight() const {
- return _overlay.h;
-}
-
-int16 LibretroGraphics::getOverlayWidth() const {
- return _overlay.w;
-}
-
-Graphics::PixelFormat LibretroGraphics::getOverlayFormat() const {
- return _overlay.format;
-}
-
-bool LibretroGraphics::showMouse(bool visible) {
- const bool wasVisible = _mouseVisible;
- _mouseVisible = visible;
- return wasVisible;
-}
-
-void LibretroGraphics::warpMouse(int x, int y) {
- LIBRETRO_G_SYSTEM->_mouseX = x;
- LIBRETRO_G_SYSTEM->_mouseY = y;
-}
-
-void LibretroGraphics::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
- const Graphics::PixelFormat mformat = format ? *format : Graphics::PixelFormat::createFormatCLUT8();
-
- if (_mouseImage.w != w || _mouseImage.h != h || _mouseImage.format != mformat) {
- _mouseImage.create(w, h, mformat);
- }
-
- memcpy(_mouseImage.getPixels(), buf, h * _mouseImage.pitch);
-
- _mouseHotspotX = hotspotX;
- _mouseHotspotY = hotspotY;
- _mouseKeyColor = keycolor;
- _mouseDontScale = dontScale;
-}
-
-void LibretroGraphics::setCursorPalette(const byte *colors, uint start, uint num) {
- _mousePalette.set(colors, start, num);
- _mousePaletteEnabled = true;
-}
-
-bool LibretroGraphics::isOverlayInGUI(void) {
- return _overlayInGUI;
-}
-
-const Graphics::Surface *LibretroGraphics::getScreen() {
- const Graphics::Surface &srcSurface = (_overlayInGUI) ? _overlay : _gameScreen;
-
- if (srcSurface.w != _screen.w || srcSurface.h != _screen.h)
- _screen.create(srcSurface.w, srcSurface.h, Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
-
- return &_screen;
-}
-
-void LibretroGraphics::setPalette(const byte *colors, uint start, uint num) {
- _gamePalette.set(colors, start, num);
-}
-
-void LibretroGraphics::grabPalette(byte *colors, uint start, uint num) const {
- _gamePalette.get(colors, start, num);
-}
-
-bool LibretroGraphics::hasFeature(OSystem::Feature f) const {
- return (f == OSystem::kFeatureCursorPalette) || (f == OSystem::kFeatureCursorAlpha);
-}
-
-void LibretroGraphics::setFeatureState(OSystem::Feature f, bool enable) {
- if (f == OSystem::kFeatureCursorPalette)
- _mousePaletteEnabled = enable;
-}
-
-void LibretroGraphics::displayMessageOnOSD(const Common::U32String &msg) {
- // Display the message for 3 seconds
- GUI::TimedMessageDialog dialog(msg, 3000);
- dialog.runModal();
-}
-
-bool LibretroGraphics::getFeatureState(OSystem::Feature f) const {
- return (f == OSystem::kFeatureCursorPalette) ? _mousePaletteEnabled : false;
-}
-
-#ifdef USE_OPENGL
-LibretroOpenGLGraphics::LibretroOpenGLGraphics(OpenGL::ContextType contextType) {
- resetContext(contextType);
-}
-
-void LibretroOpenGLGraphics::refreshScreen(){
- dynamic_cast<LibretroTimerManager *>(LIBRETRO_G_SYSTEM->getTimerManager())->checkThread(THREAD_SWITCH_UPDATE);
-}
-
-void LibretroOpenGLGraphics::setMousePosition(int x, int y){
- OpenGL::OpenGLGraphicsManager::setMousePosition(x,y);
-}
-
-void LibretroOpenGLGraphics::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
- /* Workaround to fix a cursor glich (e.g. GUI with Classic theme) occurring when any overlay is activated from retroarch (e.g. keyboard overlay).
- Currently no feedback is available from frontend to detect if overlays are toggled to delete _cursor only if needed.
- @TODO: root cause to be investigated. */
- delete _cursor;
- _cursor = nullptr;
- OpenGL::OpenGLGraphicsManager::setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format, mask);
-}
-
-
-Common::Point LibretroOpenGLGraphics::convertWindowToVirtual(int x, int y) const {
- return OpenGL::OpenGLGraphicsManager::convertWindowToVirtual(x, y);
-}
-
-void LibretroHWFramebuffer::activateInternal(){
- GL_CALL(glBindFramebuffer(GL_FRAMEBUFFER, retro_get_hw_fb()));
-}
-
-void LibretroOpenGLGraphics::resetContext(OpenGL::ContextType contextType) {
- const Graphics::PixelFormat rgba8888 =
-#ifdef SCUMM_LITTLE_ENDIAN
- Graphics::PixelFormat(4, 8, 8, 8, 8, 0, 8, 16, 24);
-#else
- Graphics::PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
-#endif
- notifyContextDestroy();
- notifyContextCreate(contextType, new LibretroHWFramebuffer(), rgba8888, rgba8888);
- handleResize(RES_W_OVERLAY, RES_H_OVERLAY);
-}
-
-#endif
diff --git a/backends/platform/libretro/src/libretro-os-base.cpp b/backends/platform/libretro/src/libretro-os-base.cpp
index 21ed77fb049..bdc090ebe0c 100644
--- a/backends/platform/libretro/src/libretro-os-base.cpp
+++ b/backends/platform/libretro/src/libretro-os-base.cpp
@@ -37,7 +37,10 @@
#include "backends/platform/libretro/include/libretro-timer.h"
#include "backends/platform/libretro/include/libretro-os.h"
#include "backends/platform/libretro/include/libretro-fs.h"
-#include "backends/platform/libretro/include/libretro-graphics.h"
+#include "backends/platform/libretro/include/libretro-graphics-surface.h"
+#ifdef USE_OPENGL
+#include "backends/platform/libretro/include/libretro-graphics-opengl.h"
+#endif
OSystem_libretro::OSystem_libretro() : _mouseX(0), _mouseY(0), _mouseXAcc(0.0), _mouseYAcc(0.0), _dpadXAcc(0.0), _dpadYAcc(0.0), _dpadXVel(0.0f), _dpadYVel(0.0f), _mixer(0), _startTime(0), _cursorStatus(0) {
_fsFactory = new FS_SYSTEM_FACTORY();
@@ -125,10 +128,10 @@ void OSystem_libretro::engineInit() {
}
/* See LibretroPalette::set workaround */
- if (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_SW){
+ /*if (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_SW){
dynamic_cast<LibretroGraphics *>(_graphicsManager)->_mousePalette.reset();
dynamic_cast<LibretroGraphics *>(_graphicsManager)->_gamePalette.reset();
- }
+ }*/
}
Audio::Mixer *OSystem_libretro::getMixer() {
@@ -167,7 +170,7 @@ void OSystem_libretro::setLibretroDir(const char * path, Common::String &var) {
return;
}
-void OSystem_libretro::getScreen(const Graphics::Surface *&screen) {
+void OSystem_libretro::getScreen(const Graphics::ManagedSurface *&screen) {
if (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_SW)
screen = dynamic_cast<LibretroGraphics *>(_graphicsManager)->getScreen();
}
@@ -178,10 +181,11 @@ void OSystem_libretro::refreshScreen(void) {
}
#ifdef USE_OPENGL
+#ifdef USE_GLAD
void *OSystem_libretro::getOpenGLProcAddress(const char *name) const {
return retro_get_proc_address(name);
}
-
+#endif
void OSystem_libretro::resetGraphicsContext(void) {
if ((retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_HW) && (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_HAVE_OPENGL))
dynamic_cast<LibretroOpenGLGraphics *>(_graphicsManager)->resetContext(OpenGL::kContextGL);
@@ -191,25 +195,11 @@ void OSystem_libretro::resetGraphicsContext(void) {
#endif
int16 OSystem_libretro::getScreenWidth(void){
-#ifdef USE_OPENGL
- if (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_HW)
- return dynamic_cast<LibretroOpenGLGraphics *>(_graphicsManager)->getWindowWidth();
-#endif
- if (dynamic_cast<LibretroGraphics *>(_graphicsManager)->isOverlayInGUI())
- return dynamic_cast<LibretroGraphics *>(_graphicsManager)->getOverlayWidth();
- else
- return dynamic_cast<LibretroGraphics *>(_graphicsManager)->getWidth();
+ return dynamic_cast<WindowedGraphicsManager *>(_graphicsManager)->getWindowWidth();
}
int16 OSystem_libretro::getScreenHeight(void){
-#ifdef USE_OPENGL
- if (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_HW)
- return dynamic_cast<LibretroOpenGLGraphics *>(_graphicsManager)->getWindowHeight();
-#endif
- if (dynamic_cast<LibretroGraphics *>(_graphicsManager)->isOverlayInGUI())
- return dynamic_cast<LibretroGraphics *>(_graphicsManager)->getOverlayHeight();
- else
- return dynamic_cast<LibretroGraphics *>(_graphicsManager)->getHeight();
+ return dynamic_cast<WindowedGraphicsManager *>(_graphicsManager)->getWindowHeight();
}
bool OSystem_libretro::isOverlayInGUI(void) {
diff --git a/backends/platform/libretro/src/libretro-os-events.cpp b/backends/platform/libretro/src/libretro-os-events.cpp
index a5c6066fec5..ea86b1860a4 100644
--- a/backends/platform/libretro/src/libretro-os-events.cpp
+++ b/backends/platform/libretro/src/libretro-os-events.cpp
@@ -25,7 +25,10 @@
#include "backends/platform/libretro/include/libretro-core.h"
#include "backends/platform/libretro/include/libretro-os.h"
#include "backends/platform/libretro/include/libretro-timer.h"
-#include "backends/platform/libretro/include/libretro-graphics.h"
+#include "backends/platform/libretro/include/libretro-graphics-surface.h"
+#ifdef USE_OPENGL
+#include "backends/platform/libretro/include/libretro-graphics-opengl.h"
+#endif
bool OSystem_libretro::pollEvent(Common::Event &event) {
((LibretroTimerManager *)_timerManager)->checkThread(THREAD_SWITCH_POLL);
@@ -77,20 +80,22 @@ Common::MutexInternal *OSystem_libretro::createMutex(void) {
}
void OSystem_libretro::requestQuit() {
- Common::Event ev;
- ev.type = Common::EVENT_QUIT;
- LIBRETRO_G_SYSTEM->getEventManager()->pushEvent(ev);
+ Common::Event ev;
+ ev.type = Common::EVENT_QUIT;
+ LIBRETRO_G_SYSTEM->getEventManager()->pushEvent(ev);
}
void OSystem_libretro::resetQuit() {
- LIBRETRO_G_SYSTEM->getEventManager()->resetQuit();
+ LIBRETRO_G_SYSTEM->getEventManager()->resetQuit();
}
void OSystem_libretro::setMousePosition(int x, int y) {
#ifdef USE_OPENGL
if (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_HW)
dynamic_cast<LibretroOpenGLGraphics *>(_graphicsManager)->setMousePosition(x, y);
+ else
#endif
+ dynamic_cast<LibretroGraphics *>(_graphicsManager)->setMousePosition(x, y);
}
Common::Point OSystem_libretro::convertWindowToVirtual(int x, int y) const {
@@ -99,5 +104,5 @@ Common::Point OSystem_libretro::convertWindowToVirtual(int x, int y) const {
return dynamic_cast<LibretroOpenGLGraphics *>(_graphicsManager)->convertWindowToVirtual(x, y);
else
#endif
- return Common::Point(x, y);
+ return dynamic_cast<LibretroGraphics *>(_graphicsManager)->convertWindowToVirtual(x, y);
}
diff --git a/backends/platform/libretro/src/libretro-os-inputs.cpp b/backends/platform/libretro/src/libretro-os-inputs.cpp
index d605cfcac95..7607ee11cc2 100644
--- a/backends/platform/libretro/src/libretro-os-inputs.cpp
+++ b/backends/platform/libretro/src/libretro-os-inputs.cpp
@@ -22,7 +22,10 @@
#include "backends/platform/libretro/include/libretro-os.h"
#include "backends/platform/libretro/include/libretro-mapper.h"
#include "backends/platform/libretro/include/libretro-core.h"
-#include "backends/platform/libretro/include/libretro-graphics.h"
+#include "backends/platform/libretro/include/libretro-graphics-surface.h"
+#ifdef USE_OPENGL
+#include "backends/platform/libretro/include/libretro-graphics-opengl.h"
+#endif
void OSystem_libretro::updateMouseXY(float deltaAcc, float *cumulativeXYAcc, int doing_x) {
int *mouseXY;
@@ -149,7 +152,7 @@ void OSystem_libretro::processInputs(void) {
getMouseXYFromButton(false, y_coor_cursor);
if (_cursorStatus & CURSOR_STATUS_DOING_JOYSTICK) {
- Common::Point mouse = convertWindowToVirtual(_mouseX,_mouseY);
+ Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = Common::EVENT_MOUSEMOVE;
ev.mouse.x = mouse.x;
@@ -177,7 +180,7 @@ void OSystem_libretro::processInputs(void) {
// Handle mouse buttons
retropad_value = mapper_get_mapper_key_status(RETROKE_LEFT_BUTTON);
if (retropad_value & (1 << RETRO_DEVICE_KEY_CHANGED)) {
- Common::Point mouse = convertWindowToVirtual(_mouseX,_mouseY);
+ Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = eventID[0][(retropad_value & (1 << RETRO_DEVICE_KEY_STATUS)) ? 0 : 1];
ev.mouse.x = mouse.x;
@@ -187,7 +190,7 @@ void OSystem_libretro::processInputs(void) {
retropad_value = mapper_get_mapper_key_status(RETROKE_RIGHT_BUTTON);
if (retropad_value & (1 << RETRO_DEVICE_KEY_CHANGED)) {
- Common::Point mouse = convertWindowToVirtual(_mouseX,_mouseY);
+ Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = eventID[1][(retropad_value & (1 << RETRO_DEVICE_KEY_STATUS)) ? 0 : 1];
ev.mouse.x = mouse.x;
@@ -242,7 +245,7 @@ void OSystem_libretro::processInputs(void) {
}
if (ptrhold > 10 && _ptrmouseButton == 0) {
- Common::Point mouse = convertWindowToVirtual(_mouseX,_mouseY);
+ Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
_ptrmouseButton = 1;
Common::Event ev;
ev.type = eventID[0][_ptrmouseButton ? 0 : 1];
@@ -250,7 +253,7 @@ void OSystem_libretro::processInputs(void) {
ev.mouse.y = mouse.y;
_events.push_back(ev);
} else if (ptrhold == 0 && _ptrmouseButton == 1) {
- Common::Point mouse = convertWindowToVirtual(_mouseX,_mouseY);
+ Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
_ptrmouseButton = 0;
Common::Event ev;
ev.type = eventID[0][_ptrmouseButton ? 0 : 1];
@@ -295,7 +298,7 @@ void OSystem_libretro::processInputs(void) {
}
if (_cursorStatus & CURSOR_STATUS_DOING_MOUSE) {
- Common::Point mouse = convertWindowToVirtual(_mouseX,_mouseY);
+ Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = Common::EVENT_MOUSEMOVE;
ev.mouse.x = mouse.x;
@@ -307,7 +310,7 @@ void OSystem_libretro::processInputs(void) {
}
for (int i = 0; i < 2; i++) {
- Common::Point mouse = convertWindowToVirtual(_mouseX,_mouseY);
+ Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
bool down = retro_input_cb(0, RETRO_DEVICE_MOUSE, 0, retroButtons[i]);
if (down != _mouseButtons[i]) {
Commit: 79e0d08e917538cf964c42a712325dc8a5a54d0a
https://github.com/scummvm/scummvm/commit/79e0d08e917538cf964c42a712325dc8a5a54d0a
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2024-10-22T19:39:10+02:00
Commit Message:
LIBRETRO: JANITORIAL: cleanup
Changed paths:
backends/platform/libretro/include/libretro-graphics-surface.h
backends/platform/libretro/src/libretro-graphics-surface.cpp
backends/platform/libretro/src/libretro-os-inputs.cpp
diff --git a/backends/platform/libretro/include/libretro-graphics-surface.h b/backends/platform/libretro/include/libretro-graphics-surface.h
index f5471892e61..b12fbf5b319 100644
--- a/backends/platform/libretro/include/libretro-graphics-surface.h
+++ b/backends/platform/libretro/include/libretro-graphics-surface.h
@@ -33,8 +33,6 @@ public:
Graphics::Palette _gamePalette;
private:
- //bool _overlayInGUI;
- bool _overlayVisible;
bool _mouseDontScale;
bool _mousePaletteEnabled;
bool _mouseVisible;
diff --git a/backends/platform/libretro/src/libretro-graphics-surface.cpp b/backends/platform/libretro/src/libretro-graphics-surface.cpp
index 0285144f06d..d30ca7d5c27 100644
--- a/backends/platform/libretro/src/libretro-graphics-surface.cpp
+++ b/backends/platform/libretro/src/libretro-graphics-surface.cpp
@@ -171,9 +171,8 @@ void LibretroGraphics::setMouseCursor(const void *buf, uint w, uint h, int hotsp
const Graphics::PixelFormat mformat = format ? *format : Graphics::PixelFormat::createFormatCLUT8();
- if (_mouseImage.w != w || _mouseImage.h != h || _mouseImage.format != mformat){
+ if (_mouseImage.w != w || _mouseImage.h != h || _mouseImage.format != mformat)
_mouseImage.create(w, h, mformat);
- }
_mouseImage.copyRectToSurface(buf, _mouseImage.pitch, 0, 0, w, h);
diff --git a/backends/platform/libretro/src/libretro-os-inputs.cpp b/backends/platform/libretro/src/libretro-os-inputs.cpp
index 7607ee11cc2..42407e6063f 100644
--- a/backends/platform/libretro/src/libretro-os-inputs.cpp
+++ b/backends/platform/libretro/src/libretro-os-inputs.cpp
@@ -160,7 +160,7 @@ void OSystem_libretro::processInputs(void) {
ev.relMouse.x = _cursorStatus & CURSOR_STATUS_DOING_X ? _relMouseX : 0;
ev.relMouse.y = _cursorStatus & CURSOR_STATUS_DOING_Y ? _relMouseY : 0;
_events.push_back(ev);
- setMousePosition(_mouseX,_mouseY);
+ setMousePosition(_mouseX, _mouseY);
}
// Handle special functions
@@ -241,7 +241,7 @@ void OSystem_libretro::processInputs(void) {
ev.mouse.x = _mouseX;
ev.mouse.y = _mouseY;
_events.push_back(ev);
- setMousePosition(_mouseX,_mouseY);
+ setMousePosition(_mouseX, _mouseY);
}
if (ptrhold > 10 && _ptrmouseButton == 0) {
@@ -306,7 +306,7 @@ void OSystem_libretro::processInputs(void) {
ev.relMouse.x = _cursorStatus & CURSOR_STATUS_DOING_X ? _relMouseX : 0;
ev.relMouse.y = _cursorStatus & CURSOR_STATUS_DOING_Y ? _relMouseY : 0;
_events.push_back(ev);
- setMousePosition(_mouseX,_mouseY);
+ setMousePosition(_mouseX, _mouseY);
}
for (int i = 0; i < 2; i++) {
Commit: 35f9f7eb715c356e8697d520ac795dc655572fc2
https://github.com/scummvm/scummvm/commit/35f9f7eb715c356e8697d520ac795dc655572fc2
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2024-10-22T19:39:37+02:00
Commit Message:
LIBRETRO: handle resizing to native res in hw rendering
Changed paths:
backends/platform/libretro/include/libretro-graphics-opengl.h
backends/platform/libretro/include/libretro-os.h
backends/platform/libretro/include/portdefs.h
backends/platform/libretro/src/libretro-core.cpp
backends/platform/libretro/src/libretro-graphics-opengl.cpp
backends/platform/libretro/src/libretro-os-events.cpp
backends/platform/libretro/src/libretro-os-inputs.cpp
diff --git a/backends/platform/libretro/include/libretro-graphics-opengl.h b/backends/platform/libretro/include/libretro-graphics-opengl.h
index 380762bdacf..e7c7f5daf42 100644
--- a/backends/platform/libretro/include/libretro-graphics-opengl.h
+++ b/backends/platform/libretro/include/libretro-graphics-opengl.h
@@ -19,6 +19,11 @@
#define BACKENDS_LIBRETRO_GRAPHICS_OPENGL_H
#include "backends/graphics/opengl/opengl-graphics.h"
+#include "backends/graphics/opengl/texture.h"
+
+namespace OpenGL {
+ class Surface;
+}
class LibretroOpenGLGraphics : public OpenGL::OpenGLGraphicsManager {
public:
@@ -27,11 +32,12 @@ public:
void refreshScreen() override;
void setSystemMousePosition(const int x, const int y) override {};
void setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) override;
-
+ void initSize(uint width, uint height, const Graphics::PixelFormat *format) override;
bool isOverlayInGUI(void){ return _overlayInGUI; }
void setMousePosition(int x, int y);
- Common::Point convertWindowToVirtual(int x, int y) const;
void resetContext(OpenGL::ContextType contextType);
+protected:
+ bool gameNeedsAspectRatioCorrection() const override { return false; }
};
class LibretroHWFramebuffer : public OpenGL::Backbuffer {
diff --git a/backends/platform/libretro/include/libretro-os.h b/backends/platform/libretro/include/libretro-os.h
index e1a3aca0045..87d5315b420 100644
--- a/backends/platform/libretro/include/libretro-os.h
+++ b/backends/platform/libretro/include/libretro-os.h
@@ -114,7 +114,6 @@ public:
void resetQuit(void);
void setMousePosition(int x, int y);
- Common::Point convertWindowToVirtual(int x, int y) const;
/* Utils */
void getTimeAndDate(TimeDate &t, bool skipRecord) const override;
diff --git a/backends/platform/libretro/include/portdefs.h b/backends/platform/libretro/include/portdefs.h
index b0fe12aee60..8ad8b823305 100644
--- a/backends/platform/libretro/include/portdefs.h
+++ b/backends/platform/libretro/include/portdefs.h
@@ -38,15 +38,12 @@
This conflicts with the use of _X as a variable name. */
#undef _X
-#define RES_W 640
-#define RES_H 480
-
#if defined(DINGUX) || defined(_3DS)
#define RES_W_OVERLAY 320
-#define RES_H_OVERLAY 240
+#define RES_H_OVERLAY 200
#else
#define RES_W_OVERLAY 640
-#define RES_H_OVERLAY 480
+#define RES_H_OVERLAY 400
#endif
// HACK: With MinGW, GRIM engine seems to crash when using setjmp and longjmp if not using builtin versions
diff --git a/backends/platform/libretro/src/libretro-core.cpp b/backends/platform/libretro/src/libretro-core.cpp
index 4551d951ace..bc89c5c4381 100644
--- a/backends/platform/libretro/src/libretro-core.cpp
+++ b/backends/platform/libretro/src/libretro-core.cpp
@@ -83,17 +83,16 @@ char cmd_params_num;
static uint8 video_hw_mode = 0;
-static unsigned base_width = RES_W;
-static unsigned base_height = RES_H;
-static unsigned max_width = RES_W;
-static unsigned max_height = RES_H;
+static unsigned base_width = RES_W_OVERLAY;
+static unsigned base_height = RES_H_OVERLAY;
+static unsigned max_width = RES_W_OVERLAY;
+static unsigned max_height = RES_H_OVERLAY;
static uint32 current_frame = 0;
static uint8 frameskip_no;
static uint8 frameskip_type;
static uint8 frameskip_threshold;
static uint32 frameskip_counter = 0;
-static uint8 frameskip_events = 0;
static uint8 audio_status = AUDIO_STATUS_MUTE;
@@ -144,7 +143,7 @@ static void setup_hw_rendering(void) {
retro_log_cb(RETRO_LOG_WARN, "RETRO_PIXEL_FORMAT_XRGB8888 not supported.\n");
hw_render.context_reset = context_reset;
hw_render.context_destroy = context_destroy;
- hw_render.cache_context = true;
+ hw_render.cache_context = false;
hw_render.bottom_left_origin = true;
#if defined(HAVE_OPENGL)
hw_render.context_type = RETRO_HW_CONTEXT_OPENGL;
@@ -842,7 +841,7 @@ void retro_get_system_av_info(struct retro_system_av_info *info) {
info->geometry.base_height = base_height;
info->geometry.max_width = max_width;
info->geometry.max_height = max_height;
- info->geometry.aspect_ratio = 4.0f / 3.0f;
+ info->geometry.aspect_ratio = (float)base_width / (float)base_height;
info->timing.fps = frame_rate;
info->timing.sample_rate = sample_rate;
}
@@ -1067,10 +1066,12 @@ void retro_run(void) {
environ_cb(RETRO_ENVIRONMENT_SET_GEOMETRY, &info);
audio_status &= ~AUDIO_STATUS_UPDATE_GEOMETRY;
} else {
- printf("\retro_run\n");
environ_cb(RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO, &info);
audio_status &= ~AUDIO_STATUS_UPDATE_AV_INFO;
}
+#ifdef USE_OPENGL
+ context_reset();
+#endif
}
if (audio_status & AUDIO_STATUS_UPDATE_LATENCY) {
diff --git a/backends/platform/libretro/src/libretro-graphics-opengl.cpp b/backends/platform/libretro/src/libretro-graphics-opengl.cpp
index 5613e2b2e68..630d098c713 100644
--- a/backends/platform/libretro/src/libretro-graphics-opengl.cpp
+++ b/backends/platform/libretro/src/libretro-graphics-opengl.cpp
@@ -14,7 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-
#include "backends/graphics/opengl/opengl-graphics.h"
#include "backends/graphics/opengl/framebuffer.h"
#include "graphics/opengl/debug.h"
@@ -25,6 +24,8 @@
#include "backends/platform/libretro/include/libretro-timer.h"
#include "backends/platform/libretro/include/libretro-graphics-opengl.h"
+#include "gui/gui-manager.h"
+
LibretroOpenGLGraphics::LibretroOpenGLGraphics(OpenGL::ContextType contextType) {
resetContext(contextType);
}
@@ -38,7 +39,7 @@ void LibretroOpenGLGraphics::setMousePosition(int x, int y){
}
void LibretroOpenGLGraphics::setMouseCursor(const void *buf, uint w, uint h, int hotspotX, int hotspotY, uint32 keycolor, bool dontScale, const Graphics::PixelFormat *format, const byte *mask) {
- /* Workaround to fix a cursor glich (e.g. GUI with Classic theme) occurring when any overlay is activated from retroarch (e.g. keyboard overlay).
+ /* Workaround to fix a cursor glitch (e.g. GUI with Classic theme) occurring when any overlay is activated from retroarch (e.g. keyboard overlay).
Currently no feedback is available from frontend to detect if overlays are toggled to delete _cursor only if needed.
@TODO: root cause to be investigated. */
delete _cursor;
@@ -46,8 +47,16 @@ void LibretroOpenGLGraphics::setMouseCursor(const void *buf, uint w, uint h, int
OpenGL::OpenGLGraphicsManager::setMouseCursor(buf, w, h, hotspotX, hotspotY, keycolor, dontScale, format, mask);
}
-Common::Point LibretroOpenGLGraphics::convertWindowToVirtual(int x, int y) const {
- return OpenGL::OpenGLGraphicsManager::convertWindowToVirtual(x, y);
+void LibretroOpenGLGraphics::initSize(uint width, uint height, const Graphics::PixelFormat *format) {
+ /* Override for ScummVM Launcher */
+ if (nullptr == ConfMan.getActiveDomain()){
+ width = RES_W_OVERLAY;
+ height = RES_H_OVERLAY;
+ }
+ retro_set_size(width, height);
+ handleResize(width, height);
+ OpenGL::OpenGLGraphicsManager::initSize(width, height, format);
+ LIBRETRO_G_SYSTEM->refreshRetroSettings();
}
void LibretroHWFramebuffer::activateInternal(){
@@ -63,5 +72,7 @@ void LibretroOpenGLGraphics::resetContext(OpenGL::ContextType contextType) {
#endif
notifyContextDestroy();
notifyContextCreate(contextType, new LibretroHWFramebuffer(), rgba8888, rgba8888);
- handleResize(RES_W_OVERLAY, RES_H_OVERLAY);
+
+ if (_overlayInGUI)
+ g_gui.scheduleFullRedraw();
}
diff --git a/backends/platform/libretro/src/libretro-os-events.cpp b/backends/platform/libretro/src/libretro-os-events.cpp
index ea86b1860a4..a3f0d36c99b 100644
--- a/backends/platform/libretro/src/libretro-os-events.cpp
+++ b/backends/platform/libretro/src/libretro-os-events.cpp
@@ -97,12 +97,3 @@ void OSystem_libretro::setMousePosition(int x, int y) {
#endif
dynamic_cast<LibretroGraphics *>(_graphicsManager)->setMousePosition(x, y);
}
-
-Common::Point OSystem_libretro::convertWindowToVirtual(int x, int y) const {
-#ifdef USE_OPENGL
- if (retro_get_video_hw_mode() & VIDEO_GRAPHIC_MODE_REQUEST_HW)
- return dynamic_cast<LibretroOpenGLGraphics *>(_graphicsManager)->convertWindowToVirtual(x, y);
- else
-#endif
- return dynamic_cast<LibretroGraphics *>(_graphicsManager)->convertWindowToVirtual(x, y);
-}
diff --git a/backends/platform/libretro/src/libretro-os-inputs.cpp b/backends/platform/libretro/src/libretro-os-inputs.cpp
index 42407e6063f..33eef5030ad 100644
--- a/backends/platform/libretro/src/libretro-os-inputs.cpp
+++ b/backends/platform/libretro/src/libretro-os-inputs.cpp
@@ -17,7 +17,6 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_strcpy
#define FORBIDDEN_SYMBOL_EXCEPTION_strcat
-//#include "backends/platform/libretro/include/config.h"
#include "backends/platform/libretro/include/libretro-defs.h"
#include "backends/platform/libretro/include/libretro-os.h"
#include "backends/platform/libretro/include/libretro-mapper.h"
@@ -152,11 +151,10 @@ void OSystem_libretro::processInputs(void) {
getMouseXYFromButton(false, y_coor_cursor);
if (_cursorStatus & CURSOR_STATUS_DOING_JOYSTICK) {
- Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = Common::EVENT_MOUSEMOVE;
- ev.mouse.x = mouse.x;
- ev.mouse.y = mouse.y;
+ ev.mouse.x = _mouseX;
+ ev.mouse.y = _mouseY;
ev.relMouse.x = _cursorStatus & CURSOR_STATUS_DOING_X ? _relMouseX : 0;
ev.relMouse.y = _cursorStatus & CURSOR_STATUS_DOING_Y ? _relMouseY : 0;
_events.push_back(ev);
@@ -180,21 +178,19 @@ void OSystem_libretro::processInputs(void) {
// Handle mouse buttons
retropad_value = mapper_get_mapper_key_status(RETROKE_LEFT_BUTTON);
if (retropad_value & (1 << RETRO_DEVICE_KEY_CHANGED)) {
- Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = eventID[0][(retropad_value & (1 << RETRO_DEVICE_KEY_STATUS)) ? 0 : 1];
- ev.mouse.x = mouse.x;
- ev.mouse.y = mouse.y;
+ ev.mouse.x = _mouseX;
+ ev.mouse.y = _mouseY;
_events.push_back(ev);
}
retropad_value = mapper_get_mapper_key_status(RETROKE_RIGHT_BUTTON);
if (retropad_value & (1 << RETRO_DEVICE_KEY_CHANGED)) {
- Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = eventID[1][(retropad_value & (1 << RETRO_DEVICE_KEY_STATUS)) ? 0 : 1];
- ev.mouse.x = mouse.x;
- ev.mouse.y = mouse.y;
+ ev.mouse.x = _mouseX;
+ ev.mouse.y = _mouseY;
_events.push_back(ev);
}
@@ -223,7 +219,6 @@ void OSystem_libretro::processInputs(void) {
int p_press = retro_input_cb(0, RETRO_DEVICE_POINTER, 0, RETRO_DEVICE_ID_POINTER_PRESSED);
int px = (int)((p_x + 0x7fff) * getScreenWidth() / 0xffff);
int py = (int)((p_y + 0x7fff) * getScreenHeight() / 0xffff);
- // printf("(%d,%d) p:%d\n",px,py,pp);
static int ptrhold = 0;
@@ -298,11 +293,10 @@ void OSystem_libretro::processInputs(void) {
}
if (_cursorStatus & CURSOR_STATUS_DOING_MOUSE) {
- Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
ev.type = Common::EVENT_MOUSEMOVE;
- ev.mouse.x = mouse.x;
- ev.mouse.y = mouse.y;
+ ev.mouse.x = _mouseX;
+ ev.mouse.y = _mouseY;
ev.relMouse.x = _cursorStatus & CURSOR_STATUS_DOING_X ? _relMouseX : 0;
ev.relMouse.y = _cursorStatus & CURSOR_STATUS_DOING_Y ? _relMouseY : 0;
_events.push_back(ev);
@@ -310,14 +304,13 @@ void OSystem_libretro::processInputs(void) {
}
for (int i = 0; i < 2; i++) {
- Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
Common::Event ev;
bool down = retro_input_cb(0, RETRO_DEVICE_MOUSE, 0, retroButtons[i]);
if (down != _mouseButtons[i]) {
_mouseButtons[i] = down;
ev.type = eventID[i][down ? 0 : 1];
- ev.mouse.x = mouse.x;
- ev.mouse.y = mouse.y;
+ ev.mouse.x = _mouseX;
+ ev.mouse.y = _mouseY;
_events.push_back(ev);
}
}
Commit: 8dffadf6724b3f0ec98ec10154f26e5f3cc98962
https://github.com/scummvm/scummvm/commit/8dffadf6724b3f0ec98ec10154f26e5f3cc98962
Author: Rudi Heitbaum (rudi at heitbaum.com)
Date: 2024-10-22T19:39:54+02:00
Commit Message:
LIBRETRO: BUILD: Allow fallback to curl if wget is missing (#68)
Changed paths:
backends/platform/libretro/scripts/bundle_datafiles.sh
diff --git a/backends/platform/libretro/scripts/bundle_datafiles.sh b/backends/platform/libretro/scripts/bundle_datafiles.sh
index 80ecbd834f2..590f017e798 100755
--- a/backends/platform/libretro/scripts/bundle_datafiles.sh
+++ b/backends/platform/libretro/scripts/bundle_datafiles.sh
@@ -110,7 +110,12 @@ fi
if [ ! $3 = "bundle" ]; then
# Update from libretro ScummVM.dat
-wget -NO "$BUILD_PATH"/ScummVM.dat https://raw.githubusercontent.com/libretro/libretro-database/master/dat/ScummVM.dat
+if command -v wget >/dev/null; then
+ wget -NO "$BUILD_PATH"/ScummVM.dat https://raw.githubusercontent.com/libretro/libretro-database/master/dat/ScummVM.dat
+else
+ # if wget is not available use curl
+ curl -f -o "$BUILD_PATH"/ScummVM.dat https://raw.githubusercontent.com/libretro/libretro-database/master/dat/ScummVM.dat
+fi
[ -f "$BUILD_PATH"/ScummVM.dat ] && SUPPORTED_EXTENSIONS="$(cat $BUILD_PATH/ScummVM.dat | grep 'rom (' | sed -e 's/\" .*//g' -e 's/.*\.//g' | sort -u | tr '\n' '|')" || SUPPORTED_EXTENSIONS="$ALLOWED_EXT"
# Create core.info file
Commit: 133eea820cb2ce18dca5652f4ad0e1924bc01e62
https://github.com/scummvm/scummvm/commit/133eea820cb2ce18dca5652f4ad0e1924bc01e62
Author: Giovanni Cascione (ing.cascione at gmail.com)
Date: 2024-10-22T19:40:07+02:00
Commit Message:
LIBRETRO: fix pointer input coordinates
Changed paths:
backends/platform/libretro/src/libretro-os-inputs.cpp
diff --git a/backends/platform/libretro/src/libretro-os-inputs.cpp b/backends/platform/libretro/src/libretro-os-inputs.cpp
index 33eef5030ad..745ace09d01 100644
--- a/backends/platform/libretro/src/libretro-os-inputs.cpp
+++ b/backends/platform/libretro/src/libretro-os-inputs.cpp
@@ -240,20 +240,18 @@ void OSystem_libretro::processInputs(void) {
}
if (ptrhold > 10 && _ptrmouseButton == 0) {
- Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
_ptrmouseButton = 1;
Common::Event ev;
ev.type = eventID[0][_ptrmouseButton ? 0 : 1];
- ev.mouse.x = mouse.x;
- ev.mouse.y = mouse.y;
+ ev.mouse.x = _mouseX;
+ ev.mouse.y = _mouseY;
_events.push_back(ev);
} else if (ptrhold == 0 && _ptrmouseButton == 1) {
- Common::Point mouse = convertWindowToVirtual(_mouseX, _mouseY);
_ptrmouseButton = 0;
Common::Event ev;
ev.type = eventID[0][_ptrmouseButton ? 0 : 1];
- ev.mouse.x = mouse.x;
- ev.mouse.y = mouse.y;
+ ev.mouse.x = _mouseX;
+ ev.mouse.y = _mouseY;
_events.push_back(ev);
}
More information about the Scummvm-git-logs
mailing list