527 Commits

Author SHA1 Message Date
Colin Snover
cd538ffffa BACKENDS: Do not send mouse events to games occurring outside the game draw rect 2017-10-15 13:24:21 -05:00
Colin Snover
319ab07fe0 SDL: Minor code cleanup to declare variables at point of first use 2017-10-15 13:24:20 -05:00
Colin Snover
5d8cf6ba42 BACKENDS: Fix GraphicsManager handling of empty cursors
The SDL graphics manager was just ignoring calls from CursorMan to
set the cursor to a blank cursor, which meant engines that did not
immediately send a cursor to CursorMan at startup would still show
the launcher's cursor (usually with a broken palette).

The OpenGL graphics manager would try to generate and draw an
invalid cursor surface when receiving an empty cursor.
2017-10-15 13:24:20 -05:00
Colin Snover
da0a8db704 BACKENDS: Also hide mouse cursor outside game area when an engine has hidden the cursor
The only reason we show the system cursor outside the game area is
to show users where their mouse is when the window is resized and
the mouse is outside the game area. If the game cannot be
interacted with, then the mouse also does not need to be shown in
the black areas.
2017-10-15 13:24:20 -05:00
Colin Snover
de2bbe3b97 BACKENDS: Refactor OpenGL & SDL graphics backends
This patch refactors the OpenGL and SDL graphics backends,
primarily to unify window scaling and mouse handling, and to
fix coordinate mapping between the ScummVM window and the
virtual game screen when they have different aspect ratios.

Unified code for these two backends has been moved to a new
header-only WindowedGraphicsManager class, so named because it
contains code for managing graphics managers that interact with
a windowing system and render virtual screens within a larger
physical content window.

The biggest behavioral change here is with the coordinate
system mapping:

Previously, mouse offsets were converted by mapping the whole
space within the window as input to the virtual game screen
without maintaining aspect ratio. This was done to prevent
'stickiness' when the mouse cursor was within the window but
outside of the virtual game screen, but it caused noticeable
distortion of mouse movement speed on the axis with blank
space.

Instead of introducing mouse speed distortion to prevent
stickiness, this patch changes coordinate transformation to
show the system cursor when the mouse moves outside of the virtual
game screen when mouse grab is off, or by holding the mouse inside
the virtual game screen (instead of the entire window) when mouse
grab is on.

This patch also improves some other properties of the
GraphicsManager/PaletteManager interfaces:

* Nullipotent operations (getWidth, getHeight, etc.) of the
  PaletteManager/GraphicsManager interfaces are now const
* Methods marked `virtual` but not inherited by any subclass have
  been de-virtualized
* Extra unnecessary calculations of hardware height in
  SurfaceSdlGraphicsManager have been removed
* Methods have been renamed where appropriate for clarity
  (setWindowSize -> handleResize, etc.)
* C++11 support improved with `override` specifier added on
  overridden virtual methods in subclasses (primarily to avoid
  myself accidentally creating new methods in the subclasses
  by changing types/names during refactoring)

Additional refactoring can and should be done at some point to
continue to deduplicate code between the OpenGL and SDL backends.
Since the primary goal here was to improve the coordinate mapping,
full refactoring of these backends was not completed here.
2017-10-15 13:24:20 -05:00
Colin Snover
969dd565a1 SDL: Allow window resize with non-OpenGL SDL2 backend
The GUI is not redrawn when the window size changes, but that is
not as important as being able to resize the games themselves.
2017-10-15 13:24:20 -05:00
Colin Snover
b53020f704 BACKENDS: Fix some comment typos 2017-10-15 13:24:20 -05:00
Colin Snover
20bd289ebe BACKENDS: Remove references to old normal1xScaler transaction property from ports 2017-10-07 15:25:47 -05:00
Colin Snover
04f357e6ff BACKENDS: Make initSizeHint an optional extension point
There is no particular reason why backends that don't need to
calculate screen dimensions in advance should still need to
implement initSizeHint at this point.
2017-10-07 12:30:29 -05:00
Colin Snover
6e157429b7 BACKENDS: Fix window sizing of games that switch between multiple resolutions 2017-10-07 12:30:29 -05:00
Colin Snover
9a82bc6d96 SDL: Deduplicate scaling factors 2017-10-07 12:30:29 -05:00
Colin Snover
432fd522d2 ENGINES: Remove default1x scaler flag
This flag is removed for a few reasons:

