Skip to content

Commit

Permalink
Use OpenGL canvas on Android by default
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
askmeaboutlo0m committed Oct 16, 2024
1 parent 3f96f6d commit cefcec9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions src/desktop/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
21 changes: 9 additions & 12 deletions src/desktop/view/glcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions src/libclient/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cefcec9

Please sign in to comment.