Remove support for pixmap cache

This code has issues and there is no evidence that it improves performance.

Remove LyXRC variable \use_pixmap_cache and update rc format to 29.

Now the global pixmap cache is only used by GuiCompleter. Therefore
there is no need to reset it when fonts change.
This commit is contained in:
Jean-Marc Lasgouttes 2018-10-07 14:48:05 +02:00
parent ff933b52f5
commit 9fe101e890
11 changed files with 17 additions and 152 deletions

View File

@ -29,6 +29,9 @@
* \use_qimage
This is no longer necessary due to the rewrite of the painter.
* \use_pixmap_cacheqimage
There is no evidence that this painting mode was useful anymore.
* \date_insert_format
The function date-insert has been removed and superseded by info-insert date.
The latter does not need a pref value anymore.

View File

@ -1798,7 +1798,7 @@ if __name__ == '__main__':
lyx_check_config = True
lyx_kpsewhich = True
outfile = 'lyxrc.defaults'
lyxrc_fileformat = 27
lyxrc_fileformat = 29
rc_entries = ''
lyx_keep_temps = False
version_suffix = ''

View File

@ -114,6 +114,9 @@
# Incremented to format 28, by spitz
# Remove date_insert_format
# Incremented to format 29, by lasgouttes
# Remove use_pixmap_cache
# NOTE: The format should also be updated in LYXRC.cpp and
# in configure.py.
@ -413,6 +416,11 @@ def remove_date_insert_format(line):
return no_match
return (True, "")
def remove_use_pixmap_cache(line):
if not line.lower().startswith("\\use_pixmap_cache "):
return no_match
return (True, "")
# End conversions for LyX 2.3 to 2.4
####################################
@ -455,5 +463,6 @@ conversions = [
[ 25, [remove_use_qimage]],
[ 26, [remove_font_encoding]],
[ 27, []],
[ 28, [remove_date_insert_format]]
[ 28, [remove_date_insert_format]],
[ 29, [remove_use_pixmap_cache]]
]

View File

