changeset 1113:261a00010918 spectrogram-minor-refactor

Consts and willRenderOpaque
author Chris Cannam
date Tue, 19 Jul 2016 14:49:46 +0100
parents d578b685d912
children a42e5a3c63ef
files layer/Colour3DPlotLayer.cpp layer/Colour3DPlotLayer.h layer/Colour3DPlotRenderer.cpp layer/Colour3DPlotRenderer.h layer/ScrollableImageCache.cpp layer/ScrollableImageCache.h layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h layer/VerticalBinLayer.h
diffstat 9 files changed, 45 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Tue Jul 19 14:49:46 2016 +0100
@@ -614,9 +614,9 @@
     if (m_normalizeVisibleArea) {
         return false;
     }
-//!!!    if (shouldPaintDenseIn(v)) {
-//        return true;
-//    }
+    if (getRenderer(v)->willRenderOpaque(v)) {
+        return true;
+    }
     QPoint discard;
     return !v->shouldIlluminateLocalFeatures(this, discard);
 }
@@ -724,7 +724,7 @@
 }
 
 double
-Colour3DPlotLayer::getYForBin(LayerGeometryProvider *v, double bin) const
+Colour3DPlotLayer::getYForBin(const LayerGeometryProvider *v, double bin) const
 {
     double y = bin;
     if (!m_model) return y;
@@ -742,7 +742,7 @@
 }
 
 double
-Colour3DPlotLayer::getBinForY(LayerGeometryProvider *v, double y) const
+Colour3DPlotLayer::getBinForY(const LayerGeometryProvider *v, double y) const
 {
     double bin = y;
     if (!m_model) return bin;
@@ -1064,7 +1064,7 @@
 }
 */
 Colour3DPlotRenderer *
