ANativeWindow: add queues-to-window-composer check.
This change adds a new 'method' to the ANativeWindow interface to check
whether buffers queued to the window will be sent directly to the system
window compositor.
Change-Id: I4d4b199e328c110b68b250029aea650f03c8724d
Bug: 3495535
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 554fa43..7b19a4c 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -327,6 +327,40 @@
const_cast<SurfaceFlinger*>(this)->signalEvent();
}
+bool SurfaceFlinger::authenticateSurface(const sp<ISurface>& surface) const {
+ Mutex::Autolock _l(mStateLock);
+ sp<IBinder> surfBinder(surface->asBinder());
+
+ // Check the visible layer list for the ISurface
+ const LayerVector& currentLayers = mCurrentState.layersSortedByZ;
+ size_t count = currentLayers.size();
+ for (size_t i=0 ; i<count ; i++) {
+ const sp<LayerBase>& layer(currentLayers[i]);
+ sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
+ if (lbc != NULL && lbc->getSurfaceBinder() == surfBinder) {
+ return true;
+ }
+ }
+
+ // Check the layers in the purgatory. This check is here so that if a
+ // Surface gets destroyed before all the clients are done using it, the
+ // error will not be reported as "surface XYZ is not authenticated", but
+ // will instead fail later on when the client tries to use the surface,
+ // which should be reported as "surface XYZ returned an -ENODEV". The
+ // purgatorized layers are no less authentic than the visible ones, so this
+ // should not cause any harm.
+ size_t purgatorySize = mLayerPurgatory.size();
+ for (size_t i=0 ; i<purgatorySize ; i++) {
+ const sp<LayerBase>& layer(mLayerPurgatory.itemAt(i));
+ sp<LayerBaseClient> lbc(layer->getLayerBaseClient());
+ if (lbc != NULL && lbc->getSurfaceBinder() == surfBinder) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
status_t SurfaceFlinger::postMessageAsync(const sp<MessageBase>& msg,
nsecs_t reltime, uint32_t flags)
{
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 6dd91ac..9566819 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -209,6 +209,7 @@
virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags);
virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
virtual void signal() const;
+ virtual bool authenticateSurface(const sp<ISurface>& surface) const;
virtual status_t captureScreen(DisplayID dpy,
sp<IMemoryHeap>* heap,