* Engines universally set this flag to true for widths > 320,
  which made it redundant everywhere;
* This flag functioned primarily as a "force 1x scaler" flag,
  since its behaviour was almost completely undocumented and users
  would need to figure out that they'd need an explicit non-default
  scaler set to get a scaler to operate at widths > 320;
* (Most importantly) engines should not be in the business of
  deciding how the backend may choose to render its virtual screen.
  The choice of rendering behaviour belongs to the user, and the
  backend, in that order.

A nearby future commit restores the default1x scaler behaviour in
the SDL backend code for the moment, but in the future it is my
hope that there will be a better configuration UI to allow users
to specify how they want scaling to work for high resolutions.
2017-10-07 12:30:29 -05:00
Colin Snover
ebe6c40a6a SDL: Do not reset window size when engines update rendering surface
This change allows:

* Engines to update their target rendering surface/size and pixel
  format with the backend multiple times during gameplay;
* Users to resize the ScummVM window without having it reset
  size/position every time an engine updates its target surface
  format;
* Conversions/scaling to continue to run efficiently in hardware,
  instead of requiring engines to pick their maximum possible
  output format once and upscale inefficiently in software;
* The window to reset size once when an engine calls to set its
  initial output size, and to reset again once ScummVM returns to
  the launcher.

This is relevant for at least SCI32 and DreamWeb engines, which
perform graphics mode switches during games.
2017-10-07 12:30:29 -05:00
Colin Snover
9203bdcf4e SDL: Remove USE_RGB_COLOR #ifdefs from detectSupportedFormats
This function is only defined when USE_RGB_COLOR is defined so
these additional conditions are redundant.
2017-09-15 23:05:48 -05:00
Colin Snover
c2a4784706 SDL: Fix compilation on PSP2 2017-09-12 11:27:45 -05:00
Colin Snover
2228ae255c SDL: List supported 32bpp pixel formats when using SDL2
_hwscreen is always initialized to 16bpp so the supported 32bpp
pixel formats would never be put into the list of supported pixel
formats, making it useless for engines to query for usable 32bpp
pixel formats.

This patch changes things so that the native desktop pixel format
is at the top of the supported formats list, and all pixel formats
<= the default desktop pixel format will now show up in the list
of supported formats. ("Supported" is somewhat of a misnomer here
since there is no hardware querying beyond checking the default
desktop pixel format. SDL generally accepts a wide variety of pixel
formats and tries to convert them to whatever the hardware
supports.)
2017-09-12 10:12:53 -05:00
Colin Snover
d2b4e16ab2 SDL: Fix unsafe sprintf usage
Translation strings come from external data sources and can cause
a stack buffer overflow here just by accidentally (or maliciously)
being too long.
2017-09-03 20:00:23 -05:00
Eugene Sandulenko
1d086b9f20 BACKENDS: SURFACESDL: Add missing break statement 2017-08-11 21:59:59 +02:00
Bastien Bouclet
8e4697946e OPENGL: Always clear the whole backbuffer
Previously we were clearing the whole backbuffer for 3 frames after a
window size change, and then only clearing the game area. This assumes
the OpenGL driver uses at most 3 render buffer and uses them in
sequential order. This does not seem to be the case on Linux when using
an Intel integrated GPU.
Instead we now clear the whole backbuffer on each frame to make sure
there are no leftovers remaining on the screen. All semi-recent GPUs
should have hardware clear anyway so this should not impact negatively
performance.

