OSDN Git Service

drm_hwcomposer: Fix all cases which triggers an error on -Wsign-compare
authorRoman Stratiienko <roman.o.stratiienko@globallogic.com>
Mon, 6 Dec 2021 10:59:26 +0000 (12:59 +0200)
committerRoman Stratiienko <roman.o.stratiienko@globallogic.com>
Tue, 7 Dec 2021 09:55:39 +0000 (11:55 +0200)
Android-9 has -Wsign-compare enabled by default and it causes build issues.
Enable -Wsign-compare option in CI, so we won't introduce such issues anymore.

Signed-off-by: Roman Stratiienko <roman.o.stratiienko@globallogic.com>
.ci/.common.sh
backend/Backend.cpp
bufferinfo/legacy/BufferInfoLibdrm.cpp
drm/DrmFbImporter.cpp

index d9b5b3c..48cc594 100644 (file)
@@ -4,7 +4,7 @@ CLANG="clang++-12"
 CLANG_TIDY="clang-tidy-12"
 
 CXXARGS="-fPIC -Wall -Werror -DPLATFORM_SDK_VERSION=30 -D__ANDROID_API__=30 -Wsign-promo -Wimplicit-fallthrough"
-CXXARGS+=" -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -Wno-gnu-include-next "
+CXXARGS+=" -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -Wno-gnu-include-next -Wsign-compare"
 CXXARGS+=" -fvisibility-inlines-hidden -std=gnu++17 -DHWC2_USE_CPP11 -DHWC2_INCLUDE_STRINGIFICATION -fno-rtti"
 
 BUILD_FILES=(
index bd1855f..ce606dd 100644 (file)
@@ -72,7 +72,7 @@ std::tuple<int, size_t> Backend::GetClientLayers(
   int client_start = -1;
   size_t client_size = 0;
 
-  for (int z_order = 0; z_order < layers.size(); ++z_order) {
+  for (size_t z_order = 0; z_order < layers.size(); ++z_order) {
     if (IsClientLayer(display, layers[z_order])) {
       if (client_start < 0)
         client_start = (int)z_order;
@@ -100,7 +100,7 @@ bool Backend::HardwareSupportsLayerType(HWC2::Composition comp_type) {
 uint32_t Backend::CalcPixOps(const std::vector<DrmHwcTwo::HwcLayer *> &layers,
                              size_t first_z, size_t size) {
   uint32_t pixops = 0;
-  for (int z_order = 0; z_order < layers.size(); ++z_order) {
+  for (size_t z_order = 0; z_order < layers.size(); ++z_order) {
     if (z_order >= first_z && z_order < first_z + size) {
       hwc_rect_t df = layers[z_order]->display_frame();
       pixops += (df.right - df.left) * (df.bottom - df.top);
@@ -111,7 +111,7 @@ uint32_t Backend::CalcPixOps(const std::vector<DrmHwcTwo::HwcLayer *> &layers,
 
 void Backend::MarkValidated(std::vector<DrmHwcTwo::HwcLayer *> &layers,
                             size_t client_first_z, size_t client_size) {
-  for (int z_order = 0; z_order < layers.size(); ++z_order) {
+  for (size_t z_order = 0; z_order < layers.size(); ++z_order) {
     if (z_order >= client_first_z && z_order < client_first_z + client_size)
       layers[z_order]->set_validated_type(HWC2::Composition::Client);
     else
@@ -152,12 +152,12 @@ std::tuple<int, int> Backend::GetExtraClientRange(
       steps = 1 + layers.size() - extra_client;
     }
 
-    uint32_t gpu_pixops = INT_MAX;
-    for (int i = 0; i < steps; i++) {
+    uint32_t gpu_pixops = UINT32_MAX;
+    for (size_t i = 0; i < steps; i++) {
       uint32_t po = CalcPixOps(layers, start + i, client_size);
       if (po < gpu_pixops) {
         gpu_pixops = po;
-        client_start = start + i;
+        client_start = start + int(i);
       }
     }
   }
index e70536b..47481b2 100644 (file)
@@ -66,15 +66,15 @@ static const struct DroidYuvFormat kDroidYuvFormats[] = {
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
-static int get_fourcc_yuv(uint32_t native, enum chroma_order chroma_order,
-                          size_t chroma_step) {
+static uint32_t get_fourcc_yuv(uint32_t native, enum chroma_order chroma_order,
+                               size_t chroma_step) {
   for (auto droid_yuv_format : kDroidYuvFormats)
     if (droid_yuv_format.native == native &&
         droid_yuv_format.chroma_order == chroma_order &&
         droid_yuv_format.chroma_step == chroma_step)
       return droid_yuv_format.fourcc;
 
-  return -1;
+  return UINT32_MAX;
 }
 
 static bool is_yuv(uint32_t native) {
@@ -131,7 +131,7 @@ bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle,
   /* .chroma_step is the byte distance between the same chroma channel
    * values of subsequent pixels, assumed to be the same for Cb and Cr. */
   bo->format = get_fourcc_yuv(bo->hal_format, chroma_order, ycbcr.chroma_step);
-  if (bo->format == -1) {
+  if (bo->format == UINT32_MAX) {
     ALOGW(
         "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = "
         "%d",
index 8440093..25f32b7 100644 (file)
@@ -41,7 +41,7 @@ auto DrmFbIdHandle::CreateInstance(hwc_drm_bo_t *bo, GemHandle first_gem_handle,
   int32_t err = 0;
 
   /* Framebuffer object creation require gem handle for every used plane */
-  for (int i = 1; i < local->gem_handles_.size(); i++) {
+  for (size_t i = 1; i < local->gem_handles_.size(); i++) {
     if (bo->prime_fds[i] > 0) {
       if (bo->prime_fds[i] != bo->prime_fds[0]) {
         err = drmPrimeFDToHandle(drm->fd(), bo->prime_fds[i],
@@ -101,7 +101,7 @@ DrmFbIdHandle::~DrmFbIdHandle() {
    * request via system properties)
    */
   struct drm_gem_close gem_close {};
-  for (int i = 0; i < gem_handles_.size(); i++) {
+  for (size_t i = 0; i < gem_handles_.size(); i++) {
     /* Don't close invalid handle. Close handle only once in cases
      * where several YUV planes located in the single buffer. */
     if (gem_handles_[i] == 0 ||