drm_hwcomposer: enable code analysis using clang-tidy
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>
diff --git a/drm/DrmConnector.cpp b/drm/DrmConnector.cpp
index 11c2bd2..cfafc1d 100644
--- a/drm/DrmConnector.cpp
+++ b/drm/DrmConnector.cpp
@@ -18,11 +18,11 @@
#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 @@
}
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 @@
}
}
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;
diff --git a/drm/DrmCrtc.cpp b/drm/DrmCrtc.cpp
index 3c05ba8..4da08fe 100644
--- a/drm/DrmCrtc.cpp
+++ b/drm/DrmCrtc.cpp
@@ -18,10 +18,11 @@
#include "DrmCrtc.h"
-#include <stdint.h>
#include <utils/log.h>
#include <xf86drmMode.h>
+#include <cstdint>
+
#include "DrmDevice.h"
namespace android {
diff --git a/drm/DrmDevice.cpp b/drm/DrmDevice.cpp
index 818261d..52d81d5 100644
--- a/drm/DrmDevice.cpp
+++ b/drm/DrmDevice.cpp
@@ -18,35 +18,35 @@
#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 @@
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 @@
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::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::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 @@
}
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 @@
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 @@
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 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 @@
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 @@
// 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::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 @@
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 @@
}
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 @@
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";
diff --git a/drm/DrmDevice.h b/drm/DrmDevice.h
index be68aa6..d8f347f 100644
--- a/drm/DrmDevice.h
+++ b/drm/DrmDevice.h
@@ -71,13 +71,13 @@
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 @@
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);
diff --git a/drm/DrmEncoder.cpp b/drm/DrmEncoder.cpp
index bcf0926..ad05f88 100644
--- a/drm/DrmEncoder.cpp
+++ b/drm/DrmEncoder.cpp
@@ -16,19 +16,20 @@
#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 @@
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) {
diff --git a/drm/DrmEncoder.h b/drm/DrmEncoder.h
index f4464d0..4c01bc1 100644
--- a/drm/DrmEncoder.h
+++ b/drm/DrmEncoder.h
@@ -30,7 +30,7 @@
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;
diff --git a/drm/DrmEventListener.cpp b/drm/DrmEventListener.cpp
index 6cfa37d..13a1273 100644
--- a/drm/DrmEventListener.cpp
+++ b/drm/DrmEventListener.cpp
@@ -18,12 +18,12 @@
#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 @@
}
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 @@
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::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 @@
int ret;
struct timespec ts;
+
uint64_t timestamp = 0;
ret = clock_gettime(CLOCK_MONOTONIC, &ts);
if (!ret)
@@ -95,9 +98,10 @@
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 @@
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::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);
}
diff --git a/drm/DrmGenericImporter.cpp b/drm/DrmGenericImporter.cpp
index 171d889..6627cc8 100644
--- a/drm/DrmGenericImporter.cpp
+++ b/drm/DrmGenericImporter.cpp
@@ -21,11 +21,12 @@
#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 @@
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 @@
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 @@
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;
}
diff --git a/drm/DrmGenericImporter.h b/drm/DrmGenericImporter.h
index ca53762..27cfc3b 100644
--- a/drm/DrmGenericImporter.h
+++ b/drm/DrmGenericImporter.h
@@ -33,8 +33,7 @@
class Importer {
public:
- virtual ~Importer() {
- }
+ virtual ~Importer() = default;
// Imports the buffer referred to by handle into bo.
//
@@ -52,7 +51,7 @@
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;
diff --git a/drm/DrmMode.cpp b/drm/DrmMode.cpp
index 6a879e8..dd25758 100644
--- a/drm/DrmMode.cpp
+++ b/drm/DrmMode.cpp
@@ -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 @@
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 {
diff --git a/drm/DrmPlane.cpp b/drm/DrmPlane.cpp
index 1cc6ee0..a7ad3c0 100644
--- a/drm/DrmPlane.cpp
+++ b/drm/DrmPlane.cpp
@@ -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 @@
}
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 {
diff --git a/drm/DrmProperty.cpp b/drm/DrmProperty.cpp
index b8ce680..4c5f44f 100644
--- a/drm/DrmProperty.cpp
+++ b/drm/DrmProperty.cpp
@@ -16,11 +16,10 @@
#include "DrmProperty.h"
-#include <errno.h>
#include <xf86drmMode.h>
+#include <cerrno>
#include <cstdint>
-#include <cstring>
#include <string>
#include "DrmDevice.h"
@@ -31,11 +30,7 @@
: 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 @@
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 @@
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 @@
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<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);
}
}
diff --git a/drm/DrmProperty.h b/drm/DrmProperty.h
index d293da3..3f4d15e 100644
--- a/drm/DrmProperty.h
+++ b/drm/DrmProperty.h
@@ -41,7 +41,7 @@
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 DrmPropertyEnum {
public:
DrmPropertyEnum(drm_mode_property_enum *e);
- ~DrmPropertyEnum();
+ ~DrmPropertyEnum() = default;
uint64_t value_;
std::string name_;
diff --git a/drm/ResourceManager.cpp b/drm/ResourceManager.cpp
index efd5de1..3e16fbb 100644
--- a/drm/ResourceManager.cpp
+++ b/drm/ResourceManager.cpp
@@ -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 @@
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 @@
(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 @@
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 @@
if (drm->HandlesDisplay(display))
return drm.get();
}
- return NULL;
+ return nullptr;
}
std::shared_ptr<Importer> ResourceManager::GetImporter(int display) {
@@ -142,7 +143,7 @@
if (drms_[i]->HandlesDisplay(display))
return importers_[i];
}
- return NULL;
+ return nullptr;
}
const gralloc_module_t *ResourceManager::gralloc() {
diff --git a/drm/ResourceManager.h b/drm/ResourceManager.h
index 7102cea..a17ae03 100644
--- a/drm/ResourceManager.h
+++ b/drm/ResourceManager.h
@@ -45,7 +45,7 @@
}
private:
- int AddDrmDevice(std::string path);
+ int AddDrmDevice(std::string const &path);
static bool IsKMSDev(const char *path);
int num_displays_;
diff --git a/drm/VSyncWorker.cpp b/drm/VSyncWorker.cpp
index 7f8882d..8565aac 100644
--- a/drm/VSyncWorker.cpp
+++ b/drm/VSyncWorker.cpp
@@ -18,26 +18,24 @@
#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 @@
void VSyncWorker::RegisterCallback(std::shared_ptr<VsyncCallback> callback) {
Lock();
- callback_ = callback;
+ callback_ = std::move(callback);
Unlock();
}
@@ -81,7 +79,7 @@
* 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 @@
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 @@
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;
diff --git a/drm/VSyncWorker.h b/drm/VSyncWorker.h
index 7454b51..76f2854 100644
--- a/drm/VSyncWorker.h
+++ b/drm/VSyncWorker.h
@@ -31,15 +31,14 @@
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 @@
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_;