[wesnoth-commits] [wesnoth/wesnoth] b2d39d: Only render the visible area in canvas.cpp

Steve Cotton noreply at github.com
Thu Apr 29 10:35:30 UTC 2021


  Branch: refs/heads/master
  Home:   https://github.com/wesnoth/wesnoth
  Commit: b2d39d27543757609ce932cb173ba4113d499bab
      https://github.com/wesnoth/wesnoth/commit/b2d39d27543757609ce932cb173ba4113d499bab
  Author: Steve Cotton <steve at octalot.co.uk>
  Date:   2021-04-29 (Thu, 29 Apr 2021)

  Changed paths:
    M changelog.md
    M src/gui/core/canvas.cpp
    M src/gui/core/canvas.hpp
    M src/gui/core/canvas_private.hpp

  Log Message:
  -----------
  Only render the visible area in canvas.cpp

If a widget is partially hidden or off-screen, this commit makes canvas.cpp
optimise and only draw the visible part.

Many of the asserts in canvas.cpp are removed, as the surface is no longer the
full canvas. The SDL_Render* functions do support the out-of-bounds and
negative values for x and y that are now passed to them, these are tested by
SDL2's testviewport.c.

Scrolling by a single pixel will force canvas::draw to do the full work of
redrawing the canvas. I had considered rendering a few of the off-screen lines
too, however it seems this isn't optimisable because the dirty flag is already
set on each redraw - that can be traced to window.cpp's push_draw_event()
causing canvas::set_is_dirty(true) to be called.

Refactor handling of the x, y, w, h variables with a common rect_bounded_shape
class, so that there are less code paths that might have unnoticed bugs.





More information about the Commits mailing list