OSDN Git Service

Set the swap interval of virtual display surfaces to 0
authorJesse Hall <jessehall@google.com>
Wed, 7 Aug 2013 00:08:53 +0000 (17:08 -0700)
committerJesse Hall <jessehall@google.com>
Wed, 7 Aug 2013 02:32:02 +0000 (19:32 -0700)
This prevents slow/malicious virtual display consumers from
backpressuring SurfaceFlinger and preventing it from updating other
displays.

Bug: 10193714
Change-Id: I3e877d97202628d2d9abea24b66576f38299c14d

services/surfaceflinger/DisplayDevice.cpp
services/surfaceflinger/DisplayDevice.h

index c67f4d8..0e3c7c6 100644 (file)
@@ -63,7 +63,6 @@ DisplayDevice::DisplayDevice(
       mDisplaySurface(displaySurface),
       mDisplay(EGL_NO_DISPLAY),
       mSurface(EGL_NO_SURFACE),
-      mContext(EGL_NO_CONTEXT),
       mDisplayWidth(), mDisplayHeight(), mFormat(),
       mFlags(),
       mPageFlipCount(),
@@ -79,6 +78,16 @@ DisplayDevice::DisplayDevice(
     int format;
     window->query(window, NATIVE_WINDOW_FORMAT, &format);
 
+    // Make sure that composition can never be stalled by a virtual display
+    // consumer that isn't processing buffers fast enough. We have to do this
+    // in two places:
+    // * Here, in case the display is composed entirely by HWC.
+    // * In makeCurrent(), using eglSwapInterval. Some EGL drivers set the
+    //   window's swap interval in eglMakeCurrent, so they'll override the
+    //   interval we set here.
+    if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
+        window->setSwapInterval(window, 0);
+
     /*
      * Create our display's surface
      */
@@ -253,6 +262,8 @@ EGLBoolean DisplayDevice::makeCurrent(EGLDisplay dpy, EGLContext ctx) const {
     if (sur != mSurface) {
         result = eglMakeCurrent(dpy, mSurface, mSurface, ctx);
         if (result == EGL_TRUE) {
+            if (mType >= DisplayDevice::DISPLAY_VIRTUAL)
+                eglSwapInterval(dpy, 0);
             setViewportAndProjection();
         }
     }
index 748be1a..86fbc87 100644 (file)
@@ -170,7 +170,6 @@ private:
 
     EGLDisplay      mDisplay;
     EGLSurface      mSurface;
-    EGLContext      mContext;
     int             mDisplayWidth;
     int             mDisplayHeight;
     PixelFormat     mFormat;