Possibly fixes #10025.
2017-08-05 08:36:32 +02:00
Eugene Sandulenko
940b2a20f1 Revert "COMMON: Change way the Singleton instances are instantiated"
This reverts commit eefa72afa1978a9dea10f5b1833fcc8f58a3468e.

With this patch ConfigManager is broken.
2017-07-10 21:17:41 +02:00
Thierry Crozat
eefa72afa1 COMMON: Change way the Singleton instances are instantiated
This fixes tons of warnings with clang from a recent xcode version on
macOS (and possibly other systems) complaining that an instantiation
of _singleton is required but no definition is available.
2017-07-10 21:11:20 +02:00
Colin Snover
332fabcb8a SDL: Only recreate SDL2 window when necessary
Destroying and recreating the SDL window whenever the video mode
changes in SDL2 is not necessary and causes several problems:

1. In windowed mode, the game window shifts position;
2. In fullscreen mode in macOS, every time the window is
   recreated, it causes the OS to play its switch-to-fullscreen
   animation again and emit system alert noises;
3. The window content flickers; and
4. The engine loses events from the old destroyed window.

This patch changes the SDL backend code to avoid destroying and
recreating the SDL window when using SDL2, except when switching
OpenGL modes, since there is no way to change the OpenGL feature
of a window.

There are still some outstanding issues with OpenGL where window
size ends up getting reset even though the user has resized it;
this will probably need to be addressed at some point in another
patch.

Thanks to @bgK and @criezy for their feedback which made this
patch much better.

Co-Authored-By: Bastien Bouclet <bastien.bouclet@gmail.com>
2017-07-06 19:11:54 -05:00
Colin Snover
fa0bb7dd5a BACKENDS: Compress screenshots using PNG if available
Closes gh-948.
2017-05-21 15:55:39 -05:00
Bastien Bouclet
23abcffbc5 OPENGL: Don't update the cursor's texture when the cursor is invisible
Updating the cursor's texture is not necessary if it is not going to be drawn.

