Add texture filtering override to debugger

https://codereview.chromium.org/27716003/



git-svn-id: http://skia.googlecode.com/svn/trunk@11846 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/debugger/QT/SkDebuggerGUI.cpp b/debugger/QT/SkDebuggerGUI.cpp
index 4383f65..fad5c0c 100644
--- a/debugger/QT/SkDebuggerGUI.cpp
+++ b/debugger/QT/SkDebuggerGUI.cpp
@@ -94,6 +94,7 @@
 #if SK_SUPPORT_GPU
     connect(&fSettingsWidget, SIGNAL(glSettingsChanged()), this, SLOT(actionGLWidget()));
 #endif
+    connect(&fSettingsWidget, SIGNAL(texFilterSettingsChanged()), this, SLOT(actionTextureFilter()));
     connect(fSettingsWidget.getRasterCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionRasterWidget(bool)));
     connect(fSettingsWidget.getOverdrawVizCheckBox(), SIGNAL(toggled(bool)), this, SLOT(actionOverdrawVizWidget(bool)));
     connect(&fActionPause, SIGNAL(toggled(bool)), this, SLOT(pauseDrawing(bool)));
@@ -521,6 +522,13 @@
     fCanvasWidget.update();
 }
 
+void SkDebuggerGUI::actionTextureFilter() {
+    SkPaint::FilterLevel level;
+    bool enabled = fSettingsWidget.getFilterOverride(&level);
+    fDebugger.setTexFilterOverride(enabled, level);
+    fCanvasWidget.update();
+}
+
 void SkDebuggerGUI::actionRewind() {
     fListWidget.setCurrentRow(0);
 }
diff --git a/debugger/QT/SkDebuggerGUI.h b/debugger/QT/SkDebuggerGUI.h
index 13ec181..a478428 100644
--- a/debugger/QT/SkDebuggerGUI.h
+++ b/debugger/QT/SkDebuggerGUI.h
@@ -141,6 +141,11 @@
     void actionOverdrawVizWidget(bool isToggled);
 
     /**
+        Applies the new texture filter override
+     */
+    void actionTextureFilter();
+
+    /**
         Rewinds from the current step back to the start of the commands.
      */
     void actionRewind();
diff --git a/debugger/QT/SkSettingsWidget.cpp b/debugger/QT/SkSettingsWidget.cpp
index fa619ea..ca0436e 100644
--- a/debugger/QT/SkSettingsWidget.cpp
+++ b/debugger/QT/SkSettingsWidget.cpp
@@ -91,6 +91,34 @@
     connect(&fGLMSAA16On, SIGNAL(toggled(bool)), this, SIGNAL(glSettingsChanged()));
 #endif
 
