am ebdcae73: Merge "Add third video to default system videos." into ics-factoryrom

* commit 'ebdcae732f648871dd0df6586a5ba57aae015bd4':
  Add third video to default system videos.
diff --git a/include/utils/threads.h b/include/utils/threads.h
index c685625..ab3e8cd 100644
--- a/include/utils/threads.h
+++ b/include/utils/threads.h
@@ -143,6 +143,10 @@
 // in either case errno is set.  Thread ID zero means current thread.
 extern int androidSetThreadPriority(pid_t tid, int prio);
 
+// Get the current priority of a particular thread. Returns one of the
+// ANDROID_PRIORITY constants or a negative result in case of error.
+extern int androidGetThreadPriority(pid_t tid);
+
 // Get the current scheduling group of a particular thread. Normally returns
 // one of the ANDROID_TGROUP constants other than ANDROID_TGROUP_DEFAULT.
 // Returns ANDROID_TGROUP_DEFAULT if no pthread support (e.g. on host) or if
diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp
index 02c380b..38c4b35 100644
--- a/libs/utils/Threads.cpp
+++ b/libs/utils/Threads.cpp
@@ -368,6 +368,10 @@
     return rc;
 }
 
+int androidGetThreadPriority(pid_t tid) {
+    return getpriority(PRIO_PROCESS, tid);
+}
+
 int androidGetThreadSchedulingGroup(pid_t tid)
 {
     int ret = ANDROID_TGROUP_DEFAULT;
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index edbc7b0..f85ce7f 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -404,7 +404,9 @@
 void Layer::lockPageFlip(bool& recomputeVisibleRegions)
 {
     if (mQueuedFrames > 0) {
+        // Capture the old state of the layer for comparisons later
         const bool oldOpacity = isOpaque();
+        sp<GraphicBuffer> oldActiveBuffer = mActiveBuffer;
 
         // signal another event if we have more frames pending
         if (android_atomic_dec(&mQueuedFrames) > 1) {
@@ -417,7 +419,8 @@
             return;
         }
 
-        sp<GraphicBuffer> newFrontBuffer(mSurfaceTexture->getCurrentBuffer());
+        // update the active buffer
+        mActiveBuffer = mSurfaceTexture->getCurrentBuffer();
 
         const Rect crop(mSurfaceTexture->getCurrentCrop());
         const uint32_t transform(mSurfaceTexture->getCurrentTransform());
@@ -439,16 +442,16 @@
             mFlinger->invalidateHwcGeometry();
         }
 
-        uint32_t bufWidth  = newFrontBuffer->getWidth();
-        uint32_t bufHeight = newFrontBuffer->getHeight();
-        if (mActiveBuffer != NULL) {
-            if (bufWidth != uint32_t(mActiveBuffer->width) ||
-                bufHeight != uint32_t(mActiveBuffer->height)) {
+        uint32_t bufWidth  = mActiveBuffer->getWidth();
+        uint32_t bufHeight = mActiveBuffer->getHeight();
+        if (oldActiveBuffer != NULL) {
+            if (bufWidth != uint32_t(oldActiveBuffer->width) ||
+                bufHeight != uint32_t(oldActiveBuffer->height)) {
                 mFlinger->invalidateHwcGeometry();
             }
         }
 
-        mCurrentOpacity = getOpacityForFormat(newFrontBuffer->format);
+        mCurrentOpacity = getOpacityForFormat(mActiveBuffer->format);
         if (oldOpacity != isOpaque()) {
             recomputeVisibleRegions = true;
         }
@@ -462,9 +465,6 @@
         // FIXME: mPostedDirtyRegion = dirty & bounds
         mPostedDirtyRegion.set(front.w, front.h);
 
-        // update active buffer
-        mActiveBuffer = newFrontBuffer;
-
         if ((front.w != front.requested_w) ||
             (front.h != front.requested_h))
         {