From 9fe101e8900300661c999e1edc834f1dbcf2e40c Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sun, 7 Oct 2018 14:48:05 +0200 Subject: [PATCH] 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. --- lib/RELEASE-NOTES | 3 + lib/configure.py | 2 +- lib/scripts/prefs2prefs_prefs.py | 11 ++- src/LyXRC.cpp | 22 +----- src/LyXRC.h | 3 - src/frontends/qt4/GuiApplication.cpp | 5 -- src/frontends/qt4/GuiPainter.cpp | 90 +---------------------- src/frontends/qt4/GuiPainter.h | 5 -- src/frontends/qt4/GuiPrefs.cpp | 14 ---- src/frontends/qt4/GuiView.cpp | 4 - src/frontends/qt4/ui/PrefScreenFontsUi.ui | 10 --- 11 files changed, 17 insertions(+), 152 deletions(-) diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES index 6e19d292ae..c834957aed 100644 --- a/lib/RELEASE-NOTES +++ b/lib/RELEASE-NOTES @@ -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. diff --git a/lib/configure.py b/lib/configure.py index 05ee457c23..1aaecb8b5b 100644 --- a/lib/configure.py +++ b/lib/configure.py @@ -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 = '' diff --git a/lib/scripts/prefs2prefs_prefs.py b/lib/scripts/prefs2prefs_prefs.py index 5e7c0bf627..0679072376 100644 --- a/lib/scripts/prefs2prefs_prefs.py +++ b/lib/scripts/prefs2prefs_prefs.py @@ -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]] ] diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp index d11181fcc5..42dfad3731 100644 --- a/src/LyXRC.cpp +++ b/src/LyXRC.cpp @@ -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(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; diff --git a/src/LyXRC.h b/src/LyXRC.h index 8a371d902c..6e1ccfd7c8 100644 --- a/src/LyXRC.h +++ b/src/LyXRC.h @@ -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 diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index cbea58ad1c..c47610937b 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -102,7 +102,6 @@ #include #include #include -#include #include #include #include @@ -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()); diff --git a/src/frontends/qt4/GuiPainter.cpp b/src/frontends/qt4/GuiPainter.cpp index 2c6529a938..2f0cc8fa4b 100644 --- a/src/frontends/qt4/GuiPainter.cpp +++ b/src/frontends/qt4/GuiPainter.cpp @@ -29,17 +29,8 @@ #include -#include #include -// 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(f.family()))); - sig.append(QChar(static_cast(f.series()))); - sig.append(QChar(static_cast(f.realShape()))); - sig.append(QChar(static_cast(f.size()))); - Color const & color = f.realColor(); - sig.append(QChar(static_cast(color.baseColor))); - sig.append(QChar(static_cast(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(min.red()))); - sig.append(QChar(static_cast(min.green()))); - sig.append(QChar(static_cast(min.blue()))); - sig.append(QChar(static_cast(max.red()))); - sig.append(QChar(static_cast(max.green()))); - sig.append(QChar(static_cast(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(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(pixelRatio() * w), - static_cast(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 ptl = diff --git a/src/frontends/qt4/GuiPainter.h b/src/frontends/qt4/GuiPainter.h index 7513965ea6..54b86e4744 100644 --- a/src/frontends/qt4/GuiPainter.h +++ b/src/frontends/qt4/GuiPainter.h @@ -196,8 +196,6 @@ private: Painter::line_style current_ls_; int current_lw_; /// - bool const use_pixmap_cache_; - /// std::stack monochrome_min_; /// std::stack 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 diff --git a/src/frontends/qt4/GuiPrefs.cpp b/src/frontends/qt4/GuiPrefs.cpp index c08245c858..afbce50e94 100644 --- a/src/frontends/qt4/GuiPrefs.cpp +++ b/src/frontends/qt4/GuiPrefs.cpp @@ -61,7 +61,6 @@ #include #include #include -#include #include #include #include @@ -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 - } diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 2fb58deb84..56f4f7b4c6 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -100,7 +100,6 @@ #include #include #include -#include #include #include #include @@ -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; diff --git a/src/frontends/qt4/ui/PrefScreenFontsUi.ui b/src/frontends/qt4/ui/PrefScreenFontsUi.ui index 2eaa453360..24b91624d6 100644 --- a/src/frontends/qt4/ui/PrefScreenFontsUi.ui +++ b/src/frontends/qt4/ui/PrefScreenFontsUi.ui @@ -407,16 +407,6 @@ - - - - Checking this improves performance, but might decrease the on-screen quality of fonts - - - &Use pixmap cache to speed up font rendering - - - -- 2.39.5