diff options
Diffstat (limited to 'libhwc2.1/libhwchelper/ExynosHWCHelper.h')
-rw-r--r-- | libhwc2.1/libhwchelper/ExynosHWCHelper.h | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/libhwc2.1/libhwchelper/ExynosHWCHelper.h b/libhwc2.1/libhwchelper/ExynosHWCHelper.h index ed9964a..de99b99 100644 --- a/libhwc2.1/libhwchelper/ExynosHWCHelper.h +++ b/libhwc2.1/libhwchelper/ExynosHWCHelper.h @@ -26,6 +26,7 @@ #include <optional> #include <sstream> #include <string> +#include <unordered_map> #include <vector> #include "DeconCommonHeader.h" @@ -162,7 +163,7 @@ const format_description_t exynos_format_desc[] = { 1, 1, 32, RGB | BIT10 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("RGBA_1010102"), 0}, {HAL_PIXEL_FORMAT_EXYNOS_ARGB_8888, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_ARGB8888, 1, 1, 32, RGB | BIT8 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("EXYNOS_ARGB_8888"), 0}, - {HAL_PIXEL_FORMAT_RGBA_FP16, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_ARGB16161616F, + {HAL_PIXEL_FORMAT_RGBA_FP16, DECON_PIXEL_FORMAT_MAX, DRM_FORMAT_ABGR16161616F, 1, 1, 64, RGB | BIT16 | COMP_TYPE_NONE | COMP_TYPE_AFBC, true, String8("RGBA_FP16"), 0}, /* YUV 420 */ @@ -628,11 +629,18 @@ public: CtrlValue() : value_(), dirty_(false) {} CtrlValue(const T& value) : value_(value), dirty_(false) {} - void store(T value) { + void store(const T& value) { if (value == value_) return; dirty_ = true; value_ = value; }; + + void store(T&& value) { + if (value == value_) return; + dirty_ = true; + value_ = std::move(value); + }; + const T &get() { return value_; }; bool is_dirty() { return dirty_; }; void clear_dirty() { dirty_ = false; }; @@ -664,6 +672,56 @@ struct RollingAverage { } }; +class FileNodeWriter { +public: + FileNodeWriter(const std::string& nodePath) : mNodePath(nodePath) {} + + ~FileNodeWriter() { + for (auto& node : mOperateNodes) { + close(node.second); + } + } + + template <typename T> + bool WriteCommandString(const std::string& nodeName, T cmd) { + // ref: https://elixir.bootlin.com/linux/latest/source/include/linux/kstrtox.h + static_assert(std::is_integral_v<T>); + + int fd = getOperateNodeFileHandle(nodeName); + if (fd >= 0) { + std::string cmdString = std::to_string(cmd); + int ret = write(fd, cmdString.c_str(), std::strlen(cmdString.c_str())); + if (ret < 0) { + ALOGE("Write to file node %s failed, ret = %d errno = %d", mNodePath.c_str(), ret, + errno); + return false; + } + } else { + ALOGE("Write to invalid file node %s", mNodePath.c_str()); + return false; + } + return true; + } + +private: + int getOperateNodeFileHandle(const std::string& nodeName) { + if (mOperateNodes.count(nodeName) > 0) { + return mOperateNodes[nodeName]; + } + std::string fullPath = mNodePath + nodeName; + int fd = open(fullPath.c_str(), O_WRONLY, 0); + if (fd < 0) { + ALOGE("Open file node failed, fd = %d", fd); + return fd; + } + mOperateNodes[nodeName] = fd; + return fd; + } + + std::string mNodePath; + std::unordered_map<std::string, int> mOperateNodes; +}; + // Waits for a given property value, or returns std::nullopt if unavailable std::optional<std::string> waitForPropertyValue(const std::string &property, int64_t timeoutMs); |