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/Layer.h b/services/surfaceflinger/Layer.h
index e2100fc..1d4eee7 100644
--- a/services/surfaceflinger/Layer.h
+++ b/services/surfaceflinger/Layer.h
@@ -210,6 +210,8 @@
void onLayerDisplayed(const sp<const DisplayDevice>& hw,
HWComposer::HWCLayerInterface* layer);
+ bool shouldPresentNow(const DispSync& dispSync) const;
+
/*
* called before composition.
* returns true if the layer has pending updates.
@@ -331,6 +333,7 @@
private:
// Interface implementation for SurfaceFlingerConsumer::ContentsChangedListener
virtual void onFrameAvailable(const BufferItem& item);
+ virtual void onFrameReplaced(const BufferItem& item);
virtual void onSidebandStreamChanged();
void commitTransaction();
@@ -404,6 +407,10 @@
// This layer can be a cursor on some displays.
bool mPotentialCursor;
+
+ // Local copy of the queued contents of the incoming BufferQueue
+ mutable Mutex mQueueItemLock;
+ Vector<BufferItem> mQueueItems;
};
// ---------------------------------------------------------------------------