changeset 915:f6d9f28f37cb osx-retina

Experiment with querying paint rect separately from view rect
author Chris Cannam
date Wed, 11 Mar 2015 15:35:20 +0000
parents 59e51842cf39
children 94e4952a6774
files layer/WaveformLayer.cpp view/View.cpp view/View.h
diffstat 3 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/layer/WaveformLayer.cpp	Wed Mar 11 13:54:01 2015 +0000
+++ b/layer/WaveformLayer.cpp	Wed Mar 11 15:35:20 2015 +0000
@@ -494,8 +494,8 @@
                                      mergingChannels, mixingChannels);
     if (channels == 0) return;
 
-    int w = v->width();
-    int h = v->height();
+    int w = v->getPaintWidth();
+    int h = v->getPaintHeight();
 
     bool ready = m_model->isReady();
     QPainter *paint;
@@ -559,7 +559,7 @@
     y1 = rect.bottom();
 
     if (x0 > 0) --x0;
-    if (x1 < v->width()) ++x1;
+    if (x1 < w) ++x1;
 
     // Our zoom level may differ from that at which the underlying
     // model has its blocks.
@@ -939,7 +939,7 @@
 
     if (m_aggressive) {
 
-	if (ready && rect == v->rect()) {
+	if (ready && rect == v->getPaintRect()) {
 	    m_cacheValid = true;
 	    m_cacheZoomLevel = zoomLevel;
 	}
--- a/view/View.cpp	Wed Mar 11 13:54:01 2015 +0000
+++ b/view/View.cpp	Wed Mar 11 15:35:20 2015 +0000
@@ -58,6 +58,7 @@
     m_followPlayIsDetached(false),
     m_playPointerFrame(0),
     m_showProgress(showProgress),
+    m_paintScale(1),
     m_cache(0),
     m_cacheCentreFrame(0),
     m_cacheZoomLevel(1024),
@@ -1658,6 +1659,14 @@
     paint.setFont(font);
 }
 
+QRect
+View::getPaintRect() const
+{
+    QRect r(rect());
+    return QRect(r.x() * m_paintScale, r.y() * m_paintScale, 
+                 r.width() * m_paintScale, r.height() * m_paintScale);
+}
+
 void
 View::paintEvent(QPaintEvent *e)
 {
@@ -1838,9 +1847,11 @@
 	if (repaintCache) {
             paint.begin(m_cache);
             rectToPaint = scaledCacheRect;
+            m_paintScale = dpratio;
         } else {
             paint.begin(this);
             rectToPaint = cacheRect;
+            m_paintScale = 1;
         }
 
         setPaintFont(paint);
--- a/view/View.h	Wed Mar 11 13:54:01 2015 +0000
+++ b/view/View.h	Wed Mar 11 15:35:20 2015 +0000
@@ -315,6 +315,18 @@
     sv_frame_t getModelsStartFrame() const;
     sv_frame_t getModelsEndFrame() const;
 
+    /**
+     * To be called from a layer, to obtain the extent of the surface
+     * that the layer is currently painting to. This may be the extent
+     * of the view (if 1x display scaling is in effect) or of a larger
+     * cached pixmap (if greater display scaling is in effect).
+     */
+    QRect getPaintRect() const;
+
+    QSize getPaintSize() const { return getPaintRect().size(); }
+    int getPaintWidth() const { return getPaintRect().width(); }
+    int getPaintHeight() const { return getPaintRect().height(); }
+
     typedef std::set<Model *> ModelSet;
     ModelSet getModels();
 
@@ -415,6 +427,7 @@
     sv_frame_t          m_playPointerFrame;
     bool                m_lightBackground;
     bool                m_showProgress;
+    int                 m_paintScale;
 
     QPixmap            *m_cache;
     sv_frame_t          m_cacheCentreFrame;