OSDN Git Service

SurfaceFlinger: Adds the functionality to reduce refresh rate to half of
authorRuchi Kandoi <kandoiruchi@google.com>
Thu, 24 Apr 2014 23:42:35 +0000 (16:42 -0700)
committerRuchi Kandoi <kandoiruchi@google.com>
Thu, 1 May 2014 18:29:33 +0000 (18:29 +0000)
the default.

Feature added for the low power mode.

Change-Id: I2849e5ea335c0d2509fea1c315392bce7f20451d
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
services/surfaceflinger/DispSync.cpp
services/surfaceflinger/DispSync.h
services/surfaceflinger/SurfaceFlinger.cpp

index 602f20a..a00ccdb 100644 (file)
@@ -61,7 +61,10 @@ class DispSyncThread: public Thread {
 public:
 
     DispSyncThread():
+            mLowPowerMode(false),
             mStop(false),
+            mLastVsyncSent(false),
+            mLastBufferFull(false),
             mPeriod(0),
             mPhase(0),
             mWakeupLatency(0) {
@@ -145,7 +148,18 @@ public:
             }
 
             if (callbackInvocations.size() > 0) {
-                fireCallbackInvocations(callbackInvocations);
+                if (mLowPowerMode) {
+                    if (!mLastVsyncSent || !mLastBufferFull) {
+                        fireCallbackInvocations(callbackInvocations);
+                        mLastVsyncSent = true;
+                    } else
+                        mLastVsyncSent = false;
+                } else {
+                    fireCallbackInvocations(callbackInvocations);
+                }
+                mLastBufferFull = true;
+            } else {
+                mLastBufferFull = false;
             }
         }
 
@@ -200,6 +214,7 @@ public:
         return !mEventListeners.empty();
     }
 
+    bool mLowPowerMode;
 private:
 
     struct EventListener {
@@ -272,6 +287,8 @@ private:
     }
 
     bool mStop;
+    bool mLastVsyncSent;
+    bool mLastBufferFull;
 
     nsecs_t mPeriod;
     nsecs_t mPhase;
@@ -395,6 +412,10 @@ status_t DispSync::addEventListener(nsecs_t phase,
     return mThread->addEventListener(phase, callback);
 }
 
+void DispSync::setLowPowerMode(bool enabled) {
+    mThread->mLowPowerMode = enabled;
+}
+
 status_t DispSync::removeEventListener(const sp<Callback>& callback) {
     Mutex::Autolock lock(mMutex);
     return mThread->removeEventListener(callback);
index c4280aa..c2ae135 100644 (file)
@@ -88,6 +88,9 @@ public:
     // turned on.  It should NOT be used after that.
     void setPeriod(nsecs_t period);
 
+    // Setting the low power mode reduces the frame rate to half of the default
+    void setLowPowerMode(bool enabled);
+
     // addEventListener registers a callback to be called repeatedly at the
     // given phase offset from the hardware vsync events.  The callback is
     // called from a separate thread and it should return reasonably quickly
index a346520..0142992 100644 (file)
@@ -2643,6 +2643,16 @@ status_t SurfaceFlinger::onTransact(
                 repaintEverything();
                 return NO_ERROR;
             }
+            // This is an experimental interface
+            // Needs to be shifted to proper binder interface when we productize
+            case 1016: {
+                mPrimaryDispSync.setLowPowerMode(true);
+                return NO_ERROR;
+            }
+            case 1017: {
+                mPrimaryDispSync.setLowPowerMode(false);
+                return NO_ERROR;
+            }
         }
     }
     return err;