# HG changeset patch # User Chris Cannam # Date 1196333034 0 # Node ID 813170c57b13fcc4871845a85e15aa561cc527ac # Parent 4a542ba875c2ad2f74adb8a4e3881ab09167829d * Spectrogram paint-from-cache fix diff -r 4a542ba875c2 -r 813170c57b13 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Wed Nov 28 17:45:37 2007 +0000 +++ b/layer/SpectrogramLayer.cpp Thu Nov 29 10:43:54 2007 +0000 @@ -1852,6 +1852,7 @@ } #endif cache.validArea = QRect(); +// recreateWholePixmapCache = true; } } @@ -1947,8 +1948,15 @@ cache.validArea = QRect (std::min(vx0, x0), cache.validArea.y(), std::max(vx1 - std::min(vx0, x0), - x1 - std::min(vx0, x0)), + x1 - std::min(vx0, x0)), cache.validArea.height()); + +#ifdef DEBUG_SPECTROGRAM_REPAINT + std::cerr << "Valid area becomes " << cache.validArea.x() + << ", " << cache.validArea.y() << ", " + << cache.validArea.width() << "x" + << cache.validArea.height() << std::endl; +#endif } else { if (x1 > x0 + paintBlockWidth) { @@ -1963,6 +1971,10 @@ x1 = x0 + paintBlockWidth; } } +#ifdef DEBUG_SPECTROGRAM_REPAINT + std::cerr << "Valid area becomes " << x0 << ", 0, " << (x1-x0) + << "x" << h << std::endl; +#endif cache.validArea = QRect(x0, 0, x1 - x0, h); } @@ -2084,6 +2096,9 @@ float s0 = 0, s1 = 0; if (!getXBinRange(v, x0 + x, s0, s1)) { +#ifdef DEBUG_SPECTROGRAM_REPAINT + std::cerr << "Out of range at " << x0 + x << std::endl; +#endif assert(x <= m_drawBuffer.width()); continue; } @@ -2288,17 +2303,6 @@ Profiler profiler2("SpectrogramLayer::paint: draw image", true); - if (w > 0) { -#ifdef DEBUG_SPECTROGRAM_REPAINT - std::cerr << "Painting " << w << "x" << rect.height() - << " from draw buffer at " << 0 << "," << rect.y() - << " to window at " << x0 << "," << rect.y() << std::endl; -#endif - - paint.drawImage(x0, rect.y(), m_drawBuffer, - 0, rect.y(), w, rect.height()); - } - if (recreateWholePixmapCache) { std::cerr << "Recreating pixmap cache: width = " << v->width() << ", height = " << h << std::endl; @@ -2317,6 +2321,17 @@ cachePainter.end(); } + QRect pr = rect & cache.validArea; + +#ifdef DEBUG_SPECTROGRAM_REPAINT + std::cerr << "Painting " << pr.width() << "x" << pr.height() + << " from cache at " << pr.x() << "," << pr.y() + << " to window" << std::endl; +#endif + + paint.drawPixmap(pr.x(), pr.y(), cache.pixmap, + pr.x(), pr.y(), pr.width(), pr.height()); + cache.startFrame = startFrame; cache.zoomLevel = zoomLevel;