From ad88487cd0c6e4871f65997b2e6b83c20aeefcc3 Mon Sep 17 00:00:00 2001 From: Simon1511 Date: Fri, 25 Mar 2022 17:25:33 +0100 Subject: [PATCH] sm7125: livedisplay: Add support for DisplayColorCalibration Change-Id: Ic8e05a1662bc210cad706a8053322800ee5fbef2 --- configs/framework_compatibility_matrix.xml | 4 ++ configs/manifest.xml | 5 ++ livedisplay/Android.bp | 1 + livedisplay/DisplayColorCalibration.cpp | 77 ++++++++++++++++++++++ livedisplay/DisplayColorCalibration.h | 54 +++++++++++++++ livedisplay/service.cpp | 20 ++++++ 6 files changed, 161 insertions(+) create mode 100644 livedisplay/DisplayColorCalibration.cpp create mode 100644 livedisplay/DisplayColorCalibration.h diff --git a/configs/framework_compatibility_matrix.xml b/configs/framework_compatibility_matrix.xml index 5087813..c3f418f 100644 --- a/configs/framework_compatibility_matrix.xml +++ b/configs/framework_compatibility_matrix.xml @@ -167,6 +167,10 @@ IAdaptiveBacklight default + + IDisplayColorCalibration + default + IDisplayModes default diff --git a/configs/manifest.xml b/configs/manifest.xml index 98260c5..b8eacc3 100644 --- a/configs/manifest.xml +++ b/configs/manifest.xml @@ -300,6 +300,10 @@ IAdaptiveBacklight default + + IDisplayColorCalibration + default + IDisplayModes default @@ -309,6 +313,7 @@ default @2.0::IAdaptiveBacklight/default + @2.0::IDisplayColorCalibration/default @2.0::IDisplayModes/default @2.0::ISunlightEnhancement/default diff --git a/livedisplay/Android.bp b/livedisplay/Android.bp index 93ec875..88bcafa 100644 --- a/livedisplay/Android.bp +++ b/livedisplay/Android.bp @@ -21,6 +21,7 @@ cc_binary { "AdaptiveBacklight.cpp", "DisplayModes.cpp", "SunlightEnhancement.cpp", + "DisplayColorCalibration.cpp", "service.cpp", ], shared_libs: [ diff --git a/livedisplay/DisplayColorCalibration.cpp b/livedisplay/DisplayColorCalibration.cpp new file mode 100644 index 0000000..9ce3d44 --- /dev/null +++ b/livedisplay/DisplayColorCalibration.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2019 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#include + +#include "DisplayColorCalibration.h" + +using android::base::ReadFileToString; +using android::base::Split; +using android::base::Trim; +using android::base::WriteStringToFile; + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace samsung { + +static constexpr const char* kColorPath = "/sys/class/mdnie/mdnie/sensorRGB"; + +bool DisplayColorCalibration::isSupported() { + std::fstream rgb(kColorPath, rgb.in | rgb.out); + return rgb.good(); +} + +Return DisplayColorCalibration::getMaxValue() { + return 255; +} + +Return DisplayColorCalibration::getMinValue() { + return 1; +} + +Return DisplayColorCalibration::getCalibration(getCalibration_cb resultCb) { + std::vector rgb; + std::string tmp; + + if (ReadFileToString(kColorPath, &tmp)) { + std::vector colors = Split(Trim(tmp), " "); + for (const std::string& color : colors) { + rgb.push_back(std::stoi(color)); + } + } + + resultCb(rgb); + return Void(); +} + +Return DisplayColorCalibration::setCalibration(const hidl_vec& rgb) { + std::string contents; + for (const int32_t& color : rgb) { + contents += std::to_string(color) + " "; + } + return WriteStringToFile(Trim(contents), kColorPath, true); +} + +} // namespace samsung +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/DisplayColorCalibration.h b/livedisplay/DisplayColorCalibration.h new file mode 100644 index 0000000..94188c0 --- /dev/null +++ b/livedisplay/DisplayColorCalibration.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2019-2022 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V2_0 { +namespace samsung { + +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::sp; + +class DisplayColorCalibration : public IDisplayColorCalibration { + public: + bool isSupported(); + + // Methods from ::vendor::lineage::livedisplay::V2_0::IDisplayColorCalibration follow. + Return getMaxValue() override; + Return getMinValue() override; + Return getCalibration(getCalibration_cb resultCb) override; + Return setCalibration(const hidl_vec& rgb) override; + + // Methods from ::android::hidl::base::V1_0::IBase follow. +}; + +} // namespace samsung +} // namespace V2_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/livedisplay/service.cpp b/livedisplay/service.cpp index e13c7f6..c1ee7bc 100644 --- a/livedisplay/service.cpp +++ b/livedisplay/service.cpp @@ -27,6 +27,7 @@ #include "AdaptiveBacklight.h" #include "DisplayModes.h" #include "SunlightEnhancement.h" +#include "DisplayColorCalibration.h" using android::hardware::configureRpcThreadpool; using android::hardware::joinRpcThreadpool; @@ -37,11 +38,13 @@ using android::OK; using vendor::lineage::livedisplay::V2_0::samsung::AdaptiveBacklight; using vendor::lineage::livedisplay::V2_0::samsung::DisplayModes; using vendor::lineage::livedisplay::V2_0::samsung::SunlightEnhancement; +using vendor::lineage::livedisplay::V2_0::samsung::DisplayColorCalibration; int main() { sp adaptiveBacklight; sp displayModes; sp sunlightEnhancement; + sp displayColorCalibration; status_t status; LOG(INFO) << "LiveDisplay HAL service is starting."; @@ -66,6 +69,13 @@ int main() { goto shutdown; } + displayColorCalibration = new DisplayColorCalibration(); + if (displayColorCalibration == nullptr) { + LOG(ERROR) << "Can not create an instance of LiveDisplay HAL DisplayColorCalibration " + "Iface, exiting."; + goto shutdown; + } + configureRpcThreadpool(1, true /*callerWillJoin*/); if (adaptiveBacklight->isSupported()) { @@ -96,6 +106,16 @@ int main() { } } + if (displayColorCalibration->isSupported()) { + status = displayColorCalibration->registerAsService(); + if (status != OK) { + LOG(ERROR) + << "Could not register service for LiveDisplay HAL DisplayColorCalibration Iface (" + << status << ")"; + goto shutdown; + } + } + LOG(INFO) << "LiveDisplay HAL service is ready."; joinRpcThreadpool(); // Should not pass this line