Classes | |
struct | error |
An error specifically indicating video subsystem problems. More... | |
class | quit |
Type that can be thrown as an exception to quit to desktop. More... | |
Enumerations | |
enum class | fake { none , no_window , no_draw , hide_window } |
For describing the type of faked display, if any. More... | |
Functions | |
void | render_screen () |
static void | init_window (bool hidden=false) |
static void | init_test_window () |
static void | init_fake () |
static void | init_test () |
static bool | update_framebuffer () |
static bool | update_test_framebuffer () |
Returns true if the buffer was changed. More... | |
static point | draw_offset () |
void | init (fake fake_type=fake::none) |
Initialize the video subsystem. More... | |
void | deinit () |
Deinitialize the video subsystem. More... | |
bool | headless () |
The game is running headless. More... | |
bool | testing () |
The game is running unit tests. More... | |
bool | has_window () |
Whether the game has set up a window to render into. More... | |
point | output_size () |
Returns the size of the final render target. More... | |
point | window_size () |
Returns the size of the window in display units / screen coordinates. More... | |
rect | game_canvas () |
The game canvas area, in drawing coordinates. More... | |
point | game_canvas_size () |
The size of the game canvas, in drawing coordinates / game pixels. More... | |
point | draw_size () |
The size of the current render target in drawing coordinates. More... | |
rect | draw_area () |
The current drawable area. More... | |
rect | output_area () |
{0, 0, output_size().x, output_size().y} More... | |
rect | to_output (const rect &draw_space_rect) |
Convert coordinates in draw space to coordinates in render space. More... | |
rect | input_area () |
Returns the input area of the window, in display coordinates. More... | |
int | get_pixel_scale () |
Get the current active pixel scale multiplier. More... | |
int | current_refresh_rate () |
The refresh rate of the screen. More... | |
void | force_render_target (const texture &t) |
Set the render target, without any provided way of setting it back. More... | |
void | clear_render_target () |
Reset the render target to the main window / screen. More... | |
void | reset_render_target () |
Reset the render target to the primary render buffer. More... | |
texture | get_render_target () |
Get the current render target. More... | |
surface | read_pixels (SDL_Rect *r=nullptr) |
Copy back a portion of the render target that is already drawn. More... | |
surface | read_pixels_low_res (SDL_Rect *r=nullptr) |
The same as read_pixels, but returns a low-resolution surface suitable for use with the old drawing system. More... | |
void | set_window_title (const std::string &title) |
Sets the title of the main window. More... | |
void | set_window_icon (surface &icon) |
Sets the icon of the main window. More... | |
SDL_Renderer * | get_renderer () |
SDL_Window * | get_window () |
std::string | current_driver () |
The current video driver in use, or else "<not initialized>". More... | |
std::vector< std::string > | enumerate_drivers () |
A list of available video drivers. More... | |
static bool | window_has_flags (uint32_t flags) |
Tests whether the given flags are currently set on the SDL window. More... | |
bool | window_is_visible () |
True iff the window is not hidden. More... | |
bool | window_has_focus () |
True iff the window has mouse or input focus. More... | |
bool | window_has_mouse_focus () |
True iff the window has mouse focus. More... | |
std::vector< point > | get_available_resolutions (bool include_current=false) |
Returns the list of available screen resolutions. More... | |
point | current_resolution () |
The current window size in desktop coordinates. More... | |
bool | is_fullscreen () |
Whether we are currently in fullscreen mode. More... | |
void | set_fullscreen (bool) |
Set the fullscreen state. More... | |
void | toggle_fullscreen () |
Toggle fullscreen mode. More... | |
bool | set_resolution (const point &resolution) |
Set the window resolution. More... | |
void | update_buffers (bool autoupdate=true) |
Update buffers to match current resolution and pixel scale settings. More... | |
std::pair< float, float > | get_dpi () |
Retrieves the current game screen DPI for the build_info API. More... | |
std::vector< std::pair< std::string, std::string > > | renderer_report () |
Provides diagnostic information about the current renderer for the build_info API. More... | |
|
strong |
For describing the type of faked display, if any.
fake::no_window never tries to create a window, or draw anything. fake::no_draw does create an offscreen window, but does not draw to it. fake::hide_window creates a window as normal, but does not display it.
Enumerator | |
---|---|
none | |
no_window | |
no_draw | |
hide_window |
void video::clear_render_target | ( | ) |
Reset the render target to the main window / screen.
Definition at line 527 of file video.cpp.
References force_render_target().
Referenced by render_screen().
std::string video::current_driver | ( | ) |
int video::current_refresh_rate | ( | ) |
The refresh rate of the screen.
In most cases, this will be the native refresh rate of the display, but could be lower if FPS has been artificially capped (i.e., through –max-fps).
If a refresh cannot be detected, this may return 0, or it may return a substitute value.
Definition at line 486 of file video.cpp.
References prefs::get().
Referenced by draw_manager::get_frame_length().
point video::current_resolution | ( | ) |
The current window size in desktop coordinates.
Definition at line 758 of file video.cpp.
References draw::point().
Referenced by get_available_resolutions(), set_resolution(), and gui2::dialogs::preferences_dialog::set_resolution_list().
void video::deinit | ( | ) |
Deinitialize the video subsystem.
This flushes all texture caches and disconnects the SDL video subsystem.
Definition at line 110 of file video.cpp.
References image::flush_cache(), font::flush_texture_cache(), and LOG_DP.
Referenced by game_launcher::~game_launcher().
rect video::draw_area | ( | ) |
The current drawable area.
Equivalent to {0, 0, draw_size().x, draw_size().y}.
Definition at line 442 of file video.cpp.
Referenced by draw::get_viewport(), read_pixels(), and update_framebuffer().
|
static |
Definition at line 447 of file video.cpp.
References draw_size(), output_size(), and xbrz::scale().
Referenced by to_output().
point video::draw_size | ( | ) |
The size of the current render target in drawing coordinates.
This will be the same as game_canvas_size() unless the render target has been manually changed.
Definition at line 437 of file video.cpp.
Referenced by draw_offset(), and read_pixels_low_res().
std::vector< std::string > video::enumerate_drivers | ( | ) |
void video::force_render_target | ( | const texture & | t | ) |
Set the render target, without any provided way of setting it back.
End-users should not use this function directly. In stead use draw::set_render_target(), which returns a setter object which will automatically restore the render target upon leaving scope.
t | The new render target. This must be a texture created with SDL_TEXTUREACCESS_TARGET, or an empty texture to indicate the underlying window. |
Definition at line 496 of file video.cpp.
References DBG_DP, ERR_DP, get_renderer(), and t.
Referenced by clear_render_target(), draw::render_target_setter::render_target_setter(), reset_render_target(), update_framebuffer(), update_test_framebuffer(), and draw::render_target_setter::~render_target_setter().
rect video::game_canvas | ( | ) |
The game canvas area, in drawing coordinates.
This is the "screen area", as seen by game systems, and as used for specifying where to draw things on-screen. It may differ, in high-dpi contexts, from input area, window area, and output area.
Usually this is the only area game components should use or care about.
The units it uses can be considered "pixels". Final output will be rendered in higher resolution automatically if and when appropriate.
Definition at line 427 of file video.cpp.
Referenced by display::draw_all_panels(), display::draw_label(), display::draw_panel(), draw_manager::invalidate_all(), display::layout_buttons(), display::map_outside_area(), display::minimap_area(), display::palette_area(), controller_base::play_slice(), display::queue_rerender(), display::refresh_report(), display::screen_location(), display::set_theme(), display::unit_image_area(), and display::update_render_textures().
point video::game_canvas_size | ( | ) |
The size of the game canvas, in drawing coordinates / game pixels.
Definition at line 432 of file video.cpp.
Referenced by sdl::get_mouse_state(), gui::scrollarea::handle_event(), gui2::event::sdl_event_handler::handle_event(), controller_base::handle_scroll(), help::unit_topic_generator::operator()(), events::pump(), editor::editor_display::set_help_string(), editor::editor_display::set_status(), and gui2::settings::update_screen_size_variables().
std::vector< point > video::get_available_resolutions | ( | const bool | include_current | ) |
Returns the list of available screen resolutions.
Definition at line 706 of file video.cpp.
References current_resolution(), i, pref_constants::min_window_height, pref_constants::min_window_width, and PLAIN_LOG.
Referenced by gui2::dialogs::preferences_dialog::set_resolution_list().
std::pair< float, float > video::get_dpi | ( | ) |
Retrieves the current game screen DPI for the build_info API.
Definition at line 845 of file video.cpp.
References desktop::apple::get_scale_factor(), and sdl::get_version().
int video::get_pixel_scale | ( | ) |
Get the current active pixel scale multiplier.
This is equal to output_size() / game_canvas_size(). Currently it is always integer, and the same in both dimensions.
This may differ from prefs::get().pixel_scale() in some cases, For example if the window is too small to fit the desired scale.
Definition at line 481 of file video.cpp.
Referenced by gui2::rich_label::get_parsed_text(), draw::tiled_highres(), font::pango_text::update_pixel_scale(), display::update_render_textures(), and gui2::window::update_render_textures().
texture video::get_render_target | ( | ) |
Get the current render target.
Will return an empty texture if the render target is the underlying window.
Definition at line 537 of file video.cpp.
References get_renderer().
Referenced by draw::render_target_setter::render_target_setter().
SDL_Renderer * video::get_renderer | ( | ) |
Definition at line 648 of file video.cpp.
Referenced by force_render_target(), get_render_target(), renderer(), texture::reset(), and texture::texture().
SDL_Window * video::get_window | ( | ) |
Definition at line 657 of file video.cpp.
Referenced by windows_tray_notification::get_window_handle().
bool video::has_window | ( | ) |
bool video::headless | ( | ) |
The game is running headless.
There is no window or renderer.
Definition at line 139 of file video.cpp.
Referenced by display_chat_manager::add_chat_message(), play_controller::check_time_over(), play_controller::check_victory(), display::create_buttons(), font::floating_label::create_texture(), gui2::dialogs::loading_screen::display(), display::draw(), game_events::wml_event_pump::flush_messages(), sdl::get_mouse_state(), game_lua_kernel::impl_run_animation(), play_controller::init(), playsingle_controller::init_gui(), savegame::loadgame::load_game_ingame(), playmp_controller::maybe_linger(), playsingle_controller::play_some(), play_controller::process_oos(), display::queue_rerender(), display::recalculate_minimap(), display::scroll(), display::scroll_to_xy(), gui2::dialogs::modeless_dialog::show(), gui2::dialogs::modal_dialog::show(), draw_manager::sparkle(), prefs::theme(), prefs::turbo(), display::turbo_speed(), font::floating_label::update(), and display::update_render_textures().
void video::init | ( | fake | fake_type = fake::none | ) |
Initialize the video subsystem.
This must be called before attempting to use any video functions.
Definition at line 81 of file video.cpp.
References ERR_DP, hide_window, init_fake(), init_test(), init_window(), LOG_DP, no_draw, no_window, and none.
Referenced by test_utils::fake_display_manager::fake_display_manager(), and game_launcher::init_video().
|
static |
|
static |
|
static |
Definition at line 331 of file video.cpp.
References LOG_DP, and update_test_framebuffer().
Referenced by init_test().
|
static |
Definition at line 352 of file video.cpp.
References prefs::get(), h, LOG_DP, pref_constants::min_window_height, pref_constants::min_window_width, PLAIN_LOG, prefs::resolution(), update_framebuffer(), and w.
Referenced by init().
rect video::input_area | ( | ) |
Returns the input area of the window, in display coordinates.
This can be slightly offset within the window, if the drawable area is not the same as the full window area. This will happen if output size is not a perfect multiple of the draw size.
In general this will be almost, but not quite, equal to window_size().
input_area() represents the portion of the window corresponding to game_canvas().
Definition at line 476 of file video.cpp.
Referenced by sdl::get_mouse_state().
bool video::is_fullscreen | ( | ) |
Whether we are currently in fullscreen mode.
Definition at line 766 of file video.cpp.
Referenced by set_fullscreen().
rect video::output_area | ( | ) |
{0, 0, output_size().x, output_size().y}
Definition at line 460 of file video.cpp.
References output_size(), and p.
point video::output_size | ( | ) |
Returns the size of the final render target.
This is irrelevant for most purposes. Use game_canvas_size() in stead.
Definition at line 410 of file video.cpp.
Referenced by draw_offset(), and output_area().
surface video::read_pixels | ( | SDL_Rect * | r = nullptr | ) |
Copy back a portion of the render target that is already drawn.
This area is specified in draw coordinates, not render coordinates. Thus the size of the retrieved surface may not match the size of r.
If not null, r will be automatically clipped to the drawing area.
Note: This is a very slow function! Its use should be phased out for everything except maybe screenshots.
r | The portion of the render target to retrieve, in draw coordinates. If not null, this will be modified to reflect the portion of the draw area that has been returned. |
Definition at line 582 of file video.cpp.
References rect::clip(), DBG_DP, draw_area(), texture::draw_size(), ERR_DP, texture::get(), texture::get_raw_size(), s, t, to_output(), and WRN_DP.
Referenced by gui2::dialogs::make_screenshot(), read_pixels_low_res(), and display::screenshot().
surface video::read_pixels_low_res | ( | SDL_Rect * | r = nullptr | ) |
The same as read_pixels, but returns a low-resolution surface suitable for use with the old drawing system.
This should be considered deprecated, and phased out ASAP.
Definition at line 622 of file video.cpp.
References draw_size(), read_pixels(), s, scale_surface(), and WRN_DP.
Referenced by gui2::canvas::update_blur().
void video::render_screen | ( | ) |
Definition at line 547 of file video.cpp.
References clear_render_target(), ERR_DP, reset_render_target(), and WRN_DP.
Referenced by draw_manager::sparkle().
std::vector< std::pair< std::string, std::string > > video::renderer_report | ( | ) |
void video::reset_render_target | ( | ) |
Reset the render target to the primary render buffer.
Definition at line 532 of file video.cpp.
References force_render_target().
Referenced by render_screen(), and draw::render_target_setter::render_target_setter().
void video::set_fullscreen | ( | bool | ) |
Set the fullscreen state.
If the setting matches the current fullscreen state, the window state will not be changed.
If false and the window is fullscreen, the window will be restored to its last saved non-fullscreen configuration.
Definition at line 774 of file video.cpp.
References prefs::get(), is_fullscreen(), and update_buffers().
Referenced by gui2::dialogs::preferences_dialog::fullscreen_toggle_callback(), and toggle_fullscreen().
bool video::set_resolution | ( | const point & | resolution | ) |
Set the window resolution.
resolution | The new width and height. |
Definition at line 803 of file video.cpp.
References current_resolution(), prefs::get(), LOG_DP, prefs::set_resolution(), update_buffers(), and update_test_framebuffer().
Referenced by test_utils::get_fake_display(), and gui2::dialogs::preferences_dialog::handle_res_select().
void video::set_window_icon | ( | surface & | icon | ) |
Sets the icon of the main window.
Definition at line 642 of file video.cpp.
Referenced by game_launcher::init_video().
void video::set_window_title | ( | const std::string & | title | ) |
Sets the title of the main window.
Definition at line 636 of file video.cpp.
Referenced by game_launcher::change_language(), game_launcher::init_video(), editor::context_manager::set_window_title(), and editor::context_manager::~context_manager().
bool video::testing | ( | ) |
The game is running unit tests.
There is a window and offscreen render buffer, but performing actual rendering is unnecessary.
Definition at line 144 of file video.cpp.
Referenced by playsingle_controller::init_gui(), and draw_manager::sparkle().
Convert coordinates in draw space to coordinates in render space.
Definition at line 466 of file video.cpp.
References draw_offset(), rect::origin(), rect::size(), and utf8::size().
Referenced by read_pixels(), and update_framebuffer().
void video::toggle_fullscreen | ( | ) |
Toggle fullscreen mode.
Equivalent to set_fullscreen(!is_fullscreen()).
Definition at line 798 of file video.cpp.
References prefs::get(), and set_fullscreen().
Referenced by hotkey::command_executor::execute_command_wrap(), and gui2::dialogs::preferences_dialog::initialize_callbacks().
void video::update_buffers | ( | bool | autoupdate = true | ) |
Update buffers to match current resolution and pixel scale settings.
If autoupdate
is true and buffers are changed by this call, a full redraw is also triggered.
If nothing has changed, it will not generate any new buffers or queue the redraw.
Definition at line 833 of file video.cpp.
References draw_manager::invalidate_all(), LOG_DP, and update_framebuffer().
Referenced by gui2::dialogs::preferences_dialog::apply_pixel_scale(), events::pump(), set_fullscreen(), and set_resolution().
|
static |
Definition at line 207 of file video.cpp.
References pref_constants::def_window_height, pref_constants::def_window_width, draw_area(), force_render_target(), prefs::get(), h, LOG_DP, pref_constants::max_pixel_scale, pref_constants::max_window_height, pref_constants::max_window_width, pref_constants::min_window_height, pref_constants::min_window_width, rect::origin(), prefs::pixel_scale(), xbrz::scale(), rect::size(), to_output(), update_test_framebuffer(), and w.
Referenced by init_window(), and update_buffers().
|
static |
Returns true if the buffer was changed.
Definition at line 165 of file video.cpp.
References force_render_target(), h, LOG_DP, and w.
Referenced by init_test_window(), set_resolution(), and update_framebuffer().
|
static |
Tests whether the given flags are currently set on the SDL window.
flags | The flags to test, OR'd together. |
Definition at line 686 of file video.cpp.
Referenced by window_has_focus(), window_has_mouse_focus(), and window_is_visible().
bool video::window_has_focus | ( | ) |
True iff the window has mouse or input focus.
Definition at line 696 of file video.cpp.
References window_has_flags().
bool video::window_has_mouse_focus | ( | ) |
True iff the window has mouse focus.
Definition at line 701 of file video.cpp.
References window_has_flags().
Referenced by controller_base::handle_scroll().
bool video::window_is_visible | ( | ) |
True iff the window is not hidden.
Definition at line 691 of file video.cpp.
References window_has_flags().
point video::window_size | ( | ) |
Returns the size of the window in display units / screen coordinates.
This should match the value sent by window resize events, and also those used for setting resolution.
Definition at line 419 of file video.cpp.
Referenced by gui2::dialogs::help_browser::on_topic_select(), gui2::dialogs::help_browser::pre_show(), events::pump(), and events::raise_resize_event().