Fixes glDrawArrays sometimes failing due to using a framebuffer with an
incomplete color attachment. In SCI32 games, the framebuffer is incomplete
because the engine does not define pixel data for the cursor.
2017-05-08 06:50:30 +02:00
Thierry Crozat
a9ae691513 SDL: Improve debug and warning messages when saving screenshots
In particular this adds a warning when failing to save a screenshot
in OpenGL mode (there was already one in SurfaceSDL mode).
2017-04-24 01:07:16 +01:00
Thierry Crozat
438f23f272 SDL: Use dynamic cast instead of C cast to get screenshot path 2017-04-24 01:06:40 +01:00
Pala
3849a3e90e WINDOWS: Change location where screenshot are saved
This fixes bug #9701: WINDOWS: Flow of taking screenshots
on Windows is broken
2017-04-24 01:06:29 +01:00
rsn8887
44de995bb6 SDL: Fix trying to init non-supported shaders (#917) 2017-03-06 08:57:21 -06:00
Eugene Sandulenko
8b8fd13d56 BACKENDS: Fix const'ness which led to warnings 2017-03-05 00:56:27 +01:00
Eugene Sandulenko
9cf5ebecdf BACKENDS: Fix crash on startup 2017-03-05 00:43:49 +01:00
cpasjuste
70988527c6 PSP2: Add Playstation Vita (PSP2) support 2017-03-04 15:42:19 -06:00
Colin Snover
e49cf11275 OPENGLSDL: Fix signed/unsigned comparison 2016-11-20 16:13:51 -06:00
Eugene Sandulenko
43438fbe13 CHEWY: Plug memory leaks 2016-11-13 16:36:43 +01:00
Thierry Crozat
cbfa598446 OPENGL: Remove hack to avoid issues with OSD messages from other threads 2016-10-29 15:13:32 +01:00
Ori Avtalion
fc85eb461d SDL: Fix typo in function name 2016-10-18 19:24:51 +03:00
Thierry Crozat
aa39a6ce4b SURFACESDL: Improve toggling filtering on/off
We don't need to recreate the window when turning filtering on or off.
Only the texture needs to be recreated.
2016-10-13 01:46:27 +01:00
Thierry Crozat
fd77916f86 SURFACESDL: Add hotkey to enable/disable filtering 2016-10-13 01:46:26 +01:00
Thierry Crozat
529a7ca26c OPENGLSDL: Add hotkey to enable/disable filtering
Crtl-Alt-f now enables/disables filtering instead of changing the
graphics mode. Since there is only one graphics mode now, a hotkey
to change it is a bit useless.
2016-10-13 01:46:26 +01:00
Thierry Crozat
3a69898729 SURFACESDL: Add support for filtering feature when using SDL2
This implements the request from ticket #9573: SDL1/2: Different
rendering/filtering?
2016-10-13 01:45:01 +01:00
Thierry Crozat
c6ce1c8002 OPENGL: Add support for filtering feature
This replaces the two graphics modes "OpenGL (No filtering)" and
"OpenGL". Now there is a single "OpenGL" mode and filtering is
controlled by the kFeatureFilteringMode.
2016-10-13 01:45:01 +01:00
Thierry Crozat
d0b2770243 OPENGLSDL: Make some OSD messages translatable
Also change some OSD messages to be the same or similar to
messages used by the Surface SDL code.
2016-10-13 01:15:38 +01:00
Bastien Bouclet
7941e5d530 SDL: Switch to full screen updates when the OSD is transparent
Previous releases also did full screen updates for transparent OSD messages.
There should be no performance regression with that regard.

Computing smaller update rects is non trivial, but should be looked into if
performance is an issue for OSD icons.

Fixes #9598
2016-10-03 07:31:18 +02:00
Bastien Bouclet
5e133cdd34 OPENGL: Make sure the cloud icon is cleared immediatly after it is hidden 2016-09-18 17:55:09 +02:00
Bastien Bouclet
0f9583e4ca SDL: Make sure the cloud icon is cleared immediatly after it is hidden 2016-09-18 17:55:09 +02:00
Bastien Bouclet
75599a4c25 OPENGL: Remove multithread support from displayActivityIconOnOSD
It is no longer being called by another thread.
2016-09-18 17:55:09 +02:00
Thierry Crozat
1fd4dbfdce SDL: Ignore outdated SDL resize event in OpenGL mode
Those outdated resize events are sent from SDL_DestroyWindow when the
window is fullscreen and doesn't have the SDL_WINDOW_FULLSCREEN_DESKTOP
flag (thus Surface SDL is not affected). Switching resolutions in fullscreen, or
switching from fullscreen to windowed will therefore cause a resize event to
be received with the former fullscreen resolution after we have already setup
the window to use the new resolution. If we don't ignore this event we end up
with a texture size and a window size that are not consistent and for example
see only a part of the texture (if the old resolution is bigger than the new one.
2016-09-18 04:23:37 +01:00
Thierry Crozat
2d651fd0f4 OPENGL: Fix dereferencing null pointer in OpenGLGraphicsManager
This fixes a crash when calling displayActivityIconOnOSD with a
NULL icon, which is used to remove the current activity icon.
2016-09-13 22:58:13 +01:00
Bastien Bouclet
0802bbd8ee OSYSTEM: Remove the API allowing to draw to the OSD surface directly 2016-09-13 20:41:26 +02:00
Bastien Bouclet
9cbaad6140 SDL: Switch the OpenGL renderer to use small textures to draw the OSD 2016-09-13 20:41:26 +02:00
Bastien Bouclet
05bc82b622 SDL: Switch the surface renderer to use small surfaces for OSD drawing 2016-09-13 20:33:42 +02:00