From 7fadabc96496c92a50a616b0f8a3aa9285dd79ea Mon Sep 17 00:00:00 2001 From: Dominggoes Isakh Date: Sat, 2 Feb 2019 00:29:19 +0100 Subject: Exynos4: Initial implementation of LiveDisplay 1.0 Change-Id: Ic42ac877b5bbd437b07616c0bcaedd7d846d07c2 --- exynos4/interfaces/livedisplay/1.0/.clang-format | 13 + exynos4/interfaces/livedisplay/1.0/Android.bp | 45 +++ exynos4/interfaces/livedisplay/1.0/Exynos4.cpp | 148 ++++++++ exynos4/interfaces/livedisplay/1.0/include/Color.h | 99 ++++++ .../livedisplay/1.0/include/ColorBackend.h | 64 ++++ .../interfaces/livedisplay/1.0/include/Exynos4.h | 102 ++++++ exynos4/interfaces/livedisplay/1.0/include/Types.h | 79 +++++ exynos4/interfaces/livedisplay/1.0/include/Utils.h | 41 +++ .../1.0/include/controller/Exynos4Controller.h | 73 ++++ exynos4/interfaces/livedisplay/1.0/service.cpp | 69 ++++ exynos4/interfaces/livedisplay/1.0/src/Color.cpp | 378 +++++++++++++++++++++ exynos4/interfaces/livedisplay/1.0/src/Utils.cpp | 74 ++++ ...ndor.lineage.livedisplay@1.0-service-exynos4.rc | 4 + 13 files changed, 1189 insertions(+) create mode 100644 exynos4/interfaces/livedisplay/1.0/.clang-format create mode 100644 exynos4/interfaces/livedisplay/1.0/Android.bp create mode 100644 exynos4/interfaces/livedisplay/1.0/Exynos4.cpp create mode 100644 exynos4/interfaces/livedisplay/1.0/include/Color.h create mode 100644 exynos4/interfaces/livedisplay/1.0/include/ColorBackend.h create mode 100644 exynos4/interfaces/livedisplay/1.0/include/Exynos4.h create mode 100644 exynos4/interfaces/livedisplay/1.0/include/Types.h create mode 100644 exynos4/interfaces/livedisplay/1.0/include/Utils.h create mode 100644 exynos4/interfaces/livedisplay/1.0/include/controller/Exynos4Controller.h create mode 100644 exynos4/interfaces/livedisplay/1.0/service.cpp create mode 100644 exynos4/interfaces/livedisplay/1.0/src/Color.cpp create mode 100644 exynos4/interfaces/livedisplay/1.0/src/Utils.cpp create mode 100644 exynos4/interfaces/livedisplay/1.0/vendor.lineage.livedisplay@1.0-service-exynos4.rc (limited to 'exynos4') diff --git a/exynos4/interfaces/livedisplay/1.0/.clang-format b/exynos4/interfaces/livedisplay/1.0/.clang-format new file mode 100644 index 0000000..fc4eb1b --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/.clang-format @@ -0,0 +1,13 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortFunctionsOnASingleLine: false + +AccessModifierOffset: -2 +ColumnLimit: 100 +CommentPragmas: NOLINT:.* +DerivePointerAlignment: false +IndentWidth: 4 +PointerAlignment: Left +TabWidth: 4 +UseTab: Never +PenaltyExcessCharacter: 32 diff --git a/exynos4/interfaces/livedisplay/1.0/Android.bp b/exynos4/interfaces/livedisplay/1.0/Android.bp new file mode 100644 index 0000000..0867fdb --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/Android.bp @@ -0,0 +1,45 @@ +// Copyright (C) 2017-2018 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. + +cc_defaults { + name: "livedisplay_exynos4_defaults", + relative_install_path: "hw", + defaults: ["hidl_defaults"], + local_include_dirs: ["include"], + srcs: [ + "service.cpp", + "src/Color.cpp", + "src/Utils.cpp" + ], + shared_libs: [ + "libbase", + "libbinder", + "libcutils", + "libhardware", + "libhidlbase", + "libhidltransport", + "libutils", + "vendor.lineage.livedisplay@1.0", + ], +} + +cc_binary { + name: "vendor.lineage.livedisplay@1.0-service-exynos4", + init_rc: ["vendor.lineage.livedisplay@1.0-service-exynos4.rc"], + defaults: ["livedisplay_exynos4_defaults"], + proprietary: true, + srcs: [ + "Exynos4.cpp", + ], +} diff --git a/exynos4/interfaces/livedisplay/1.0/Exynos4.cpp b/exynos4/interfaces/livedisplay/1.0/Exynos4.cpp new file mode 100644 index 0000000..8b8b61b --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/Exynos4.cpp @@ -0,0 +1,148 @@ +/* +** Copyright 2016, The CyanogenMod Project +** Copyright (C) 2017-2018 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. +*/ + +#define LOG_NDEBUG 0 + +#define LOG_TAG "LiveDisplay-Exynos4" + +#include "Exynos4.h" +#include "Utils.h" + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +using android::BAD_VALUE; +using android::NO_INIT; +using android::OK; +using android::sp; +using android::status_t; + +Exynos4::Exynos4() { + memset(&mDefaultPictureAdjustment, 0, sizeof(HSIC)); + + if (hasFeature(Feature::DISPLAY_MODES)) { + int32_t id; + status_t rc = Utils::readInt(DISPLAY_MODE_DEFAULT, &id); + if (rc != OK || id < 0) { + Utils::writeInt(DISPLAY_MODE_DEFAULT, DEFAULT_DISPLAY_MODE); + } + + auto mode = getDefaultDisplayMode(); + if (mode != nullptr) { + setDisplayMode(mode->id, false); + } + } +} + +Exynos4::~Exynos4() { +} + +status_t Exynos4::getDisplayModes(std::vector>& profiles) { + struct d_mode { + int id; + char name[10]; + }; + + struct d_mode d_mode_profiles[6] = { + { 0, "Dynamic" }, + { 1, "Standard" }, + { 2, "Natural" }, + { 3, "Cinema" }, + { 4, "Adaptive" }, + { 5, "Reading" }, + }; + + for (uint32_t i = 0; i < getNumDisplayModes(); i++) { + const sp m = new disp_mode; + m->id = d_mode_profiles[i].id; + m->name = d_mode_profiles[i].name; + m->privFlags = 0; + profiles.push_back(m); + } + + return OK; +} + +status_t Exynos4::setDisplayMode(int32_t modeID, bool makeDefault) { + if (makeDefault) { + Utils::writeInt(DISPLAY_MODE_DEFAULT, modeID); + } + return Utils::writeInt(DISPLAY_MODE, modeID); +} + +sp Exynos4::getCurrentDisplayMode() { + int32_t id = 0; + + status_t rc = Utils::readInt(DISPLAY_MODE, &id); + if (rc != OK || id < 0) { + return nullptr; + } + return getDisplayModeById(id); +} + +sp Exynos4::getDefaultDisplayMode() { + int32_t id = 0; + status_t rc = Utils::readInt(DISPLAY_MODE_DEFAULT, &id); + if (rc != OK || id < 0) { + return getDisplayModeById(1); + } + return getDisplayModeById(id); +} + +bool Exynos4::hasFeature(Feature feature) { + return feature == Feature::DISPLAY_MODES; +} + +uint32_t Exynos4::getNumDisplayModes() { + int32_t num = 0; + status_t rc = Utils::readInt(DISPLAY_MODE_MAX, &num); + if (rc != OK) { + return 0; + } + return num; +} + +sp Exynos4::getDisplayModeById(int32_t id) { + std::vector> profiles; + status_t rc = getDisplayModes(profiles); + if (rc == OK) { + for (const auto& mode : profiles) { + if (id == mode->id) { + return mode; + } + } + } + + return nullptr; +} + +HSIC Exynos4::getDefaultPictureAdjustment() { + return mDefaultPictureAdjustment; +} + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/exynos4/interfaces/livedisplay/1.0/include/Color.h b/exynos4/interfaces/livedisplay/1.0/include/Color.h new file mode 100644 index 0000000..58b6bbf --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/include/Color.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * Copyright (C) 2017-2018 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. + */ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V1_0_COLOR_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_COLOR_H + +#include + +#include + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_vec; + +using ::vendor::lineage::livedisplay::V1_0::IColor; + +class ColorBackend; + +class Color : public IColor { + public: + Color(); + + Return getSupportedFeatures() override; + + Return getDisplayModes(getDisplayModes_cb _hidl_cb) override; + Return getCurrentDisplayMode(getCurrentDisplayMode_cb _hidl_cb) override; + Return getDefaultDisplayMode(getDefaultDisplayMode_cb _hidl_cb) override; + Return setDisplayMode(int32_t modeID, bool makeDefault) override; + + Return setAdaptiveBacklightEnabled(bool enabled) override; + Return isAdaptiveBacklightEnabled() override; + + Return setOutdoorModeEnabled(bool enabled) override; + Return isOutdoorModeEnabled() override; + + Return getColorBalanceRange(getColorBalanceRange_cb _hidl_cb) override; + Return getColorBalance() override; + Return setColorBalance(int32_t value) override; + + Return setPictureAdjustment(const HSIC& hsic) override; + Return getPictureAdjustment(getPictureAdjustment_cb _hidl_cb) override; + Return getDefaultPictureAdjustment(getDefaultPictureAdjustment_cb _hidl_cb) override; + + Return getHueRange(getHueRange_cb _hidl_cb) override; + Return getSaturationRange(getSaturationRange_cb _hidl_cb) override; + Return getIntensityRange(getIntensityRange_cb _hidl_cb) override; + Return getContrastRange(getContrastRange_cb _hidl_cb) override; + Return getSaturationThresholdRange(getSaturationThresholdRange_cb _hidl_cb) override; + + ~Color(); + + private: + bool connect(); + void reset(); + + uint32_t mFeatures; + bool mConnected; + + bool check(Feature f); + + void error(const char* msg = NULL); + + void addFeature(Feature f) { + mFeatures |= (uint32_t)f; + }; + + std::unique_ptr mBackend; + android::Mutex mLock; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_COLOR_H diff --git a/exynos4/interfaces/livedisplay/1.0/include/ColorBackend.h b/exynos4/interfaces/livedisplay/1.0/include/ColorBackend.h new file mode 100644 index 0000000..c5d06fa --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/include/ColorBackend.h @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2018 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. + */ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V1_0_COLORBACKEND_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_COLORBACKEND_H + +#include "Types.h" + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +class ColorBackend { + public: + virtual android::status_t setAdaptiveBacklightEnabled(bool enabled) = 0; + virtual bool isAdaptiveBacklightEnabled() = 0; + + virtual android::status_t setOutdoorModeEnabled(bool enabled) = 0; + virtual bool isOutdoorModeEnabled() = 0; + + virtual android::status_t getColorBalanceRange(Range& range) = 0; + virtual android::status_t setColorBalance(int32_t balance) = 0; + virtual int32_t getColorBalance() = 0; + + virtual android::status_t getDisplayModes(std::vector>& profiles) = 0; + virtual android::status_t setDisplayMode(int32_t modeID, bool makeDefault) = 0; + virtual android::sp getCurrentDisplayMode() = 0; + virtual android::sp getDefaultDisplayMode() = 0; + + virtual android::status_t getPictureAdjustmentRanges(HSICRanges& ranges) = 0; + virtual android::status_t getPictureAdjustment(HSIC& hsic) = 0; + virtual HSIC getDefaultPictureAdjustment() = 0; + virtual android::status_t setPictureAdjustment(const HSIC& hsic) = 0; + + virtual bool hasFeature(Feature feature) = 0; + + virtual ~ColorBackend() { + } +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_COLORBACKEND_H diff --git a/exynos4/interfaces/livedisplay/1.0/include/Exynos4.h b/exynos4/interfaces/livedisplay/1.0/include/Exynos4.h new file mode 100644 index 0000000..d15b707 --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/include/Exynos4.h @@ -0,0 +1,102 @@ +/* +** Copyright 2016, The CyanogenMod 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. +*/ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V1_0_Exynos4_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_Exynos4_H + +#include "ColorBackend.h" + +#define DEFAULT_DISPLAY_MODE 1 // Standard +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +constexpr char DISPLAY_MODE[] = "/sys/class/mdnie/mdnie/mode"; +constexpr char DISPLAY_MODE_MAX[] = "/sys/class/mdnie/mdnie/mode_max"; +constexpr char DISPLAY_MODE_DEFAULT[] = "/data/misc/.displaymodedefault"; + +class Exynos4 : public ColorBackend { + public: + Exynos4(); + ~Exynos4(); + + virtual android::status_t setAdaptiveBacklightEnabled(bool /* enabled */) override { + return android::NO_INIT; + } + + virtual bool isAdaptiveBacklightEnabled() override { + return false; + } + + virtual android::status_t setOutdoorModeEnabled(bool /* enabled */) override { + return android::NO_INIT; + } + + virtual bool isOutdoorModeEnabled() override { + return false; + } + + virtual android::status_t getColorBalanceRange(Range& /* range */) override { + return android::NO_INIT; + } + + virtual android::status_t setColorBalance(int32_t /* balance */) override { + return android::NO_INIT; + } + + virtual int32_t getColorBalance() override { + return 0; + } + + virtual android::status_t getPictureAdjustmentRanges(HSICRanges& /* ranges */) override { + return android::NO_INIT; + } + + virtual android::status_t getPictureAdjustment(HSIC& /* hsic */) override { + return android::NO_INIT; + } + + virtual HSIC getDefaultPictureAdjustment() override; + + virtual android::status_t setPictureAdjustment(const HSIC& /* hsic */) override { + return android::NO_INIT; + } + + + + virtual android::status_t getDisplayModes(std::vector>& profiles) override; + virtual android::status_t setDisplayMode(int32_t modeID, bool makeDefault) override; + virtual android::sp getCurrentDisplayMode() override; + virtual android::sp getDefaultDisplayMode() override; + + virtual bool hasFeature(Feature feature) override; + + private: + uint32_t getNumDisplayModes(); + android::sp getDisplayModeById(int32_t id); + + HSIC mDefaultPictureAdjustment; +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_Exynos4_H diff --git a/exynos4/interfaces/livedisplay/1.0/include/Types.h b/exynos4/interfaces/livedisplay/1.0/include/Types.h new file mode 100644 index 0000000..4a6f39d --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/include/Types.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2018 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. + */ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V1_0_TYPES_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_TYPES_H + +#include +#include +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +struct disp_mode : public android::RefBase { + int32_t id; + std::string name; + + uint32_t privFlags; + std::string privData; + + disp_mode() : id(-1) { + } +}; + +inline bool isNonZero(Range r) { + return r.min != 0 || r.max != 0; +} + +inline bool isNonZero(FloatRange r) { + return r.min != 0.f || r.max != 0.f; +} + +struct HSICRanges { + HSICRanges() { + } + HSICRanges(Range _hue, FloatRange _saturation, FloatRange _intensity, FloatRange _contrast, + FloatRange _saturationThreshold) + : hue(_hue), + saturation(_saturation), + intensity(_intensity), + contrast(_contrast), + saturationThreshold(_saturationThreshold) { + } + + Range hue; + FloatRange saturation; + FloatRange intensity; + FloatRange contrast; + FloatRange saturationThreshold; + + bool isValid() { + return isNonZero(hue) && isNonZero(saturation) && isNonZero(intensity) && + isNonZero(contrast); + } +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_TYPES_H diff --git a/exynos4/interfaces/livedisplay/1.0/include/Utils.h b/exynos4/interfaces/livedisplay/1.0/include/Utils.h new file mode 100644 index 0000000..5aa9f8a --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/include/Utils.h @@ -0,0 +1,41 @@ +/* +** Copyright 2016, The CyanogenMod Project +** 2017-2018, 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. +*/ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V1_0_UTILS_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_UTILS_H + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +class Utils { + public: + static android::status_t readInt(const char* node, int32_t* value); + static android::status_t writeInt(const char* node, int32_t value); +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_UTILS_H diff --git a/exynos4/interfaces/livedisplay/1.0/include/controller/Exynos4Controller.h b/exynos4/interfaces/livedisplay/1.0/include/controller/Exynos4Controller.h new file mode 100644 index 0000000..24b3fab --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/include/controller/Exynos4Controller.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2018 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. + */ + +#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V1_0_EXYNOS4CONTROLLER_H +#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_EXYNOS4CONTROLLER_H + +#include + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +class Exynos4Controller { + public: + Exynos4Controller(); + + int32_t init(int32_t init); + int32_t get_color_balance_range(int32_t disp_id, void* range); + int32_t set_color_balance(int32_t disp_id, int32_t warmness); + int32_t get_color_balance(int32_t disp_id, int32_t* warmness); + int32_t get_num_display_modes(int32_t disp_id, int32_t mode_type, uint32_t* mode_cnt); + int32_t get_display_modes(int32_t disp_id, int32_t mode_type, void* modes, int32_t mode_cnt); + int32_t get_active_display_mode(int32_t disp_id, int32_t* mode_id, uint32_t* mask); + int32_t set_active_display_mode(int32_t disp_id, int32_t mode_id); + int32_t set_default_display_mode(int32_t disp_id, int32_t mode_id); + int32_t get_default_display_mode(int32_t disp_id, int32_t* mode_id); + int32_t get_pa_range(int32_t disp_id, void* range); + int32_t get_pa_config(int32_t disp_id, void* cfg); + int32_t set_pa_config(int32_t disp_id, void* cfg); + int32_t supported(int32_t disp_id, uint32_t feature_id); + + private: + typedef int32_t (*disp_api_init)(int32_t); + typedef int32_t (*disp_api_get_color_balance_range)(int32_t, void*); + typedef int32_t (*disp_api_set_color_balance)(int32_t, int32_t); + typedef int32_t (*disp_api_get_color_balance)(int32_t, int32_t*); + typedef int32_t (*disp_api_get_num_display_modes)(int32_t, int32_t, uint32_t*); + typedef int32_t (*disp_api_get_display_modes)(int32_t, int32_t, void*, int32_t); + typedef int32_t (*disp_api_get_active_display_mode)(int32_t, int32_t*, uint32_t*); + typedef int32_t (*disp_api_set_active_display_mode)(int32_t, int32_t); + typedef int32_t (*disp_api_set_default_display_mode)(int32_t, int32_t); + typedef int32_t (*disp_api_get_default_display_mode)(int32_t, int32_t*); + typedef int32_t (*disp_api_get_pa_range)(int32_t, void*); + typedef int32_t (*disp_api_get_pa_config)(int32_t, void*); + typedef int32_t (*disp_api_set_pa_config)(int32_t, void*); + typedef int32_t (*disp_api_supported)(int32_t, uint32_t); + +}; + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor + +#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_EXYNOS4CONTROLLER_H diff --git a/exynos4/interfaces/livedisplay/1.0/service.cpp b/exynos4/interfaces/livedisplay/1.0/service.cpp new file mode 100644 index 0000000..87ea7fe --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/service.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2017-2018 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. + */ + +#define LOG_TAG "vendor.lineage.livedisplay@1.0-service-exynos4" + +#include +#include +#include + +#include "Color.h" + +using android::hardware::configureRpcThreadpool; +using android::hardware::joinRpcThreadpool; +using android::OK; +using android::sp; +using android::status_t; + +using ::vendor::lineage::livedisplay::V1_0::IColor; +using ::vendor::lineage::livedisplay::V1_0::implementation::Color; + +int main() { + status_t status; + + LOG(ERROR) << "LiveDisplay HAL service is starting."; + +#ifdef LIVES_IN_SYSTEM + // The LiveDisplay HAL may communicate to other components via /dev/binder + android::ProcessState::initWithDriver("/dev/binder"); +#else + // The LiveDisplay HAL may communicate to other vendor components via /dev/vndbinder + android::ProcessState::initWithDriver("/dev/vndbinder"); +#endif + + android::sp service = new Color(); + if (service == nullptr) { + LOG(ERROR) << "Can not create an instance of LiveDisplay HAL Iface, exiting."; + goto shutdown; + } + + configureRpcThreadpool(1, true /*callerWillJoin*/); + + status = service->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL Iface (" << status << ")"; + goto shutdown; + } + + LOG(INFO) << "LiveDisplay HAL service is ready."; + joinRpcThreadpool(); +// Should not pass this line + +shutdown: + // In normal operation, we don't expect the thread pool to exit + LOG(ERROR) << "LiveDisplay HAL service is shutting down."; + return 1; +} diff --git a/exynos4/interfaces/livedisplay/1.0/src/Color.cpp b/exynos4/interfaces/livedisplay/1.0/src/Color.cpp new file mode 100644 index 0000000..dd54cac --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/src/Color.cpp @@ -0,0 +1,378 @@ +/* + * Copyright (C) 2017-2018 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. + */ + +// #define LOG_NDEBUG 0 + +#define LOG_TAG "LiveDisplay-HIDL" + +#include "Color.h" + +#include "ColorBackend.h" +#include "Exynos4.h" + +#include + +namespace { + +using vendor::lineage::livedisplay::V1_0::DisplayMode; +using vendor::lineage::livedisplay::V1_0::implementation::disp_mode; + +DisplayMode modePointerToObj(android::sp mode) { + DisplayMode m; + m.id = mode->id; + m.name = mode->name; + return m; +} + +DisplayMode invalidDisplayMode() { + DisplayMode mode; + mode.id = -1; + return mode; +} +} // anonymous namespace + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +using ::android::Mutex; +using ::android::NO_INIT; +using ::android::OK; +using ::android::sp; +using ::android::status_t; + +Color::Color() : mConnected(false), mBackend(nullptr) { +} + +Color::~Color() { + reset(); +} + +void Color::reset() { + if (mConnected) { + mBackend = nullptr; + } + mFeatures = 0; + mConnected = false; +} + +bool Color::check(Feature f) { + return connect() && (mFeatures & (uint32_t)f); +} + +void Color::error(const char* msg) { + if (msg != NULL) { + LOG(ERROR) << msg; + } + + reset(); +} + +bool Color::connect() { + if (mConnected) { + return true; + } + + mFeatures = 0; + + mBackend.reset(new Exynos4()); + if (mBackend == nullptr) { + LOG(ERROR) << "Failed to initialize backend!"; + return false; + } + + for (uint32_t i = 1; i <= (uint32_t)Feature::MAX; i <<= 1) { + Feature f = static_cast(i); + if (mBackend->hasFeature(f)) { + addFeature(f); + } + } + mConnected = true; + + return mFeatures > 0; +} + +Return Color::getSupportedFeatures() { + connect(); + return mFeatures; +} + +Return Color::getDisplayModes(getDisplayModes_cb _hidl_cb) { + hidl_vec profiles; + status_t rc = NO_INIT; + Mutex::Autolock _l(mLock); + + if (check(Feature::DISPLAY_MODES)) { + std::vector> spProfiles; + rc = mBackend->getDisplayModes(spProfiles); + if (rc != OK) { + error("Unable to fetch display modes!"); + } else { + profiles.resize(spProfiles.size()); + for (size_t i = 0; i < spProfiles.size(); i++) { + profiles[i].id = spProfiles[i]->id; + profiles[i].name = spProfiles[i]->name; + } + } + } + + _hidl_cb(profiles); + return Void(); +} + +Return Color::getCurrentDisplayMode(getCurrentDisplayMode_cb _hidl_cb) { + DisplayMode mode; + Mutex::Autolock _l(mLock); + + if (check(Feature::DISPLAY_MODES)) { + sp m = mBackend->getCurrentDisplayMode(); + if (m != nullptr) { + mode = modePointerToObj(m); + } else { + mode = invalidDisplayMode(); + } + } + _hidl_cb(mode); + return Void(); +} + +Return Color::getDefaultDisplayMode(getDefaultDisplayMode_cb _hidl_cb) { + DisplayMode mode; + Mutex::Autolock _l(mLock); + + if (check(Feature::DISPLAY_MODES)) { + sp m = mBackend->getDefaultDisplayMode(); + if (m != nullptr) { + mode = modePointerToObj(m); + } else { + mode = invalidDisplayMode(); + } + } + _hidl_cb(mode); + return Void(); +} + +Return Color::setDisplayMode(int32_t modeID, bool makeDefault) { + status_t rc = NO_INIT; + Mutex::Autolock _l(mLock); + + if (check(Feature::DISPLAY_MODES)) { + rc = mBackend->setDisplayMode(modeID, makeDefault); + if (rc != OK) { + error("Unable to set display mode!"); + } + } + return rc == OK; +} + +Return Color::setAdaptiveBacklightEnabled(bool enabled) { + status_t rc = NO_INIT; + Mutex::Autolock _l(mLock); + + if (check(Feature::ADAPTIVE_BACKLIGHT)) { + rc = mBackend->setAdaptiveBacklightEnabled(enabled); + if (rc != OK) { + error("Unable to set adaptive backlight state!"); + } + } + return rc == OK; +} + +Return Color::isAdaptiveBacklightEnabled() { + Mutex::Autolock _l(mLock); + + if (check(Feature::ADAPTIVE_BACKLIGHT)) { + return mBackend->isAdaptiveBacklightEnabled(); + } + return false; +} + +Return Color::setOutdoorModeEnabled(bool enabled) { + status_t rc = NO_INIT; + Mutex::Autolock _l(mLock); + + if (check(Feature::OUTDOOR_MODE)) { + rc = mBackend->setOutdoorModeEnabled(enabled); + if (rc != OK) { + error("Unable to toggle outdoor mode!"); + } + } + return rc == OK; +} + +Return Color::isOutdoorModeEnabled() { + Mutex::Autolock _l(mLock); + + if (check(Feature::OUTDOOR_MODE)) { + return mBackend->isOutdoorModeEnabled(); + } + return false; +} + +Return Color::getColorBalanceRange(getColorBalanceRange_cb _hidl_cb) { + Range range; + Mutex::Autolock _l(mLock); + + if (check(Feature::COLOR_BALANCE)) { + status_t rc = mBackend->getColorBalanceRange(range); + if (rc != OK) { + error("Unable to fetch color balance range!"); + range.max = range.min = 0; + } + } + + _hidl_cb(range); + return Void(); +} + +Return Color::getColorBalance() { + Mutex::Autolock _l(mLock); + + if (check(Feature::COLOR_BALANCE)) { + return mBackend->getColorBalance(); + } + + return 0; +} + +Return Color::setColorBalance(int32_t value) { + status_t rc = NO_INIT; + Mutex::Autolock _l(mLock); + + if (check(Feature::COLOR_BALANCE)) { + rc = mBackend->setColorBalance(value); + if (rc != OK) { + error("Unable to set color balance!"); + } + } + return rc == OK; +} + +Return Color::setPictureAdjustment(const HSIC& hsic) { + status_t rc = NO_INIT; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + rc = mBackend->setPictureAdjustment(hsic); + if (rc != OK) { + error("Unable to set picture adjustment!"); + } + } + return rc == OK; +} + +Return Color::getPictureAdjustment(getPictureAdjustment_cb _hidl_cb) { + HSIC hsic; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + status_t rc = mBackend->getPictureAdjustment(hsic); + if (rc != OK) { + error("Unable to get picture adjustment!"); + } + } + _hidl_cb(hsic); + return Void(); +} + +Return Color::getDefaultPictureAdjustment(getDefaultPictureAdjustment_cb _hidl_cb) { + HSIC hsic; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + hsic = mBackend->getDefaultPictureAdjustment(); + } + _hidl_cb(hsic); + return Void(); +} + +Return Color::getHueRange(getHueRange_cb _hidl_cb) { + HSICRanges ranges; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + status_t rc = mBackend->getPictureAdjustmentRanges(ranges); + if (rc != OK) { + error("Unable to get hue range!"); + } + } + _hidl_cb(ranges.hue); + return Void(); +} + +Return Color::getSaturationRange(getSaturationRange_cb _hidl_cb) { + HSICRanges ranges; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + status_t rc = mBackend->getPictureAdjustmentRanges(ranges); + if (rc != OK) { + error("Unable to get saturation range!"); + } + } + _hidl_cb(ranges.saturation); + return Void(); +} + +Return Color::getIntensityRange(getIntensityRange_cb _hidl_cb) { + HSICRanges ranges; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + status_t rc = mBackend->getPictureAdjustmentRanges(ranges); + if (rc != OK) { + error("Unable to get intensity range!"); + } + } + _hidl_cb(ranges.intensity); + return Void(); +} + +Return Color::getContrastRange(getContrastRange_cb _hidl_cb) { + HSICRanges ranges; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + status_t rc = mBackend->getPictureAdjustmentRanges(ranges); + if (rc != OK) { + error("Unable to get contrast range!"); + } + } + _hidl_cb(ranges.contrast); + return Void(); +} + +Return Color::getSaturationThresholdRange(getSaturationThresholdRange_cb _hidl_cb) { + HSICRanges ranges; + Mutex::Autolock _l(mLock); + + if (check(Feature::PICTURE_ADJUSTMENT)) { + status_t rc = mBackend->getPictureAdjustmentRanges(ranges); + if (rc != OK) { + error("Unable to get saturation threshold range!"); + } + } + _hidl_cb(ranges.saturationThreshold); + return Void(); +} + +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/exynos4/interfaces/livedisplay/1.0/src/Utils.cpp b/exynos4/interfaces/livedisplay/1.0/src/Utils.cpp new file mode 100644 index 0000000..8215172 --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/src/Utils.cpp @@ -0,0 +1,74 @@ +/* +** Copyright 2016, The CyanogenMod Project +** 2017-2018, 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 "Utils.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace vendor { +namespace lineage { +namespace livedisplay { +namespace V1_0 { +namespace implementation { + +using ::android::NO_INIT; +using ::android::OK; +using ::android::status_t; + +status_t Utils::readInt(const char* node, int32_t* value) { + std::string buf; + status_t ret = OK; + std::ifstream fin(node); + if (!fin.good()) { + return errno; + } + fin >> *value; + if (fin.fail()) { + ret = errno; + } + fin.close(); + return ret; +} + +status_t Utils::writeInt(const char* node, int32_t value) { + status_t ret = OK; + std::ofstream fout(node); + if (!fout.good()) { + return errno; + } + fout << value << std::endl; + if (fout.fail()) { + ret = errno; + } + fout.close(); + return ret; +} +} // namespace implementation +} // namespace V1_0 +} // namespace livedisplay +} // namespace lineage +} // namespace vendor diff --git a/exynos4/interfaces/livedisplay/1.0/vendor.lineage.livedisplay@1.0-service-exynos4.rc b/exynos4/interfaces/livedisplay/1.0/vendor.lineage.livedisplay@1.0-service-exynos4.rc new file mode 100644 index 0000000..6642fc7 --- /dev/null +++ b/exynos4/interfaces/livedisplay/1.0/vendor.lineage.livedisplay@1.0-service-exynos4.rc @@ -0,0 +1,4 @@ +service vendor.livedisplay-hal-1-0 /vendor/bin/hw/vendor.lineage.livedisplay@1.0-service-exynos4 + class hal + user system + group system -- cgit v1.2.3