# HG changeset patch # User Chris Cannam # Date 1430131081 -3600 # Node ID b1aa74ce697e76bc3bfa67d2d70d8e053dce4b4d # Parent 53e039d99b5df407f169e341d58cf1b28cecc7c3 Always render to a buffer, then from that to the widget diff -r 53e039d99b5d -r b1aa74ce697e view/View.cpp --- a/view/View.cpp Mon Apr 20 15:59:03 2015 +0100 +++ b/view/View.cpp Mon Apr 27 11:38:01 2015 +0100 @@ -60,6 +60,7 @@ m_playPointerFrame(0), m_showProgress(showProgress), m_cache(0), + m_buffer(0), m_cacheCentreFrame(0), m_cacheZoomLevel(1024), m_selectionCached(false), @@ -1752,10 +1753,14 @@ int dpratio = devicePixelRatio(); - QSize scaledCacheSize(width() * dpratio, height() * dpratio); - QRect scaledCacheRect(cacheRect.x() * dpratio, cacheRect.y() * dpratio, - cacheRect.width() * dpratio, cacheRect.height() * dpratio); - + QSize scaledCacheSize(scaledSize(size(), dpratio)); + QRect scaledCacheRect(scaledRect(cacheRect, dpratio)); + + if (!m_buffer || scaledCacheSize != m_buffer->size()) { + delete m_buffer; + m_buffer = new QPixmap(scaledCacheSize); + } + if (!scrollables.empty()) { #ifdef DEBUG_VIEW_WIDGET_PAINT @@ -1823,8 +1828,8 @@ #ifdef DEBUG_VIEW_WIDGET_PAINT cerr << "View(" << this << ")::paintEvent: cache is good" << endl; #endif - paint.begin(this); - paint.drawPixmap(cacheRect, *m_cache, scaledCacheRect); + paint.begin(m_buffer); + paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect); paint.end(); QFrame::paintEvent(e); paintedCacheRect = true; @@ -1850,8 +1855,8 @@ paint.begin(m_cache); rectToPaint = scaledCacheRect; } else { - paint.begin(this); - rectToPaint = cacheRect; + paint.begin(m_buffer); + rectToPaint = scaledCacheRect; } setPaintFont(paint); @@ -1883,8 +1888,9 @@ if (repaintCache) { cacheRect |= (e ? e->rect() : rect()); - paint.begin(this); - paint.drawPixmap(cacheRect, *m_cache, scaledCacheRect); + scaledCacheRect = scaledRect(cacheRect, dpratio); + paint.begin(m_buffer); + paint.drawPixmap(scaledCacheRect, *m_cache, scaledCacheRect); paint.end(); } } @@ -1895,13 +1901,15 @@ nonCacheRect |= cacheRect; - paint.begin(this); - paint.setClipRect(nonCacheRect); + QRect scaledNonCacheRect = scaledRect(nonCacheRect, dpratio); + + paint.begin(m_buffer); + paint.setClipRect(scaledNonCacheRect); setPaintFont(paint); if (scrollables.empty()) { paint.setPen(getBackground()); paint.setBrush(getBackground()); - paint.drawRect(nonCacheRect); + paint.drawRect(scaledNonCacheRect); } paint.setPen(getForeground()); @@ -1912,14 +1920,14 @@ #ifdef DEBUG_VIEW_WIDGET_PAINT cerr << "Painting non-scrollable layer " << *i << " without proxy with repaintCache = " << repaintCache << ", dpratio = " << dpratio << ", rectToPaint = " << nonCacheRect.x() << "," << nonCacheRect.y() << " " << nonCacheRect.width() << "x" << nonCacheRect.height() << endl; #endif - (*i)->paint(this, paint, nonCacheRect); + (*i)->paint(&proxy, paint, scaledNonCacheRect); } paint.end(); - paint.begin(this); + paint.begin(m_buffer); setPaintFont(paint); - if (e) paint.setClipRect(e->rect()); + if (e) paint.setClipRect(scaledRect(e->rect(), dpratio)); if (!m_selectionCached) { drawSelections(paint); } @@ -1940,7 +1948,12 @@ showPlayPointer = false; } } - + + paint.begin(this); + QRect finalPaintRect = e ? e->rect() : rect(); + paint.drawPixmap(finalPaintRect, *m_buffer, scaledRect(finalPaintRect, dpratio)); + paint.end(); + if (showPlayPointer) { paint.begin(this); diff -r 53e039d99b5d -r b1aa74ce697e view/View.h --- a/view/View.h Mon Apr 20 15:59:03 2015 +0100 +++ b/view/View.h Mon Apr 27 11:38:01 2015 +0100 @@ -389,6 +389,14 @@ virtual bool shouldLabelSelections() const { return true; } virtual bool render(QPainter &paint, int x0, sv_frame_t f0, sv_frame_t f1); virtual void setPaintFont(QPainter &paint); + + QSize scaledSize(const QSize &s, int factor) { + return QSize(s.width() * factor, s.height() * factor); + } + QRect scaledRect(const QRect &r, int factor) { + return QRect(r.x() * factor, r.y() * factor, + r.width() * factor, r.height() * factor); + } typedef std::vector LayerList; @@ -429,6 +437,7 @@ bool m_showProgress; QPixmap *m_cache; + QPixmap *m_buffer; sv_frame_t m_cacheCentreFrame; int m_cacheZoomLevel; bool m_selectionCached;