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>
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
+)
. ./.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[@]}"
. ./.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
#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"
}
}
- 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;
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);
}
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"
<< " Pixel operations (free units)"
<< " : [TOTAL: " << delta.total_pixops_
<< " / GPU: " << delta.gpu_pixops_ << "]\n"
- << " Composition efficiency: " << Ratio)
+ << " Composition efficiency: " << ratio)
.str();
}
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;
}
}
uint32_t DrmHwcTwo::GetMaxVirtualDisplayCount() {
- // TODO: Implement virtual display
+ // TODO(nobody): Implement virtual display
unsupported(__func__);
return 0;
}
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;
}
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) {
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);
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;
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;
}
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
// 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
// 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(),
// 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() &&
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;
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;
}
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;
.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);
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;
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);
}
}
HWC2::Error DrmHwcTwo::HwcDisplay::GetSupportedContentTypes(
- uint32_t *outNumSupportedContentTypes, uint32_t *outSupportedContentTypes) {
+ uint32_t *outNumSupportedContentTypes,
+ const uint32_t *outSupportedContentTypes) {
if (outSupportedContentTypes == nullptr)
*outNumSupportedContentTypes = 0;
uint32_t *outNumCapabilities, uint32_t *outCapabilities) {
unsupported(__func__, outCapabilities);
- if (outNumCapabilities == NULL) {
+ if (outNumCapabilities == nullptr) {
return HWC2::Error::BadParameter;
}
}
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;
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);
}
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;
}
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;
}
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_;
&HwcLayer::SetLayerZOrder, uint32_t>);
case HWC2::FunctionDescriptor::Invalid:
default:
- return NULL;
+ return nullptr;
}
}
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;
}
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
.name = "DrmHwcTwo module",
.author = "The Android Open Source Project",
.methods = &hwc2_module_methods,
- .dso = NULL,
+ .dso = nullptr,
.reserved = {0},
};
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,
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
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 :
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;
} 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;
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;
}
}
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,
namespace android {
-const std::vector<std::string> BackendManager::client_devices_ = {
+const std::vector<std::string> BackendManager::kClientDevices = {
"kirin",
"mediatek-drm",
};
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()) {
}
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]();
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_;
};
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
}
}
-__attribute__((weak)) LegacyBufferInfoGetter *
+__attribute__((weak)) std::unique_ptr<LegacyBufferInfoGetter>
LegacyBufferInfoGetter::CreateInstance() {
ALOGE("No legacy buffer info getters available");
return nullptr;
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_;
#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
#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 {
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;
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} */
/* 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;
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;
}
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;
}
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;
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;
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;
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;
#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"
namespace android {
-DrmDisplayComposition::~DrmDisplayComposition() {
-}
-
int DrmDisplayComposition::Init(DrmDevice *drm, DrmCrtc *crtc,
Importer *importer, Planner *planner,
uint64_t frame_no) {
separator = true;
}
- uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipH |
+ uint32_t valid_bits = DrmHwcTransform::kFlipH | DrmHwcTransform::kFlipV |
DrmHwcTransform::kRotate90 |
DrmHwcTransform::kRotate180 |
DrmHwcTransform::kRotate270;
public:
DrmDisplayComposition() = default;
DrmDisplayComposition(const DrmDisplayComposition &) = delete;
- ~DrmDisplayComposition();
+ ~DrmDisplayComposition() = default;
int Init(DrmDevice *drm, DrmCrtc *crtc, Importer *importer, Planner *planner,
uint64_t frame_no);
#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>
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);
}
};
DrmDisplayCompositor::DrmDisplayCompositor()
- : resource_manager_(NULL),
+ : resource_manager_(nullptr),
display_(-1),
initialized_(false),
active_(false),
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;
std::unique_ptr<DrmDisplayComposition> DrmDisplayCompositor::CreateComposition()
const {
- return std::unique_ptr<DrmDisplayComposition>(new DrmDisplayComposition());
+ return std::make_unique<DrmDisplayComposition>();
}
std::unique_ptr<DrmDisplayComposition>
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);
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;
}
if (DisablePlanes(active_composition_.get()))
return;
- active_composition_.reset(NULL);
+ active_composition_.reset(nullptr);
vsync_worker_.VSyncControl(false);
}
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()) {
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
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))
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))
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 {
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
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;
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;
return ret;
}
- protected_zorder = i->first;
i = layers.erase(i);
}
// 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;
}
#include "DrmConnector.h"
-#include <errno.h>
-#include <stdint.h>
#include <xf86drmMode.h>
#include <array>
+#include <cerrno>
+#include <cstdint>
#include <sstream>
#include "DrmDevice.h"
namespace android {
-constexpr size_t TYPES_COUNT = 17;
+constexpr size_t kTypesCount = 17;
DrmConnector::DrmConnector(DrmDevice *drm, drmModeConnectorPtr c,
DrmEncoder *current_encoder,
}
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() {
}
}
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;
#include "DrmCrtc.h"
-#include <stdint.h>
#include <utils/log.h>
#include <xf86drmMode.h>
+#include <cstdint>
+
#include "DrmDevice.h"
namespace android {
#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);
}
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),
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);
}
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());
}
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])
}
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);
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());
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 {
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;
}
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;
}
// 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;
}
}
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;
return 0;
}
-int DrmDevice::DestroyPropertyBlob(uint32_t blob_id) {
+int DrmDevice::DestroyPropertyBlob(uint32_t blob_id) const {
if (!blob_id)
return 0;
}
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);
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";
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);
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);
#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 {
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) {
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;
#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"
}
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();
return -errno;
}
+ // NOLINTNEXTLINE(readability-isolate-declaration)
FD_ZERO(&fds_);
FD_SET(drm_->fd(), &fds_);
FD_SET(uevent_fd_.get(), &fds_);
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;
int ret;
struct timespec ts;
+
uint64_t timestamp = 0;
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
if (!ret)
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;
}
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;
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);
}
#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) {
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) {
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;
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;
}
class Importer {
public:
- virtual ~Importer() {
- }
+ virtual ~Importer() = default;
// Imports the buffer referred to by handle into bo.
//
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;
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),
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 {
#include <errno.h>
#include <stdint.h>
+#include <cerrno>
#include <cinttypes>
+#include <cstdint>
#include "DrmDevice.h"
#include "bufferinfo/BufferInfoGetter.h"
}
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 {
#include "DrmProperty.h"
-#include <errno.h>
#include <xf86drmMode.h>
+#include <cerrno>
#include <cstdint>
-#include <cstring>
#include <string>
#include "DrmDevice.h"
: 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);
}
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;
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_) {
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]);
}
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);
}
}
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;
class DrmPropertyEnum {
public:
DrmPropertyEnum(drm_mode_property_enum *e);
- ~DrmPropertyEnum();
+ ~DrmPropertyEnum() = default;
uint64_t value_;
std::string name_;
namespace android {
-ResourceManager::ResourceManager() : num_displays_(0), gralloc_(NULL) {
+ResourceManager::ResourceManager() : num_displays_(0), gralloc_(nullptr) {
}
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());
- }
}
}
(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;
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)
if (drm->HandlesDisplay(display))
return drm.get();
}
- return NULL;
+ return nullptr;
}
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() {
}
private:
- int AddDrmDevice(std::string path);
+ int AddDrmDevice(std::string const &path);
static bool IsKMSDev(const char *path);
int num_displays_;
#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;
void VSyncWorker::RegisterCallback(std::shared_ptr<VsyncCallback> callback) {
Lock();
- callback_ = callback;
+ callback_ = std::move(callback);
Unlock();
}
* 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;
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;
int64_t timestamp;
ret = drmWaitVBlank(drm_->fd(), &vblank);
- if (ret == -EINTR) {
+ if (ret == -EINTR)
return;
- } else if (ret) {
+
+ if (ret) {
ret = SyntheticWaitVBlank(×tamp);
if (ret)
return;
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);
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_;
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;
#include "autolock.h"
-#include <errno.h>
+#include <log/log.h>
#include <pthread.h>
-#include <log/log.h>
+#include <cerrno>
namespace android {
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;
}
}
return ret;
}
- if (importer_ != NULL) {
+ if (importer_ != nullptr) {
importer_->ReleaseBuffer(&bo_);
}
}
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;
}
}