diff options
| author | LuK1337 <priv.luk@gmail.com> | 2024-08-28 18:06:41 +0200 |
|---|---|---|
| committer | Julian Veit <Claymore1298@gmail.com> | 2024-11-08 11:55:59 +0100 |
| commit | c923fa3e25915e73c8451cdbdcc56896cbea2abd (patch) | |
| tree | df0e450f77f074b118a32244c3b3005994675ea4 | |
| parent | a6465b8675cb9e3fba582de01014babc58c4c2cf (diff) | |
livedisplay: Import DisplayModes from OnePlus SM8150
$(call soong_config_set,OPLUS_LINEAGE_LIVEDISPLAY_HAL,ENABLE_DM,false)
Change-Id: I26ef7a7a05a19e640a7937ab34f183978389e47e
| -rw-r--r-- | hidl/livedisplay/Android.bp | 27 | ||||
| -rw-r--r-- | hidl/livedisplay/DisplayModes.cpp | 95 | ||||
| -rw-r--r-- | hidl/livedisplay/include/livedisplay/oplus/DisplayModes.h | 58 | ||||
| -rw-r--r-- | hidl/livedisplay/service.cpp | 15 | ||||
| -rw-r--r-- | hidl/livedisplay/vendor.lineage.livedisplay@2.1-service.oplus-dm.xml | 11 |
5 files changed, 204 insertions, 2 deletions
diff --git a/hidl/livedisplay/Android.bp b/hidl/livedisplay/Android.bp index 6542be6..4bf1d51 100644 --- a/hidl/livedisplay/Android.bp +++ b/hidl/livedisplay/Android.bp @@ -16,7 +16,7 @@ soong_config_module_type { name: "oplus_lineage_livedisplay_hal_cc_defaults", module_type: "cc_defaults", config_namespace: "OPLUS_LINEAGE_LIVEDISPLAY_HAL", - variables: ["ENABLE_AF", "ENABLE_PA", "ENABLE_SE"], + variables: ["ENABLE_AF", "ENABLE_DM", "ENABLE_PA", "ENABLE_SE"], properties: ["cflags", "vintf_fragments"], } @@ -26,6 +26,11 @@ soong_config_string_variable { } soong_config_string_variable { + name: "ENABLE_DM", + values: ["true", "false"], +} + +soong_config_string_variable { name: "ENABLE_PA", values: ["true", "false"], } @@ -52,6 +57,20 @@ oplus_lineage_livedisplay_hal_cc_defaults { vintf_fragments: [], }, }, + ENABLE_DM: { + true: { + cflags: ["-DENABLE_DM=true"], + vintf_fragments: ["vendor.lineage.livedisplay@2.1-service.oplus-dm.xml"], + }, + false: { + cflags: ["-DENABLE_DM=false"], + vintf_fragments: [], + }, + conditions_default: { + cflags: ["-DENABLE_DM=false"], + vintf_fragments: [], + }, + }, ENABLE_PA: { true: { cflags: ["-DENABLE_PA=true"], @@ -89,6 +108,11 @@ filegroup { } filegroup { + name: "vendor.lineage.livedisplay@2.1-oplus-dm", + srcs: ["DisplayModes.cpp"], +} + +filegroup { name: "vendor.lineage.livedisplay@2.1-oplus-se", srcs: ["SunlightEnhancement.cpp"], } @@ -111,6 +135,7 @@ cc_binary { ":vendor.lineage.livedisplay@2.0-sdm-pa", ":vendor.lineage.livedisplay@2.0-sdm-utils", ":vendor.lineage.livedisplay@2.1-oplus-af", + ":vendor.lineage.livedisplay@2.1-oplus-dm", ":vendor.lineage.livedisplay@2.1-oplus-se", "service.cpp", ], diff --git a/hidl/livedisplay/DisplayModes.cpp b/hidl/livedisplay/DisplayModes.cpp new file mode 100644 index 0000000..7c85dbc --- /dev/null +++ b/hidl/livedisplay/DisplayModes.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2019 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define LOG_TAG "DisplayModesService" + +#include <android-base/logging.h> +#include <android-base/properties.h> +#include <fcntl.h> +#include <livedisplay/oplus/DisplayModes.h> +#include <oplus/oplus_display_panel.h> +#include <fstream> + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +static const std::string kModeBasePath = "/sys/class/drm/card0-DSI-1/"; +static const std::string kDefaultPath = "/data/vendor/display/default_display_mode"; + +// Mode ids here must match qdcm display mode ids +const std::map<int32_t, DisplayModes::ModeInfo> DisplayModes::kModeMap = { + {0, {"Vivid", 0, 0}}, + {1, {"Natural", 1, 1}}, + {2, {"Cinematic", 0, 1}}, + {3, {"Brilliant", 4, 0}}, +}; + +DisplayModes::DisplayModes(std::shared_ptr<V2_0::sdm::SDMController> controller) + : mController(std::move(controller)), + mOplusDisplayFd(open("/dev/oplus_display", O_RDWR)), + mCurrentModeId(0), + mDefaultModeId(0) { + std::ifstream defaultFile(kDefaultPath); + + defaultFile >> mDefaultModeId; + LOG(DEBUG) << "Default file read result " << mDefaultModeId << " fail " << defaultFile.fail(); + + setDisplayMode(mDefaultModeId, false); +} + +// Methods from ::vendor::lineage::livedisplay::V2_1::IDisplayModes follow. +Return<void> DisplayModes::getDisplayModes(getDisplayModes_cb resultCb) { + std::vector<V2_0::DisplayMode> modes; + + for (const auto& entry : kModeMap) { + modes.push_back({entry.first, entry.second.name}); + } + resultCb(modes); + return Void(); +} + +Return<void> DisplayModes::getCurrentDisplayMode(getCurrentDisplayMode_cb resultCb) { + resultCb({mCurrentModeId, kModeMap.at(mCurrentModeId).name}); + return Void(); +} + +Return<void> DisplayModes::getDefaultDisplayMode(getDefaultDisplayMode_cb resultCb) { + resultCb({mDefaultModeId, kModeMap.at(mDefaultModeId).name}); + return Void(); +} + +Return<bool> DisplayModes::setDisplayMode(int32_t modeID, bool makeDefault) { + const auto iter = kModeMap.find(modeID); + if (iter == kModeMap.end()) { + return false; + } + if (mOplusDisplayFd >= 0) { + ioctl(mOplusDisplayFd, PANEL_IOCTL_SET_SEED, &iter->second.seedMode); + } + mController->setActiveDisplayMode(iter->second.displayModeId); + mCurrentModeId = iter->first; + if (makeDefault) { + std::ofstream defaultFile(kDefaultPath); + defaultFile << iter->first; + if (!defaultFile.fail()) { + mController->setDefaultDisplayMode(iter->second.displayModeId); + mDefaultModeId = iter->first; + } + } + if (mOnDisplayModeSet) { + mOnDisplayModeSet(); + } + return true; +} + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/hidl/livedisplay/include/livedisplay/oplus/DisplayModes.h b/hidl/livedisplay/include/livedisplay/oplus/DisplayModes.h new file mode 100644 index 0000000..b102bf9 --- /dev/null +++ b/hidl/livedisplay/include/livedisplay/oplus/DisplayModes.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2019 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#include <hidl/MQDescriptor.h> +#include <hidl/Status.h> +#include <livedisplay/sdm/SDMController.h> +#include <vendor/lineage/livedisplay/2.1/IDisplayModes.h> +#include <map> + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_1 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::Return; +using ::android::hardware::Void; + +class DisplayModes : public IDisplayModes { + public: + DisplayModes(std::shared_ptr<V2_0::sdm::SDMController> controller); + + using DisplayModeSetCallback = std::function<void()>; + inline void registerDisplayModeSetCallback(DisplayModeSetCallback callback) { + mOnDisplayModeSet = callback; + } + + // Methods from ::vendor::lineage::livedisplay::V2_1::IDisplayModes follow. + Return<void> getDisplayModes(getDisplayModes_cb resultCb) override; + Return<void> getCurrentDisplayMode(getCurrentDisplayMode_cb resultCb) override; + Return<void> getDefaultDisplayMode(getDefaultDisplayMode_cb ResultCb) override; + Return<bool> setDisplayMode(int32_t modeID, bool makeDefault) override; + + private: + struct ModeInfo { + std::string name; + int32_t displayModeId; + uint32_t seedMode; + }; + static const std::map<int32_t, ModeInfo> kModeMap; + std::shared_ptr<V2_0::sdm::SDMController> mController; + int32_t mOplusDisplayFd; + int32_t mCurrentModeId; + int32_t mDefaultModeId; + DisplayModeSetCallback mOnDisplayModeSet; +}; + +} // namespace implementation +} // namespace V2_1 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/hidl/livedisplay/service.cpp b/hidl/livedisplay/service.cpp index 71c549a..6ab1584 100644 --- a/hidl/livedisplay/service.cpp +++ b/hidl/livedisplay/service.cpp @@ -20,6 +20,7 @@ #include <binder/ProcessState.h> #include <hidl/HidlTransportSupport.h> #include <livedisplay/oplus/AntiFlicker.h> +#include <livedisplay/oplus/DisplayModes.h> #include <livedisplay/oplus/SunlightEnhancement.h> #include <livedisplay/sdm/PictureAdjustment.h> #include <vendor/lineage/livedisplay/2.1/IPictureAdjustment.h> @@ -33,9 +34,11 @@ using ::android::hardware::joinRpcThreadpool; using ::vendor::lineage::livedisplay::V2_0::sdm::PictureAdjustment; using ::vendor::lineage::livedisplay::V2_0::sdm::SDMController; using ::vendor::lineage::livedisplay::V2_1::IAntiFlicker; +using ::vendor::lineage::livedisplay::V2_1::IDisplayModes; using ::vendor::lineage::livedisplay::V2_1::IPictureAdjustment; using ::vendor::lineage::livedisplay::V2_1::ISunlightEnhancement; using ::vendor::lineage::livedisplay::V2_1::implementation::AntiFlicker; +using ::vendor::lineage::livedisplay::V2_1::implementation::DisplayModes; using ::vendor::lineage::livedisplay::V2_1::implementation::SunlightEnhancement; int main() { @@ -46,9 +49,10 @@ int main() { LOG(INFO) << "LiveDisplay HAL service is starting."; std::shared_ptr<SDMController> controller = - ENABLE_PA ? std::make_shared<SDMController>() : nullptr; + ENABLE_DM || ENABLE_PA ? std::make_shared<SDMController>() : nullptr; sp<AntiFlicker> af = ENABLE_AF ? new AntiFlicker() : nullptr; + sp<DisplayModes> dm = ENABLE_DM ? new DisplayModes(controller) : nullptr; sp<PictureAdjustment> pa = ENABLE_PA ? new PictureAdjustment(controller) : nullptr; sp<SunlightEnhancement> se = ENABLE_SE ? new SunlightEnhancement() : nullptr; @@ -63,6 +67,15 @@ int main() { } } + if (dm) { + status = dm->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL DisplayModes Iface (" + << status << ")"; + goto shutdown; + } + } + if (pa) { status = pa->registerAsService(); if (status != OK) { diff --git a/hidl/livedisplay/vendor.lineage.livedisplay@2.1-service.oplus-dm.xml b/hidl/livedisplay/vendor.lineage.livedisplay@2.1-service.oplus-dm.xml new file mode 100644 index 0000000..126028f --- /dev/null +++ b/hidl/livedisplay/vendor.lineage.livedisplay@2.1-service.oplus-dm.xml @@ -0,0 +1,11 @@ +<manifest version="1.0" type="device"> + <hal format="hidl"> + <name>vendor.lineage.livedisplay</name> + <transport>hwbinder</transport> + <version>2.1</version> + <interface> + <name>IDisplayModes</name> + <instance>default</instance> + </interface> + </hal> +</manifest> |
