drm_hwcomposer: Fix all cases which triggers an error on -Wsign-compare
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>
diff --git a/.ci/.common.sh b/.ci/.common.sh
index d9b5b3c..48cc594 100644
--- a/.ci/.common.sh
+++ b/.ci/.common.sh
@@ -4,7 +4,7 @@
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=(
diff --git a/backend/Backend.cpp b/backend/Backend.cpp
index bd1855f..ce606dd 100644
--- a/backend/Backend.cpp
+++ b/backend/Backend.cpp
@@ -72,7 +72,7 @@
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 @@
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 @@
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 @@
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);
}
}
}
diff --git a/bufferinfo/legacy/BufferInfoLibdrm.cpp b/bufferinfo/legacy/BufferInfoLibdrm.cpp
index e70536b..47481b2 100644
--- a/bufferinfo/legacy/BufferInfoLibdrm.cpp
+++ b/bufferinfo/legacy/BufferInfoLibdrm.cpp
@@ -66,15 +66,15 @@
#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 @@
/* .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",
diff --git a/drm/DrmFbImporter.cpp b/drm/DrmFbImporter.cpp
index 8440093..25f32b7 100644
--- a/drm/DrmFbImporter.cpp
+++ b/drm/DrmFbImporter.cpp
@@ -41,7 +41,7 @@
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 @@
* 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 ||