Move DrawStrategy enum to update_flags.h.

Introduce new drawStrategy() and drawStrategyDescription() methods to
frontend::Application.

Show the current draw strategy in About dialog.
This commit is contained in:
Jean-Marc Lasgouttes 2024-06-18 14:28:28 +02:00
parent 95a7440b0e
commit c263463cad
9 changed files with 62 additions and 30 deletions

View File

@ -58,6 +58,7 @@
#include "mathed/MathRow.h"
#include "frontends/alert.h"
#include "frontends/Application.h"
#include "frontends/CaretGeometry.h"
#include "frontends/Delegates.h"
#include "frontends/FontMetrics.h"
@ -592,7 +593,7 @@ void BufferView::processUpdateFlags(Update::flags flags)
flags = (flags & ~Update::FitCursor) | Update::ForceDraw;
}
if (lyxrc.draw_strategy == LyXRC::DS_FULL)
if (theApp()->drawStrategy() == DrawStrategy::Full)
flags = flags | Update::ForceDraw;
// Add flags to the the update flags. These will be reset to None

View File

@ -1144,11 +1144,11 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
if (lexrc.next()) {
string const tmp = lexrc.getString();
if (tmp == "partial")
draw_strategy = DS_PARTIAL;
draw_strategy = DrawStrategy::Partial;
else if (tmp == "backingstore")
draw_strategy = DS_BACKINGSTORE;
draw_strategy = DrawStrategy::Backingstore;
else if (tmp == "full")
draw_strategy = DS_FULL;
draw_strategy = DrawStrategy::Full;
else {
LYXERR0("Unrecognized draw strategy " << tmp <<'"');
}
@ -2056,13 +2056,13 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
draw_strategy != system_lyxrc.draw_strategy) {
string status;
switch (draw_strategy) {
case DS_FULL:
case DrawStrategy::Full:
status = "full";
break;
case DS_PARTIAL:
case DrawStrategy::Partial:
status = "partial";
break;
case DS_BACKINGSTORE:
case DrawStrategy::Backingstore:
status = "backingstore";
break;
}

View File

@ -19,6 +19,7 @@
#define LYXRC_H
#include "LyX.h"
#include "update_flags.h"
#include "support/Length.h"
#include "support/strfwd.h"
@ -579,16 +580,8 @@ public:
///
BookmarksVisibility bookmarks_visibility = BMK_NONE;
enum DrawStrategy {
// draw all
DS_FULL,
// draw only what has changed
DS_PARTIAL,
// draw in backing store (only what has changed)
DS_BACKINGSTORE
};
///
DrawStrategy draw_strategy = DS_PARTIAL;
DrawStrategy draw_strategy = DrawStrategy::Partial;
};

View File

@ -13,6 +13,7 @@
#include "ColorCode.h"
#include "FuncCode.h"
#include "update_flags.h"
#include "support/strfwd.h"
@ -203,6 +204,11 @@ public:
/// Like getRgbColor(), but static and slower
static bool getRgbColorUncached(ColorCode col, RGBColor & rgbcol);
/// \returns the draw strategy used by the application
virtual DrawStrategy drawStrategy() const = 0;
/// \returns the description of the draw strategy used by the application
virtual docstring drawStrategyDescription() const = 0;
/**
* @return true if LyX uses a dark theme
*/

View File

@ -298,6 +298,11 @@ static QString version(bool const plain = false)
out << "</p><p>";
#endif
out << toqstr(bformat(_("Python detected: %1$s"), from_utf8(os::python_info())));
if (plain)
out << '\n';
else
out << "</p><p>";
out << toqstr(bformat(_("Draw strategy: %1$s"), guiApp->drawStrategyDescription()));
if (!plain)
out << toqstr("</p></body></html>");
return res;

View File

@ -2730,16 +2730,36 @@ Menus & GuiApplication::menus()
}
bool GuiApplication::noPartialDraw() const
DrawStrategy GuiApplication::drawStrategy() const
{
/* Qt on macOS and Wayland does not respect the
* Qt::WA_OpaquePaintEvent attribute and resets the widget backing
* store at each update. Therefore, if it not good to use
* "partial" draw strategy in these cases. It is also possible to
* force the use of the backing store for cases like x11 with
* "partial" draw strategy in these cases. It can also be useful
* to force the use of the backing store for cases like X11 with
* transparent WM themes.
*/
return platformName() == "cocoa" || platformName().contains("wayland");
if (lyxrc.draw_strategy == DrawStrategy::Partial
&& (platformName() == "cocoa" || platformName().contains("wayland")))
return DrawStrategy::Backingstore;
else
return lyxrc.draw_strategy;
}
docstring GuiApplication::drawStrategyDescription() const
{
switch(drawStrategy()) {
case DrawStrategy::Partial:
return _("partial draw");
break;
case DrawStrategy::Backingstore:
return _("partial draw on backing store");
break;
case DrawStrategy::Full:
return _("full draw");
}
return docstring();
}

View File

@ -113,8 +113,9 @@ public:
///
Menus & menus();
/// \returns true the "partial" draw strategy is known to be broken
bool noPartialDraw() const;
/// \returns the draw strategy used by the application
DrawStrategy drawStrategy() const;
virtual docstring drawStrategyDescription() const override;
/// \name Methods inherited from QApplication class
//@{

View File

@ -130,14 +130,8 @@ SyntheticMouseEvent::SyntheticMouseEvent()
GuiWorkArea::Private::Private(GuiWorkArea * parent)
: p(parent), completer_(new GuiCompleter(p, p))
{
use_backingstore_ = lyxrc.draw_strategy == LyXRC::DS_BACKINGSTORE
|| (lyxrc.draw_strategy == LyXRC::DS_PARTIAL && guiApp->noPartialDraw());
if (use_backingstore_)
LYXERR(Debug::WORKAREA, "Drawing strategy: partial draw on backing store");
else
LYXERR(Debug::WORKAREA, "Drawing strategy: "
<< (lyxrc.draw_strategy == LyXRC::DS_PARTIAL ? "partial draw"
: "full draw"));
use_backingstore_ = guiApp->drawStrategy() == DrawStrategy::Backingstore;
LYXERR(Debug::WORKAREA, "Drawing strategy: " << guiApp->drawStrategyDescription());
int const time = QApplication::cursorFlashTime() / 2;
if (time > 0) {

View File

@ -51,5 +51,17 @@ inline flags operator~(flags const f)
} // namespace Update
// How the work area gets drawn (painted)
enum class DrawStrategy {
// draw all
Full,
// draw only what has changed
Partial,
// draw in backing store (only what has changed)
Backingstore
};
} // namespace lyx
#endif