drm_hwcomposer: Add property that allows disabling of hardware scaling

Set `hwc.drm.scale_with_gpu` property to 1 in case composer hardware
do not have scaling support.

That will force layers that require scaling to be merged by GPU,
and allow other layers to be merged by DRM.

Signed-off-by: Roman Stratiienko <roman.stratiienko@globallogic.com>
diff --git a/include/drmhwctwo.h b/include/drmhwctwo.h
index 89ae2f6..444c6ed 100644
--- a/include/drmhwctwo.h
+++ b/include/drmhwctwo.h
@@ -22,6 +22,7 @@
 
 #include <hardware/hwcomposer2.h>
 
+#include <math.h>
 #include <array>
 #include <map>
 
@@ -93,6 +94,19 @@
 
     void PopulateDrmLayer(DrmHwcLayer *layer);
 
+    bool RequireScalingOrPhasing() {
+      float src_width = source_crop_.right - source_crop_.left;
+      float src_height = source_crop_.bottom - source_crop_.top;
+
+      float dest_width = display_frame_.right - display_frame_.left;
+      float dest_height = display_frame_.bottom - display_frame_.top;
+
+      bool scaling = src_width != dest_width || src_height != dest_height;
+      bool phasing = (source_crop_.left - floor(source_crop_.left) != 0) ||
+                     (source_crop_.top - floor(source_crop_.top) != 0);
+      return scaling || phasing;
+    }
+
     // Layer hooks
     HWC2::Error SetCursorPosition(int32_t x, int32_t y);
     HWC2::Error SetLayerBlendMode(int32_t mode);
diff --git a/include/resourcemanager.h b/include/resourcemanager.h
index f10af45..7a86828 100644
--- a/include/resourcemanager.h
+++ b/include/resourcemanager.h
@@ -40,6 +40,9 @@
   int getDisplayCount() const {
     return num_displays_;
   }
+  bool ForcedScalingWithGpu() {
+    return scale_with_gpu_;
+  }
 
  private:
   int AddDrmDevice(std::string path);
@@ -48,6 +51,8 @@
   std::vector<std::unique_ptr<DrmDevice>> drms_;
   std::vector<std::shared_ptr<Importer>> importers_;
   const gralloc_module_t *gralloc_;
+
+  bool scale_with_gpu_;
 };
 }  // namespace android