comparison layer/Colour3DPlotRenderer.cpp @ 1451:f72fb7fac92a single-point

When invalidating cache in a time-constrained context, don't start rendering in the same cycle as well - leave it for a further update. Slightly experimental effort to make the UI feel more responsive.
author Chris Cannam
date Wed, 01 May 2019 15:15:26 +0100
parents 6cf3cb6641e1
children 11a150e65ee1
comparison
equal deleted inserted replaced
1450:6cf3cb6641e1 1451:f72fb7fac92a
127 int x1 = v->getXForViewX(rect.x() + rect.width()); 127 int x1 = v->getXForViewX(rect.x() + rect.width());
128 if (x0 < 0) x0 = 0; 128 if (x0 < 0) x0 = 0;
129 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth(); 129 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
130 130
131 sv_frame_t startFrame = v->getStartFrame(); 131 sv_frame_t startFrame = v->getStartFrame();
132
133 bool justInvalidated =
134 (m_cache.getSize() != v->getPaintSize() ||
135 m_cache.getZoomLevel() != v->getZoomLevel());
132 136
133 m_cache.resize(v->getPaintSize()); 137 m_cache.resize(v->getPaintSize());
134 m_cache.setZoomLevel(v->getZoomLevel()); 138 m_cache.setZoomLevel(v->getZoomLevel());
135 139
136 m_magCache.resize(v->getPaintSize().width()); 140 m_magCache.resize(v->getPaintSize().width());
151 << " x1 " << x1 155 << " x1 " << x1
152 << endl; 156 << endl;
153 #endif 157 #endif
154 158
155 static HitCount count("Colour3DPlotRenderer: image cache"); 159 static HitCount count("Colour3DPlotRenderer: image cache");
156 160
157 if (m_cache.isValid()) { // some part of the cache is valid 161 if (m_cache.isValid()) { // some part of the cache is valid
158 162
159 if (v->getXForFrame(m_cache.getStartFrame()) == 163 if (v->getXForFrame(m_cache.getStartFrame()) ==
160 v->getXForFrame(startFrame) && 164 v->getXForFrame(startFrame) &&
161 m_cache.getValidLeft() <= x0 && 165 m_cache.getValidLeft() <= x0 &&
290 294
291 renderToCacheBinResolution(v, x0, x1 - x0); 295 renderToCacheBinResolution(v, x0, x1 - x0);
292 296
293 } else { // must be DrawBufferPixelResolution, handled DirectTranslucent earlier 297 } else { // must be DrawBufferPixelResolution, handled DirectTranslucent earlier
294 298
295 renderToCachePixelResolution(v, x0, x1 - x0, rightToLeft, timeConstrained); 299 if (timeConstrained && justInvalidated) {
300 SVDEBUG << "render: just invalidated cache in time-constrained context, that's all we're doing for now - wait for next update to start filling" << endl;
301 } else {
302 renderToCachePixelResolution(v, x0, x1 - x0, rightToLeft, timeConstrained);
303 }
296 } 304 }
297 305
298 QRect pr = rect & m_cache.getValidArea(); 306 QRect pr = rect & m_cache.getValidArea();
299 paint.drawImage(pr.x(), pr.y(), m_cache.getImage(), 307 paint.drawImage(pr.x(), pr.y(), m_cache.getImage(),
300 pr.x(), pr.y(), pr.width(), pr.height()); 308 pr.x(), pr.y(), pr.width(), pr.height());
301 309
302 if (!timeConstrained && (pr != rect)) { 310 if (!timeConstrained && (pr != rect)) {
303 SVCERR << "WARNING: failed to render entire requested rect " 311 SVCERR << "WARNING: failed to render entire requested rect "
304 << "even when not time-constrained: requested " 312 << "even when not time-constrained: wanted "
305 << rect.x() << "," << rect.y() << " " 313 << rect.x() << "," << rect.y() << " "
306 << rect.width() << "x" << rect.height() << ", have " 314 << rect.width() << "x" << rect.height() << ", got "
307 << pr.x() << "," << pr.y() << " " 315 << pr.x() << "," << pr.y() << " "
308 << pr.width() << "x" << pr.height() 316 << pr.width() << "x" << pr.height()
317 << ", after request of width " << (x1 - x0)
309 << endl; 318 << endl;
310 } 319 }
311 320
312 MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0); 321 MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0);
313 322
991 1000
992 int modelWidth = sourceModel->getWidth(); 1001 int modelWidth = sourceModel->getWidth();
993 1002
994 #ifdef DEBUG_COLOUR_PLOT_REPAINT 1003 #ifdef DEBUG_COLOUR_PLOT_REPAINT
995 SVDEBUG << "modelWidth " << modelWidth << ", divisor " << divisor << endl; 1004 SVDEBUG << "modelWidth " << modelWidth << ", divisor " << divisor << endl;
1005 SVDEBUG << "start = " << start << ", finish = " << finish << ", step = " << step << endl;
996 #endif 1006 #endif
997 1007
998 for (int x = start; x != finish; x += step) { 1008 for (int x = start; x != finish; x += step) {
999 1009
1000 // x is the on-canvas pixel coord; sx (later) will be the 1010 // x is the on-canvas pixel coord; sx (later) will be the
1082 } 1092 }
1083 1093
1084 double fractionComplete = double(xPixelCount) / double(w); 1094 double fractionComplete = double(xPixelCount) / double(w);
1085 if (timer.outOfTime(fractionComplete)) { 1095 if (timer.outOfTime(fractionComplete)) {
1086 #ifdef DEBUG_COLOUR_PLOT_REPAINT 1096 #ifdef DEBUG_COLOUR_PLOT_REPAINT
1087 SVDEBUG << "out of time" << endl; 1097 SVDEBUG << "out of time with xPixelCount = " << xPixelCount << endl;
1088 #endif 1098 #endif
1089 updateTimings(timer, xPixelCount); 1099 updateTimings(timer, xPixelCount);
1090 return xPixelCount; 1100 return xPixelCount;
1091 } 1101 }
1092 } 1102 }
1093 1103
1094 updateTimings(timer, xPixelCount); 1104 updateTimings(timer, xPixelCount);
1105
1106 #ifdef DEBUG_COLOUR_PLOT_REPAINT
1107 SVDEBUG << "completed with xPixelCount = " << xPixelCount << endl;
1108 #endif
1095 return xPixelCount; 1109 return xPixelCount;
1096 } 1110 }
1097 1111
1098 int 1112 int
1099 Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v, 1113 Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v,