drm_hwcomposer: only check the composition after a geometry change

Do not check the composition with kernel for every frame. We are currently
using synchronous atomic ioctl calls, so all test-only calls are serialized
with the actual commits.

BUG=25866352
TEST=same test procedure as crosbug.com/p/47206

Change-Id: Ia423243c279fc677ff6213115a8f20efa40c235e
diff --git a/drmdisplaycomposition.h b/drmdisplaycomposition.h
index 9be5fdd..3c94e6b 100644
--- a/drmdisplaycomposition.h
+++ b/drmdisplaycomposition.h
@@ -17,8 +17,8 @@
 #ifndef ANDROID_DRM_DISPLAY_COMPOSITION_H_
 #define ANDROID_DRM_DISPLAY_COMPOSITION_H_
 
-#include "drmhwcomposer.h"
 #include "drmcrtc.h"
+#include "drmhwcomposer.h"
 #include "drmplane.h"
 #include "glworker.h"
 #include "importer.h"
@@ -100,6 +100,10 @@
     return composition_planes_;
   }
 
+  bool geometry_changed() const {
+    return geometry_changed_;
+  }
+
   uint64_t frame_no() const {
     return frame_no_;
   }
diff --git a/drmdisplaycompositor.cpp b/drmdisplaycompositor.cpp
index f1d925a..95e2333 100644
--- a/drmdisplaycompositor.cpp
+++ b/drmdisplaycompositor.cpp
@@ -926,19 +926,21 @@
         ALOGE("Failed to prepare frame for display %d", display_);
         return ret;
       }
-      // Send the composition to the kernel to ensure we can commit it. This is
-      // just a test, it won't actually commit the frame. If the kernel rejects
-      // it, squash the frame into one layer and use the squashed composition
-      ret = CommitFrame(composition.get(), true);
-      if (ret) {
-        ALOGI("Commit test failed, squashing frame for display %d", display_);
-        std::unique_ptr<DrmDisplayComposition> squashed = CreateComposition();
-        ret = SquashFrame(composition.get(), squashed.get());
-        if (!ret) {
-          composition = std::move(squashed);
-        } else {
-          ALOGE("Failed to squash frame for display %d", display_);
-          return ret;
+      if (composition->geometry_changed()) {
+        // Send the composition to the kernel to ensure we can commit it. This
+        // is just a test, it won't actually commit the frame. If rejected,
+        // squash the frame into one layer and use the squashed composition
+        ret = CommitFrame(composition.get(), true);
+        if (ret) {
+          ALOGI("Commit test failed, squashing frame for display %d", display_);
+          std::unique_ptr<DrmDisplayComposition> squashed = CreateComposition();
+          ret = SquashFrame(composition.get(), squashed.get());
+          if (!ret) {
+            composition = std::move(squashed);
+          } else {
+            ALOGE("Failed to squash frame for display %d", display_);
+            return ret;
+          }
         }
       }
       frame_worker_.QueueFrame(std::move(composition), ret);