hwc: enforce X-coordinate alignment constraints

The FIMD requires buffers' X coordinates to be aligned to word
boundaries.  Use a Gscaler to convert unaligned buffers to 32-bpp, which
have no alignment constraints (1 word == 1 pixel).

Bug: 7242154
Change-Id: I169f89d3eaff4d7694a1e7fc4696caaf4bbd512d
Signed-off-by: Greg Hackmann <ghackmann@google.com>
diff --git a/libhwc/hwc.cpp b/libhwc/hwc.cpp
index 7ff722c..15db935 100644
--- a/libhwc/hwc.cpp
+++ b/libhwc/hwc.cpp
@@ -299,6 +299,18 @@
     }
 }
 
+static bool is_x_aligned(const hwc_layer_1_t &layer, int format)
+{
+    if (!exynos5_format_is_supported(format))
+        return true;
+
+    uint8_t bpp = exynos5_format_to_bpp(format);
+    uint8_t pixel_alignment = 32 / bpp;
+
+    return (layer.displayFrame.left % pixel_alignment) == 0 &&
+            (layer.displayFrame.right % pixel_alignment) == 0;
+}
+
 static bool exynos5_supports_gscaler(hwc_layer_1_t &layer, int format,
         bool local_path)
 {
@@ -341,7 +353,7 @@
 static bool exynos5_requires_gscaler(hwc_layer_1_t &layer, int format)
 {
     return exynos5_format_requires_gscaler(format) || is_scaled(layer)
-            || is_transformed(layer);
+            || is_transformed(layer) || !is_x_aligned(layer, format);
 }
 
 int hdmi_get_config(struct exynos5_hwc_composer_device_1_t *dev)