-Colour3DPlotLayer::getRenderer(LayerGeometryProvider *v) const
+Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const
 {
     if (m_renderers.find(v->getId()) == m_renderers.end()) {
 
--- a/layer/Colour3DPlotLayer.h	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/Colour3DPlotLayer.h	Tue Jul 19 14:49:46 2016 +0100
@@ -187,7 +187,7 @@
 
     typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
     mutable ViewRendererMap m_renderers;
-    Colour3DPlotRenderer *getRenderer(LayerGeometryProvider *) const;
+    Colour3DPlotRenderer *getRenderer(const LayerGeometryProvider *) const;
     void invalidateRenderers();
         
     /**
@@ -196,7 +196,7 @@
      * and the vertical scale is the usual way up). Bin number may be
      * fractional, to obtain a position part-way through a bin.
      */
-    double getYForBin(LayerGeometryProvider *, double bin) const;
+    double getYForBin(const LayerGeometryProvider *, double bin) const;
     
     /**
      * Return the bin number, possibly fractional, at the given y
@@ -204,7 +204,7 @@
      * at which the bins "start" (i.e. the bottom of the visible bin,
      * if the vertical scale is the usual way up).
      */
-    double getBinForY(LayerGeometryProvider *, double y) const;
+    double getBinForY(const LayerGeometryProvider *, double y) const;
     
     DenseThreeDimensionalModel::Column getColumn(int col) const;
 
--- a/layer/Colour3DPlotRenderer.cpp	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Tue Jul 19 14:49:46 2016 +0100
@@ -33,13 +33,13 @@
 using namespace std;
 
 Colour3DPlotRenderer::RenderResult
-Colour3DPlotRenderer::render(LayerGeometryProvider *v, QPainter &paint, QRect rect)
+Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect)
 {
     return render(v, paint, rect, false);
 }
 
 Colour3DPlotRenderer::RenderResult
-Colour3DPlotRenderer::renderTimeConstrained(LayerGeometryProvider *v,
+Colour3DPlotRenderer::renderTimeConstrained(const LayerGeometryProvider *v,
                                             QPainter &paint, QRect rect)
 {
     return render(v, paint, rect, true);
@@ -62,7 +62,7 @@
 }
 
 Colour3DPlotRenderer::RenderResult
-Colour3DPlotRenderer::render(LayerGeometryProvider *v,
+Colour3DPlotRenderer::render(const LayerGeometryProvider *v,
                              QPainter &paint, QRect rect, bool timeConstrained)
 {
     RenderType renderType = decideRenderType(v);
@@ -223,7 +223,7 @@
 }
 
 Colour3DPlotRenderer::RenderType
-Colour3DPlotRenderer::decideRenderType(LayerGeometryProvider *v) const
+Colour3DPlotRenderer::decideRenderType(const LayerGeometryProvider *v) const
 {
     const DenseThreeDimensionalModel *model = m_sources.source;
     if (!model || !v || !(v->getViewManager())) {
@@ -261,7 +261,7 @@
 }
 
 void
-Colour3DPlotRenderer::renderDirectTranslucent(LayerGeometryProvider *v,
+Colour3DPlotRenderer::renderDirectTranslucent(const LayerGeometryProvider *v,
                                               QPainter &paint,
                                               QRect rect)
 {
@@ -421,7 +421,7 @@
 }
 
 void
-Colour3DPlotRenderer::renderToCachePixelResolution(LayerGeometryProvider *v,
+Colour3DPlotRenderer::renderToCachePixelResolution(const LayerGeometryProvider *v,
                                                    int x0, int repaintWidth,
                                                    bool rightToLeft,
                                                    bool timeConstrained)
@@ -513,7 +513,7 @@
 }
 
 void
-Colour3DPlotRenderer::renderToCacheBinResolution(LayerGeometryProvider *v,
+Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v,
                                                  int x0, int repaintWidth)
 {
     cerr << "renderToCacheBinResolution" << endl;
@@ -788,7 +788,7 @@
 }
 
 int
-Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(LayerGeometryProvider *v,
+Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v,
                                                       int w, int h,
                                                       const vector<int> &binforx,
                                                       const vector<double> &binfory,
--- a/layer/Colour3DPlotRenderer.h	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/Colour3DPlotRenderer.h	Tue Jul 19 14:49:46 2016 +0100
@@ -120,7 +120,7 @@
      * that the LayerGeometryProvider returns valid results; it is the
      * caller's responsibility to ensure these.
      */
-    RenderResult render(LayerGeometryProvider *v, QPainter &paint, QRect rect);
+    RenderResult render(const LayerGeometryProvider *v, QPainter &paint, QRect rect);
     
     /**
      * Render the requested area using the given painter, obtaining
@@ -147,7 +147,7 @@
      * that the LayerGeometryProvider returns valid results; it is the
      * caller's responsibility to ensure these.
      */
-    RenderResult renderTimeConstrained(LayerGeometryProvider *v,
+    RenderResult renderTimeConstrained(const LayerGeometryProvider *v,
                                        QPainter &paint, QRect rect);
 
     /**
@@ -163,6 +163,15 @@
      * Returns an empty QRect if the cache is entirely valid.
      */
     QRect getLargestUncachedRect();
+
+    /**
+     * 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.
+     */
+    bool willRenderOpaque(const LayerGeometryProvider *v) {
+        return decideRenderType(v) != DirectTranslucent;
+    }
     
 private:
     Sources m_sources;
@@ -183,17 +192,17 @@
     // then repainting from cache to the requested painter.
     ScrollableImageCache m_cache;
 
-    RenderResult render(LayerGeometryProvider *v,
+    RenderResult render(const LayerGeometryProvider *v,
                         QPainter &paint, QRect rect, bool timeConstrained);
 
-    void renderDirectTranslucent(LayerGeometryProvider *v,
+    void renderDirectTranslucent(const LayerGeometryProvider *v,
                                  QPainter &paint, QRect rect);
     
-    void renderToCachePixelResolution(LayerGeometryProvider *v, int x0,
+    void renderToCachePixelResolution(const LayerGeometryProvider *v, int x0,
                                       int repaintWidth, bool rightToLeft,
                                       bool timeConstrained);
 
-    void renderToCacheBinResolution(LayerGeometryProvider *v, int x0,
+    void renderToCacheBinResolution(const LayerGeometryProvider *v, int x0,
                                     int repaintWidth);
 
     int renderDrawBuffer(int w, int h,
@@ -203,7 +212,7 @@
                          bool rightToLeft,
                          bool timeConstrained);
 
-    int renderDrawBufferPeakFrequencies(LayerGeometryProvider *v,
+    int renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v,
                                         int w, int h,
                                         const std::vector<int> &binforx,
                                         const std::vector<double> &binfory,
@@ -219,7 +228,7 @@
         DirectTranslucent
     };
 
-    RenderType decideRenderType(LayerGeometryProvider *) const;
+    RenderType decideRenderType(const LayerGeometryProvider *) const;
 };
 
 #endif
--- a/layer/ScrollableImageCache.cpp	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/ScrollableImageCache.cpp	Tue Jul 19 14:49:46 2016 +0100
@@ -20,7 +20,8 @@
 #define DEBUG_SCROLLABLE_IMAGE_CACHE 1
 
 void
-ScrollableImageCache::scrollTo(LayerGeometryProvider *v, sv_frame_t newStartFrame)
+ScrollableImageCache::scrollTo(const LayerGeometryProvider *v,
+                               sv_frame_t newStartFrame)
 {
     if (m_startFrame == newStartFrame) {
 	// haven't moved
--- a/layer/ScrollableImageCache.h	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/ScrollableImageCache.h	Tue Jul 19 14:49:46 2016 +0100
@@ -116,7 +116,7 @@
      * also moving along any existing valid data within the cache so
      * that it continues to be valid for the new start frame.
      */
-    void scrollTo(LayerGeometryProvider *v, sv_frame_t newStartFrame);
+    void scrollTo(const LayerGeometryProvider *v, sv_frame_t newStartFrame);
 
     /**
      * Take a left coordinate and width describing a region, and
--- a/layer/SpectrogramLayer.cpp	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/SpectrogramLayer.cpp	Tue Jul 19 14:49:46 2016 +0100
@@ -1089,13 +1089,13 @@
 }
 
 double
-SpectrogramLayer::getYForBin(LayerGeometryProvider *, double) const {
+SpectrogramLayer::getYForBin(const LayerGeometryProvider *, double) const {
     //!!! not implemented
     throw std::logic_error("not implemented");
 }
 
 double
-SpectrogramLayer::getBinForY(LayerGeometryProvider *v, double y) const
+SpectrogramLayer::getBinForY(const LayerGeometryProvider *v, double y) const
 {
     //!!! overlap with range methods above (but using double arg)
     //!!! tidy this
--- a/layer/SpectrogramLayer.h	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/SpectrogramLayer.h	Tue Jul 19 14:49:46 2016 +0100
@@ -195,8 +195,8 @@
     double getFrequencyForY(const LayerGeometryProvider *v, int y) const;
 
     //!!! VerticalBinLayer methods. Note overlap with get*BinRange()
-    double getYForBin(LayerGeometryProvider *, double bin) const;
-    double getBinForY(LayerGeometryProvider *, double y) const;
+    double getYForBin(const LayerGeometryProvider *, double bin) const;
+    double getBinForY(const LayerGeometryProvider *, double y) const;
     
     virtual int getCompletion(LayerGeometryProvider *v) const;
     virtual QString getError(LayerGeometryProvider *v) const;
--- a/layer/VerticalBinLayer.h	Tue Jul 19 10:12:30 2016 +0100
+++ b/layer/VerticalBinLayer.h	Tue Jul 19 14:49:46 2016 +0100
@@ -33,12 +33,12 @@
      * and the vertical scale is the usual way up). Bin number may be
      * fractional, to obtain a position part-way through a bin.
      */
-    virtual double getYForBin(LayerGeometryProvider *, double bin) const = 0;
+    virtual double getYForBin(const LayerGeometryProvider *, double bin) const = 0;
 
     /**
      * As getYForBin, but rounding to integer values.
      */
-    virtual int getIYForBin(LayerGeometryProvider *v, int bin) const {
+    virtual int getIYForBin(const LayerGeometryProvider *v, int bin) const {
         return int(round(getYForBin(v, bin)));
     }
     
@@ -48,12 +48,12 @@
      * at which the bins "start" (i.e. the bottom of the visible bin,
      * if the vertical scale is the usual way up).
      */
-    virtual double getBinForY(LayerGeometryProvider *, double y) const = 0;
+    virtual double getBinForY(const LayerGeometryProvider *, double y) const = 0;
 
     /**
      * As getBinForY, but rounding to integer values.
      */
-    virtual int getIBinForY(LayerGeometryProvider *v, int y) const {
+    virtual int getIBinForY(const LayerGeometryProvider *v, int y) const {
         return int(floor(getBinForY(v, y)));
     }
 };