From 6e0ab8ae907fa8926e0e25261d0bfabd5f944153 Mon Sep 17 00:00:00 2001 From: bspinner Date: Tue, 14 Nov 2017 21:42:09 +0100 Subject: [PATCH] Handle missing cursor support correctly (#153) * Fixes whitespaces * Fix DEBUG builds for odroid xu4 * Fixes log filename and adds flag to Makefile * More whitespace * Keeps cursor disabled if unsupported Without these changes, the cursor will be activated but not drawn. This commit disables the cursor if implementation for current gfx is missing. Moreover, the cursorSurface will be freed after use. --- Makefile | 50 +++++++++++++++++++-------------- src/osdep/amiberry.cpp | 4 +-- src/osdep/gui/InGameMessage.cpp | 2 +- src/osdep/gui/main_window.cpp | 48 +++++++++++++++++++++++++------ 4 files changed, 71 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 9c355c77..55fcd732 100644 --- a/Makefile +++ b/Makefile @@ -3,31 +3,36 @@ ifeq ($(PLATFORM),) endif ifeq ($(PLATFORM),rpi3) - CPU_FLAGS += -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard - MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON -DCAPSLOCK_DEBIAN_WORKAROUND - MORE_CFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads + CPU_FLAGS += -march=armv8-a -mfpu=neon-fp-armv8 -mfloat-abi=hard + MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON -DCAPSLOCK_DEBIAN_WORKAROUND + MORE_CFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads LDFLAGS += -lbcm_host -lvchiq_arm -lvcos -llzma -lfreetype -logg -lm -L/opt/vc/lib PROFILER_PATH = /home/pi/projects/amiberry/amiberry-sdl2-prof else ifeq ($(PLATFORM),rpi2) - CPU_FLAGS += -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard - MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON -DCAPSLOCK_DEBIAN_WORKAROUND - MORE_CFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads + CPU_FLAGS += -march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard + MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON -DCAPSLOCK_DEBIAN_WORKAROUND + MORE_CFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads LDFLAGS += -lbcm_host -lvchiq_arm -lvcos -llzma -lfreetype -logg -lm -L/opt/vc/lib PROFILER_PATH = /home/pi/projects/amiberry/amiberry-sdl2-prof else ifeq ($(PLATFORM),rpi1) - CPU_FLAGS += -march=armv6zk -mfpu=vfp -mfloat-abi=hard - MORE_CFLAGS += -DCAPSLOCK_DEBIAN_WORKAROUND - MORE_CFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads + CPU_FLAGS += -march=armv6zk -mfpu=vfp -mfloat-abi=hard + MORE_CFLAGS += -DCAPSLOCK_DEBIAN_WORKAROUND + MORE_CFLAGS += -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads LDFLAGS += -lbcm_host -lvchiq_arm -lvcos -llzma -lfreetype -logg -lm -L/opt/vc/lib PROFILER_PATH = /home/pi/projects/amiberry/amiberry-sdl2-prof else ifeq ($(PLATFORM),Pandora) - CPU_FLAGS += -march=armv7-a -mfpu=neon -mfloat-abi=softfp - MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON -DPANDORA -msoft-float - PROFILER_PATH = /media/MAINSD/pandora/test + CPU_FLAGS += -march=armv7-a -mfpu=neon -mfloat-abi=softfp + MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON -DPANDORA -msoft-float + PROFILER_PATH = /media/MAINSD/pandora/test else ifeq ($(PLATFORM),xu4) - CPU_FLAGS += -march=armv7ve -mcpu=cortex-a15.cortex-a7 -mtune=cortex-a15.cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard - MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON - LDFLAGS += -llzma -lfreetype -logg + CPU_FLAGS += -march=armv7ve -mcpu=cortex-a15.cortex-a7 -mtune=cortex-a15.cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard + MORE_CFLAGS += -DARMV6T2 -DUSE_ARMNEON + LDFLAGS += -llzma -lfreetype -logg + ifdef DEBUG + # Otherwise we'll get compilation errors, check https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here + # quote: The assembly code in bn_mul.h is optimized for the ARM platform and uses some registers, including r7 to efficiently do an operation. GCC also uses r7 as the frame pointer under ARM Thumb assembly. + MORE_CFLAGS += -fomit-frame-pointer + endif endif NAME = amiberry-sdl2 @@ -63,12 +68,15 @@ LDFLAGS += -lpthread -lz -lpng -lrt -lxml2 -lFLAC -lmpg123 -ldl -lmpeg2convert - LDFLAGS += -lSDL2 -lSDL2_image -lSDL2_ttf -lguisan -Lsrc/guisan/lib ifndef DEBUG -MORE_CFLAGS += -Ofast -pipe -MORE_CFLAGS += -fweb -frename-registers -MORE_CFLAGS += -funroll-loops -ftracer -funswitch-loops + MORE_CFLAGS += -Ofast -pipe + MORE_CFLAGS += -fweb -frename-registers + MORE_CFLAGS += -funroll-loops -ftracer -funswitch-loops else -MORE_CFLAGS += -g -rdynamic -funwind-tables -mapcs-frame -DDEBUG -Wl,--export-dynamic + MORE_CFLAGS += -g -rdynamic -funwind-tables -mapcs-frame -DDEBUG -Wl,--export-dynamic +endif +ifdef WITH_LOGGING + MORE_CFLAGS += -DWITH_LOGGING endif ASFLAGS += $(CPU_FLAGS) @@ -76,10 +84,10 @@ ASFLAGS += $(CPU_FLAGS) CXXFLAGS += $(SDL_CFLAGS) $(CPU_FLAGS) $(DEFS) $(MORE_CFLAGS) ifdef GEN_PROFILE -MORE_CFLAGS += -fprofile-generate=$(PROFILER_PATH) -fprofile-arcs -fvpt + MORE_CFLAGS += -fprofile-generate=$(PROFILER_PATH) -fprofile-arcs -fvpt endif ifdef USE_PROFILE -MORE_CFLAGS += -fprofile-use -fbranch-probabilities -fvpt + MORE_CFLAGS += -fprofile-use -fbranch-probabilities -fvpt endif OBJS = \ diff --git a/src/osdep/amiberry.cpp b/src/osdep/amiberry.cpp index 222815e3..18cc7ee6 100644 --- a/src/osdep/amiberry.cpp +++ b/src/osdep/amiberry.cpp @@ -100,12 +100,12 @@ void logging_init(void) debugfile = 0; } - sprintf(debugfilename, "%s/uae4arm_log.txt", start_path_data); + sprintf(debugfilename, "%s/amiberry_log.txt", start_path_data); if (!debugfile) debugfile = fopen(debugfilename, "wt"); first++; - write_log("UAE4ARM Logfile\n\n"); + write_log("AMIBERRY Logfile\n\n"); #endif } diff --git a/src/osdep/gui/InGameMessage.cpp b/src/osdep/gui/InGameMessage.cpp index f0f3f051..b8b2d684 100644 --- a/src/osdep/gui/InGameMessage.cpp +++ b/src/osdep/gui/InGameMessage.cpp @@ -156,7 +156,7 @@ void InGameMessage(const char* msg) // Now we let the Gui object draw itself. msg_gui->draw(); // Finally we update the screen. - if (!drawn) + if (!drawn && cursor != nullptr) { SDL_ShowCursor(SDL_ENABLE); updatedisplayarea(); diff --git a/src/osdep/gui/main_window.cpp b/src/osdep/gui/main_window.cpp index aaacb191..9d038c42 100644 --- a/src/osdep/gui/main_window.cpp +++ b/src/osdep/gui/main_window.cpp @@ -187,26 +187,47 @@ void UpdateGuiScreen() namespace sdl { - void gui_init() + // Sets the cursor image up + void setup_cursor() { - //------------------------------------------------- - // Create new screen for GUI - //------------------------------------------------- + // Detect resolution and load appropiate cursor image if (sdlMode.w > 1280) { - // High resolution detected, we'll use a double-size cursor cursorSurface = SDL_LoadBMP("data/cursor-x2.bmp"); } else { cursorSurface = SDL_LoadBMP("data/cursor.bmp"); } - if (cursorSurface) + + if (cursorSurface == nullptr) { - cursor = SDL_CreateColorCursor(cursorSurface, 0, 0); - SDL_SetCursor(cursor); + // Load failed. Log error. + cout << "Could not load cursor bitmap: " << SDL_GetError() << endl; + return; } + // Create new cursor with surface + cursor = SDL_CreateColorCursor(cursorSurface, 0, 0); + if (cursor == nullptr) + { + // Cursor creation failed. Log error and free surface + cout << "Could not create color cursor: " << SDL_GetError() << endl; + SDL_FreeSurface(cursorSurface); + cursorSurface = nullptr; + return; + } + + SDL_SetCursor(cursor); + } + + void gui_init() + { + //------------------------------------------------- + // Create new screen for GUI + //------------------------------------------------- + setup_cursor(); + // make the scaled rendering look smoother (linear scaling). SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear"); @@ -218,7 +239,10 @@ namespace sdl gui_texture = SDL_CreateTextureFromSurface(renderer, gui_screen); check_error_sdl(gui_texture == nullptr, "Unable to create texture"); - SDL_ShowCursor(SDL_ENABLE); + if (cursor) + { + SDL_ShowCursor(SDL_ENABLE); + } //------------------------------------------------- // Create helpers for guisan @@ -250,6 +274,12 @@ namespace sdl if (cursor) { SDL_FreeCursor(cursor); + cursor = nullptr; + } + if (cursorSurface) + { + SDL_FreeSurface(cursorSurface); + cursorSurface = nullptr; } gui_screen = nullptr; }