+    {
+        // set up filter buttons
+        fFilterButtonGroup.setTitle("Filtering");
+        fFilterButtonGroup.setMinimumWidth(178);
+        fFilterButtonGroup.setMaximumWidth(178);
+
+        fFilterDefault.setText("As encoded");
+        fFilterDefault.setChecked(true);
+        fFilterNone.setText("None");
+        fFilterLow.setText("Low");
+        fFilterMed.setText("Med");
+        fFilterHigh.setText("High");
+
+        fFilterLayout.addWidget(&fFilterDefault);
+        fFilterLayout.addWidget(&fFilterNone);
+        fFilterLayout.addWidget(&fFilterLow);
+        fFilterLayout.addWidget(&fFilterMed);
+        fFilterLayout.addWidget(&fFilterHigh);
+
+        fFilterButtonGroup.setLayout(&fFilterLayout);
+
+        connect(&fFilterDefault, SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
+        connect(&fFilterNone,    SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
+        connect(&fFilterLow,     SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
+        connect(&fFilterMed,     SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
+        connect(&fFilterHigh,    SIGNAL(toggled(bool)), this, SIGNAL(texFilterSettingsChanged()));
+    }
+
     fRasterLayout.addWidget(&fRasterLabel);
     fRasterLayout.addWidget(&fRasterCheckBox);
 
@@ -110,6 +138,7 @@
     fCanvasLayout.addLayout(&fGLLayout);
     fCanvasLayout.addWidget(&fGLMSAAButtonGroup);
 #endif
+    fCanvasLayout.addWidget(&fFilterButtonGroup);
 
     // Command Toggle
     fCommandToggle.setText("Command Scrolling Preferences");
diff --git a/debugger/QT/SkSettingsWidget.h b/debugger/QT/SkSettingsWidget.h
index e5662ee..fc8fda7 100644
--- a/debugger/QT/SkSettingsWidget.h
+++ b/debugger/QT/SkSettingsWidget.h
@@ -20,6 +20,8 @@
 #include <QCheckBox>
 #include <QLineEdit>
 
+#include "SkPaint.h"
+
 /** \class SkSettingsWidget
 
     The SettingsWidget contains multiple checkboxes and toggles for altering
@@ -56,6 +58,25 @@
 
 #endif
 
+    bool getFilterOverride(SkPaint::FilterLevel* filterLevel) {
+        if (fFilterDefault.isChecked()) {
+            *filterLevel = SkPaint::kNone_FilterLevel;
+            return false;
+        }
+
+        if (fFilterNone.isChecked()) {
+            *filterLevel = SkPaint::kNone_FilterLevel;
+        } else if (fFilterLow.isChecked()) {
+            *filterLevel = SkPaint::kLow_FilterLevel;
+        } else if (fFilterMed.isChecked()) {
+            *filterLevel = SkPaint::kMedium_FilterLevel;
+        } else {
+            *filterLevel = SkPaint::kHigh_FilterLevel;
+        }
+
+        return true;
+    }
+
     QCheckBox* getRasterCheckBox() {
         return &fRasterCheckBox;
     }
@@ -72,6 +93,7 @@
     void scrollingPreferences(bool isStickyActivate);
     void showStyle(bool isSingleCommand);
     void visibilityFilter(bool isEnabled);
+    void texFilterSettingsChanged();
 #if SK_SUPPORT_GPU
     void glSettingsChanged();
 #endif
@@ -122,6 +144,15 @@
     QRadioButton fGLMSAA16On;
 #endif
 
+    // for filtering group
+    QGroupBox fFilterButtonGroup;
+    QVBoxLayout fFilterLayout;
+    QRadioButton fFilterDefault;
+    QRadioButton fFilterNone;
+    QRadioButton fFilterLow;
+    QRadioButton fFilterMed;
+    QRadioButton fFilterHigh;
+
     QFrame fZoomFrame;
     QHBoxLayout fZoomLayout;
     QLabel fZoomSetting;
diff --git a/debugger/SkDebugger.h b/debugger/SkDebugger.h
index 42356f8..182f226 100644
--- a/debugger/SkDebugger.h
+++ b/debugger/SkDebugger.h
@@ -107,6 +107,12 @@
         }
     }
 
+    void setTexFilterOverride(bool texFilterOverride, SkPaint::FilterLevel level) {
+        if (NULL != fDebugCanvas) {
+            fDebugCanvas->overrideTexFiltering(texFilterOverride, level);
+        }
+    }
+
     void getOverviewText(const SkTDArray<double>* typeTimes, double totTime,
                          SkString* overview, int numRuns);
 
diff --git a/src/utils/debugger/SkDebugCanvas.cpp b/src/utils/debugger/SkDebugCanvas.cpp
index bf81983..5553e14 100644
--- a/src/utils/debugger/SkDebugCanvas.cpp
+++ b/src/utils/debugger/SkDebugCanvas.cpp
@@ -24,6 +24,8 @@
         : INHERITED(make_noconfig_bm(width, height))
         , fOverdrawViz(false)
         , fOverdrawFilter(NULL)
+        , fOverrideTexFiltering(false)
+        , fTexOverrideFilter(NULL)
         , fOutstandingSaveCount(0) {
     // TODO(chudy): Free up memory from all draw commands in destructor.
     fWidth = width;
@@ -109,13 +111,13 @@
 
 // The OverdrawFilter modifies every paint to use an SkProcXfermode which
 // in turn invokes OverdrawXferModeProc
-class OverdrawFilter : public SkDrawFilter {
+class SkOverdrawFilter : public SkDrawFilter {
 public:
-    OverdrawFilter() {
+    SkOverdrawFilter() {
         fXferMode = new SkProcXfermode(OverdrawXferModeProc);
     }
 
-    virtual ~OverdrawFilter() {
+    virtual ~SkOverdrawFilter() {
         delete fXferMode;
     }
 
@@ -131,6 +133,29 @@
     typedef SkDrawFilter INHERITED;
 };
 
+// SkTexOverrideFilter modifies every paint to use the specified 
+// texture filtering mode
+class SkTexOverrideFilter : public SkDrawFilter {
+public:
+    SkTexOverrideFilter() : fFilterLevel(SkPaint::kNone_FilterLevel) {
+    }
+
+    void setFilterLevel(SkPaint::FilterLevel filterLevel) {
+        fFilterLevel = filterLevel;
+    }
+
+    virtual bool filter(SkPaint* p, Type) SK_OVERRIDE {
+        p->setFilterLevel(fFilterLevel);
+        return true;
+    }
+
+protected:
+    SkPaint::FilterLevel fFilterLevel;
+
+private:
+    typedef SkDrawFilter INHERITED;
+};
+
 void SkDebugCanvas::drawTo(SkCanvas* canvas, int index) {
     SkASSERT(!fCommandVector.isEmpty());
     SkASSERT(index < fCommandVector.count());
@@ -161,12 +186,20 @@
     // call setDrawFilter on anything but the root layer odd things happen.
     if (fOverdrawViz) {
         if (NULL == fOverdrawFilter) {
-            fOverdrawFilter = new OverdrawFilter;
+            fOverdrawFilter = new SkOverdrawFilter;
         }
 
         if (fOverdrawFilter != canvas->getDrawFilter()) {
             canvas->setDrawFilter(fOverdrawFilter);
         }
+    } else if (fOverrideTexFiltering) {
+        if (NULL == fTexOverrideFilter) {
+            fTexOverrideFilter = new SkTexOverrideFilter;
+        }
+
+        if (fTexOverrideFilter != canvas->getDrawFilter()) {
+            canvas->setDrawFilter(fTexOverrideFilter);
+        }
     } else {
         canvas->setDrawFilter(NULL);
     }
@@ -246,6 +279,15 @@
     fFilter = toggle;
 }
 
+void SkDebugCanvas::overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level) { 
+    if (NULL == fTexOverrideFilter) {
+        fTexOverrideFilter = new SkTexOverrideFilter;
+    }
+
+    fOverrideTexFiltering = overrideTexFiltering; 
+    fTexOverrideFilter->setFilterLevel(level);
+}
+
 void SkDebugCanvas::clear(SkColor color) {
     addDrawCommand(new SkClearCommand(color));
 }
diff --git a/src/utils/debugger/SkDebugCanvas.h b/src/utils/debugger/SkDebugCanvas.h
index 705f49a..aad768b 100644
--- a/src/utils/debugger/SkDebugCanvas.h
+++ b/src/utils/debugger/SkDebugCanvas.h
@@ -16,6 +16,8 @@
 #include "SkTArray.h"
 #include "SkString.h"
 
+class SkTexOverrideFilter;
+
 class SK_API SkDebugCanvas : public SkCanvas {
 public:
     SkDebugCanvas(int width, int height);
@@ -29,6 +31,11 @@
     void setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
 
     /**
+     * Enable or disable texure filtering override
+     */
+    void overrideTexFiltering(bool overrideTexFiltering, SkPaint::FilterLevel level); 
+
+    /**
         Executes all draw calls to the canvas.
         @param canvas  The canvas being drawn to
      */
@@ -245,9 +252,13 @@
     SkMatrix fUserMatrix;
     SkMatrix fMatrix;
     SkIRect fClip;
+
     bool fOverdrawViz;
     SkDrawFilter* fOverdrawFilter;
 
+    bool fOverrideTexFiltering;
+    SkTexOverrideFilter* fTexOverrideFilter;
+
     /**
         Number of unmatched save() calls at any point during a draw.
         If there are any saveLayer() calls outstanding, we need to resolve