summaryrefslogtreecommitdiffstats
path: root/libs/gui/include
diff options
context:
space:
mode:
authorMarissa Wall <marissaw@google.com>2019-03-15 14:58:34 -0700
committerMarissa Wall <marissaw@google.com>2019-03-22 14:13:10 -0700
commit78b7220f542826771223f9b5c0b876874dd398d2 (patch)
treead06c575e7f760c4d4b79448cd69026d8cffe6e8 /libs/gui/include
parent4c6f904ffde2795886477f6de54edcae5d036e68 (diff)
downloadandroid_frameworks_native-78b7220f542826771223f9b5c0b876874dd398d2.tar.gz
android_frameworks_native-78b7220f542826771223f9b5c0b876874dd398d2.tar.bz2
android_frameworks_native-78b7220f542826771223f9b5c0b876874dd398d2.zip
blast: drop buffer from SF's cache when destroyed
When an app drops its reference to an AHardwareBuffer, the buffer should be removed from the client and SurfaceFlinger caches. Ideally, both caches would have wp to the buffer and the buffer would automatically be removed from the cache. Unfortunately, GraphicBuffers are refcounted per process. If SurfaceFlinger just has a wp to the GraphicBuffer, the buffer's destructor will be called and SurfaceFlinger will lose access to the buffer. SurfaceFlinger can't just hold onto a sp to the buffer because then the buffer wouldn't be destoryed when the app drops its reference. Instead, when the app process drops its last strong reference, GraphicBuffer will send a callback to the client side cache. The cache will send a Transaction to SurfaceFlinger to drop its sp to the buffer. Bug: 127689853 Test: SurfaceFlinger_test Change-Id: I2182578ed33d7c731945cb88cd1decb2892266b0
Diffstat (limited to 'libs/gui/include')
-rw-r--r--libs/gui/include/gui/ISurfaceComposer.h4
-rw-r--r--libs/gui/include/gui/LayerState.h9
-rw-r--r--libs/gui/include/gui/SurfaceComposerClient.h10
3 files changed, 18 insertions, 5 deletions
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index 8f54fee22..0ef5b3964 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -40,6 +40,7 @@
namespace android {
// ----------------------------------------------------------------------------
+struct cached_buffer_t;
struct ComposerState;
struct DisplayState;
struct DisplayInfo;
@@ -131,7 +132,8 @@ public:
const Vector<DisplayState>& displays, uint32_t flags,
const sp<IBinder>& applyToken,
const InputWindowCommands& inputWindowCommands,
- int64_t desiredPresentTime) = 0;
+ int64_t desiredPresentTime,
+ const cached_buffer_t& uncacheBuffer) = 0;
/* signal that we're done booting.
* Requires ACCESS_SURFACE_FLINGER permission
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 35e795c30..77bf8f1dc 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -41,6 +41,11 @@ namespace android {
class Parcel;
class ISurfaceComposerClient;
+struct cached_buffer_t {
+ sp<IBinder> token = nullptr;
+ uint64_t cacheId;
+};
+
/*
* Used to communicate layer information between SurfaceFlinger and its clients.
*/
@@ -133,10 +138,6 @@ struct layer_state_t {
float dtdy{0};
float dsdy{0};
};
- struct cached_buffer_t {
- sp<IBinder> token = nullptr;
- int32_t bufferId = -1;
- };
sp<IBinder> surface;
uint64_t what;
float x;
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 39d6d1368..593a5e7d8 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -165,6 +165,12 @@ public:
static void doDropReferenceTransaction(const sp<IBinder>& handle,
const sp<ISurfaceComposerClient>& client);
+ /**
+ * Uncaches a buffer in ISurfaceComposer. It must be uncached via a transaction so that it is
+ * in order with other transactions that use buffers.
+ */
+ static void doUncacheBufferTransaction(uint64_t cacheId);
+
// Queries whether a given display is wide color display.
static status_t isWideColorDisplay(const sp<IBinder>& display, bool* outIsWideColorDisplay);
@@ -279,6 +285,9 @@ public:
bool mAnimation = false;
bool mEarlyWakeup = false;
+ // Indicates that the Transaction contains a buffer that should be cached
+ bool mContainsBuffer = false;
+
// mDesiredPresentTime is the time in nanoseconds that the client would like the transaction
// to be presented. When it is not possible to present at exactly that time, it will be
// presented after the time has passed.
@@ -297,6 +306,7 @@ public:
layer_state_t* getLayerState(const sp<SurfaceControl>& sc);
DisplayState& getDisplayState(const sp<IBinder>& token);
+ void cacheBuffers();
void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc);
public: