drm_hwcomposer: filter out empty or invalid rects.

We can safely ignore zero-area rects because they do not affect the outcome
of the separate_rects() function. Furthermore the line sweep algorithm would
break when two identical START or END events are added to the same set.

Additionally any rect with |left| greater than |right| or |top| greater than
|bottom| is invalid and shall be ignored.

Added test cases with empty and invalid rects. This case would have crashed (or
failed the assert in a debug build) without this fix.

BUG=chrome-os-partner:47103
TEST=verify no crash with Photos app

Change-Id: I80950ef376390a14a892c58b563eb3c0f79db71c
diff --git a/seperate_rects.cpp b/seperate_rects.cpp
index 06fbe39..9344873 100644
--- a/seperate_rects.cpp
+++ b/seperate_rects.cpp
@@ -108,6 +108,11 @@
   // algorithm sweeps from left to right.
   for (TId i = 0; i < in.size(); i++) {
     const Rect<TNum> &rect = in[i];
+
+    // Filter out empty or invalid rects.
+    if (rect.left >= rect.right || rect.top >= rect.bottom)
+      continue;
+
     SweepEvent<TId, TNum> evt;
     evt.rect_id = i;
 
@@ -346,6 +351,11 @@
   in.push_back({50, 51, 52, 53});
   in.push_back({50, 51, 52, 53});
 
+  in.push_back({0, 0, 0, 10});
+  in.push_back({0, 0, 10, 0});
+  in.push_back({10, 0, 0, 10});
+  in.push_back({0, 10, 10, 0});
+
   for (int i = 0; i < 100000; i++) {
     out.clear();
     seperate_rects(in, &out);