@ -59,7 +59,7 @@ namespace {
// The format should also be updated in configure.py, and conversion code
// should be added to prefs2prefs_prefs.py.
static unsigned int const LYXRC_FILEFORMAT = 28; // spitz: remove \\date_insert_format
static unsigned int const LYXRC_FILEFORMAT = 29; // spitz: remove \\date_insert_format
// when adding something to this array keep it sorted!
LexerKeyword lyxrcTags[] = {
{ "\\accept_compound", LyXRC::RC_ACCEPT_COMPOUND },
@ -193,7 +193,6 @@ LexerKeyword lyxrcTags[] = {
{ "\\use_converter_needauth_forbidden", LyXRC::RC_USE_CONVERTER_NEEDAUTH_FORBIDDEN },
{ "\\use_lastfilepos", LyXRC::RC_USELASTFILEPOS },
{ "\\use_native_filedialog", LyXRC::RC_USE_NATIVE_FILEDIALOG },
{ "\\use_pixmap_cache", LyXRC::RC_USE_PIXMAP_CACHE },
// compatibility with versions older than 1.4.0 only
{ "\\use_system_colors", LyXRC::RC_USE_SYSTEM_COLORS },
{ "\\use_system_theme_icons", LyXRC::RC_USE_SYSTEM_THEME_ICONS },
@ -326,7 +325,6 @@ void LyXRC::setDefaults()
use_converter_needauth = true;
use_system_colors = false;
use_tooltip = true;
use_pixmap_cache = false;
converter_cache_maxage = 6 * 30 * 24 * 3600; // 6 months
user_name = to_utf8(support::user_name());
user_email = to_utf8(support::user_email());
@ -877,9 +875,6 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
case RC_USE_TOOLTIP:
lexrc >> use_tooltip;
break;
case RC_USE_PIXMAP_CACHE:
lexrc >> use_pixmap_cache;
break;
case RC_SPELLCHECKER:
lexrc >> spellchecker;
break;
@ -2414,16 +2409,6 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
if (tag != RC_LAST)
break;
// fall through
case RC_USE_PIXMAP_CACHE:
if (ignore_system_lyxrc ||
use_pixmap_cache != system_lyxrc.use_pixmap_cache) {
os << "\\use_pixmap_cache "
<< convert<string>(use_pixmap_cache)
<< '\n';
}
if (tag != RC_LAST)
break;
// fall through
os << "\n#\n"
<< "# LANGUAGE SUPPORT SECTION ##########################\n"
@ -3005,7 +2990,6 @@ void actOnUpdatedPrefs(LyXRC const & lyxrc_orig, LyXRC const & lyxrc_new)
case LyXRC::RC_USE_NATIVE_FILEDIALOG:
case LyXRC::RC_USE_SYSTEM_COLORS:
case LyXRC::RC_USE_TOOLTIP:
case LyXRC::RC_USE_PIXMAP_CACHE:
case LyXRC::RC_USE_SYSTEM_THEME_ICONS:
case LyXRC::RC_VIEWDVI_PAPEROPTION:
case LyXRC::RC_SINGLE_CLOSE_TAB_BUTTON:
@ -3419,10 +3403,6 @@ string const LyXRC::getDescription(LyXRCTags tag)
str = _("Enable the automatic appearance of tool tips in the work area.");
break;
case RC_USE_PIXMAP_CACHE:
str = _("Enable the pixmap cache that might improve performance on Mac and Windows.");
break;
case RC_VIEWDVI_PAPEROPTION:
_("Specify the paper command to DVI viewer (leave empty or use \"-paper\")");
break;

View File

@ -173,7 +173,6 @@ public:
RC_USE_NATIVE_FILEDIALOG,
RC_USE_SYSTEM_COLORS,
RC_USE_TOOLTIP,
RC_USE_PIXMAP_CACHE,
RC_USE_SYSTEM_THEME_ICONS,
RC_VIEWDVI_PAPEROPTION,
RC_VIEWER,
@ -333,8 +332,6 @@ public:
bool use_system_colors;
/// use native file dialog or our own ?
bool use_native_filedialog;
/// Use pixmap cache?
bool use_pixmap_cache;
/// Spellchecker engine: aspell, hunspell, etc
std::string spellchecker;
/// Alternate language for spellchecker

View File

@ -102,7 +102,6 @@
#include <QMimeData>
#include <QObject>
#include <QPixmap>
#include <QPixmapCache>
#include <QRegExp>
#include <QSessionManager>
#include <QSettings>
@ -1078,10 +1077,6 @@ GuiApplication::GuiApplication(int & argc, char ** argv)
guiApp = this;
// Set the cache to 5120 kilobytes which corresponds to screen size of
// 1280 by 1024 pixels with a color depth of 32 bits.
QPixmapCache::setCacheLimit(5120);
// Initialize RC Fonts
if (lyxrc.roman_font_name.empty())
lyxrc.roman_font_name = fromqstr(romanFontName());

View File

@ -29,17 +29,8 @@
#include <algorithm>
#include <QPixmapCache>
#include <QTextLayout>
// Set USE_PIXMAP_CACHE to 1 for enabling the use of a Pixmap cache when
// drawing text. This is especially useful for older PPC/Mac systems.
#if defined(Q_WS_X11) || defined(QPA_XCB)
#define USE_PIXMAP_CACHE 0
#else
#define USE_PIXMAP_CACHE 1
#endif
using namespace std;
using namespace lyx::support;
@ -49,8 +40,7 @@ namespace frontend {
const int Painter::thin_line = 1;
GuiPainter::GuiPainter(QPaintDevice * device, double pixel_ratio)
: QPainter(device), Painter(pixel_ratio),
use_pixmap_cache_(lyxrc.use_pixmap_cache && USE_PIXMAP_CACHE)
: QPainter(device), Painter(pixel_ratio)
{
// set cache correctly
current_color_ = pen().color();
@ -93,33 +83,6 @@ void GuiPainter::setQPainterPen(QColor const & col,
}
QString GuiPainter::generateStringSignature(QString const & str,
FontInfo const & f,
double wordspacing)
{
QString sig = str;
sig.append(QChar(static_cast<short>(f.family())));
sig.append(QChar(static_cast<short>(f.series())));
sig.append(QChar(static_cast<short>(f.realShape())));
sig.append(QChar(static_cast<short>(f.size())));
Color const & color = f.realColor();
sig.append(QChar(static_cast<short>(color.baseColor)));
sig.append(QChar(static_cast<short>(color.mergeColor)));
sig.append(QString::number(wordspacing));
if (!monochrome_min_.empty()) {
QColor const & min = monochrome_min_.top();
QColor const & max = monochrome_max_.top();
sig.append(QChar(static_cast<short>(min.red())));
sig.append(QChar(static_cast<short>(min.green())));
sig.append(QChar(static_cast<short>(min.blue())));
sig.append(QChar(static_cast<short>(max.red())));
sig.append(QChar(static_cast<short>(max.green())));
sig.append(QChar(static_cast<short>(max.blue())));
}
return sig;
}
QColor GuiPainter::computeColor(Color col)
{
return filterColor(guiApp->colorCache().get(col));
@ -396,7 +359,7 @@ void GuiPainter::text(int x, int y, docstring const & s,
int textwidth = 0;
if (tw == 0.0)
// Note that we have to take in account space stretching (word spacing)
// Take into account space stretching (word spacing)
textwidth = fm.width(s) +
static_cast<int>(fm.countExpanders(s) * wordspacing);
else
@ -404,55 +367,6 @@ void GuiPainter::text(int x, int y, docstring const & s,
textDecoration(f, x, y, textwidth);
if (use_pixmap_cache_) {
QPixmap pm;
QString key = generateStringSignature(str, f, wordspacing);
// Warning: Left bearing is in general negative! Only the case
// where left bearing is negative is of interest WRT the
// pixmap width and the text x-position.
// Only the left bearing of the first character is important
// as we always write from left to right, even for
// right-to-left languages.
// FIXME: this is probably broken for RTL now that we draw full strings.
// Morover the first/last element is possibly not the right one since the glyph may have changed.
int const lb = min(fm.lbearing(s[0]), 0);
int const mA = fm.maxAscent();
if (QPixmapCache::find(key, pm)) {
// Draw the cached pixmap.
drawPixmap(x + lb, y - mA, pm);
return;
}
// Only the right bearing of the last character is
// important as we always write from left to right,
// even for right-to-left languages.
int const rb = fm.rbearing(s[s.size()-1]);
int const w = textwidth + rb - lb;
int const mD = fm.maxDescent();
int const h = mA + mD;
if (w > 0 && h > 0) {
pm = QPixmap(static_cast<int>(pixelRatio() * w),
static_cast<int>(pixelRatio() * h));
#if QT_VERSION >= 0x050000
pm.setDevicePixelRatio(pixelRatio());
#endif
pm.fill(Qt::transparent);
GuiPainter p(&pm, pixelRatio());
p.do_drawText(-lb, mA, str, dir, f, ff);
QPixmapCache::insert(key, pm);
//LYXERR(Debug::PAINTING, "h=" << h << " mA=" << mA << " mD=" << mD
// << " w=" << w << " lb=" << lb << " tw=" << textwidth
// << " rb=" << rb);
// Draw the new cached pixmap.
drawPixmap(x + lb, y - mA, pm);
//rectangle(x-lb, y-mA, w, h, Color_green);
}
return;
}
// don't use the pixmap cache
setQPainterPen(computeColor(f.realColor()));
if (dir != Auto) {
shared_ptr<QTextLayout const> ptl =

View File

@ -196,8 +196,6 @@ private:
Painter::line_style current_ls_;
int current_lw_;
///
bool const use_pixmap_cache_;
///
std::stack<QColor> monochrome_min_;
///
std::stack<QColor> monochrome_max_;
@ -205,9 +203,6 @@ private:
QColor computeColor(Color col);
/// possibly apply monochrome mode
QColor filterColor(QColor const & col);
///
QString generateStringSignature(QString const & str, FontInfo const & f,
double wordspacing);
};
} // namespace frontend

View File

@ -61,7 +61,6 @@
#include <QHeaderView>
#include <QLineEdit>
#include <QMessageBox>
#include <QPixmapCache>
#include <QPushButton>
#include <QSpinBox>
#include <QString>
@ -995,8 +994,6 @@ PrefScreenFonts::PrefScreenFonts(GuiPreferences * form)
this, SIGNAL(changed()));
connect(screenHugerED, SIGNAL(textChanged(QString)),
this, SIGNAL(changed()));
connect(pixmapCacheCB, SIGNAL(toggled(bool)),
this, SIGNAL(changed()));
screenTinyED->setValidator(new QDoubleValidator(screenTinyED));
screenSmallestED->setValidator(new QDoubleValidator(screenSmallestED));
@ -1033,17 +1030,12 @@ void PrefScreenFonts::applyRC(LyXRC & rc) const
rc.font_sizes[FONT_SIZE_LARGEST] = widgetToDoubleStr(screenLargestED);
rc.font_sizes[FONT_SIZE_HUGE] = widgetToDoubleStr(screenHugeED);
rc.font_sizes[FONT_SIZE_HUGER] = widgetToDoubleStr(screenHugerED);
rc.use_pixmap_cache = pixmapCacheCB->isChecked();
if (rc.font_sizes != oldrc.font_sizes
|| rc.roman_font_name != oldrc.roman_font_name
|| rc.sans_font_name != oldrc.sans_font_name
|| rc.typewriter_font_name != oldrc.typewriter_font_name
|| rc.defaultZoom != oldrc.defaultZoom) {
// The global QPixmapCache is used in GuiPainter to cache text
// painting so we must reset it in case any of the above
// parameter is changed.
QPixmapCache::clear();
guiApp->fontLoader().update();
form_->updateScreenFonts();
}
@ -1065,12 +1057,6 @@ void PrefScreenFonts::updateRC(LyXRC const & rc)
screenZoomSB->setValue(rc.defaultZoom);
updateScreenFontSizes(rc);
pixmapCacheCB->setChecked(rc.use_pixmap_cache);
#if defined(Q_WS_X11) || defined(QPA_XCB)
pixmapCacheCB->setEnabled(false);
#endif
}

View File

@ -100,7 +100,6 @@
#include <QMovie>
#include <QPainter>
#include <QPixmap>
#include <QPixmapCache>
#include <QPoint>
#include <QPushButton>
#include <QScrollBar>
@ -4293,9 +4292,6 @@ void GuiView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
dr.setMessage(bformat(_("Zoom level is now %1$d% (default value: %2$d%)"),
lyxrc.currentZoom, lyxrc.defaultZoom));
// The global QPixmapCache is used in GuiPainter to cache text
// painting so we must reset it.
QPixmapCache::clear();
guiApp->fontLoader().update();
dr.screenUpdate(Update::Force | Update::FitCursor);
break;

View File

@ -407,16 +407,6 @@
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="pixmapCacheCB">
<property name="toolTip">
<string>Checking this improves performance, but might decrease the on-screen quality of fonts</string>
</property>
<property name="text">
<string>&amp;Use pixmap cache to speed up font rendering</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer>
<property name="orientation">