OSDN Git Service

drm_hwcomposer: enable code analysis using clang-tidy
authorRoman Stratiienko <r.stratiienko@gmail.com>
Sat, 13 Feb 2021 08:57:47 +0000 (10:57 +0200)
committerRoman Stratiienko <r.stratiienko@gmail.com>
Wed, 3 Mar 2021 14:07:25 +0000 (16:07 +0200)
Drm hwcomposer project has some code-style inconsistencies.
This is the initial step to unify code-style of the code.

Clang-tidy is a great tool which can not only suggest correct styling,
but also allow predicting the errors in the code and suggest correct
coding approaches to avoid potential weaknesses.

CI was tuned to check clang-tidy recommendation for some part of the
code which is ready ATM (can be built outside AOSP tree).
For this part a limited set of clang-tidy checks has applied (coarse check).
Header files aren't checked at all.

Starting from now new code files must be included into the list that is
checked by almost all clang-tidy checks (fine checklist). New header files
should be also included into this list.
See '.gitlab-ci-clang-tidy-fine.sh'.

Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
42 files changed:
.ci/.common.sh
.ci/.gitlab-ci-clang-build.sh
.ci/.gitlab-ci-clang-tidy-coarse.sh
DrmHwcTwo.cpp
DrmHwcTwo.h
backend/Backend.cpp
backend/Backend.h
backend/BackendManager.cpp
backend/BackendManager.h
bufferinfo/BufferInfoGetter.cpp
bufferinfo/BufferInfoGetter.h
bufferinfo/BufferInfoMapperMetadata.cpp
bufferinfo/legacy/BufferInfoImagination.cpp
bufferinfo/legacy/BufferInfoLibdrm.cpp
bufferinfo/legacy/BufferInfoMaliHisi.cpp
bufferinfo/legacy/BufferInfoMaliMediatek.cpp
bufferinfo/legacy/BufferInfoMaliMeson.cpp
bufferinfo/legacy/BufferInfoMinigbm.cpp
compositor/DrmDisplayComposition.cpp
compositor/DrmDisplayComposition.h
compositor/DrmDisplayCompositor.cpp
compositor/Planner.cpp
drm/DrmConnector.cpp
drm/DrmCrtc.cpp
drm/DrmDevice.cpp
drm/DrmDevice.h
drm/DrmEncoder.cpp
drm/DrmEncoder.h
drm/DrmEventListener.cpp
drm/DrmGenericImporter.cpp
drm/DrmGenericImporter.h
drm/DrmMode.cpp
drm/DrmPlane.cpp
drm/DrmProperty.cpp
drm/DrmProperty.h
drm/ResourceManager.cpp
drm/ResourceManager.h
drm/VSyncWorker.cpp
drm/VSyncWorker.h
utils/Worker.cpp
utils/autolock.cpp
utils/hwcutils.cpp

index 7fa5a88..4dbe745 100644 (file)
@@ -6,3 +6,14 @@ CLANG_TIDY="clang-tidy-11"
 CXXARGS="-fPIC -Wall -Werror -DPLATFORM_SDK_VERSION=30 -Wsign-promo -Wimplicit-fallthrough"
 CXXARGS+=" -D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS -Wno-gnu-include-next "
 CXXARGS+=" -fvisibility-inlines-hidden -std=gnu++17 -DHWC2_USE_CPP11 -DHWC2_INCLUDE_STRINGIFICATION -fexceptions -fno-rtti"
+
+BUILD_FILES=(
+drm/DrmConnector.cpp
+drm/DrmCrtc.cpp
+drm/DrmDevice.cpp
+drm/DrmEncoder.cpp
+drm/DrmEventListener.cpp
+drm/DrmMode.cpp
+drm/DrmProperty.cpp
+utils/Worker.cpp
+)
index 11dd817..1070365 100755 (executable)
@@ -2,17 +2,6 @@
 
 . ./.ci/.common.sh
 
-BUILD_FILES=(
-drm/DrmConnector.cpp
-drm/DrmCrtc.cpp
-drm/DrmDevice.cpp
-drm/DrmEncoder.cpp
-drm/DrmEventListener.cpp
-drm/DrmMode.cpp
-drm/DrmProperty.cpp
-utils/Worker.cpp
-)
-
 set -xe
 
 for source in "${BUILD_FILES[@]}"
index bb7373c..cd22516 100755 (executable)
@@ -2,12 +2,28 @@
 
 . ./.ci/.common.sh
 
-TIDY_FILES=(
-)
+TIDY_COARSE_CHECKS="-*,android-*,bugprone-*,cert-*,"
+TIDY_COARSE_CHECKS+="google-*,"
+TIDY_COARSE_CHECKS+="-google-readability-braces-around-statements,"
+TIDY_COARSE_CHECKS+="-google-readability-casting,"
+TIDY_COARSE_CHECKS+="misc-*,"
+TIDY_COARSE_CHECKS+="modernize-*,"
+TIDY_COARSE_CHECKS+="-modernize-avoid-c-arrays,"
+TIDY_COARSE_CHECKS+="-modernize-use-trailing-return-type,"
+TIDY_COARSE_CHECKS+="performance-*,"
+TIDY_COARSE_CHECKS+="portability-*,"
+TIDY_COARSE_CHECKS+="readability-*,"
+TIDY_COARSE_CHECKS+="-readability-braces-around-statements,"
+TIDY_COARSE_CHECKS+="-readability-convert-member-functions-to-static,"
+TIDY_COARSE_CHECKS+="-readability-implicit-bool-conversion,"
+TIDY_COARSE_CHECKS+="-readability-magic-numbers,"
+TIDY_COARSE_CHECKS+="-readability-use-anyofallof"
+
+TIDY_FILES=( "${BUILD_FILES[@]}" )
 
 set -xe
 
 for source in "${TIDY_FILES[@]}"
 do
-    $CLANG_TIDY $source -- -x c++ $INCLUDE_DIRS
+    $CLANG_TIDY $source --checks=$TIDY_COARSE_CHECKS -- -x c++ $INCLUDE_DIRS
 done
index db5f351..02ad03d 100644 (file)
@@ -22,9 +22,9 @@
 #include <cutils/properties.h>
 #include <hardware/hardware.h>
 #include <hardware/hwcomposer2.h>
-#include <inttypes.h>
 #include <log/log.h>
 
+#include <cinttypes>
 #include <string>
 
 #include "backend/BackendManager.h"
@@ -83,8 +83,8 @@ HWC2::Error DrmHwcTwo::Init() {
     }
   }
 
