don't filter when capturing a screenshot unless needed

bug: 6919952
Change-Id: Ia6fbe9bc7e533a64cfdd6ef7f0cd6b9f11feb947
diff --git a/services/surfaceflinger/LayerBase.cpp b/services/surfaceflinger/LayerBase.cpp
index 9d3a505..f1bf984 100644
--- a/services/surfaceflinger/LayerBase.cpp
+++ b/services/surfaceflinger/LayerBase.cpp
@@ -316,11 +316,9 @@
     onDraw(hw, clip);
 }
 
-void LayerBase::drawForScreenShot(const DisplayDevice& hw)
+void LayerBase::draw(const DisplayDevice& hw)
 {
-    setFiltering(true);
     onDraw( hw, Region(hw.bounds()) );
-    setFiltering(false);
 }
 
 void LayerBase::clearWithOpenGL(const DisplayDevice& hw, const Region& clip,
diff --git a/services/surfaceflinger/LayerBase.h b/services/surfaceflinger/LayerBase.h
index e1d6793..663a864 100644
--- a/services/surfaceflinger/LayerBase.h
+++ b/services/surfaceflinger/LayerBase.h
@@ -146,7 +146,7 @@
      * to perform the actual drawing.  
      */
     virtual void draw(const DisplayDevice& hw, const Region& clip) const;
-    virtual void drawForScreenShot(const DisplayDevice& hw);
+    virtual void draw(const DisplayDevice& hw);
     
     /**
      * onDraw - draws the surface.
@@ -249,14 +249,14 @@
 
     void clearWithOpenGL(const DisplayDevice& hw, const Region& clip) const;
 
+    void setFiltering(bool filtering);
+    bool getFiltering() const;
+
 protected:
           void clearWithOpenGL(const DisplayDevice& hw, const Region& clip,
                   GLclampf r, GLclampf g, GLclampf b, GLclampf alpha) const;
           void drawWithOpenGL(const DisplayDevice& hw, const Region& clip) const;
 
-          void setFiltering(bool filtering);
-          bool getFiltering() const;
-
                 sp<SurfaceFlinger> mFlinger;
 
 private:
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 3775734..7fb825a 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -698,7 +698,7 @@
             const size_t count = layers.size();
             for (size_t i=0 ; i<count ; ++i) {
                 const sp<LayerBase>& layer(layers[i]);
-                layer->drawForScreenShot(hw);
+                layer->draw(hw);
             }
 
             success = eglSwapBuffers(eglGetCurrentDisplay(), externalDisplaySurface);
@@ -2026,7 +2026,7 @@
     const size_t count = layers.size();
     for (size_t i=0 ; i<count ; ++i) {
         const sp<LayerBase>& layer(layers[i]);
-        layer->drawForScreenShot(hw);
+        layer->draw(hw);
     }
 
     hw.compositionComplete();
@@ -2544,6 +2544,7 @@
     sw = (!sw) ? hw_w : sw;
     sh = (!sh) ? hw_h : sh;
     const size_t size = sw * sh * 4;
+    const bool filtering = sw != hw_w || sh != hw_h;
 
     //ALOGD("screenshot: sw=%d, sh=%d, minZ=%d, maxZ=%d",
     //        sw, sh, minLayerZ, maxLayerZ);
@@ -2586,7 +2587,9 @@
             if (!(flags & ISurfaceComposer::eLayerHidden)) {
                 const uint32_t z = layer->drawingState().z;
                 if (z >= minLayerZ && z <= maxLayerZ) {
-                    layer->drawForScreenShot(hw);
+                    if (filtering) layer->setFiltering(true);
+                    layer->draw(hw);
+                    if (filtering) layer->setFiltering(false);
                 }
             }
         }