# HG changeset patch # User Chris Cannam # Date 1469192184 -3600 # Node ID 94370157b2653f3e70edb6f31ff80f79a245f00d # Parent d930ff725f64aa189e7627cceceb146a31a3cf34 Fixes and debug output for mag range calculations diff -r d930ff725f64 -r 94370157b265 layer/Colour3DPlotRenderer.cpp --- a/layer/Colour3DPlotRenderer.cpp Fri Jul 22 12:17:55 2016 +0100 +++ b/layer/Colour3DPlotRenderer.cpp Fri Jul 22 13:56:24 2016 +0100 @@ -69,6 +69,24 @@ } } +bool +Colour3DPlotRenderer::geometryChanged(const LayerGeometryProvider *v) +{ + RenderType renderType = decideRenderType(v); + + if (renderType == DirectTranslucent) { + return true; // never cached + } + + if (m_cache.getSize() == v->getPaintSize() && + m_cache.getZoomLevel() == v->getZoomLevel() && + m_cache.getStartFrame() == v->getStartFrame()) { + return false; + } else { + return true; + } +} + Colour3DPlotRenderer::RenderResult Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect, bool timeConstrained) @@ -129,7 +147,7 @@ // throw std::logic_error("Columns not set in mag cache"); } - MagnitudeRange range = m_magCache.getRange(x0, x1-x0); + MagnitudeRange range = m_magCache.getRange(x0, x1 - x0); return { rect, range }; @@ -163,6 +181,9 @@ bool rightToLeft = false; + int reqx0 = x0; + int reqx1 = x1; + if (!m_cache.isValid() && timeConstrained) { // When rendering the whole area, in a context where we might // not be able to complete the work, start from somewhere near @@ -223,14 +244,7 @@ throw std::logic_error("internal error: failed to render entire requested rect even when not time-constrained"); } - //!!! a dev debug check - if (!m_magCache.areColumnsSet(x0, x1 - x0)) { - cerr << "NB Columns (" << x0 << " -> " << x1-x0 - << ") not set in mag cache" << endl; -// throw std::logic_error("Columns not set in mag cache"); - } - - MagnitudeRange range = m_magCache.getRange(x0, x1-x0); + MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0); return { pr, range }; diff -r d930ff725f64 -r 94370157b265 layer/Colour3DPlotRenderer.h --- a/layer/Colour3DPlotRenderer.h Fri Jul 22 12:17:55 2016 +0100 +++ b/layer/Colour3DPlotRenderer.h Fri Jul 22 13:56:24 2016 +0100 @@ -166,6 +166,14 @@ QRect getLargestUncachedRect(const LayerGeometryProvider *v); /** + * Return true if the provider's geometry differs from the cache, + * or if we are not using a cache. i.e. if the cache will be + * regenerated for the next render, or the next render performed + * from scratch. + */ + bool geometryChanged(const LayerGeometryProvider *v); + + /** * Return true if the rendering will be opaque. This may be used * by the calling layer to determine whether it can scroll * directly without regard to any other layers beneath. diff -r d930ff725f64 -r 94370157b265 layer/ScrollableImageCache.cpp --- a/layer/ScrollableImageCache.cpp Fri Jul 22 12:17:55 2016 +0100 +++ b/layer/ScrollableImageCache.cpp Fri Jul 22 13:56:24 2016 +0100 @@ -23,19 +23,19 @@ ScrollableImageCache::scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame) { + int dx = (v->getXForFrame(m_startFrame) - + v->getXForFrame(newStartFrame)); + +#ifdef DEBUG_SCROLLABLE_IMAGE_CACHE + cerr << "ScrollableImageCache::scrollTo: start frame " << m_startFrame + << " -> " << newStartFrame << ", dx = " << dx << endl; +#endif + if (m_startFrame == newStartFrame) { // haven't moved return; } - int dx = (v->getXForFrame(m_startFrame) - - v->getXForFrame(newStartFrame)); - -#ifdef DEBUG_SCROLLABLE_IMAGE_CACHE - cerr << "ScrollableImageCache::scrollTo: start frame " << m_startFrame - << " -> " << newStartFrame << ", dx = " << dx << endl; -#endif - m_startFrame = newStartFrame; if (!isValid()) { diff -r d930ff725f64 -r 94370157b265 layer/ScrollableMagRangeCache.cpp --- a/layer/ScrollableMagRangeCache.cpp Fri Jul 22 12:17:55 2016 +0100 +++ b/layer/ScrollableMagRangeCache.cpp Fri Jul 22 13:56:24 2016 +0100 @@ -22,12 +22,7 @@ void ScrollableMagRangeCache::scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame) -{ - if (m_startFrame == newStartFrame) { - // haven't moved - return; - } - +{ int dx = (v->getXForFrame(m_startFrame) - v->getXForFrame(newStartFrame)); @@ -35,6 +30,11 @@ cerr << "ScrollableMagRangeCache::scrollTo: start frame " << m_startFrame << " -> " << newStartFrame << ", dx = " << dx << endl; #endif + + if (m_startFrame == newStartFrame) { + // haven't moved + return; + } m_startFrame = newStartFrame; @@ -61,7 +61,7 @@ auto newRanges = vector(-dx); newRanges.insert(newRanges.end(), - m_ranges.begin(), m_ranges.begin() + w + dx); + m_ranges.begin(), m_ranges.begin() + (w + dx)); m_ranges = newRanges; } else { @@ -75,6 +75,25 @@ m_ranges.begin() + dx, m_ranges.end()); m_ranges = newRanges; } + + cerr << "maxes now: "; + for (int i = 0; in_range_for(m_ranges, i); ++i) { + cerr << m_ranges[i].getMax() << " "; + } + cerr << endl; +} + +MagnitudeRange +ScrollableMagRangeCache::getRange(int x, int count) const +{ + MagnitudeRange r; +#ifdef DEBUG_SCROLLABLE_MAG_RANGE_CACHE + cerr << "ScrollableMagRangeCache::getRange(" << x << ", " << count << ")" << endl; +#endif + for (int i = 0; i < count; ++i) { + r.sample(m_ranges.at(x + i)); + } + return r; } void @@ -90,6 +109,7 @@ } } +//!!! unneeded? void ScrollableMagRangeCache::sampleColumn(const LayerGeometryProvider *v, sv_frame_t frame, diff -r d930ff725f64 -r 94370157b265 layer/ScrollableMagRangeCache.h --- a/layer/ScrollableMagRangeCache.h Fri Jul 22 12:17:55 2016 +0100 +++ b/layer/ScrollableMagRangeCache.h Fri Jul 22 13:56:24 2016 +0100 @@ -113,13 +113,7 @@ /** * Get the magnitude range for a range of columns. */ - MagnitudeRange getRange(int x, int count) const { - MagnitudeRange r; - for (int i = 0; i < count; ++i) { - r.sample(m_ranges.at(x + i)); - } - return r; - } + MagnitudeRange getRange(int x, int count) const; /** * Set the new start frame for the cache, according to the diff -r d930ff725f64 -r 94370157b265 layer/SpectrogramLayer.cpp --- a/layer/SpectrogramLayer.cpp Fri Jul 22 12:17:55 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Fri Jul 22 13:56:24 2016 +0100 @@ -1491,6 +1491,15 @@ Colour3DPlotRenderer *renderer = getRenderer(v); Colour3DPlotRenderer::RenderResult result; + MagnitudeRange magRange; + int viewId = v->getId(); + + if (!renderer->geometryChanged(v)) { + cerr << "geometry unchanged, extending view mag range" << endl; + magRange = m_viewMags[viewId]; + } else { + cerr << "geometry changed!! creating new view mag range" << endl; + } if (m_synchronous) { @@ -1500,7 +1509,8 @@ result = renderer->renderTimeConstrained(v, paint, rect); - cerr << "mag range in this paint: " << result.range.getMin() << " -> " + cerr << "rect width from this paint: " << result.rendered.width() + << ", mag range in this paint: " << result.range.getMin() << " -> " << result.range.getMax() << endl; //!!! @@ -1513,17 +1523,22 @@ } } - //!!! at the mo this measures the range of the whole thing, not - //!!! just the view - need to reset it when view extents change - - m_viewMags[v->getId()].sample(result.range); + magRange.sample(result.range); + + if (magRange.isSet()) { + if (m_viewMags[viewId] == magRange) { + cerr << "mag range unchanged" << endl; + } else { + cerr << "mag range changed!!" << endl; + m_viewMags[viewId] = magRange; + } + } cerr << "mag range in this view: " - << m_viewMags[v->getId()].getMin() + << m_viewMags[viewId].getMin() << " -> " - << m_viewMags[v->getId()].getMax() + << m_viewMags[viewId].getMax() << endl; - } void