Splitting of layers for correct intersections

Sorting 3d-sorted layers and rendering them in that order causes issues
when layers intersect. Instead place 3d-sorted layers in a bsp tree and
fragment any intersecting layers into non-rectangular quads. We can then
render the fragments in the correct sorted order regardless of
intersections.

BUG=455918,159225,132122,230833

Review URL: https://codereview.chromium.org/595593002

Cr-Commit-Position: refs/heads/master@{#320276}


CrOS-Libchrome-Original-Commit: 3d8eb1d841ec1ea36906d351bc65af4d7d27718a
diff --git a/ui/gfx/geometry/quad_f.h b/ui/gfx/geometry/quad_f.h
index ada5c54..d795064 100644
--- a/ui/gfx/geometry/quad_f.h
+++ b/ui/gfx/geometry/quad_f.h
@@ -10,6 +10,7 @@
 #include <iosfwd>
 #include <string>
 
+#include "base/logging.h"
 #include "ui/gfx/geometry/point_f.h"
 #include "ui/gfx/geometry/rect_f.h"
 #include "ui/gfx/gfx_export.h"
@@ -67,6 +68,18 @@
     return RectF(rl, rt, rr - rl, rb - rt);
   }
 
+  // Realigns the corners in the quad by rotating them n corners to the right.
+  void Realign(size_t times) {
+    DCHECK_LE(times, 4u);
+    for (size_t i = 0; i < times; ++i) {
+      PointF temp = p1_;
+      p1_ = p2_;
+      p2_ = p3_;
+      p3_ = p4_;
+      p4_ = temp;
+    }
+  }
+
   // Add a vector to the quad, offseting each point in the quad by the vector.
   void operator+=(const Vector2dF& rhs);
   // Subtract a vector from the quad, offseting each point in the quad by the