From 72c0a512c3553aa04f313729833052d7f3fc3ce6 Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Thu, 17 Oct 2024 00:54:37 +0200 Subject: [PATCH] Use OpenGL canvas on Android by default Because it's just much more performant and there shouldn't be any driver issues here. Still, if initialization crashes, it is now reverted to the software canvas. --- ChangeLog | 1 + src/desktop/main.cpp | 6 +----- src/desktop/view/glcanvas.cpp | 21 +++++++++------------ src/libclient/settings.h | 16 ++++++++++++++++ 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2554e4fad7..d7e6893e10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -39,6 +39,7 @@ Unreleased Version 2.2.2-pre * Feature: Allow assigning keyboard shortcuts to brushes. Assigning the same shortcut to multiple brushes will toggle through them. Thanks annoy for suggesting. * Fix: Make user interface scaling not round to multiple of 100% anymore. Thanks blau, Buch, Chryssabliss and ShotgunnerFox for reporting. * Fix: Don't use system message boxes on Android, since they behave in various broken and nonsensical ways, like showing you a yes button three times. Thanks Hopfel for reporting. + * Feature: Use hardware renderer on Android by default. 2024-08-09 Version 2.2.2-beta.3 * Fix: Use more accurate timers for performance profiles if the platform supports it. diff --git a/src/desktop/main.cpp b/src/desktop/main.cpp index 34f45254a7..7449533be9 100644 --- a/src/desktop/main.cpp +++ b/src/desktop/main.cpp @@ -389,11 +389,7 @@ int DrawpileApp::getCanvasImplementationFor(int canvasImplementation) case int(CanvasImplementation::Software): return canvasImplementation; default: -#ifdef __EMSCRIPTEN__ - return int(CanvasImplementation::OpenGl); -#else - return int(CanvasImplementation::GraphicsView); -#endif + return int(CANVAS_IMPLEMENTATION_DEFAULT); } } diff --git a/src/desktop/view/glcanvas.cpp b/src/desktop/view/glcanvas.cpp index 7ca06fab81..627f287548 100644 --- a/src/desktop/view/glcanvas.cpp +++ b/src/desktop/view/glcanvas.cpp @@ -994,27 +994,24 @@ void GlCanvas::initializeGL() } d->initialized = true; -#ifndef __EMSCRIPTEN__ +#ifdef CANVAS_IMPLEMENTATION_FALLBACK // Calling OpenGL functions can crash if the driver is sufficiently bad. // Set it to the default renderer temporarily so the user doesn't get stuck. desktop::settings::Settings *settings = nullptr; int originalRenderCanvas = -1; if(dpApp().isCanvasImplementationFromSettings()) { - constexpr int DEFAULT_RENDER_CANVAS = - int(libclient::settings::CanvasImplementation::Default); + constexpr int fallback = int(CANVAS_IMPLEMENTATION_FALLBACK); settings = &dpApp().settings(); originalRenderCanvas = settings->renderCanvas(); - if(originalRenderCanvas == DEFAULT_RENDER_CANVAS) { + if(originalRenderCanvas == fallback) { qCWarning( - lcDpGlCanvas, - "Canvas implementation is already set to the default %d", - DEFAULT_RENDER_CANVAS); + lcDpGlCanvas, "Canvas implementation is already set to %d", + fallback); } else { qCDebug( - lcDpGlCanvas, - "Reverting canvas implementation from %d to default %d", - originalRenderCanvas, DEFAULT_RENDER_CANVAS); - settings->setRenderCanvas(DEFAULT_RENDER_CANVAS); + lcDpGlCanvas, "Reverting canvas implementation from %d to %d", + originalRenderCanvas, fallback); + settings->setRenderCanvas(fallback); settings->trySubmit(); } } @@ -1121,7 +1118,7 @@ void GlCanvas::initializeGL() d->dirty = Private::Dirty(); -#ifndef __EMSCRIPTEN__ +#ifdef CANVAS_IMPLEMENTATION_FALLBACK if(settings && originalRenderCanvas >= 0) { qCDebug( lcDpGlCanvas, "Restoring canvas implementation to %d", diff --git a/src/libclient/settings.h b/src/libclient/settings.h index ed3ab0ed29..42dd73f746 100644 --- a/src/libclient/settings.h +++ b/src/libclient/settings.h @@ -43,6 +43,22 @@ enum class CanvasImplementation : int { }; Q_ENUM_NS(CanvasImplementation) +#if defined(__EMSCRIPTEN__) +# define CANVAS_IMPLEMENTATION_DEFAULT \ + ::libclient::settings::CanvasImplementation::OpenGl +# undef CANVAS_IMPLEMENTATION_FALLBACK +#elif defined(Q_OS_ANDROID) +# define CANVAS_IMPLEMENTATION_DEFAULT \ + ::libclient::settings::CanvasImplementation::OpenGl +# define CANVAS_IMPLEMENTATION_FALLBACK \ + ::libclient::settings::CanvasImplementation::GraphicsView +#else +# define CANVAS_IMPLEMENTATION_DEFAULT \ + ::libclient::settings::CanvasImplementation::GraphicsView +# define CANVAS_IMPLEMENTATION_FALLBACK \ + ::libclient::settings::CanvasImplementation::Default +#endif + // On most platforms, tablet input comes at a very high precision and frequency, // so some smoothing is sensible by default. On Android (at least on a Samsung // Galaxy S6 Lite, a Samsung Galaxy S8 Ultra and reports from unknown devices)