-  auto &drmDevices = resource_manager_.getDrmDevices();
-  for (auto &device : drmDevices) {
+  auto &drm_devices = resource_manager_.getDrmDevices();
+  for (auto &device : drm_devices) {
     device->RegisterHotplugHandler(new DrmHotplugHandler(this, device.get()));
   }
   return ret;
@@ -103,12 +103,12 @@ static inline void supported(char const *func) {
 HWC2::Error DrmHwcTwo::CreateVirtualDisplay(uint32_t width, uint32_t height,
                                             int32_t *format,
                                             hwc2_display_t *display) {
-  // TODO: Implement virtual display
+  // TODO(nobody): Implement virtual display
   return unsupported(__func__, width, height, format, display);
 }
 
 HWC2::Error DrmHwcTwo::DestroyVirtualDisplay(hwc2_display_t display) {
-  // TODO: Implement virtual display
+  // TODO(nobody): Implement virtual display
   return unsupported(__func__, display);
 }
 
@@ -116,7 +116,7 @@ std::string DrmHwcTwo::HwcDisplay::DumpDelta(
     DrmHwcTwo::HwcDisplay::Stats delta) {
   if (delta.total_pixops_ == 0)
     return "No stats yet";
-  double Ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_);
+  double ratio = 1.0 - double(delta.gpu_pixops_) / double(delta.total_pixops_);
 
   return (std::stringstream()
           << " Total frames count: " << delta.total_frames_ << "\n"
@@ -130,7 +130,7 @@ std::string DrmHwcTwo::HwcDisplay::DumpDelta(
           << " Pixel operations (free units)"
           << " : [TOTAL: " << delta.total_pixops_
           << " / GPU: " << delta.gpu_pixops_ << "]\n"
-          << " Composition efficiency: " << Ratio)
+          << " Composition efficiency: " << ratio)
       .str();
 }
 
@@ -153,8 +153,8 @@ void DrmHwcTwo::Dump(uint32_t *outSize, char *outBuffer) {
   supported(__func__);
 
   if (outBuffer != nullptr) {
-    auto copiedBytes = mDumpString.copy(outBuffer, *outSize);
-    *outSize = static_cast<uint32_t>(copiedBytes);
+    auto copied_bytes = mDumpString.copy(outBuffer, *outSize);
+    *outSize = static_cast<uint32_t>(copied_bytes);
     return;
   }
 
@@ -170,7 +170,7 @@ void DrmHwcTwo::Dump(uint32_t *outSize, char *outBuffer) {
 }
 
 uint32_t DrmHwcTwo::GetMaxVirtualDisplayCount() {
-  // TODO: Implement virtual display
+  // TODO(nobody): Implement virtual display
   unsupported(__func__);
   return 0;
 }
@@ -183,8 +183,8 @@ HWC2::Error DrmHwcTwo::RegisterCallback(int32_t descriptor,
   switch (static_cast<HWC2::Callback>(descriptor)) {
     case HWC2::Callback::Hotplug: {
       SetHotplugCallback(data, function);
-      auto &drmDevices = resource_manager_.getDrmDevices();
-      for (auto &device : drmDevices)
+      auto &drm_devices = resource_manager_.getDrmDevices();
+      for (auto &device : drm_devices)
         HandleInitialHotplugState(device.get());
       break;
     }
@@ -212,7 +212,7 @@ DrmHwcTwo::HwcDisplay::HwcDisplay(ResourceManager *resource_manager,
                                   hwc2_display_t handle, HWC2::DisplayType type)
     : resource_manager_(resource_manager),
       drm_(drm),
-      importer_(importer),
+      importer_(std::move(importer)),
       handle_(handle),
       type_(type),
       color_transform_hint_(HAL_COLOR_TRANSFORM_IDENTITY) {
@@ -250,7 +250,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) {
   char use_overlay_planes_prop[PROPERTY_VALUE_MAX];
   property_get("vendor.hwc.drm.use_overlay_planes", use_overlay_planes_prop,
                "1");
-  bool use_overlay_planes = atoi(use_overlay_planes_prop);
+  bool use_overlay_planes = strtol(use_overlay_planes_prop, nullptr, 10);
   for (auto &plane : *planes) {
     if (plane->type() == DRM_PLANE_TYPE_PRIMARY)
       primary_planes_.push_back(plane);
@@ -288,7 +288,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::Init(std::vector<DrmPlane *> *planes) {
 HWC2::Error DrmHwcTwo::HwcDisplay::ChosePreferredConfig() {
   // Fetch the number of modes from the display
   uint32_t num_configs;
-  HWC2::Error err = GetDisplayConfigs(&num_configs, NULL);
+  HWC2::Error err = GetDisplayConfigs(&num_configs, nullptr);
   if (err != HWC2::Error::None || !num_configs)
     return err;
 
@@ -373,11 +373,10 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetClientTargetSupport(uint32_t width,
   if (width > max.first || height > max.second)
     return HWC2::Error::Unsupported;
 
-  if (dataspace != HAL_DATASPACE_UNKNOWN &&
-      dataspace != HAL_DATASPACE_STANDARD_UNSPECIFIED)
+  if (dataspace != HAL_DATASPACE_UNKNOWN)
     return HWC2::Error::Unsupported;
 
-  // TODO: Validate format can be handled by either GL or planes
+  // TODO(nobody): Validate format can be handled by either GL or planes
   return HWC2::Error::None;
 }
 
@@ -420,7 +419,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayAttribute(hwc2_config_t config,
       break;
     case HWC2::Attribute::VsyncPeriod:
       // in nanoseconds
-      *value = 1000 * 1000 * 1000 / mode->v_refresh();
+      *value = 1000.0 * 1000.0 * 1000.0 / mode->v_refresh();
       break;
     case HWC2::Attribute::DpiX:
       // Dots per 1000 inches
@@ -466,7 +465,8 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
   // at least one non-interlaced alternative and only offer a single WxH@R
   // mode with at least the prefered mode from in DrmConnector::UpdateModes()
 
-  // TODO: Remove the following block of code until AOSP handles all modes
+  // TODO(nobody): Remove the following block of code until AOSP handles all
+  // modes
   std::vector<DrmMode> sel_modes;
 
   // Add the preferred mode first to be sure it's not dropped
@@ -485,11 +485,11 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
   // Cycle over the modes and filter out "similar" modes, keeping only the
   // first ones in the order given by DRM (from CEA ids and timings order)
   for (const DrmMode &mode : connector_->modes()) {
-    // TODO: Remove this when 3D Attributes are in AOSP
+    // TODO(nobody): Remove this when 3D Attributes are in AOSP
     if (mode.flags() & DRM_MODE_FLAG_3D_MASK)
       continue;
 
-    // TODO: Remove this when the Interlaced attribute is in AOSP
+    // TODO(nobody): Remove this when the Interlaced attribute is in AOSP
     if (mode.flags() & DRM_MODE_FLAG_INTERLACE) {
       auto m = std::find_if(connector_->modes().begin(),
                             connector_->modes().end(),
@@ -506,7 +506,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayConfigs(uint32_t *num_configs,
 
     // Search for a similar WxH@R mode in the filtered list and drop it if
     // another mode with the same WxH@R has already been selected
-    // TODO: Remove this when AOSP handles duplicates modes
+    // TODO(nobody): Remove this when AOSP handles duplicates modes
     auto m = std::find_if(sel_modes.begin(), sel_modes.end(),
                           [&mode](DrmMode const &m) {
                             return m.h_display() == mode.h_display() &&
@@ -554,7 +554,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayRequests(int32_t *display_requests,
                                                       hwc2_layer_t *layers,
                                                       int32_t *layer_requests) {
   supported(__func__);
-  // TODO: I think virtual display should request
+  // TODO(nobody): I think virtual display should request
   //      HWC2_DISPLAY_REQUEST_WRITE_CLIENT_TARGET_TO_OUTPUT here
   unsupported(__func__, display_requests, num_elements, layers, layer_requests);
   *num_elements = 0;
@@ -589,9 +589,10 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetReleaseFences(uint32_t *num_elements,
 
   for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l : layers_) {
     ++num_layers;
-    if (layers == NULL || fences == NULL) {
+    if (layers == nullptr || fences == nullptr)
       continue;
-    } else if (num_layers > *num_elements) {
+
+    if (num_layers > *num_elements) {
       ALOGW("Overflow num_elements %d/%d", num_layers, *num_elements);
       return HWC2::Error::None;
     }
@@ -628,7 +629,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) {
   DrmCompositionDisplayLayersMap &map = layers_map.back();
 
   map.display = static_cast<int>(handle_);
-  map.geometry_changed = true;  // TODO: Fix this
+  map.geometry_changed = true;  // TODO(nobody): Fix this
 
   // order the layers by z-order
   bool use_client_layer = false;
@@ -670,7 +671,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::CreateComposition(bool test) {
                                                            .CreateComposition();
   composition->Init(drm_, crtc_, importer_.get(), planner_.get(), frame_no_);
 
-  // TODO: Don't always assume geometry changed
+  // TODO(nobody): Don't always assume geometry changed
   int ret = composition->SetLayers(map.layers.data(), map.layers.size(), true);
   if (ret) {
     ALOGE("Failed to set layers in the composition ret=%d", ret);
@@ -783,10 +784,10 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetClientTarget(buffer_handle_t target,
   hwc_drm_bo bo{};
   BufferInfoGetter::GetInstance()->ConvertBoInfo(target, &bo);
 
-  hwc_frect_t source_crop = {.left = 0.0f,
-                             .top = 0.0f,
-                             .right = bo.width + 0.0f,
-                             .bottom = bo.height + 0.0f};
+  hwc_frect_t source_crop = {.left = 0.0F,
+                             .top = 0.0F,
+                             .right = bo.width + 0.0F,
+                             .bottom = bo.height + 0.0F};
   client_layer_.SetLayerSourceCrop(source_crop);
 
   return HWC2::Error::None;
@@ -825,7 +826,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetColorTransform(const float *matrix,
 HWC2::Error DrmHwcTwo::HwcDisplay::SetOutputBuffer(buffer_handle_t buffer,
                                                    int32_t release_fence) {
   supported(__func__);
-  // TODO: Need virtual display support
+  // TODO(nobody): Need virtual display support
   return unsupported(__func__, buffer, release_fence);
 }
 
@@ -938,7 +939,8 @@ HWC2::Error DrmHwcTwo::HwcDisplay::SetAutoLowLatencyMode(bool /*on*/) {
 }
 
 HWC2::Error DrmHwcTwo::HwcDisplay::GetSupportedContentTypes(
-    uint32_t *outNumSupportedContentTypes, uint32_t *outSupportedContentTypes) {
+    uint32_t *outNumSupportedContentTypes,
+    const uint32_t *outSupportedContentTypes) {
   if (outSupportedContentTypes == nullptr)
     *outNumSupportedContentTypes = 0;
 
@@ -986,7 +988,7 @@ HWC2::Error DrmHwcTwo::HwcDisplay::GetDisplayCapabilities(
     uint32_t *outNumCapabilities, uint32_t *outCapabilities) {
   unsupported(__func__, outCapabilities);
 
-  if (outNumCapabilities == NULL) {
+  if (outNumCapabilities == nullptr) {
     return HWC2::Error::BadParameter;
   }
 
@@ -1071,7 +1073,7 @@ HWC2::Error DrmHwcTwo::HwcLayer::SetLayerBuffer(buffer_handle_t buffer,
 }
 
 HWC2::Error DrmHwcTwo::HwcLayer::SetLayerColor(hwc_color_t color) {
-  // TODO: Put to client composition here?
+  // TODO(nobody): Put to client composition here?
   supported(__func__);
   layer_color_ = color;
   return HWC2::Error::None;
@@ -1103,7 +1105,7 @@ HWC2::Error DrmHwcTwo::HwcLayer::SetLayerPlaneAlpha(float alpha) {
 HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSidebandStream(
     const native_handle_t *stream) {
   supported(__func__);
-  // TODO: We don't support sideband
+  // TODO(nobody): We don't support sideband
   return unsupported(__func__, stream);
 }
 
@@ -1115,7 +1117,7 @@ HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSourceCrop(hwc_frect_t crop) {
 
 HWC2::Error DrmHwcTwo::HwcLayer::SetLayerSurfaceDamage(hwc_region_t damage) {
   supported(__func__);
-  // TODO: We don't use surface damage, marking as unsupported
+  // TODO(nobody): We don't use surface damage, marking as unsupported
   unsupported(__func__, damage);
   return HWC2::Error::None;
 }
@@ -1128,7 +1130,7 @@ HWC2::Error DrmHwcTwo::HwcLayer::SetLayerTransform(int32_t transform) {
 
 HWC2::Error DrmHwcTwo::HwcLayer::SetLayerVisibleRegion(hwc_region_t visible) {
   supported(__func__);
-  // TODO: We don't use this information, marking as unsupported
+  // TODO(nobody): We don't use this information, marking as unsupported
   unsupported(__func__, visible);
   return HWC2::Error::None;
 }
@@ -1163,7 +1165,7 @@ void DrmHwcTwo::HwcLayer::PopulateDrmLayer(DrmHwcLayer *layer) {
   layer->acquire_fence = acquire_fence_.Release();
   layer->release_fence = std::move(release_fence);
   layer->SetDisplayFrame(display_frame_);
-  layer->alpha = static_cast<uint16_t>(65535.0f * alpha_ + 0.5f);
+  layer->alpha = lround(65535.0F * alpha_);
   layer->SetSourceCrop(source_crop_);
   layer->SetTransform(static_cast<int32_t>(transform_));
   layer->dataspace = dataspace_;
@@ -1484,7 +1486,7 @@ hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction(
                     &HwcLayer::SetLayerZOrder, uint32_t>);
     case HWC2::FunctionDescriptor::Invalid:
     default:
-      return NULL;
+      return nullptr;
   }
 }
 
@@ -1492,7 +1494,7 @@ hwc2_function_pointer_t DrmHwcTwo::HookDevGetFunction(
 int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name,
                            struct hw_device_t **dev) {
   supported(__func__);
-  if (strcmp(name, HWC_HARDWARE_COMPOSER)) {
+  if (strcmp(name, HWC_HARDWARE_COMPOSER) != 0) {
     ALOGE("Invalid module name- %s", name);
     return -EINVAL;
   }
@@ -1511,7 +1513,7 @@ int DrmHwcTwo::HookDevOpen(const struct hw_module_t *module, const char *name,
 
   ctx->common.module = const_cast<hw_module_t *>(module);
   *dev = &ctx->common;
-  ctx.release();
+  ctx.release();  // NOLINT(bugprone-unused-return-value)
   return 0;
 }
 }  // namespace android
@@ -1527,6 +1529,6 @@ hw_module_t HAL_MODULE_INFO_SYM = {
     .name = "DrmHwcTwo module",
     .author = "The Android Open Source Project",
     .methods = &hwc2_module_methods,
-    .dso = NULL,
+    .dso = nullptr,
     .reserved = {0},
 };
index 7a08d64..c75b2e9 100644 (file)
@@ -137,7 +137,7 @@ class DrmHwcTwo : public hwc2_device_t {
     HWC2::Error SetLayerSurfaceDamage(hwc_region_t damage);
     HWC2::Error SetLayerTransform(int32_t transform);
     HWC2::Error SetLayerVisibleRegion(hwc_region_t visible);
-    HWC2::Error SetLayerZOrder(uint32_t z);
+    HWC2::Error SetLayerZOrder(uint32_t order);
 
    private:
     // sf_type_ stores the initial type given to us by surfaceflinger,
@@ -227,8 +227,9 @@ class DrmHwcTwo : public hwc2_device_t {
         hwc_vsync_period_change_constraints_t *vsyncPeriodChangeConstraints,
         hwc_vsync_period_change_timeline_t *outTimeline);
     HWC2::Error SetAutoLowLatencyMode(bool on);
-    HWC2::Error GetSupportedContentTypes(uint32_t *outNumSupportedContentTypes,
-                                         uint32_t *outSupportedContentTypes);
+    HWC2::Error GetSupportedContentTypes(
+        uint32_t *outNumSupportedContentTypes,
+        const uint32_t *outSupportedContentTypes);
 
     HWC2::Error SetContentType(int32_t contentType);
 #endif
index 887eb0e..15a9ff1 100644 (file)
@@ -36,7 +36,8 @@ HWC2::Error Backend::ValidateDisplay(DrmHwcTwo::HwcDisplay *display,
   if (avail_planes < display->layers().size())
     avail_planes--;
 
-  std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map, z_map_tmp;
+  std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map;
+  std::map<uint32_t, DrmHwcTwo::HwcLayer *> z_map_tmp;
   uint32_t z_index = 0;
   // First create a map of layers and z_order values
   for (std::pair<const hwc2_layer_t, DrmHwcTwo::HwcLayer> &l :
@@ -49,7 +50,8 @@ HWC2::Error Backend::ValidateDisplay(DrmHwcTwo::HwcDisplay *display,
   uint32_t total_pixops = display->CalcPixOps(z_map, 0, z_map.size());
   uint32_t gpu_pixops = 0;
 
-  int client_start = -1, client_size = 0;
+  int client_start = -1;
+  size_t client_size = 0;
 
   if (display->compositor().ShouldFlattenOnClient()) {
     client_start = 0;
@@ -58,17 +60,18 @@ HWC2::Error Backend::ValidateDisplay(DrmHwcTwo::HwcDisplay *display,
   } else {
     std::tie(client_start, client_size) = GetClientLayers(display, z_map);
 
-    int extra_client = (z_map.size() - client_size) - avail_planes;
+    size_t extra_client = (z_map.size() - client_size) - avail_planes;
     if (extra_client > 0) {
-      int start = 0, steps;
+      int start = 0;
+      size_t steps;
       if (client_size != 0) {
-        int prepend = std::min(client_start, extra_client);
-        int append = std::min(int(z_map.size() - (client_start + client_size)),
-                              extra_client);
-        start = client_start - prepend;
+        size_t prepend = std::min((size_t)client_start, extra_client);
+        size_t append = std::min(z_map.size() - (client_start + client_size),
+                                 extra_client);
+        start = client_start - (int)prepend;
         client_size += extra_client;
         steps = 1 + std::min(std::min(append, prepend),
-                             int(z_map.size()) - (start + client_size));
+                             z_map.size() - (start + client_size));
       } else {
         client_size = extra_client;
         steps = 1 + z_map.size() - extra_client;
@@ -107,15 +110,16 @@ HWC2::Error Backend::ValidateDisplay(DrmHwcTwo::HwcDisplay *display,
   return *num_types ? HWC2::Error::HasChanges : HWC2::Error::None;
 }
 
-std::tuple<int, int> Backend::GetClientLayers(
+std::tuple<int, size_t> Backend::GetClientLayers(
     DrmHwcTwo::HwcDisplay *display,
     const std::map<uint32_t, DrmHwcTwo::HwcLayer *> &z_map) {
-  int client_start = -1, client_size = 0;
+  int client_start = -1;
+  size_t client_size = 0;
 
-  for (auto & [ z_order, layer ] : z_map) {
+  for (auto &[z_order, layer] : z_map) {
     if (IsClientLayer(display, layer)) {
       if (client_start < 0)
-        client_start = z_order;
+        client_start = (int)z_order;
       client_size = (z_order - client_start) + 1;
     }
   }
index 898fece..2725809 100644 (file)
@@ -27,7 +27,7 @@ class Backend {
   virtual HWC2::Error ValidateDisplay(DrmHwcTwo::HwcDisplay *display,
                                       uint32_t *num_types,
                                       uint32_t *num_requests);
-  virtual std::tuple<int, int> GetClientLayers(
+  virtual std::tuple<int, size_t> GetClientLayers(
       DrmHwcTwo::HwcDisplay *display,
       const std::map<uint32_t, DrmHwcTwo::HwcLayer *> &z_map);
   virtual bool IsClientLayer(DrmHwcTwo::HwcDisplay *display,
index 0bacdcd..a346d46 100644 (file)
@@ -23,7 +23,7 @@
 
 namespace android {
 
-const std::vector<std::string> BackendManager::client_devices_ = {
+const std::vector<std::string> BackendManager::kClientDevices = {
     "kirin",
     "mediatek-drm",
 };
@@ -45,7 +45,7 @@ int BackendManager::SetBackendForDisplay(DrmHwcTwo::HwcDisplay *display) {
   char backend_override[PROPERTY_VALUE_MAX];
   property_get("vendor.hwc.backend_override", backend_override,
                driver_name.c_str());
-  std::string backend_name(std::move(backend_override));
+  std::string backend_name(backend_override);
 
   display->set_backend(GetBackendByName(backend_name));
   if (!display->backend()) {
@@ -63,15 +63,15 @@ int BackendManager::SetBackendForDisplay(DrmHwcTwo::HwcDisplay *display) {
 }
 
 std::unique_ptr<Backend> BackendManager::GetBackendByName(std::string &name) {
-  if (!available_backends_.size()) {
+  if (available_backends_.empty()) {
     ALOGE("No backends are specified");
     return nullptr;
   }
 
   auto it = available_backends_.find(name);
   if (it == available_backends_.end()) {
-    auto it = std::find(client_devices_.begin(), client_devices_.end(), name);
-    name = it == client_devices_.end() ? "generic" : "client";
+    auto it = std::find(kClientDevices.begin(), kClientDevices.end(), name);
+    name = it == kClientDevices.end() ? "generic" : "client";
   }
 
   return available_backends_[name]();
index e86c098..9b314db 100644 (file)
@@ -48,7 +48,7 @@ class BackendManager {
  private:
   BackendManager() = default;
 
-  static const std::vector<std::string> client_devices_;
+  static const std::vector<std::string> kClientDevices;
 
   std::map<std::string, backend_constructor_t> available_backends_;
 };
index afdc50e..d8e63a9 100644 (file)
@@ -40,7 +40,7 @@ BufferInfoGetter *BufferInfoGetter::GetInstance() {
       ALOGW(
           "Generic buffer getter is not available. Falling back to legacy...");
 #endif
-      inst.reset(LegacyBufferInfoGetter::CreateInstance());
+      inst = LegacyBufferInfoGetter::CreateInstance();
 #if PLATFORM_SDK_VERSION >= 30
     }
 #endif
@@ -109,7 +109,7 @@ bool BufferInfoGetter::IsDrmFormatRgb(uint32_t drm_format) {
   }
 }
 
-__attribute__((weak)) LegacyBufferInfoGetter *
+__attribute__((weak)) std::unique_ptr<LegacyBufferInfoGetter>
 LegacyBufferInfoGetter::CreateInstance() {
   ALOGE("No legacy buffer info getters available");
   return nullptr;
index 19ff02b..60ca985 100644 (file)
@@ -51,7 +51,7 @@ class LegacyBufferInfoGetter : public BufferInfoGetter {
 
   int ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) override = 0;
 
-  static LegacyBufferInfoGetter *CreateInstance();
+  static std::unique_ptr<LegacyBufferInfoGetter> CreateInstance();
 
   static uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
   const gralloc_module_t *gralloc_;
@@ -60,19 +60,18 @@ class LegacyBufferInfoGetter : public BufferInfoGetter {
 #ifdef DISABLE_LEGACY_GETTERS
 #define LEGACY_BUFFER_INFO_GETTER(getter_)
 #else
-#define LEGACY_BUFFER_INFO_GETTER(getter_)                           \
-  LegacyBufferInfoGetter *LegacyBufferInfoGetter::CreateInstance() { \
-    auto *instance = new getter_();                                  \
-    if (!instance)                                                   \
-      return NULL;                                                   \
-                                                                     \
-    int ret = instance->Init();                                      \
-    if (ret) {                                                       \
-      ALOGE("Failed to initialize the " #getter_ " getter %d", ret); \
-      delete instance;                                               \
-      return NULL;                                                   \
-    }                                                                \
-    return instance;                                                 \
+#define LEGACY_BUFFER_INFO_GETTER(getter_)                             \
+  std::unique_ptr<LegacyBufferInfoGetter>                              \
+  LegacyBufferInfoGetter::CreateInstance() {                           \
+    auto instance = std::make_unique<getter_>();                       \
+    if (instance) {                                                    \
+      int ret = instance->Init();                                      \
+      if (ret) {                                                       \
+        ALOGE("Failed to initialize the " #getter_ " getter %d", ret); \
+        instance.reset();                                              \
+      }                                                                \
+    }                                                                  \
+    return std::move(instance);                                        \
   }
 #endif
 
index 7d64ce8..516c7e1 100644 (file)
 #include "BufferInfoMapperMetadata.h"
 
 #include <drm/drm_fourcc.h>
-#include <inttypes.h>
 #include <log/log.h>
 #include <ui/GraphicBufferMapper.h>
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 
-using android::hardware::graphics::common::V1_1::BufferUsage;
+#include <cinttypes>
 
 namespace android {
 
index 84c177e..b3c1d33 100644 (file)
@@ -29,7 +29,7 @@ LEGACY_BUFFER_INFO_GETTER(BufferInfoImagination);
 
 int BufferInfoImagination::ConvertBoInfo(buffer_handle_t handle,
                                          hwc_drm_bo_t *bo) {
-  IMG_native_handle_t *hnd = (IMG_native_handle_t *)handle;
+  auto *hnd = (IMG_native_handle_t *)handle;
   if (!hnd)
     return -EINVAL;
 
index c794810..1634f8a 100644 (file)
@@ -30,11 +30,11 @@ namespace android {
 LEGACY_BUFFER_INFO_GETTER(BufferInfoLibdrm);
 
 enum chroma_order {
-  YCbCr,
-  YCrCb,
+  kYCbCr,
+  kYCrCb,
 };
 
-struct droid_yuv_format {
+struct DroidYuvFormat {
   /* Lookup keys */
   int native;                     /* HAL_PIXEL_FORMAT_ */
   enum chroma_order chroma_order; /* chroma order is {Cb, Cr} or {Cr, Cb} */
@@ -46,37 +46,37 @@ struct droid_yuv_format {
 
 /* The following table is used to look up a DRI image FourCC based
  * on native format and information contained in android_ycbcr struct. */
-static const struct droid_yuv_format droid_yuv_formats[] = {
+static const struct DroidYuvFormat kDroidYuvFormats[] = {
     /* Native format, YCrCb, Chroma step, DRI image FourCC */
-    {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 2, DRM_FORMAT_NV12},
-    {HAL_PIXEL_FORMAT_YCbCr_420_888, YCbCr, 1, DRM_FORMAT_YUV420},
-    {HAL_PIXEL_FORMAT_YCbCr_420_888, YCrCb, 1, DRM_FORMAT_YVU420},
-    {HAL_PIXEL_FORMAT_YV12, YCrCb, 1, DRM_FORMAT_YVU420},
+    {HAL_PIXEL_FORMAT_YCbCr_420_888, kYCbCr, 2, DRM_FORMAT_NV12},
+    {HAL_PIXEL_FORMAT_YCbCr_420_888, kYCbCr, 1, DRM_FORMAT_YUV420},
+    {HAL_PIXEL_FORMAT_YCbCr_420_888, kYCrCb, 1, DRM_FORMAT_YVU420},
+    {HAL_PIXEL_FORMAT_YV12, kYCrCb, 1, DRM_FORMAT_YVU420},
     /* HACK: See droid_create_image_from_prime_fds() and
      * https://issuetracker.google.com/32077885. */
-    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 2, DRM_FORMAT_NV12},
-    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCbCr, 1, DRM_FORMAT_YUV420},
-    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_YVU420},
-    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_AYUV},
-    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, YCrCb, 1, DRM_FORMAT_XYUV8888},
+    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, kYCbCr, 2, DRM_FORMAT_NV12},
+    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, kYCbCr, 1, DRM_FORMAT_YUV420},
+    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, kYCrCb, 1, DRM_FORMAT_YVU420},
+    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, kYCrCb, 1, DRM_FORMAT_AYUV},
+    {HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED, kYCrCb, 1, DRM_FORMAT_XYUV8888},
 };
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 static int get_fourcc_yuv(int native, enum chroma_order chroma_order,
                           int chroma_step) {
-  for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i)
-    if (droid_yuv_formats[i].native == native &&
-        droid_yuv_formats[i].chroma_order == chroma_order &&
-        droid_yuv_formats[i].chroma_step == chroma_step)
-      return droid_yuv_formats[i].fourcc;
+  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;
 }
 
 static bool is_yuv(int native) {
-  for (int i = 0; i < ARRAY_SIZE(droid_yuv_formats); ++i)
-    if (droid_yuv_formats[i].native == native)
+  for (auto droid_yuv_format : kDroidYuvFormats)
+    if (droid_yuv_format.native == native)
       return true;
 
   return false;
@@ -109,11 +109,11 @@ bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle,
   bo->offsets[0] = (size_t)ycbcr.y;
   /* We assume here that all the planes are located in one DMA-buf. */
   if ((size_t)ycbcr.cr < (size_t)ycbcr.cb) {
-    chroma_order = YCrCb;
+    chroma_order = kYCrCb;
     bo->offsets[1] = (size_t)ycbcr.cr;
     bo->offsets[2] = (size_t)ycbcr.cb;
   } else {
-    chroma_order = YCbCr;
+    chroma_order = kYCbCr;
     bo->offsets[1] = (size_t)ycbcr.cb;
     bo->offsets[2] = (size_t)ycbcr.cr;
   }
@@ -132,7 +132,7 @@ bool BufferInfoLibdrm::GetYuvPlaneInfo(int num_fds, buffer_handle_t handle,
     ALOGW(
         "unsupported YUV format, native = %x, chroma_order = %s, chroma_step = "
         "%d",
-        bo->hal_format, chroma_order == YCbCr ? "YCbCr" : "YCrCb",
+        bo->hal_format, chroma_order == kYCbCr ? "YCbCr" : "YCrCb",
         (int)ycbcr.chroma_step);
     return false;
   }
index 877a83f..559cb5c 100644 (file)
@@ -70,8 +70,7 @@ int BufferInfoMaliHisi::ConvertBoInfo(buffer_handle_t handle,
                                       hwc_drm_bo_t *bo) {
   bool is_rgb;
 
-  private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
-      handle);
+  auto const *hnd = reinterpret_cast<private_handle_t const *>(handle);
   if (!hnd)
     return -EINVAL;
 
index ce47343..13c7a34 100644 (file)
@@ -34,8 +34,7 @@ LEGACY_BUFFER_INFO_GETTER(BufferInfoMaliMediatek);
 
 int BufferInfoMaliMediatek::ConvertBoInfo(buffer_handle_t handle,
                                           hwc_drm_bo_t *bo) {
-  private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
-      handle);
+  auto const *hnd = reinterpret_cast<private_handle_t const *>(handle);
   if (!hnd)
     return -EINVAL;
 
index cf7a873..1dfe4d2 100644 (file)
@@ -63,8 +63,7 @@ uint64_t BufferInfoMaliMeson::ConvertGrallocFormatToDrmModifiers(
 
 int BufferInfoMaliMeson::ConvertBoInfo(buffer_handle_t handle,
                                        hwc_drm_bo_t *bo) {
-  private_handle_t const *hnd = reinterpret_cast<private_handle_t const *>(
-      handle);
+  auto const *hnd = reinterpret_cast<private_handle_t const *>(handle);
   if (!hnd)
     return -EINVAL;
 
index d5ffa1f..f5e661f 100644 (file)
@@ -31,7 +31,7 @@ namespace android {
 LEGACY_BUFFER_INFO_GETTER(BufferInfoMinigbm);
 
 int BufferInfoMinigbm::ConvertBoInfo(buffer_handle_t handle, hwc_drm_bo_t *bo) {
-  cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
+  auto *gr_handle = (cros_gralloc_handle *)handle;
   if (!gr_handle)
     return -EINVAL;
 
index 4d2e19a..1e9e127 100644 (file)
 #include "DrmDisplayComposition.h"
 
 #include <log/log.h>
-#include <stdlib.h>
 #include <sync/sync.h>
 #include <xf86drmMode.h>
 
 #include <algorithm>
+#include <cstdlib>
 #include <unordered_set>
 
 #include "DrmDisplayCompositor.h"
@@ -32,9 +32,6 @@
 
 namespace android {
 
-DrmDisplayComposition::~DrmDisplayComposition() {
-}
-
 int DrmDisplayComposition::Init(DrmDevice *drm, DrmCrtc *crtc,
                                 Importer *importer, Planner *planner,
                                 uint64_t frame_no) {
@@ -211,7 +208,7 @@ static void DumpTransform(uint32_t transform, std::ostringstream *out) {
     separator = true;
   }
 
-  uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
+  uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipV |
                         DrmHwcTransform::kRotate90 |
                         DrmHwcTransform::kRotate180 |
                         DrmHwcTransform::kRotate270;
index 73a9024..5d99d23 100644 (file)
@@ -109,7 +109,7 @@ class DrmDisplayComposition {
  public:
   DrmDisplayComposition() = default;
   DrmDisplayComposition(const DrmDisplayComposition &) = delete;
-  ~DrmDisplayComposition();
+  ~DrmDisplayComposition() = default;
 
   int Init(DrmDevice *drm, DrmCrtc *crtc, Importer *importer, Planner *planner,
            uint64_t frame_no);
index 3ae42ef..b33c9c0 100644 (file)
 #include <log/log.h>
 #include <pthread.h>
 #include <sched.h>
-#include <stdlib.h>
 #include <sync/sync.h>
-#include <time.h>
 #include <utils/Trace.h>
 
 #include <array>
+#include <cstdlib>
+#include <ctime>
 #include <sstream>
 #include <vector>
 
@@ -52,11 +52,11 @@ std::ostream &operator<<(std::ostream &str, FlatteningState state) {
 
 class CompositorVsyncCallback : public VsyncCallback {
  public:
-  CompositorVsyncCallback(DrmDisplayCompositor *compositor)
+  explicit CompositorVsyncCallback(DrmDisplayCompositor *compositor)
       : compositor_(compositor) {
   }
 
-  void Callback(int display, int64_t timestamp) {
+  void Callback(int display, int64_t timestamp) override {
     compositor_->Vsync(display, timestamp);
   }
 
@@ -65,7 +65,7 @@ class CompositorVsyncCallback : public VsyncCallback {
 };
 
 DrmDisplayCompositor::DrmDisplayCompositor()
-    : resource_manager_(NULL),
+    : resource_manager_(nullptr),
       display_(-1),
       initialized_(false),
       active_(false),
@@ -113,7 +113,7 @@ int DrmDisplayCompositor::Init(ResourceManager *resource_manager, int display) {
     ALOGE("Could not find drmdevice for display");
     return -EINVAL;
   }
-  int ret = pthread_mutex_init(&lock_, NULL);
+  int ret = pthread_mutex_init(&lock_, nullptr);
   if (ret) {
     ALOGE("Failed to initialize drm compositor lock %d\n", ret);
     return ret;
@@ -130,7 +130,7 @@ int DrmDisplayCompositor::Init(ResourceManager *resource_manager, int display) {
 
 std::unique_ptr<DrmDisplayComposition> DrmDisplayCompositor::CreateComposition()
     const {
-  return std::unique_ptr<DrmDisplayComposition>(new DrmDisplayComposition());
+  return std::make_unique<DrmDisplayComposition>();
 }
 
 std::unique_ptr<DrmDisplayComposition>
@@ -172,7 +172,7 @@ std::tuple<uint32_t, uint32_t, int>
 DrmDisplayCompositor::GetActiveModeResolution() {
   DrmDevice *drm = resource_manager_->GetDrmDevice(display_);
   DrmConnector *connector = drm->GetConnectorForDisplay(display_);
-  if (connector == NULL) {
+  if (connector == nullptr) {
     ALOGE("Failed to determine display mode: no connector for display %d",
           display_);
     return std::make_tuple(0, 0, -ENODEV);
@@ -286,8 +286,8 @@ int DrmDisplayCompositor::CommitFrame(DrmDisplayComposition *display_comp,
     return -ENOMEM;
   }
 
-  if (writeback_buffer != NULL) {
-    if (writeback_conn == NULL) {
+  if (writeback_buffer != nullptr) {
+    if (writeback_conn == nullptr) {
       ALOGE("Invalid arguments requested writeback without writeback conn");
       return -EINVAL;
     }
@@ -661,7 +661,7 @@ void DrmDisplayCompositor::ClearDisplay() {
   if (DisablePlanes(active_composition_.get()))
     return;
 
-  active_composition_.reset(NULL);
+  active_composition_.reset(nullptr);
   vsync_worker_.VSyncControl(false);
 }
 
@@ -785,8 +785,8 @@ int DrmDisplayCompositor::FlattenOnDisplay(
     ALOGE("Failed to find crtc for display %d", display_);
     return -EINVAL;
   }
-  // TODO what happens if planes could go to both CRTCs, I don't think it's
-  // handled anywhere
+  // TODO(nobody) what happens if planes could go to both CRTCs, I don't think
+  // it's handled anywhere
   std::vector<DrmPlane *> primary_planes;
   std::vector<DrmPlane *> overlay_planes;
   for (auto &plane : drm->planes()) {
@@ -896,10 +896,10 @@ int DrmDisplayCompositor::FlattenOnClient() {
     SetFlattening(FlatteningState::kClientRequested);
     refresh_callback_hook_(refresh_callback_data_, display_);
     return 0;
-  } else {
-    ALOGV("No writeback connector available");
-    return -EINVAL;
   }
+
+  ALOGV("No writeback connector available");
+  return -EINVAL;
 }
 
 // Flatten a scene by enabling the writeback connector attached
@@ -976,7 +976,7 @@ int DrmDisplayCompositor::FlattenSerial(DrmConnector *writeback_conn) {
     return ret;
   }
 
-  DrmCompositionPlane squashed_comp(DrmCompositionPlane::Type::kLayer, NULL,
+  DrmCompositionPlane squashed_comp(DrmCompositionPlane::Type::kLayer, nullptr,
                                     crtc);
   for (auto &drmplane : drm->planes()) {
     if (!drmplane->GetCrtcSupported(*crtc))
@@ -1061,7 +1061,7 @@ int DrmDisplayCompositor::FlattenConcurrent(DrmConnector *writeback_conn) {
     return ret;
   }
 
-  DrmCompositionPlane squashed_comp(DrmCompositionPlane::Type::kLayer, NULL,
+  DrmCompositionPlane squashed_comp(DrmCompositionPlane::Type::kLayer, nullptr,
                                     crtc);
   for (auto &drmplane : resource_manager_->GetDrmDevice(display_)->planes()) {
     if (!drmplane->GetCrtcSupported(*crtc))
@@ -1106,12 +1106,10 @@ int DrmDisplayCompositor::FlattenActiveComposition() {
   if (writeback_conn->display() != display_) {
     SetFlattening(FlatteningState::kConcurrent);
     return FlattenConcurrent(writeback_conn);
-  } else {
-    SetFlattening(FlatteningState::kSerial);
-    return FlattenSerial(writeback_conn);
   }
 
-  return 0;
+  SetFlattening(FlatteningState::kSerial);
+  return FlattenSerial(writeback_conn);
 }
 
 bool DrmDisplayCompositor::CountdownExpired() const {
@@ -1149,7 +1147,7 @@ void DrmDisplayCompositor::Dump(std::ostringstream *out) const {
 
   uint64_t cur_ts = ts.tv_sec * 1000 * 1000 * 1000 + ts.tv_nsec;
   uint64_t num_ms = (cur_ts - dump_last_timestamp_ns_) / (1000 * 1000);
-  float fps = num_ms ? (num_frames * 1000.0f) / (num_ms) : 0.0f;
+  float fps = num_ms ? (num_frames * 1000.0F) / (num_ms) : 0.0F;
 
   *out << "--DrmDisplayCompositor[" << display_
        << "]: num_frames=" << num_frames << " num_ms=" << num_ms
index f4b5c51..fb6a8c3 100644 (file)
@@ -24,7 +24,7 @@
 
 namespace android {
 
-std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice *) {
+std::unique_ptr<Planner> Planner::CreateInstance(DrmDevice * /*device*/) {
   std::unique_ptr<Planner> planner(new Planner);
   planner->AddStage<PlanStageGreedy>();
   return planner;
@@ -123,7 +123,6 @@ int PlanStageProtected::ProvisionPlanes(
     std::map<size_t, DrmHwcLayer *> &layers, DrmCrtc *crtc,
     std::vector<DrmPlane *> *planes) {
   int ret;
-  int protected_zorder = -1;
   for (auto i = layers.begin(); i != layers.end();) {
     if (!i->second->protected_usage()) {
       ++i;
@@ -137,7 +136,6 @@ int PlanStageProtected::ProvisionPlanes(
       return ret;
     }
 
-    protected_zorder = i->first;
     i = layers.erase(i);
   }
 
@@ -155,7 +153,8 @@ int PlanStageGreedy::ProvisionPlanes(
     // We don't have any planes left
     if (ret == -ENOENT)
       break;
-    else if (ret) {
+
+    if (ret) {
       ALOGE("Failed to emplace layer %zu, dropping it", i->first);
       return ret;
     }
index 11c2bd2..cfafc1d 100644 (file)
 
 #include "DrmConnector.h"
 
-#include <errno.h>
-#include <stdint.h>
 #include <xf86drmMode.h>
 
 #include <array>
+#include <cerrno>
+#include <cstdint>
 #include <sstream>
 
 #include "DrmDevice.h"
@@ -30,7 +30,7 @@
 
 namespace android {
 
-constexpr size_t TYPES_COUNT = 17;
+constexpr size_t kTypesCount = 17;
 
 DrmConnector::DrmConnector(DrmDevice *drm, drmModeConnectorPtr c,
                            DrmEncoder *current_encoder,
@@ -144,19 +144,19 @@ bool DrmConnector::valid_type() const {
 }
 
 std::string DrmConnector::name() const {
-  constexpr std::array<const char *, TYPES_COUNT> names =
+  constexpr std::array<const char *, kTypesCount> kNames =
       {"None",   "VGA",  "DVI-I",     "DVI-D",   "DVI-A", "Composite",
        "SVIDEO", "LVDS", "Component", "DIN",     "DP",    "HDMI-A",
        "HDMI-B", "TV",   "eDP",       "Virtual", "DSI"};
 
-  if (type_ < TYPES_COUNT) {
+  if (type_ < kTypesCount) {
     std::ostringstream name_buf;
-    name_buf << names[type_] << "-" << type_id_;
+    name_buf << kNames[type_] << "-" << type_id_;
     return name_buf.str();
-  } else {
-    ALOGE("Unknown type in connector %d, could not make his name", id_);
-    return "None";
   }
+
+  ALOGE("Unknown type in connector %d, could not make his name", id_);
+  return "None";
 }
 
 int DrmConnector::UpdateModes() {
@@ -194,7 +194,7 @@ int DrmConnector::UpdateModes() {
     }
   }
   modes_.swap(new_modes);
-  if (!preferred_mode_found && modes_.size() != 0) {
+  if (!preferred_mode_found && !modes_.empty()) {
     preferred_mode_id_ = modes_[0].id();
   }
   return 0;
index 3c05ba8..4da08fe 100644 (file)
 
 #include "DrmCrtc.h"
 
-#include <stdint.h>
 #include <utils/log.h>
 #include <xf86drmMode.h>
 
+#include <cstdint>
+
 #include "DrmDevice.h"
 
 namespace android {
index 818261d..52d81d5 100644 (file)
 
 #include "DrmDevice.h"
 
-#include <errno.h>
 #include <fcntl.h>
-#include <stdint.h>
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 
 #include <algorithm>
 #include <array>
+#include <cerrno>
 #include <cinttypes>
+#include <cstdint>
 #include <sstream>
 #include <string>
 
 #include "utils/log.h"
 #include "utils/properties.h"
 
-static void trim_left(std::string &str) {
-  str.erase(std::begin(str),
-            std::find_if(std::begin(str), std::end(str),
-                         [](int ch) { return !std::isspace(ch); }));
+static void trim_left(std::string *str) {
+  str->erase(std::begin(*str),
+             std::find_if(std::begin(*str), std::end(*str),
+                          [](int ch) { return std::isspace(ch) == 0; }));
 }
 
-static void trim_right(std::string &str) {
-  str.erase(std::find_if(std::rbegin(str), std::rend(str),
-                         [](int ch) { return !std::isspace(ch); })
-                .base(),
-            std::end(str));
+static void trim_right(std::string *str) {
+  str->erase(std::find_if(std::rbegin(*str), std::rend(*str),
+                          [](int ch) { return std::isspace(ch) == 0; })
+                 .base(),
+             std::end(*str));
 }
 
-static void trim(std::string &str) {
+static void trim(std::string *str) {
   trim_left(str);
   trim_right(str);
 }
@@ -60,19 +60,19 @@ static std::vector<std::string> read_primary_display_order_prop() {
 
   std::vector<std::string> display_order;
   std::istringstream str(display_order_buf.data());
-  for (std::string conn_name = ""; std::getline(str, conn_name, ',');) {
-    trim(conn_name);
+  for (std::string conn_name; std::getline(str, conn_name, ',');) {
+    trim(&conn_name);
     display_order.push_back(std::move(conn_name));
   }
   return display_order;
 }
 
 static std::vector<DrmConnector *> make_primary_display_candidates(
-    std::vector<std::unique_ptr<DrmConnector>> &connectors) {
+    const std::vector<std::unique_ptr<DrmConnector>> &connectors) {
   std::vector<DrmConnector *> primary_candidates;
   std::transform(std::begin(connectors), std::end(connectors),
                  std::back_inserter(primary_candidates),
-                 [](std::unique_ptr<DrmConnector> &conn) {
+                 [](const std::unique_ptr<DrmConnector> &conn) {
                    return conn.get();
                  });
   primary_candidates.erase(std::remove_if(std::begin(primary_candidates),
@@ -120,7 +120,7 @@ DrmDevice::~DrmDevice() {
 
 std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) {
   /* TODO: Use drmOpenControl here instead */
-  fd_.Set(open(path, O_RDWR));
+  fd_.Set(open(path, O_RDWR | O_CLOEXEC));
   if (fd() < 0) {
     ALOGE("Failed to open dri %s: %s", path, strerror(errno));
     return std::make_tuple(-ENODEV, 0);
@@ -196,7 +196,7 @@ std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) {
     }
 
     std::vector<DrmCrtc *> possible_crtcs;
-    DrmCrtc *current_crtc = NULL;
+    DrmCrtc *current_crtc = nullptr;
     for (auto &crtc : crtcs_) {
       if ((1 << crtc->pipe()) & e->possible_crtcs)
         possible_crtcs.push_back(crtc.get());
@@ -228,7 +228,7 @@ std::tuple<int, int> DrmDevice::Init(const char *path, int num_displays) {
     }
 
     std::vector<DrmEncoder *> possible_encoders;
-    DrmEncoder *current_encoder = NULL;
+    DrmEncoder *current_encoder = nullptr;
     for (int j = 0; j < c->count_encoders; ++j) {
       for (auto &encoder : encoders_) {
         if (encoder->id() == c->encoders[j])
@@ -351,22 +351,22 @@ bool DrmDevice::HandlesDisplay(int display) const {
 }
 
 DrmConnector *DrmDevice::GetConnectorForDisplay(int display) const {
-  for (auto &conn : connectors_) {
+  for (const auto &conn : connectors_) {
     if (conn->display() == display)
       return conn.get();
   }
-  return NULL;
+  return nullptr;
 }
 
 DrmConnector *DrmDevice::GetWritebackConnectorForDisplay(int display) const {
-  for (auto &conn : writeback_connectors_) {
+  for (const auto &conn : writeback_connectors_) {
     if (conn->display() == display)
       return conn.get();
   }
-  return NULL;
+  return nullptr;
 }
 
-// TODO what happens when hotplugging
+// TODO(nobody): what happens when hotplugging
 DrmConnector *DrmDevice::AvailableWritebackConnector(int display) const {
   DrmConnector *writeback_conn = GetWritebackConnectorForDisplay(display);
   DrmConnector *display_conn = GetConnectorForDisplay(display);
@@ -377,7 +377,7 @@ DrmConnector *DrmDevice::AvailableWritebackConnector(int display) const {
     return writeback_conn;
 
   // Use another CRTC if available and doesn't have any connector
-  for (auto &crtc : crtcs_) {
+  for (const auto &crtc : crtcs_) {
     if (crtc->display() == display)
       continue;
     display_conn = GetConnectorForDisplay(crtc->display());
@@ -388,23 +388,23 @@ DrmConnector *DrmDevice::AvailableWritebackConnector(int display) const {
     if (writeback_conn)
       return writeback_conn;
   }
-  return NULL;
+  return nullptr;
 }
 
 DrmCrtc *DrmDevice::GetCrtcForDisplay(int display) const {
-  for (auto &crtc : crtcs_) {
+  for (const auto &crtc : crtcs_) {
     if (crtc->display() == display)
       return crtc.get();
   }
-  return NULL;
+  return nullptr;
 }
 
 DrmPlane *DrmDevice::GetPlane(uint32_t id) const {
-  for (auto &plane : planes_) {
+  for (const auto &plane : planes_) {
     if (plane->id() == id)
       return plane.get();
   }
-  return NULL;
+  return nullptr;
 }
 
 const std::vector<std::unique_ptr<DrmCrtc>> &DrmDevice::crtcs() const {
@@ -448,7 +448,9 @@ int DrmDevice::CreateDisplayPipe(DrmConnector *connector) {
     int ret = TryEncoderForDisplay(display, connector->encoder());
     if (!ret) {
       return 0;
-    } else if (ret != -EAGAIN) {
+    }
+
+    if (ret != -EAGAIN) {
       ALOGE("Could not set mode %d/%d", display, ret);
       return ret;
     }
@@ -459,7 +461,9 @@ int DrmDevice::CreateDisplayPipe(DrmConnector *connector) {
     if (!ret) {
       connector->set_encoder(enc);
       return 0;
-    } else if (ret != -EAGAIN) {
+    }
+
+    if (ret != -EAGAIN) {
       ALOGE("Could not set mode %d/%d", display, ret);
       return ret;
     }
@@ -472,7 +476,7 @@ int DrmDevice::CreateDisplayPipe(DrmConnector *connector) {
 // Attach writeback connector to the CRTC linked to the display_conn
 int DrmDevice::AttachWriteback(DrmConnector *display_conn) {
   DrmCrtc *display_crtc = display_conn->encoder()->crtc();
-  if (GetWritebackConnectorForDisplay(display_crtc->display()) != NULL) {
+  if (GetWritebackConnectorForDisplay(display_crtc->display()) != nullptr) {
     ALOGE("Display already has writeback attach to it");
     return -EINVAL;
   }
@@ -498,7 +502,7 @@ int DrmDevice::AttachWriteback(DrmConnector *display_conn) {
 }
 
 int DrmDevice::CreatePropertyBlob(void *data, size_t length,
-                                  uint32_t *blob_id) {
+                                  uint32_t *blob_id) const {
   struct drm_mode_create_blob create_blob;
   memset(&create_blob, 0, sizeof(create_blob));
   create_blob.length = length;
@@ -513,7 +517,7 @@ int DrmDevice::CreatePropertyBlob(void *data, size_t length,
   return 0;
 }
 
-int DrmDevice::DestroyPropertyBlob(uint32_t blob_id) {
+int DrmDevice::DestroyPropertyBlob(uint32_t blob_id) const {
   if (!blob_id)
     return 0;
 
@@ -533,7 +537,7 @@ DrmEventListener *DrmDevice::event_listener() {
 }
 
 int DrmDevice::GetProperty(uint32_t obj_id, uint32_t obj_type,
-                           const char *prop_name, DrmProperty *property) {
+                           const char *prop_name, DrmProperty *property) const {
   drmModeObjectPropertiesPtr props;
 
   props = drmModeObjectGetProperties(fd(), obj_id, obj_type);
@@ -573,8 +577,8 @@ int DrmDevice::GetConnectorProperty(const DrmConnector &connector,
                      property);
 }
 
-const std::string DrmDevice::GetName() const {
-  auto ver = drmGetVersion(fd_.get());
+std::string DrmDevice::GetName() const {
+  auto *ver = drmGetVersion(fd_.get());
   if (!ver) {
     ALOGW("Failed to get drm version for fd=%d", fd_.get());
     return "generic";
index be68aa6..d8f347f 100644 (file)
@@ -71,13 +71,13 @@ class DrmDevice {
   int GetConnectorProperty(const DrmConnector &connector, const char *prop_name,
                            DrmProperty *property);
 
-  const std::string GetName() const;
+  std::string GetName() const;
 
   const std::vector<std::unique_ptr<DrmCrtc>> &crtcs() const;
   uint32_t next_mode_id();
 
-  int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id);
-  int DestroyPropertyBlob(uint32_t blob_id);
+  int CreatePropertyBlob(void *data, size_t length, uint32_t *blob_id) const;
+  int DestroyPropertyBlob(uint32_t blob_id) const;
   bool HandlesDisplay(int display) const;
   void RegisterHotplugHandler(DrmEventHandler *handler) {
     event_listener_.RegisterHotplugHandler(handler);
@@ -86,7 +86,7 @@ class DrmDevice {
  private:
   int TryEncoderForDisplay(int display, DrmEncoder *enc);
   int GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name,
-                  DrmProperty *property);
+                  DrmProperty *property) const;
 
   int CreateDisplayPipe(DrmConnector *connector);
   int AttachWriteback(DrmConnector *display_conn);
index bcf0926..ad05f88 100644 (file)
 
 #include "DrmEncoder.h"
 
-#include <stdint.h>
 #include <xf86drmMode.h>
 
+#include <cstdint>
+
 #include "DrmDevice.h"
 
 namespace android {
 
 DrmEncoder::DrmEncoder(drmModeEncoderPtr e, DrmCrtc *current_crtc,
-                       const std::vector<DrmCrtc *> &possible_crtcs)
+                       std::vector<DrmCrtc *> possible_crtcs)
     : id_(e->encoder_id),
       crtc_(current_crtc),
       display_(-1),
-      possible_crtcs_(possible_crtcs) {
+      possible_crtcs_(std::move(possible_crtcs)) {
 }
 
 uint32_t DrmEncoder::id() const {
@@ -39,8 +40,8 @@ DrmCrtc *DrmEncoder::crtc() const {
   return crtc_;
 }
 
-bool DrmEncoder::CanClone(DrmEncoder *possible_clone) {
-  return possible_clones_.find(possible_clone) != possible_clones_.end();
+bool DrmEncoder::CanClone(DrmEncoder *encoder) {
+  return possible_clones_.find(encoder) != possible_clones_.end();
 }
 
 void DrmEncoder::AddPossibleClone(DrmEncoder *possible_clone) {
index f4464d0..4c01bc1 100644 (file)
@@ -30,7 +30,7 @@ namespace android {
 class DrmEncoder {
  public:
   DrmEncoder(drmModeEncoderPtr e, DrmCrtc *current_crtc,
-             const std::vector<DrmCrtc *> &possible_crtcs);
+             std::vector<DrmCrtc *> possible_crtcs);
   DrmEncoder(const DrmEncoder &) = delete;
   DrmEncoder &operator=(const DrmEncoder &) = delete;
 
index 6cfa37d..13a1273 100644 (file)
 
 #include "DrmEventListener.h"
 
-#include <assert.h>
-#include <errno.h>
 #include <linux/netlink.h>
 #include <sys/socket.h>
 #include <xf86drm.h>
 
+#include <cassert>
+#include <cerrno>
 #include <cstring>
 
 #include "DrmDevice.h"
@@ -39,7 +39,8 @@ DrmEventListener::DrmEventListener(DrmDevice *drm)
 }
 
 int DrmEventListener::Init() {
-  uevent_fd_.Set(socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT));
+  uevent_fd_.Set(
+      socket(PF_NETLINK, SOCK_DGRAM | SOCK_CLOEXEC, NETLINK_KOBJECT_UEVENT));
   if (uevent_fd_.get() < 0) {
     ALOGE("Failed to open uevent socket: %s", strerror(errno));
     return uevent_fd_.get();
@@ -57,6 +58,7 @@ int DrmEventListener::Init() {
     return -errno;
   }
 
+  // NOLINTNEXTLINE(readability-isolate-declaration)
   FD_ZERO(&fds_);
   FD_SET(drm_->fd(), &fds_);
   FD_SET(uevent_fd_.get(), &fds_);
@@ -73,7 +75,7 @@ void DrmEventListener::RegisterHotplugHandler(DrmEventHandler *handler) {
 void DrmEventListener::FlipHandler(int /* fd */, unsigned int /* sequence */,
                                    unsigned int tv_sec, unsigned int tv_usec,
                                    void *user_data) {
-  DrmEventHandler *handler = (DrmEventHandler *)user_data;
+  auto *handler = (DrmEventHandler *)user_data;
   if (!handler)
     return;
 
@@ -86,6 +88,7 @@ void DrmEventListener::UEventHandler() {
   int ret;
 
   struct timespec ts;
+
   uint64_t timestamp = 0;
   ret = clock_gettime(CLOCK_MONOTONIC, &ts);
   if (!ret)
@@ -95,9 +98,10 @@ void DrmEventListener::UEventHandler() {
 
   while (true) {
     ret = read(uevent_fd_.get(), &buffer, sizeof(buffer));
-    if (ret == 0) {
+    if (ret == 0)
       return;
-    } else if (ret < 0) {
+
+    if (ret < 0) {
       ALOGE("Got error reading uevent %d", ret);
       return;
     }
@@ -105,12 +109,13 @@ void DrmEventListener::UEventHandler() {
     if (!hotplug_handler_)
       continue;
 
-    bool drm_event = false, hotplug_event = false;
-    for (int i = 0; i < ret;) {
+    bool drm_event = false;
+    bool hotplug_event = false;
+    for (uint32_t i = 0; i < ret;) {
       char *event = buffer + i;
-      if (strcmp(event, "DEVTYPE=drm_minor"))
+      if (strcmp(event, "DEVTYPE=drm_minor") != 0)
         drm_event = true;
-      else if (strcmp(event, "HOTPLUG=1"))
+      else if (strcmp(event, "HOTPLUG=1") != 0)
         hotplug_event = true;
 
       i += strlen(event) + 1;
@@ -124,13 +129,13 @@ void DrmEventListener::UEventHandler() {
 void DrmEventListener::Routine() {
   int ret;
   do {
-    ret = select(max_fd_ + 1, &fds_, NULL, NULL, NULL);
+    ret = select(max_fd_ + 1, &fds_, nullptr, nullptr, nullptr);
   } while (ret == -1 && errno == EINTR);
 
   if (FD_ISSET(drm_->fd(), &fds_)) {
     drmEventContext event_context =
         {.version = 2,
-         .vblank_handler = NULL,
+         .vblank_handler = nullptr,
          .page_flip_handler = DrmEventListener::FlipHandler};
     drmHandleEvent(drm_->fd(), &event_context);
   }
index 171d889..6627cc8 100644 (file)
 #include <cutils/properties.h>
 #include <gralloc_handle.h>
 #include <hardware/gralloc.h>
-#include <inttypes.h>
 #include <log/log.h>
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 
+#include <cinttypes>
+
 namespace android {
 
 DrmGenericImporter::DrmGenericImporter(DrmDevice *drm) : drm_(drm) {
@@ -34,10 +35,7 @@ DrmGenericImporter::DrmGenericImporter(DrmDevice *drm) : drm_(drm) {
     ALOGE("drmGetCap failed. Fallback to no modifier support.");
     cap_value = 0;
   }
-  has_modifier_support_ = cap_value;
-}
-
-DrmGenericImporter::~DrmGenericImporter() {
+  has_modifier_support_ = cap_value != 0;
 }
 
 int DrmGenericImporter::ImportBuffer(hwc_drm_bo_t *bo) {
@@ -82,11 +80,11 @@ int DrmGenericImporter::ImportBuffer(hwc_drm_bo_t *bo) {
     return ret;
   }
 
-  for (int i = 0; i < HWC_DRM_BO_MAX_PLANES; i++) {
-    if (!bo->gem_handles[i])
+  for (unsigned int gem_handle : bo->gem_handles) {
+    if (!gem_handle)
       continue;
 
-    ImportHandle(bo->gem_handles[i]);
+    ImportHandle(gem_handle);
   }
 
   return ret;
@@ -97,14 +95,14 @@ int DrmGenericImporter::ReleaseBuffer(hwc_drm_bo_t *bo) {
     if (drmModeRmFB(drm_->fd(), bo->fb_id))
       ALOGE("Failed to rm fb");
 
-  for (int i = 0; i < HWC_DRM_BO_MAX_PLANES; i++) {
-    if (!bo->gem_handles[i])
+  for (unsigned int &gem_handle : bo->gem_handles) {
+    if (!gem_handle)
       continue;
 
-    if (ReleaseHandle(bo->gem_handles[i]))
-      ALOGE("Failed to release gem handle %d", bo->gem_handles[i]);
+    if (ReleaseHandle(gem_handle))
+      ALOGE("Failed to release gem handle %d", gem_handle);
     else
-      bo->gem_handles[i] = 0;
+      gem_handle = 0;
   }
   return 0;
 }
index ca53762..27cfc3b 100644 (file)
@@ -33,8 +33,7 @@ namespace android {
 
 class Importer {
  public:
-  virtual ~Importer() {
-  }
+  virtual ~Importer() = default;
 
   // Imports the buffer referred to by handle into bo.
   //
@@ -52,7 +51,7 @@ class Importer {
 class DrmGenericImporter : public Importer {
  public:
   DrmGenericImporter(DrmDevice *drm);
-  ~DrmGenericImporter() override;
+  ~DrmGenericImporter() override = default;
 
   int ImportBuffer(hwc_drm_bo_t *bo) override;
   int ReleaseBuffer(hwc_drm_bo_t *bo) override;
index 6a879e8..dd25758 100644 (file)
@@ -23,8 +23,7 @@
 namespace android {
 
 DrmMode::DrmMode(drmModeModeInfoPtr m)
-    : id_(0),
-      clock_(m->clock),
+    : clock_(m->clock),
       h_display_(m->hdisplay),
       h_sync_start_(m->hsync_start),
       h_sync_end_(m->hsync_end),
@@ -122,7 +121,7 @@ uint32_t DrmMode::v_scan() const {
 
 float DrmMode::v_refresh() const {
   // Always recalculate refresh to report correct float rate
-  return clock_ / (float)(v_total_ * h_total_) * 1000.0f;
+  return clock_ / (float)(v_total_ * h_total_) * 1000.0F;
 }
 
 uint32_t DrmMode::flags() const {
index 1cc6ee0..a7ad3c0 100644 (file)
@@ -21,7 +21,9 @@
 #include <errno.h>
 #include <stdint.h>
 
+#include <cerrno>
 #include <cinttypes>
+#include <cstdint>
 
 #include "DrmDevice.h"
 #include "bufferinfo/BufferInfoGetter.h"
@@ -161,7 +163,7 @@ uint32_t DrmPlane::id() const {
 }
 
 bool DrmPlane::GetCrtcSupported(const DrmCrtc &crtc) const {
-  return !!((1 << crtc.pipe()) & possible_crtc_mask_);
+  return ((1 << crtc.pipe()) & possible_crtc_mask_) != 0;
 }
 
 uint32_t DrmPlane::type() const {
index b8ce680..4c5f44f 100644 (file)
 
 #include "DrmProperty.h"
 
-#include <errno.h>
 #include <xf86drmMode.h>
 
+#include <cerrno>
 #include <cstdint>
-#include <cstring>
 #include <string>
 
 #include "DrmDevice.h"
@@ -31,11 +30,7 @@ DrmProperty::DrmPropertyEnum::DrmPropertyEnum(drm_mode_property_enum *e)
     : value_(e->value), name_(e->name) {
 }
 
-DrmProperty::DrmPropertyEnum::~DrmPropertyEnum() {
-}
-
-DrmProperty::DrmProperty(drmModePropertyPtr p, uint64_t value)
-    : id_(0), type_(DRM_PROPERTY_TYPE_INVALID), flags_(0), name_("") {
+DrmProperty::DrmProperty(drmModePropertyPtr p, uint64_t value) {
   Init(p, value);
 }
 
@@ -46,13 +41,13 @@ void DrmProperty::Init(drmModePropertyPtr p, uint64_t value) {
   value_ = value;
 
   for (int i = 0; i < p->count_values; ++i)
-    values_.push_back(p->values[i]);
+    values_.emplace_back(p->values[i]);
 
   for (int i = 0; i < p->count_enums; ++i)
-    enums_.push_back(DrmPropertyEnum(&p->enums[i]));
+    enums_.emplace_back(DrmPropertyEnum(&p->enums[i]));
 
   for (int i = 0; i < p->count_blobs; ++i)
-    blob_ids_.push_back(p->blob_ids[i]);
+    blob_ids_.emplace_back(p->blob_ids[i]);
 
   if (flags_ & DRM_MODE_PROP_RANGE)
     type_ = DRM_PROPERTY_TYPE_INT;
@@ -76,7 +71,7 @@ std::tuple<int, uint64_t> DrmProperty::value() const {
   if (type_ == DRM_PROPERTY_TYPE_BLOB)
     return std::make_tuple(0, value_);
 
-  if (values_.size() == 0)
+  if (values_.empty())
     return std::make_tuple(-ENOENT, 0);
 
   switch (type_) {
@@ -108,7 +103,7 @@ bool DrmProperty::is_range() const {
 std::tuple<int, uint64_t> DrmProperty::range_min() const {
   if (!is_range())
     return std::make_tuple(-EINVAL, 0);
-  if (values_.size() < 1)
+  if (values_.empty())
     return std::make_tuple(-ENOENT, 0);
 
   return std::make_tuple(0, values_[0]);
@@ -124,9 +119,9 @@ std::tuple<int, uint64_t> DrmProperty::range_max() const {
 }
 
 std::tuple<uint64_t, int> DrmProperty::GetEnumValueWithName(
-    std::string name) const {
-  for (auto it : enums_) {
-    if (it.name_.compare(name) == 0) {
+    const std::string &name) const {
+  for (const auto &it : enums_) {
+    if (it.name_ == name) {
       return std::make_tuple(it.value_, 0);
     }
   }
index d293da3..3f4d15e 100644 (file)
@@ -41,7 +41,7 @@ class DrmProperty {
   DrmProperty &operator=(const DrmProperty &) = delete;
 
   void Init(drmModePropertyPtr p, uint64_t value);
-  std::tuple<uint64_t, int> GetEnumValueWithName(std::string name) const;
+  std::tuple<uint64_t, int> GetEnumValueWithName(const std::string &name) const;
 
   uint32_t id() const;
   std::string name() const;
@@ -57,7 +57,7 @@ class DrmProperty {
   class DrmPropertyEnum {
    public:
     DrmPropertyEnum(drm_mode_property_enum *e);
-    ~DrmPropertyEnum();
+    ~DrmPropertyEnum() = default;
 
     uint64_t value_;
     std::string name_;
index efd5de1..3e16fbb 100644 (file)
@@ -28,7 +28,7 @@
 
 namespace android {
 
-ResourceManager::ResourceManager() : num_displays_(0), gralloc_(NULL) {
+ResourceManager::ResourceManager() : num_displays_(0), gralloc_(nullptr) {
 }
 
 int ResourceManager::Init() {
@@ -47,11 +47,11 @@ int ResourceManager::Init() {
       path << path_pattern << idx;
 
       struct stat buf;
-      if (stat(path.str().c_str(), &buf)) {
+      if (stat(path.str().c_str(), &buf))
         break;
-      } else if (IsKMSDev(path.str().c_str())) {
+
+      if (IsKMSDev(path.str().c_str()))
         ret = AddDrmDevice(path.str());
-      }
     }
   }
 
@@ -73,14 +73,15 @@ int ResourceManager::Init() {
                        (const hw_module_t **)&gralloc_);
 }
 
-int ResourceManager::AddDrmDevice(std::string path) {
+int ResourceManager::AddDrmDevice(std::string const &path) {
   std::unique_ptr<DrmDevice> drm = std::make_unique<DrmDevice>();
-  int displays_added, ret;
+  int displays_added;
+  int ret;
   std::tie(ret, displays_added) = drm->Init(path.c_str(), num_displays_);
   if (ret)
     return ret;
   std::shared_ptr<Importer> importer;
-  importer.reset(new DrmGenericImporter(drm.get()));
+  importer = std::make_shared<DrmGenericImporter>(drm.get());
   if (!importer) {
     ALOGE("Failed to create importer instance");
     return -ENODEV;
@@ -93,7 +94,7 @@ int ResourceManager::AddDrmDevice(std::string path) {
 
 DrmConnector *ResourceManager::AvailableWritebackConnector(int display) {
   DrmDevice *drm_device = GetDrmDevice(display);
-  DrmConnector *writeback_conn = NULL;
+  DrmConnector *writeback_conn = nullptr;
   if (drm_device) {
     writeback_conn = drm_device->AvailableWritebackConnector(display);
     if (writeback_conn)
@@ -134,7 +135,7 @@ DrmDevice *ResourceManager::GetDrmDevice(int display) {
     if (drm->HandlesDisplay(display))
       return drm.get();
   }
-  return NULL;
+  return nullptr;
 }
 
 std::shared_ptr<Importer> ResourceManager::GetImporter(int display) {
@@ -142,7 +143,7 @@ std::shared_ptr<Importer> ResourceManager::GetImporter(int display) {
     if (drms_[i]->HandlesDisplay(display))
       return importers_[i];
   }
-  return NULL;
+  return nullptr;
 }
 
 const gralloc_module_t *ResourceManager::gralloc() {
index 7102cea..a17ae03 100644 (file)
@@ -45,7 +45,7 @@ class ResourceManager {
   }
 
  private:
-  int AddDrmDevice(std::string path);
+  int AddDrmDevice(std::string const &path);
   static bool IsKMSDev(const char *path);
 
   int num_displays_;
index 7f8882d..8565aac 100644 (file)
 
 #include "VSyncWorker.h"
 
-#include <stdlib.h>
-#include <time.h>
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 
+#include <cstdlib>
+#include <ctime>
+
 #include "utils/log.h"
 
 namespace android {
 
 VSyncWorker::VSyncWorker()
     : Worker("vsync", HAL_PRIORITY_URGENT_DISPLAY),
-      drm_(NULL),
+      drm_(nullptr),
       display_(-1),
       enabled_(false),
       last_timestamp_(-1) {
 }
 
-VSyncWorker::~VSyncWorker() {
-}
-
 int VSyncWorker::Init(DrmDevice *drm, int display) {
   drm_ = drm;
   display_ = display;
@@ -47,7 +45,7 @@ int VSyncWorker::Init(DrmDevice *drm, int display) {
 
 void VSyncWorker::RegisterCallback(std::shared_ptr<VsyncCallback> callback) {
   Lock();
-  callback_ = callback;
+  callback_ = std::move(callback);
   Unlock();
 }
 
@@ -81,7 +79,7 @@ void VSyncWorker::VSyncControl(bool enabled) {
  *  Thus, we must sleep until timestamp 687 to maintain phase with the last
  *  timestamp.
  */
-int64_t VSyncWorker::GetPhasedVSync(int64_t frame_ns, int64_t current) {
+int64_t VSyncWorker::GetPhasedVSync(int64_t frame_ns, int64_t current) const {
   if (last_timestamp_ < 0)
     return current + frame_ns;
 
@@ -95,21 +93,21 @@ int VSyncWorker::SyntheticWaitVBlank(int64_t *timestamp) {
   struct timespec vsync;
   int ret = clock_gettime(CLOCK_MONOTONIC, &vsync);
 
-  float refresh = 60.0f;  // Default to 60Hz refresh rate
+  float refresh = 60.0F;  // Default to 60Hz refresh rate
   DrmConnector *conn = drm_->GetConnectorForDisplay(display_);
-  if (conn && conn->active_mode().v_refresh() != 0.0f)
+  if (conn && conn->active_mode().v_refresh() != 0.0F)
     refresh = conn->active_mode().v_refresh();
   else
     ALOGW("Vsync worker active with conn=%p refresh=%f\n", conn,
-          conn ? conn->active_mode().v_refresh() : 0.0f);
+          conn ? conn->active_mode().v_refresh() : 0.0F);
 
   int64_t phased_timestamp = GetPhasedVSync(kOneSecondNs / refresh,
                                             vsync.tv_sec * kOneSecondNs +
                                                 vsync.tv_nsec);
   vsync.tv_sec = phased_timestamp / kOneSecondNs;
-  vsync.tv_nsec = phased_timestamp - (vsync.tv_sec * kOneSecondNs);
+  vsync.tv_nsec = int(phased_timestamp - (vsync.tv_sec * kOneSecondNs));
   do {
-    ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &vsync, NULL);
+    ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &vsync, nullptr);
   } while (ret == -1 && errno == EINTR);
   if (ret)
     return ret;
@@ -149,9 +147,10 @@ void VSyncWorker::Routine() {
 
   int64_t timestamp;
   ret = drmWaitVBlank(drm_->fd(), &vblank);
-  if (ret == -EINTR) {
+  if (ret == -EINTR)
     return;
-  } else if (ret) {
+
+  if (ret) {
     ret = SyntheticWaitVBlank(&timestamp);
     if (ret)
       return;
index 7454b51..76f2854 100644 (file)
@@ -31,15 +31,14 @@ namespace android {
 
 class VsyncCallback {
  public:
-  virtual ~VsyncCallback() {
-  }
+  virtual ~VsyncCallback() = default;
   virtual void Callback(int display, int64_t timestamp) = 0;
 };
 
 class VSyncWorker : public Worker {
  public:
   VSyncWorker();
-  ~VSyncWorker() override;
+  ~VSyncWorker() override = default;
 
   int Init(DrmDevice *drm, int display);
   void RegisterCallback(std::shared_ptr<VsyncCallback> callback);
@@ -52,7 +51,7 @@ class VSyncWorker : public Worker {
   void Routine() override;
 
  private:
-  int64_t GetPhasedVSync(int64_t frame_ns, int64_t current);
+  int64_t GetPhasedVSync(int64_t frame_ns, int64_t current) const;
   int SyntheticWaitVBlank(int64_t *timestamp);
 
   DrmDevice *drm_;
index 1f30588..d2b60c8 100644 (file)
@@ -34,8 +34,7 @@ int Worker::InitWorker() {
   if (initialized())
     return -EALREADY;
 
-  thread_ = std::unique_ptr<std::thread>(
-      new std::thread(&Worker::InternalRoutine, this));
+  thread_ = std::make_unique<std::thread>(&Worker::InternalRoutine, this);
   initialized_ = true;
   exit_ = false;
 
index 4e9552a..4b5cd7e 100644 (file)
 
 #include "autolock.h"
 
-#include <errno.h>
+#include <log/log.h>
 #include <pthread.h>
 
-#include <log/log.h>
+#include <cerrno>
 
 namespace android {
 
index 322efce..9a49c41 100644 (file)
 namespace android {
 
 const hwc_drm_bo *DrmHwcBuffer::operator->() const {
-  if (importer_ == NULL) {
+  if (importer_ == nullptr) {
     ALOGE("Access of non-existent BO");
     exit(1);
-    return NULL;
+    return nullptr;
   }
   return &bo_;
 }
 
 void DrmHwcBuffer::Clear() {
-  if (importer_ != NULL) {
+  if (importer_ != nullptr) {
     importer_->ReleaseBuffer(&bo_);
-    importer_ = NULL;
+    importer_ = nullptr;
   }
 }
 
@@ -60,7 +60,7 @@ int DrmHwcBuffer::ImportBuffer(buffer_handle_t handle, Importer *importer) {
     return ret;
   }
 
-  if (importer_ != NULL) {
+  if (importer_ != nullptr) {
     importer_->ReleaseBuffer(&bo_);
   }
 
@@ -97,13 +97,13 @@ DrmHwcNativeHandle::~DrmHwcNativeHandle() {
 }
 
 void DrmHwcNativeHandle::Clear() {
-  if (handle_ != NULL) {
+  if (handle_ != nullptr) {
     GraphicBufferMapper &gm(GraphicBufferMapper::get());
     int ret = gm.freeBuffer(handle_);
     if (ret) {
       ALOGE("Failed to free buffer handle %d", ret);
     }
-    handle_ = NULL;
+    handle_ = nullptr;
   }
 }