diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 35a7fd51b..f4779e726 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -62,6 +62,7 @@ #include #include +#include #define EGL_VERSION_HW_ANDROID 0x3143 @@ -1845,6 +1846,35 @@ status_t SurfaceFlinger::renderScreenToTextureLocked(DisplayID dpy, // --------------------------------------------------------------------------- +class VSyncWaiter { + DisplayEventReceiver::Event buffer[4]; + sp looper; + sp events; + sp eventTube; +public: + VSyncWaiter(const sp& eventThread) { + looper = new Looper(true); + events = eventThread->createEventConnection(); + eventTube = events->getDataChannel(); + looper->addFd(eventTube->getFd(), 0, ALOOPER_EVENT_INPUT, 0, 0); + events->requestNextVsync(); + } + + void wait() { + ssize_t n; + + looper->pollOnce(-1); + // we don't handle any errors here, it doesn't matter + // and we don't want to take the risk to get stuck. + + // drain the events... + while ((n = DisplayEventReceiver::getEvents( + eventTube, buffer, 4)) > 0) ; + + events->requestNextVsync(); + } +}; + status_t SurfaceFlinger::electronBeamOffAnimationImplLocked() { // get screen geometry @@ -1937,6 +1967,8 @@ status_t SurfaceFlinger::electronBeamOffAnimationImplLocked() } }; + VSyncWaiter vsync(mEventThread); + // the full animation is 24 frames char value[PROPERTY_VALUE_MAX]; property_get("debug.sf.electron_frames", value, "24"); @@ -1963,6 +1995,9 @@ status_t SurfaceFlinger::electronBeamOffAnimationImplLocked() const float vg = itg(i); const float vb = itb(i); + // wait for vsync + vsync.wait(); + // clear screen glColorMask(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT); @@ -1998,6 +2033,10 @@ status_t SurfaceFlinger::electronBeamOffAnimationImplLocked() for (int i=0 ; i=0 ; i--) { const float v = itg(i); hverts(vtx, v); + + // wait for vsync + vsync.wait(); + glClear(GL_COLOR_BUFFER_BIT); glColor4f(1-v, 1-v, 1-v, 1); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); @@ -2124,6 +2169,9 @@ status_t SurfaceFlinger::electronBeamOnAnimationImplLocked() const float vg = itg(i); const float vb = itb(i); + // wait for vsync + vsync.wait(); + // clear screen glColorMask(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT);