SurfaceFlinger: Do less work when using PTS
Currently, SurfaceFlinger is very dumb about how it handles buffer
updates at less than 60fps. If there is a new frame pending, but its
timestamp says not to present it until later SurfaceFlinger will wake
up every vsync until it is time to present it. Even worse, if
SurfaceFlinger has woken up but nothing has changed, it still goes
through the entire composition process.
This change (mostly) fixes that inefficiency. SurfaceFlinger will
still wake up every refresh period while there is a new frame
pending, but if there is no work to do, it will almost immediately go
back to sleep.
Bug: 18111837
Change-Id: I7825bacd37f40bf26edcc6a5e0f051dce45291fb
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 710dac7..4deb815 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -247,8 +247,12 @@
// called on the main thread in response to setPowerMode()
void setPowerModeInternal(const sp<DisplayDevice>& hw, int mode);
- void handleMessageTransaction();
- void handleMessageInvalidate();
+ // Returns whether the transaction actually modified any state
+ bool handleMessageTransaction();
+
+ // Returns whether a new buffer has been latched (see handlePageFlip())
+ bool handleMessageInvalidate();
+
void handleMessageRefresh();
void handleTransaction(uint32_t transactionFlags);
@@ -256,10 +260,11 @@
void updateCursorAsync();
- /* handlePageFilp: this is were we latch a new buffer
- * if available and compute the dirty region.
+ /* handlePageFlip - latch a new buffer if available and compute the dirty
+ * region. Returns whether a new buffer has been latched, i.e., whether it
+ * is necessary to perform a refresh during this vsync.
*/
- void handlePageFlip();
+ bool handlePageFlip();
/* ------------------------------------------------------------------------
* Transactions