diff options
23 files changed, 0 insertions, 2648 deletions
diff --git a/livedisplay/1.0/Android.bp b/livedisplay/1.0/Android.bp deleted file mode 100644 index 8e8c7fd..0000000 --- a/livedisplay/1.0/Android.bp +++ /dev/null @@ -1,22 +0,0 @@ -// This file is autogenerated by hidl-gen -Landroidbp. - -hidl_interface { - name: "vendor.lineage.livedisplay@1.0", - root: "vendor.lineage", - srcs: [ - "types.hal", - "IColor.hal", - ], - interfaces: [ - "android.hidl.base@1.0", - ], - types: [ - "DisplayMode", - "Feature", - "FloatRange", - "HSIC", - "Range", - ], - gen_java: true, -} - diff --git a/livedisplay/1.0/IColor.hal b/livedisplay/1.0/IColor.hal deleted file mode 100644 index c5788ea..0000000 --- a/livedisplay/1.0/IColor.hal +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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. - */ - -package vendor.lineage.livedisplay@1.0; - -interface IColor { - getSupportedFeatures() generates (Features features); - - getDisplayModes() generates (vec<DisplayMode> modes); - getCurrentDisplayMode() generates (DisplayMode mode); - getDefaultDisplayMode() generates (DisplayMode mode); - setDisplayMode(int32_t modeID, bool makeDefault) generates (bool rc); - - setAdaptiveBacklightEnabled(bool enabled) generates (bool rc); - isAdaptiveBacklightEnabled() generates (bool rc); - - setOutdoorModeEnabled(bool enabled) generates (bool rc); - isOutdoorModeEnabled() generates (bool rc); - - getColorBalanceRange() generates (Range range); - getColorBalance() generates (int32_t value); - setColorBalance(int32_t value) generates (bool rc); - - setPictureAdjustment(HSIC hsic) generates (bool rc); - getPictureAdjustment() generates (HSIC hsic); - getDefaultPictureAdjustment() generates (HSIC hsic); - - getHueRange() generates (Range range); - getSaturationRange() generates (FloatRange range); - getIntensityRange() generates (FloatRange range); - getContrastRange() generates (FloatRange range); - getSaturationThresholdRange() generates (FloatRange range); -}; diff --git a/livedisplay/1.0/default/.clang-format b/livedisplay/1.0/default/.clang-format deleted file mode 100644 index fc4eb1b..0000000 --- a/livedisplay/1.0/default/.clang-format +++ /dev/null @@ -1,13 +0,0 @@ -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/livedisplay/1.0/default/Android.bp b/livedisplay/1.0/default/Android.bp deleted file mode 100644 index 42c18f6..0000000 --- a/livedisplay/1.0/default/Android.bp +++ /dev/null @@ -1,70 +0,0 @@ -// 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_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: "lineage.livedisplay@1.0-service-sdm", - init_rc: ["lineage.livedisplay@1.0-service-sdm.rc"], - defaults: ["livedisplay_defaults"], - cflags: ["-DCOLOR_BACKEND_SDM", "-DLIVES_IN_SYSTEM"], - srcs: [ - "impl/SDM.cpp", - "controller/SDMController.cpp", - ], -} - -cc_binary { - name: "vendor.lineage.livedisplay@1.0-service-legacymm", - init_rc: ["vendor.lineage.livedisplay@1.0-service-legacymm.rc"], - defaults: ["livedisplay_defaults"], - proprietary: true, - cflags: ["-DCOLOR_BACKEND_LEGACYMM"], - srcs: [ - "impl/LegacyMM.cpp", - "controller/LegacyMMController.cpp", - ], -} - -cc_binary { - name: "vendor.lineage.livedisplay@1.0-service-sdm", - init_rc: ["vendor.lineage.livedisplay@1.0-service-sdm.rc"], - defaults: ["livedisplay_defaults"], - proprietary: true, - cflags: ["-DCOLOR_BACKEND_SDM"], - srcs: [ - "impl/SDM.cpp", - "controller/SDMController.cpp", - ], -} diff --git a/livedisplay/1.0/default/controller/LegacyMMController.cpp b/livedisplay/1.0/default/controller/LegacyMMController.cpp deleted file mode 100644 index 403692b..0000000 --- a/livedisplay/1.0/default/controller/LegacyMMController.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * 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. - */ - -// #define LOG_NDEBUG 0 - -#define LOG_TAG "LiveDisplay-LegacyMM-Impl" - -#include "controller/LegacyMMController.h" - -#include <android-base/logging.h> - -#include <dlfcn.h> - -#define LOAD_MM_FUNCTION(name) \ - mFn_##name = loadFunction<disp_api_##name>(mHandle, "disp_api_" #name); - -#define CLOSE_MM_FUNCTION(name) mFn_##name = nullptr; - -#define FOR_EACH_FUNCTION(MACRO) \ - MACRO(init) \ - MACRO(get_color_balance_range) \ - MACRO(set_color_balance) \ - MACRO(get_color_balance) \ - MACRO(get_num_display_modes) \ - MACRO(get_display_modes) \ - MACRO(get_active_display_mode) \ - MACRO(set_active_display_mode) \ - MACRO(set_default_display_mode) \ - MACRO(get_default_display_mode) \ - MACRO(get_pa_range) \ - MACRO(get_pa_config) \ - MACRO(set_pa_config) \ - MACRO(supported) - -#define CONTROLLER_CHECK(function, ...) \ - if (mFn_##function == nullptr) { \ - return -1; \ - } \ - int err = mFn_##function(__VA_ARGS__); \ - if (err != 0) { \ - return err; \ - } \ - return 0; - -namespace { -constexpr char kFilename[] = "libmm-disp-apis.so"; -template <typename Function> -Function loadFunction(std::shared_ptr<void> handle, const char* name) { - void* fn = dlsym(handle.get(), name); - if (fn == nullptr) { - LOG(ERROR) << "loadFunction -- failed to load function " << name; - } - return reinterpret_cast<Function>(fn); -} -} // anonymous namespace - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V1_0 { -namespace implementation { - -LegacyMMController::LegacyMMController() { - std::shared_ptr<void> handle(dlopen(kFilename, RTLD_NOW), [this](void* p) { - FOR_EACH_FUNCTION(CLOSE_MM_FUNCTION) - if (p != nullptr) { - int err = dlclose(p); - p = nullptr; - if (err != 0) { - LOG(ERROR) << "DLCLOSE failed for " << kFilename; - } - } - }); - if (handle == nullptr) { - LOG(ERROR) << "DLOPEN failed for " << kFilename << " (" << dlerror() << ")"; - return; - } - mHandle = handle; - - FOR_EACH_FUNCTION(LOAD_MM_FUNCTION); -} - -int32_t LegacyMMController::init(int32_t initialize) { - CONTROLLER_CHECK(init, initialize); -} - -int32_t LegacyMMController::get_color_balance_range(int32_t disp_id, void* range) { - CONTROLLER_CHECK(get_color_balance_range, disp_id, range); -} - -int32_t LegacyMMController::set_color_balance(int32_t disp_id, int32_t warmness) { - CONTROLLER_CHECK(set_color_balance, disp_id, warmness); -} - -int32_t LegacyMMController::get_color_balance(int32_t disp_id, int32_t* warmness) { - CONTROLLER_CHECK(get_color_balance, disp_id, warmness); -} - -int32_t LegacyMMController::get_num_display_modes(int32_t disp_id, int32_t mode_type, - uint32_t* mode_cnt) { - CONTROLLER_CHECK(get_num_display_modes, disp_id, mode_type, mode_cnt); -} - -int32_t LegacyMMController::get_display_modes(int32_t disp_id, int32_t mode_type, void* modes, - int32_t mode_cnt) { - CONTROLLER_CHECK(get_display_modes, disp_id, mode_type, modes, mode_cnt); -} - -int32_t LegacyMMController::get_active_display_mode(int32_t disp_id, int32_t* mode_id, - uint32_t* mask) { - CONTROLLER_CHECK(get_active_display_mode, disp_id, mode_id, mask); -} - -int32_t LegacyMMController::set_active_display_mode(int32_t disp_id, int32_t mode_id) { - CONTROLLER_CHECK(set_active_display_mode, disp_id, mode_id); -} - -int32_t LegacyMMController::set_default_display_mode(int32_t disp_id, int32_t mode_id) { - CONTROLLER_CHECK(set_default_display_mode, disp_id, mode_id); -} - -int32_t LegacyMMController::get_default_display_mode(int32_t disp_id, int32_t* mode_id) { - CONTROLLER_CHECK(get_default_display_mode, disp_id, mode_id); -} - -int32_t LegacyMMController::get_pa_range(int32_t disp_id, void* range) { - CONTROLLER_CHECK(get_pa_range, disp_id, range); -} - -int32_t LegacyMMController::get_pa_config(int32_t disp_id, void* cfg) { - CONTROLLER_CHECK(get_pa_config, disp_id, cfg); -} - -int32_t LegacyMMController::set_pa_config(int32_t disp_id, void* cfg) { - CONTROLLER_CHECK(set_pa_config, disp_id, cfg); -} - -int32_t LegacyMMController::supported(int32_t disp_id, uint32_t feature_id) { - CONTROLLER_CHECK(supported, disp_id, feature_id); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor diff --git a/livedisplay/1.0/default/controller/SDMController.cpp b/livedisplay/1.0/default/controller/SDMController.cpp deleted file mode 100644 index 8d4f69a..0000000 --- a/livedisplay/1.0/default/controller/SDMController.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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. - */ - -#include "controller/SDMController.h" - -#include <android-base/logging.h> - -#include <dlfcn.h> - -#define LOAD_SDM_FUNCTION(name) \ - mFn_##name = loadFunction<disp_api_##name>(mHandle, "disp_api_" #name); - -#define CLOSE_SDM_FUNCTION(name) mFn_##name = nullptr; - -#define FOR_EACH_FUNCTION(MACRO) \ - MACRO(init) \ - MACRO(deinit) \ - MACRO(get_global_color_balance_range) \ - MACRO(set_global_color_balance) \ - MACRO(get_global_color_balance) \ - MACRO(get_num_display_modes) \ - MACRO(get_display_modes) \ - MACRO(get_active_display_mode) \ - MACRO(set_active_display_mode) \ - MACRO(set_default_display_mode) \ - MACRO(get_default_display_mode) \ - MACRO(get_global_pa_range) \ - MACRO(get_global_pa_config) \ - MACRO(set_global_pa_config) \ - MACRO(get_feature_version) - -#define CONTROLLER_CHECK(function, ...) \ - if (mFn_##function == nullptr) { \ - return -1; \ - } \ - int err = mFn_##function(__VA_ARGS__); \ - if (err != 0) { \ - return err; \ - } \ - return 0; - -namespace { -#ifdef LIVES_IN_SYSTEM -constexpr char kFilename[] = "libsdm-disp-apis.so"; -#else -constexpr char kFilename[] = "libsdm-disp-vndapis.so"; -#endif - -template <typename Function> -Function loadFunction(std::shared_ptr<void> handle, const char* name) { - void* fn = dlsym(handle.get(), name); - if (fn == nullptr) { - LOG(ERROR) << "loadFunction -- failed to load function " << name; - } - return reinterpret_cast<Function>(fn); -} -} // anonymous namespace - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V1_0 { -namespace implementation { - -SDMController::SDMController() { - std::shared_ptr<void> handle(dlopen(kFilename, RTLD_NOW), [this](void* p) { - FOR_EACH_FUNCTION(CLOSE_SDM_FUNCTION) - if (p != nullptr) { - int err = dlclose(p); - p = nullptr; - if (err != 0) { - LOG(ERROR) << "DLCLOSE failed for " << kFilename; - } - } - }); - if (handle == nullptr) { - LOG(ERROR) << "DLOPEN failed for " << kFilename << " (" << dlerror() << ")"; - return; - } - mHandle = handle; - - FOR_EACH_FUNCTION(LOAD_SDM_FUNCTION) -} - -int32_t SDMController::init(uint64_t* hctx, uint32_t flags) { - CONTROLLER_CHECK(init, hctx, flags); -} - -int32_t SDMController::deinit(uint64_t hctx, uint32_t flags) { - CONTROLLER_CHECK(deinit, hctx, flags); -} - -int32_t SDMController::get_global_color_balance_range(uint64_t hctx, uint32_t disp_id, void* range) { - CONTROLLER_CHECK(get_global_color_balance_range, hctx, disp_id, range); -} - -int32_t SDMController::set_global_color_balance(uint64_t hctx, uint32_t disp_id, int32_t warmness, - uint32_t flags) { - CONTROLLER_CHECK(set_global_color_balance, hctx, disp_id, warmness, flags); -} - -int32_t SDMController::get_global_color_balance(uint64_t hctx, uint32_t disp_id, int32_t* warmness, - uint32_t* flags) { - CONTROLLER_CHECK(get_global_color_balance, hctx, disp_id, warmness, flags); -} - -int32_t SDMController::get_num_display_modes(uint64_t hctx, uint32_t disp_id, uint32_t mode_type, - int32_t* mode_cnt, uint32_t* flags) { - CONTROLLER_CHECK(get_num_display_modes, hctx, disp_id, mode_type, mode_cnt, flags); -} - -int32_t SDMController::get_display_modes(uint64_t hctx, uint32_t disp_id, uint32_t mode_type, - void* modes, int32_t mode_cnt, uint32_t* flags) { - CONTROLLER_CHECK(get_display_modes, hctx, disp_id, mode_type, modes, mode_cnt, flags); -} - -int32_t SDMController::get_active_display_mode(uint64_t hctx, uint32_t disp_id, int32_t* mode_id, - uint32_t* mask, uint32_t* flags) { - CONTROLLER_CHECK(get_active_display_mode, hctx, disp_id, mode_id, mask, flags); -} - -int32_t SDMController::set_active_display_mode(uint64_t hctx, uint32_t disp_id, int32_t mode_id, - uint32_t flags) { - CONTROLLER_CHECK(set_active_display_mode, hctx, disp_id, mode_id, flags); -} - -int32_t SDMController::set_default_display_mode(uint64_t hctx, uint32_t disp_id, int32_t mode_id, - uint32_t flags) { - CONTROLLER_CHECK(set_default_display_mode, hctx, disp_id, mode_id, flags); -} - -int32_t SDMController::get_default_display_mode(uint64_t hctx, uint32_t disp_id, int32_t* mode_id, - uint32_t* flags) { - CONTROLLER_CHECK(get_default_display_mode, hctx, disp_id, mode_id, flags); -} - -int32_t SDMController::get_global_pa_range(uint64_t hctx, uint32_t disp_id, void* range) { - CONTROLLER_CHECK(get_global_pa_range, hctx, disp_id, range); -} - -int32_t SDMController::get_global_pa_config(uint64_t hctx, uint32_t disp_id, uint32_t* enable, - void* cfg) { - CONTROLLER_CHECK(get_global_pa_config, hctx, disp_id, enable, cfg); -} - -int32_t SDMController::set_global_pa_config(uint64_t hctx, uint32_t disp_id, uint32_t enable, - void* cfg) { - CONTROLLER_CHECK(set_global_pa_config, hctx, disp_id, enable, cfg); -} - -int32_t SDMController::get_feature_version(uint64_t hctx, uint32_t feature_id, void* ver, - uint32_t* flags) { - CONTROLLER_CHECK(get_feature_version, hctx, feature_id, ver, flags); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor diff --git a/livedisplay/1.0/default/impl/LegacyMM.cpp b/livedisplay/1.0/default/impl/LegacyMM.cpp deleted file mode 100644 index ce613a8..0000000 --- a/livedisplay/1.0/default/impl/LegacyMM.cpp +++ /dev/null @@ -1,353 +0,0 @@ -/* -** 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-LegacyMM" - -#include "impl/LegacyMM.h" - -#include "controller/LegacyMMController.h" -#include "Utils.h" - -#include <android-base/logging.h> - -namespace { -struct mm_pa_data { - int hue; - int saturation; - int intensity; - int contrast; - int saturationThreshold; -}; - -struct mm_pa_config { - int flags; - struct mm_pa_data data; -}; - -struct mm_pa_range { - struct mm_pa_data max; - struct mm_pa_data min; -}; - -struct mm_range { - int max; - int min; -}; -} // anonymous namespace - -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; - -LegacyMM::LegacyMM() { - memset(&mDefaultPictureAdjustment, 0, sizeof(HSIC)); - - mController = std::make_unique<LegacyMMController>(); - if (mController == nullptr) { - LOG(ERROR) << "Failed to create LegacyMMController"; - return; - } - - status_t rc = mController->init(0); - if (rc != OK) { - LOG(ERROR) << "Failed to initialize LegacyMMController"; - return; - } - - if (hasFeature(Feature::DISPLAY_MODES)) { - int32_t id; - // Get the initial mode from Utils - rc = Utils::readInitialModeId(&id); - if (rc != OK || id < 0) { - // Get controller default mode and save it - rc = mController->get_default_display_mode(0, &id); - if (rc == OK && id >= 0) { - Utils::writeInitialModeId(id); - } else { - Utils::writeInitialModeId(0); - } - } - - auto mode = getDefaultDisplayMode(); - if (mode != nullptr) { - setDisplayMode(mode->id, false); - } - } -} - -LegacyMM::~LegacyMM() { - status_t rc = mController->init(1); - if (rc != OK) { - LOG(ERROR) << "Failed to deinitialize LegacyMMController"; - } -} - -status_t LegacyMM::getColorBalanceRange(Range& range) { - struct mm_range r; - memset(&r, 0, sizeof(struct mm_range)); - - status_t rc = mController->get_color_balance_range(0, &r); - if (rc == OK) { - range.min = r.min; - range.max = r.max; - } - return rc; -} - -status_t LegacyMM::setColorBalance(int32_t balance) { - return mController->set_color_balance(0, balance); -} - -int32_t LegacyMM::getColorBalance() { - int32_t value = 0; - if (mController->get_color_balance(0, &value) != 0) { - value = 0; - } - return value; -} - -status_t LegacyMM::getDisplayModes(std::vector<sp<disp_mode>>& profiles) { - status_t rc = OK; - - uint32_t count = getNumDisplayModes(); - - if (!count) { - return rc; - } - - struct d_mode { - int id; - char* name; - uint32_t len; - int32_t type; - d_mode() : id(-1), len(128), type(0) { - name = new char[128]; - } - ~d_mode() { - delete name; - } - }; - - d_mode tmp[count]; - - rc = mController->get_display_modes(0, 0, tmp, count); - if (rc == 0) { - for (uint32_t i = 0; i < count; i++) { - const sp<disp_mode> m = new disp_mode; - m->id = tmp[i].id; - m->name = tmp[i].name; - m->privFlags = 0; // TODO: fix flag - profiles.push_back(m); - } - } - - return rc; -} - -status_t LegacyMM::setDisplayMode(int32_t modeID, bool makeDefault) { - auto currentMode = getCurrentDisplayMode(); - if (currentMode != nullptr && currentMode->id == modeID) { - return OK; - } - - auto mode = getDisplayModeById(modeID); - if (mode == nullptr) { - return BAD_VALUE; - } - - if (mController->set_active_display_mode(0, modeID) != 0) { - return BAD_VALUE; - } - - if (makeDefault && mController->set_default_display_mode(0, modeID) != 0) { - return BAD_VALUE; - } - - HSIC tmp; - if (getPictureAdjustment(tmp) == OK) { - mDefaultPictureAdjustment = tmp; - } - - return OK; -} - -sp<disp_mode> LegacyMM::getCurrentDisplayMode() { - int32_t id = 0; - uint32_t mask = 0; - - status_t rc = mController->get_active_display_mode(0, &id, &mask); - if (rc == OK && id >= 0) { - return getDisplayModeById(id); - } - - return nullptr; -} - -sp<disp_mode> LegacyMM::getDefaultDisplayMode() { - int32_t id = 0; - - if (Utils::readLocalModeId(&id) == OK && id >= 0) { - return getDisplayModeById(id); - } - if (Utils::readInitialModeId(&id) == OK && id >= 0) { - return getDisplayModeById(id); - } - - status_t rc = mController->get_default_display_mode(0, &id); - if (rc == OK && id >= 0) { - return getDisplayModeById(id); - } - - return nullptr; -} - -status_t LegacyMM::getPictureAdjustmentRanges(HSICRanges& ranges) { - struct mm_pa_range r; - memset(&r, 0, sizeof(struct mm_pa_range)); - - status_t rc = mController->get_pa_range(0, &r); - if (rc == OK) { - ranges.hue.min = r.min.hue; - ranges.hue.max = r.max.hue; - ranges.hue.step = 1; - ranges.saturation.min = r.min.saturation; - ranges.saturation.max = r.max.saturation; - ranges.saturation.step = 1; - ranges.intensity.min = r.min.intensity; - ranges.intensity.max = r.max.intensity; - ranges.intensity.step = 1; - ranges.contrast.min = r.min.contrast; - ranges.contrast.max = r.max.contrast; - ranges.contrast.step = 1; - ranges.saturationThreshold.min = r.min.saturationThreshold; - ranges.saturationThreshold.max = r.max.saturationThreshold; - ranges.saturationThreshold.step = 1; - } - return rc; -} - -status_t LegacyMM::getPictureAdjustment(HSIC& hsic) { - struct mm_pa_config config; - memset(&config, 0, sizeof(struct mm_pa_config)); - - status_t rc = mController->get_pa_config(0, &config); - if (rc == OK) { - hsic.hue = config.data.hue; - hsic.saturation = config.data.saturation; - hsic.intensity = config.data.intensity; - hsic.contrast = config.data.contrast; - hsic.saturationThreshold = config.data.saturationThreshold; - } - return rc; -} - -HSIC LegacyMM::getDefaultPictureAdjustment() { - return mDefaultPictureAdjustment; -} - -status_t LegacyMM::setPictureAdjustment(const HSIC& hsic) { - struct mm_pa_config config; - memset(&config, 0, sizeof(struct mm_pa_config)); - - config.flags = 0x0F; // lower 4 bits - config.data.hue = hsic.hue; - config.data.saturation = hsic.saturation; - config.data.intensity = hsic.intensity; - config.data.contrast = hsic.contrast; - config.data.saturationThreshold = hsic.saturationThreshold; - - return mController->set_pa_config(0, &config); -} - -bool LegacyMM::hasFeature(Feature feature) { - uint32_t id; - switch (feature) { - case Feature::COLOR_BALANCE: - id = 0; - break; - case Feature::DISPLAY_MODES: - id = 1; - break; - case Feature::PICTURE_ADJUSTMENT: - id = 4; - break; - default: - return false; - } - - if (mController->supported(0, id)) { - // display modes and color balance depend on each other - if (feature == Feature::DISPLAY_MODES || feature == Feature::COLOR_BALANCE) { - if (getNumDisplayModes() > 0) { - // make sure the range isn't zero - if (feature == Feature::COLOR_BALANCE) { - Range r; - if (getColorBalanceRange(r) == OK && isNonZero(r)) { - return true; - } - return false; - } - return true; - } - } - if (feature == Feature::PICTURE_ADJUSTMENT) { - HSICRanges r; - if (getPictureAdjustmentRanges(r) == OK && r.isValid()) { - return true; - } - } - } - return false; -} - -uint32_t LegacyMM::getNumDisplayModes() { - uint32_t count = 0; - if (mController->get_num_display_modes(0, 0, &count) != 0) { - count = 0; - } - return count; -} - -sp<disp_mode> LegacyMM::getDisplayModeById(int32_t id) { - std::vector<sp<disp_mode>> profiles; - status_t rc = getDisplayModes(profiles); - if (rc == OK) { - for (const auto& mode : profiles) { - if (id == mode->id) { - return mode; - } - } - } - - return nullptr; -} - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor diff --git a/livedisplay/1.0/default/impl/SDM.cpp b/livedisplay/1.0/default/impl/SDM.cpp deleted file mode 100644 index 8c3cf11..0000000 --- a/livedisplay/1.0/default/impl/SDM.cpp +++ /dev/null @@ -1,485 +0,0 @@ -/* - * Copyright (C) 2016 The CyanogenMod Project - * Copyright (C) 2017-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. - */ - -// #define LOG_NDEBUG 0 - -#define LOG_TAG "LiveDisplay-SDM" - -#include "impl/SDM.h" - -#include "Utils.h" -#include "controller/SDMController.h" - -#include <android-base/logging.h> -#include <android-base/properties.h> - -namespace { -constexpr int kDppsBufSize = 64; - -enum { - FEATURE_VER_SW_PA_API = 0x00000001, - FEATURE_VER_SW_SAVEMODES_API = 0x00000004, -}; - -constexpr char kFossProperty[] = "ro.vendor.display.foss"; -constexpr char kFossOn[] = "foss:on"; -constexpr char kFossOff[] = "foss:off"; - -// For use when only sysfs modes are available -constexpr int kStandardNodeId = 600; - -constexpr char kSrgbNode[] = "/sys/class/graphics/fb0/srgb"; -constexpr int kSrgbNodeId = 601; - -constexpr char kDciP3Node[] = "/sys/class/graphics/fb0/dci_p3"; -constexpr int kDciP3NodeId = 602; - -enum { - PRIV_MODE_FLAG_SDM = 1, - PRIV_MODE_FLAG_SYSFS, -}; - -struct hsic_config { - uint32_t flags; - vendor::lineage::livedisplay::V1_0::HSIC data; -}; - -struct hsic_float_range { - float max; - float min; - float step; -}; - -struct hsic_int_range { - int32_t max; - int32_t min; - uint32_t step; -}; - -struct hsic_ranges { - uint32_t flags; - struct hsic_int_range hue; - struct hsic_float_range saturation; - struct hsic_float_range intensity; - struct hsic_float_range contrast; - struct hsic_float_range saturationThreshold; -}; -} // anonymous namespace - -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; - -SDM::SDM() : mActiveModeId(-1) { - memset(&mDefaultPictureAdjustment, 0, sizeof(HSIC)); - - mController = std::make_unique<SDMController>(); - if (mController == nullptr) { - LOG(ERROR) << "Failed to create SDMController"; - return; - } - - status_t rc = mController->init(&mHandle, 0); - if (rc != OK) { - LOG(ERROR) << "Failed to initialize SDMController"; - return; - } - - if (hasFeature(Feature::DISPLAY_MODES)) { - rc = saveInitialDisplayMode(); - if (rc != OK) { - LOG(ERROR) << "Failed to save initial display mode! err=" << rc; - return; - } - sp<disp_mode> defMode = getDefaultDisplayMode(); - if (defMode != nullptr) { - setDisplayMode(defMode->id, false); - } - } - - mFOSSEnabled = android::base::GetBoolProperty(kFossProperty, false); -} - -SDM::~SDM() { - mController->deinit(mHandle, 0); -} - -uint32_t SDM::getNumSDMDisplayModes() { - uint32_t flags = 0; - int32_t count = 0; - if (mController->get_num_display_modes(mHandle, 0, 0, &count, &flags)) { - count = 0; - } - return count; -} - -uint32_t SDM::getNumDisplayModes() { - int32_t count = getNumSDMDisplayModes(); - if (getLocalSRGBMode() != nullptr) { - count++; - } - if (getLocalDCIP3Mode() != nullptr) { - count++; - } - return count; -} - -sp<disp_mode> SDM::getDisplayModeById(int32_t id) { - std::vector<sp<disp_mode>> profiles; - status_t rc = getDisplayModes(profiles); - if (rc == OK) { - for (const auto& mode : profiles) { - if (id == mode->id) { - return mode; - } - } - } - - return nullptr; -} - -status_t SDM::setModeState(sp<disp_mode> mode, bool state) { - int32_t id = 0; - - if (mode->privFlags == PRIV_MODE_FLAG_SYSFS) { - if (mode->id != kStandardNodeId) { - LOG(VERBOSE) << "sysfs node: " << mode->privData << " state=" << state; - return Utils::writeInt(mode->privData.c_str(), state ? 1 : 0); - } else { - // NOOP - return OK; - } - } else if (mode->privFlags == PRIV_MODE_FLAG_SDM) { - if (state) { - return mController->set_active_display_mode(mHandle, 0, mode->id, 0); - } else { - if (Utils::readInitialModeId(&id) == OK) { - LOG(VERBOSE) << "set sdm mode to default: id" << id; - return mController->set_active_display_mode(mHandle, 0, id, 0); - } - } - } - return BAD_VALUE; -} - -status_t SDM::getDisplayModes(std::vector<sp<disp_mode>>& profiles) { - status_t rc = OK; - - uint32_t count = getNumDisplayModes(); - if (!count) return rc; - - uint32_t sdm_count = getNumSDMDisplayModes(); - - if (sdm_count == 0) { - // sysfs only case, create a dummy standard mode - const sp<disp_mode> m = new disp_mode; - m->id = kStandardNodeId; - m->name = "standard"; - m->privFlags = PRIV_MODE_FLAG_SYSFS; - m->privData = ""; - profiles.push_back(m); - } else { - struct sdm_mode { - int32_t id; - int32_t type; - int32_t len; - char* name; - sdm_mode() : id(-1), type(0), len(128) { - name = new char[128]; - } - ~sdm_mode() { - delete name; - } - }; - - sdm_mode tmp[sdm_count]; - - uint32_t flags = 0; - rc = mController->get_display_modes(mHandle, 0, 0, tmp, sdm_count, &flags); - if (rc == 0) { - for (uint32_t i = 0; i < sdm_count; i++) { - const sp<disp_mode> m = new disp_mode; - m->id = tmp[i].id; - m->name = tmp[i].name; - m->privFlags = PRIV_MODE_FLAG_SDM; - profiles.push_back(m); - } - } - } - - sp<disp_mode> srgb = getLocalSRGBMode(); - sp<disp_mode> dci_p3 = getLocalDCIP3Mode(); - if (srgb != nullptr) { - profiles.push_back(srgb); - } - if (dci_p3 != nullptr) { - profiles.push_back(dci_p3); - } - - return rc; -} - -sp<disp_mode> SDM::getCurrentDisplayMode() { - return getDisplayModeById(mActiveModeId); -} - -sp<disp_mode> SDM::getDefaultDisplayMode() { - int32_t id = 0; - if (Utils::readLocalModeId(&id) == OK && id >= 0) { - return getDisplayModeById(id); - } - if (Utils::readInitialModeId(&id) == OK && id >= 0) { - return getDisplayModeById(id); - } - return nullptr; -} - -sp<disp_mode> SDM::getLocalSRGBMode() { - if (access(kSrgbNode, W_OK) != 0) { - return nullptr; - } - sp<disp_mode> m = new disp_mode; - m->id = kSrgbNodeId; - m->name = "srgb"; - m->privFlags = PRIV_MODE_FLAG_SYSFS; - m->privData = kSrgbNode; - return m; -} - -sp<disp_mode> SDM::getLocalDCIP3Mode() { - if (access(kDciP3Node, W_OK) != 0) { - return nullptr; - } - sp<disp_mode> m = new disp_mode; - m->id = kDciP3NodeId; - m->name = "dci_p3"; - m->privFlags = PRIV_MODE_FLAG_SYSFS; - m->privData = kDciP3Node; - return m; -} - -status_t SDM::getPictureAdjustmentRanges(HSICRanges& ranges) { - hsic_ranges r; - memset(&r, 0, sizeof(struct hsic_ranges)); - - status_t rc = mController->get_global_pa_range(mHandle, 0, &r); - if (rc == OK) { - ranges.hue.min = r.hue.min; - ranges.hue.max = r.hue.max; - ranges.hue.step = r.hue.step; - ranges.saturation.min = r.saturation.min; - ranges.saturation.max = r.saturation.max; - ranges.saturation.step = r.saturation.step; - ranges.intensity.min = r.intensity.min; - ranges.intensity.max = r.intensity.max; - ranges.intensity.step = r.intensity.step; - ranges.contrast.min = r.contrast.min; - ranges.contrast.max = r.contrast.max; - ranges.contrast.step = r.contrast.step; - ranges.saturationThreshold.min = r.saturationThreshold.min; - ranges.saturationThreshold.max = r.saturationThreshold.max; - ranges.saturationThreshold.step = r.saturationThreshold.step; - } - return rc; -} - -bool SDM::hasFeature(Feature feature) { - uint32_t id = 0, flags = 0; - struct version { - uint8_t x, y; - uint16_t z; - }; - version v; - - switch (feature) { - case Feature::DISPLAY_MODES: - id = FEATURE_VER_SW_SAVEMODES_API; - break; - case Feature::PICTURE_ADJUSTMENT: - id = FEATURE_VER_SW_PA_API; - break; - case Feature::ADAPTIVE_BACKLIGHT: - if (mFOSSEnabled) { - return true; - } - break; - default: - return false; - } - - if (mController->get_feature_version(mHandle, id, &v, &flags) != OK) { - return false; - } - - if (v.x <= 0 && v.y <= 0 && v.z <= 0) { - return false; - } - - if (feature == Feature::DISPLAY_MODES) { - return getNumDisplayModes() > 0; - } else if (feature == Feature::PICTURE_ADJUSTMENT) { - HSICRanges r; - if (getPictureAdjustmentRanges(r) == OK && r.isValid()) { - return true; - } - } - - return false; -} - -status_t SDM::saveInitialDisplayMode() { - int32_t id = 0; - uint32_t flags = 0; - if (Utils::readInitialModeId(&id) != OK || id < 0) { - if (mController->get_default_display_mode(mHandle, 0, &id, &flags) == OK && - id >= 0) { - return Utils::writeInitialModeId(id); - } else { - return Utils::writeInitialModeId(0); - } - } - return OK; -} - -status_t SDM::getPictureAdjustment(HSIC& hsic) { - uint32_t enable = 0; - hsic_config config; - memset(&config, 0, sizeof(struct hsic_config)); - - status_t rc = mController->get_global_pa_config(mHandle, 0, &enable, &config); - if (rc == OK) { - hsic.hue = config.data.hue; - hsic.saturation = config.data.saturation; - hsic.intensity = config.data.intensity; - hsic.contrast = config.data.contrast; - hsic.saturationThreshold = config.data.saturationThreshold; - } - return rc; -} - -status_t SDM::setDisplayMode(int32_t modeID, bool makeDefault) { - status_t rc = OK; - - if (modeID == mActiveModeId) { - return rc; - } - - sp<disp_mode> mode = getDisplayModeById(modeID); - if (mode == nullptr) { - return BAD_VALUE; - } - - LOG(DEBUG) << "setDisplayMode: current mode=" << mActiveModeId; - - if (mActiveModeId >= 0) { - sp<disp_mode> oldMode = getCurrentDisplayMode(); - LOG(DEBUG) << "setDisplayMode: oldMode=" << oldMode->id << " flags=" << oldMode->privFlags; - if (oldMode->privFlags == PRIV_MODE_FLAG_SYSFS || mode->privFlags == PRIV_MODE_FLAG_SYSFS) { - LOG(DEBUG) << "disabling old mode"; - rc = setModeState(oldMode, false); - if (rc != OK) { - LOG(ERROR) << "Failed to disable previous mode! err=" << rc; - return rc; - } - } - } - - rc = setModeState(mode, true); - if (rc == OK) { - mActiveModeId = mode->id; - if (makeDefault) { - rc = Utils::writeLocalModeId(mode->id); - if (rc != OK) { - LOG(ERROR) << "failed to save mode! err=" << rc; - return rc; - } - if (mode->privFlags == PRIV_MODE_FLAG_SDM) { - rc = mController->set_default_display_mode(mHandle, 0, mode->id, 0); - if (rc != OK) { - LOG(ERROR) << "failed to save mode! err=" << rc; - return rc; - } - } - } - HSIC tmp; - rc = getPictureAdjustment(tmp); - if (rc != OK) { - LOG(ERROR) << "failed to retrieve picture adjustment after mode setting!"; - } else { - LOG(DEBUG) << "new default PA: " << tmp.hue << " " << tmp.saturation << " " - << tmp.intensity << " " << tmp.contrast << " " << tmp.saturationThreshold; - mDefaultPictureAdjustment = tmp; - } - } else { - LOG(ERROR) << "Failed to setModeState! err=" << rc; - return rc; - } - - LOG(DEBUG) << "setDisplayMode: " << modeID << " default: " << makeDefault - << " flags: " << mode->privFlags; - return OK; -} - -status_t SDM::setAdaptiveBacklightEnabled(bool enabled) { - status_t rc = NO_INIT; - if (enabled == mCachedFOSSStatus) { - return OK; - } - char buf[kDppsBufSize]; - sprintf(buf, "%s", enabled ? kFossOn : kFossOff); - if (Utils::sendDPPSCommand(buf, kDppsBufSize) == OK) { - if (strncmp(buf, "Success", 7) == 0) { - rc = OK; - mCachedFOSSStatus = enabled; - } - } - return rc; -} - -bool SDM::isAdaptiveBacklightEnabled() { - return mCachedFOSSStatus; -} - -status_t SDM::setPictureAdjustment(const HSIC& hsic) { - hsic_config config; - memset(&config, 0, sizeof(struct hsic_config)); - config.data.hue = hsic.hue; - config.data.saturation = hsic.saturation; - config.data.intensity = hsic.intensity; - config.data.contrast = hsic.contrast; - config.data.saturationThreshold = hsic.saturationThreshold; - - return mController->set_global_pa_config(mHandle, 0, 1, &config); -} - -HSIC SDM::getDefaultPictureAdjustment() { - return mDefaultPictureAdjustment; -} - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor diff --git a/livedisplay/1.0/default/include/Color.h b/livedisplay/1.0/default/include/Color.h deleted file mode 100644 index 58b6bbf..0000000 --- a/livedisplay/1.0/default/include/Color.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 <vendor/lineage/livedisplay/1.0/IColor.h> - -#include <utils/Mutex.h> - -#include <memory> - -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<Features> getSupportedFeatures() override; - - Return<void> getDisplayModes(getDisplayModes_cb _hidl_cb) override; - Return<void> getCurrentDisplayMode(getCurrentDisplayMode_cb _hidl_cb) override; - Return<void> getDefaultDisplayMode(getDefaultDisplayMode_cb _hidl_cb) override; - Return<bool> setDisplayMode(int32_t modeID, bool makeDefault) override; - - Return<bool> setAdaptiveBacklightEnabled(bool enabled) override; - Return<bool> isAdaptiveBacklightEnabled() override; - - Return<bool> setOutdoorModeEnabled(bool enabled) override; - Return<bool> isOutdoorModeEnabled() override; - - Return<void> getColorBalanceRange(getColorBalanceRange_cb _hidl_cb) override; - Return<int32_t> getColorBalance() override; - Return<bool> setColorBalance(int32_t value) override; - - Return<bool> setPictureAdjustment(const HSIC& hsic) override; - Return<void> getPictureAdjustment(getPictureAdjustment_cb _hidl_cb) override; - Return<void> getDefaultPictureAdjustment(getDefaultPictureAdjustment_cb _hidl_cb) override; - - Return<void> getHueRange(getHueRange_cb _hidl_cb) override; - Return<void> getSaturationRange(getSaturationRange_cb _hidl_cb) override; - Return<void> getIntensityRange(getIntensityRange_cb _hidl_cb) override; - Return<void> getContrastRange(getContrastRange_cb _hidl_cb) override; - Return<void> 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<ColorBackend> 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/livedisplay/1.0/default/include/ColorBackend.h b/livedisplay/1.0/default/include/ColorBackend.h deleted file mode 100644 index c5d06fa..0000000 --- a/livedisplay/1.0/default/include/ColorBackend.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 <vector> - -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<android::sp<disp_mode>>& profiles) = 0; - virtual android::status_t setDisplayMode(int32_t modeID, bool makeDefault) = 0; - virtual android::sp<disp_mode> getCurrentDisplayMode() = 0; - virtual android::sp<disp_mode> 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/livedisplay/1.0/default/include/Types.h b/livedisplay/1.0/default/include/Types.h deleted file mode 100644 index 4a6f39d..0000000 --- a/livedisplay/1.0/default/include/Types.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 <utils/RefBase.h> -#include <vendor/lineage/livedisplay/1.0/IColor.h> -#include <string> - -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/livedisplay/1.0/default/include/Utils.h b/livedisplay/1.0/default/include/Utils.h deleted file mode 100644 index 5da0b13..0000000 --- a/livedisplay/1.0/default/include/Utils.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -** 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 <utils/Errors.h> - -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); - - static android::status_t sendDPPSCommand(char* buf, size_t len); - - static android::status_t writeLocalModeId(int32_t id); - - static android::status_t readLocalModeId(int32_t* id); - - static android::status_t writeInitialModeId(int32_t id); - - static android::status_t readInitialModeId(int32_t* id); -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_UTILS_H diff --git a/livedisplay/1.0/default/include/controller/LegacyMMController.h b/livedisplay/1.0/default/include/controller/LegacyMMController.h deleted file mode 100644 index 8265001..0000000 --- a/livedisplay/1.0/default/include/controller/LegacyMMController.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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_LEGACYMMCONTROLLER_H -#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_LEGACYMMCONTROLLER_H - -#include <memory> - -#include <stdint.h> - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V1_0 { -namespace implementation { - -class LegacyMMController { - public: - LegacyMMController(); - - 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); - - std::shared_ptr<void> mHandle; - - disp_api_init mFn_init; - disp_api_get_color_balance_range mFn_get_color_balance_range; - disp_api_set_color_balance mFn_set_color_balance; - disp_api_get_color_balance mFn_get_color_balance; - disp_api_get_num_display_modes mFn_get_num_display_modes; - disp_api_get_display_modes mFn_get_display_modes; - disp_api_get_active_display_mode mFn_get_active_display_mode; - disp_api_set_active_display_mode mFn_set_active_display_mode; - disp_api_set_default_display_mode mFn_set_default_display_mode; - disp_api_get_default_display_mode mFn_get_default_display_mode; - disp_api_get_pa_range mFn_get_pa_range; - disp_api_get_pa_config mFn_get_pa_config; - disp_api_set_pa_config mFn_set_pa_config; - disp_api_supported mFn_supported; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_LEGACYMMCONTROLLER_H diff --git a/livedisplay/1.0/default/include/controller/SDMController.h b/livedisplay/1.0/default/include/controller/SDMController.h deleted file mode 100644 index 2e634de..0000000 --- a/livedisplay/1.0/default/include/controller/SDMController.h +++ /dev/null @@ -1,102 +0,0 @@ -/* - * 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_SDMCONTROLLER_H -#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_SDMCONTROLLER_H - -#include <memory> - -#include <stdint.h> - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V1_0 { -namespace implementation { - -class SDMController { - public: - SDMController(); - - int32_t init(uint64_t* hctx, uint32_t flags); - int32_t deinit(uint64_t hctx, uint32_t flags); - int32_t get_global_color_balance_range(uint64_t hctx, uint32_t disp_id, void* range); - int32_t set_global_color_balance(uint64_t hctx, uint32_t disp_id, int32_t warmness, - uint32_t flags); - int32_t get_global_color_balance(uint64_t hctx, uint32_t disp_id, int32_t* warmness, - uint32_t* flags); - int32_t get_num_display_modes(uint64_t hctx, uint32_t disp_id, uint32_t mode_type, - int32_t* mode_cnt, uint32_t* flags); - int32_t get_display_modes(uint64_t hctx, uint32_t disp_id, uint32_t mode_type, void* modes, - int32_t mode_cnt, uint32_t* flags); - int32_t get_active_display_mode(uint64_t hctx, uint32_t disp_id, int32_t* mode_id, - uint32_t* mask, uint32_t* flags); - int32_t set_active_display_mode(uint64_t hctx, uint32_t disp_id, int32_t mode_id, - uint32_t flags); - int32_t set_default_display_mode(uint64_t hctx, uint32_t disp_id, int32_t mode_id, - uint32_t flags); - int32_t get_default_display_mode(uint64_t hctx, uint32_t disp_id, int32_t* mode_id, - uint32_t* flags); - int32_t get_global_pa_range(uint64_t hctx, uint32_t disp_id, void* range); - int32_t get_global_pa_config(uint64_t hctx, uint32_t disp_id, uint32_t* enable, void* cfg); - int32_t set_global_pa_config(uint64_t hctx, uint32_t disp_id, uint32_t enable, void* cfg); - int32_t get_feature_version(uint64_t hctx, uint32_t feature_id, void* ver, uint32_t* flags); - - private: - typedef int32_t (*disp_api_init)(uint64_t*, uint32_t); - typedef int32_t (*disp_api_deinit)(uint64_t, uint32_t); - typedef int32_t (*disp_api_get_global_color_balance_range)(uint64_t, uint32_t, void*); - typedef int32_t (*disp_api_set_global_color_balance)(uint64_t, uint32_t, int32_t, uint32_t); - typedef int32_t (*disp_api_get_global_color_balance)(uint64_t, uint32_t, int32_t*, uint32_t*); - typedef int32_t (*disp_api_get_num_display_modes)(uint64_t, uint32_t, int32_t, int32_t*, - uint32_t*); - typedef int32_t (*disp_api_get_display_modes)(uint64_t, uint32_t, int32_t, void*, int32_t, - uint32_t*); - typedef int32_t (*disp_api_get_active_display_mode)(uint64_t, uint32_t, int32_t*, uint32_t*, - uint32_t*); - typedef int32_t (*disp_api_set_active_display_mode)(uint64_t, uint32_t, int32_t, uint32_t); - typedef int32_t (*disp_api_set_default_display_mode)(uint64_t, uint32_t, int32_t, uint32_t); - typedef int32_t (*disp_api_get_default_display_mode)(uint64_t, uint32_t, int32_t*, uint32_t*); - typedef int32_t (*disp_api_get_global_pa_range)(uint64_t, uint32_t, void*); - typedef int32_t (*disp_api_get_global_pa_config)(uint64_t, uint32_t, uint32_t*, void*); - typedef int32_t (*disp_api_set_global_pa_config)(uint64_t, uint32_t, uint32_t, void*); - typedef int32_t (*disp_api_get_feature_version)(uint64_t, uint32_t, void*, uint32_t*); - - std::shared_ptr<void> mHandle; - disp_api_init mFn_init; - disp_api_deinit mFn_deinit; - disp_api_get_global_color_balance_range mFn_get_global_color_balance_range; - disp_api_set_global_color_balance mFn_set_global_color_balance; - disp_api_get_global_color_balance mFn_get_global_color_balance; - disp_api_get_num_display_modes mFn_get_num_display_modes; - disp_api_get_display_modes mFn_get_display_modes; - disp_api_get_active_display_mode mFn_get_active_display_mode; - disp_api_set_active_display_mode mFn_set_active_display_mode; - disp_api_set_default_display_mode mFn_set_default_display_mode; - disp_api_get_default_display_mode mFn_get_default_display_mode; - disp_api_get_global_pa_range mFn_get_global_pa_range; - disp_api_get_global_pa_config mFn_get_global_pa_config; - disp_api_set_global_pa_config mFn_set_global_pa_config; - disp_api_get_feature_version mFn_get_feature_version; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_SDMCONTROLLER_H diff --git a/livedisplay/1.0/default/include/impl/LegacyMM.h b/livedisplay/1.0/default/include/impl/LegacyMM.h deleted file mode 100644 index f7bcc41..0000000 --- a/livedisplay/1.0/default/include/impl/LegacyMM.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -** 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_LEGACYMM_H -#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_LEGACYMM_H - -#include "ColorBackend.h" - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V1_0 { -namespace implementation { - -class LegacyMMController; - -class LegacyMM : public ColorBackend { - public: - LegacyMM(); - ~LegacyMM(); - - 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; - virtual android::status_t setColorBalance(int32_t balance) override; - virtual int32_t getColorBalance() override; - - virtual android::status_t getDisplayModes(std::vector<android::sp<disp_mode>>& profiles) override; - virtual android::status_t setDisplayMode(int32_t modeID, bool makeDefault) override; - virtual android::sp<disp_mode> getCurrentDisplayMode() override; - virtual android::sp<disp_mode> getDefaultDisplayMode() override; - - virtual android::status_t getPictureAdjustmentRanges(HSICRanges& ranges) override; - virtual android::status_t getPictureAdjustment(HSIC& hsic) override; - virtual HSIC getDefaultPictureAdjustment() override; - virtual android::status_t setPictureAdjustment(const HSIC& hsic) override; - - virtual bool hasFeature(Feature feature) override; - - private: - uint32_t getNumDisplayModes(); - android::sp<disp_mode> getDisplayModeById(int32_t id); - - std::unique_ptr<LegacyMMController> mController; - HSIC mDefaultPictureAdjustment; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_LEGACYMM_H diff --git a/livedisplay/1.0/default/include/impl/SDM.h b/livedisplay/1.0/default/include/impl/SDM.h deleted file mode 100644 index 805172c..0000000 --- a/livedisplay/1.0/default/include/impl/SDM.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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_SDM_H -#define VENDOR_LINEAGE_LIVEDISPLAY_V1_0_SDM_H - -#include "ColorBackend.h" - -#include <vector> - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V1_0 { -namespace implementation { - -class SDMController; - -class SDM : public ColorBackend { - public: - SDM(); - ~SDM(); - - virtual android::status_t getDisplayModes(std::vector<android::sp<disp_mode>>& profiles) override; - virtual android::sp<disp_mode> getCurrentDisplayMode() override; - virtual android::sp<disp_mode> getDefaultDisplayMode() override; - virtual android::status_t setDisplayMode(int32_t modeID, bool makeDefault) override; - - virtual android::status_t setAdaptiveBacklightEnabled(bool enabled) override; - virtual bool isAdaptiveBacklightEnabled() override; - - 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 int32_t getColorBalance() override { - return 0; - } - virtual android::status_t setColorBalance(int32_t /* balance */) override { - return android::NO_INIT; - } - - virtual android::status_t getPictureAdjustmentRanges(HSICRanges& ranges) override; - virtual android::status_t setPictureAdjustment(const HSIC& hsic) override; - virtual android::status_t getPictureAdjustment(HSIC& hsic) override; - virtual HSIC getDefaultPictureAdjustment() override; - - virtual bool hasFeature(Feature f); - - private: - android::status_t saveInitialDisplayMode(); - uint32_t getNumDisplayModes(); - uint32_t getNumSDMDisplayModes(); - - android::sp<disp_mode> getDisplayModeById(int32_t id); - android::status_t setModeState(android::sp<disp_mode> mode, bool state); - android::sp<disp_mode> getLocalSRGBMode(); - android::sp<disp_mode> getLocalDCIP3Mode(); - - std::unique_ptr<SDMController> mController; - uint64_t mHandle; - bool mFOSSEnabled; - bool mCachedFOSSStatus; - int32_t mActiveModeId; - - HSIC mDefaultPictureAdjustment; -}; - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V1_0_SDM_H diff --git a/livedisplay/1.0/default/lineage.livedisplay@1.0-service-sdm.rc b/livedisplay/1.0/default/lineage.livedisplay@1.0-service-sdm.rc deleted file mode 100644 index 5347fcd..0000000 --- a/livedisplay/1.0/default/lineage.livedisplay@1.0-service-sdm.rc +++ /dev/null @@ -1,7 +0,0 @@ -on post-fs-data - mkdir /data/display 0770 system graphics - -service livedisplay-hal-1-0 /system/bin/hw/lineage.livedisplay@1.0-service-sdm - class hal - user system - group system diff --git a/livedisplay/1.0/default/service.cpp b/livedisplay/1.0/default/service.cpp deleted file mode 100644 index 161aed6..0000000 --- a/livedisplay/1.0/default/service.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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. - */ - -#if defined(COLOR_BACKEND_SDM) -#define LOG_TAG "vendor.lineage.livedisplay@1.0-service-sdm" -#elif defined(COLOR_BACKEND_LEGACYMM) -#define LOG_TAG "vendor.lineage.livedisplay@1.0-service-legacymm" -#else -#error "Color backend undefined!" -#endif - -#include <android-base/logging.h> -#include <binder/ProcessState.h> -#include <hidl/HidlTransportSupport.h> - -#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(INFO) << "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<IColor> 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/livedisplay/1.0/default/src/Color.cpp b/livedisplay/1.0/default/src/Color.cpp deleted file mode 100644 index ca02f57..0000000 --- a/livedisplay/1.0/default/src/Color.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/* - * 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" -#if defined(COLOR_BACKEND_SDM) -#include "impl/SDM.h" -#elif defined(COLOR_BACKEND_LEGACYMM) -#include "impl/LegacyMM.h" -#endif - -#include <android-base/logging.h> - -namespace { - -using vendor::lineage::livedisplay::V1_0::DisplayMode; -using vendor::lineage::livedisplay::V1_0::implementation::disp_mode; - -DisplayMode modePointerToObj(android::sp<disp_mode> 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; - -#if defined(COLOR_BACKEND_SDM) - mBackend.reset(new SDM()); -#elif defined(COLOR_BACKEND_LEGACYMM) - mBackend.reset(new LegacyMM()); -#endif - 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<Feature>(i); - if (mBackend->hasFeature(f)) { - addFeature(f); - } - } - mConnected = true; - - return mFeatures > 0; -} - -Return<Features> Color::getSupportedFeatures() { - connect(); - return mFeatures; -} - -Return<void> Color::getDisplayModes(getDisplayModes_cb _hidl_cb) { - hidl_vec<DisplayMode> profiles; - status_t rc = NO_INIT; - Mutex::Autolock _l(mLock); - - if (check(Feature::DISPLAY_MODES)) { - std::vector<sp<disp_mode>> 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<void> Color::getCurrentDisplayMode(getCurrentDisplayMode_cb _hidl_cb) { - DisplayMode mode; - Mutex::Autolock _l(mLock); - - if (check(Feature::DISPLAY_MODES)) { - sp<disp_mode> m = mBackend->getCurrentDisplayMode(); - if (m != nullptr) { - mode = modePointerToObj(m); - } else { - mode = invalidDisplayMode(); - } - } - _hidl_cb(mode); - return Void(); -} - -Return<void> Color::getDefaultDisplayMode(getDefaultDisplayMode_cb _hidl_cb) { - DisplayMode mode; - Mutex::Autolock _l(mLock); - - if (check(Feature::DISPLAY_MODES)) { - sp<disp_mode> m = mBackend->getDefaultDisplayMode(); - if (m != nullptr) { - mode = modePointerToObj(m); - } else { - mode = invalidDisplayMode(); - } - } - _hidl_cb(mode); - return Void(); -} - -Return<bool> 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<bool> 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<bool> Color::isAdaptiveBacklightEnabled() { - Mutex::Autolock _l(mLock); - - if (check(Feature::ADAPTIVE_BACKLIGHT)) { - return mBackend->isAdaptiveBacklightEnabled(); - } - return false; -} - -Return<bool> 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<bool> Color::isOutdoorModeEnabled() { - Mutex::Autolock _l(mLock); - - if (check(Feature::OUTDOOR_MODE)) { - return mBackend->isOutdoorModeEnabled(); - } - return false; -} - -Return<void> 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<int32_t> Color::getColorBalance() { - Mutex::Autolock _l(mLock); - - if (check(Feature::COLOR_BALANCE)) { - return mBackend->getColorBalance(); - } - - return 0; -} - -Return<bool> 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<bool> 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<void> 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<void> 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<void> 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<void> 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<void> 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<void> 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<void> 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/livedisplay/1.0/default/src/Utils.cpp b/livedisplay/1.0/default/src/Utils.cpp deleted file mode 100644 index 7db6efc..0000000 --- a/livedisplay/1.0/default/src/Utils.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* -** 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 <fcntl.h> -#include <poll.h> -#include <signal.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fstream> -#include <string> - -#include <cutils/sockets.h> - -#ifdef LIVES_IN_SYSTEM -constexpr char LOCAL_STORAGE_PATH[] = "/data/display"; -#else -constexpr char LOCAL_STORAGE_PATH[] = "/data/vendor/display"; -#endif -constexpr char LOCAL_MODE_ID[] = "livedisplay_mode"; -constexpr char LOCAL_INITIAL_MODE_ID[] = "livedisplay_initial_mode"; - -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; -} - -status_t Utils::readLocalModeId(int32_t* id) { - char buf[PATH_MAX]; - sprintf(buf, "%s/%s", LOCAL_STORAGE_PATH, LOCAL_MODE_ID); - return readInt(buf, id); -} - -status_t Utils::writeLocalModeId(int32_t id) { - char buf[PATH_MAX]; - sprintf(buf, "%s/%s", LOCAL_STORAGE_PATH, LOCAL_MODE_ID); - return writeInt(buf, id); -} - -status_t Utils::readInitialModeId(int32_t* id) { - char buf[PATH_MAX]; - sprintf(buf, "%s/%s", LOCAL_STORAGE_PATH, LOCAL_INITIAL_MODE_ID); - return readInt(buf, id); -} - -status_t Utils::writeInitialModeId(int32_t id) { - char buf[PATH_MAX]; - sprintf(buf, "%s/%s", LOCAL_STORAGE_PATH, LOCAL_INITIAL_MODE_ID); - return writeInt(buf, id); -} - -status_t Utils::sendDPPSCommand(char* buf, size_t len) { - status_t rc = OK; - int sock = socket_local_client("pps", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_STREAM); - if (sock < 0) { - return sock; - } - - if (write(sock, buf, strlen(buf) + 1) > 0) { - memset(buf, 0, len); - ssize_t ret; - while ((ret = read(sock, buf, len)) > 0) { - if ((size_t)ret == len) { - break; - } - len -= ret; - buf += ret; - - struct pollfd p = {.fd = sock, .events = POLLIN, .revents = 0}; - - ret = poll(&p, 1, 20); - if ((ret <= 0) || !(p.revents & POLLIN)) { - break; - } - } - } else { - rc = NO_INIT; - } - close(sock); - return rc; -} - -} // namespace implementation -} // namespace V1_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor diff --git a/livedisplay/1.0/default/vendor.lineage.livedisplay@1.0-service-legacymm.rc b/livedisplay/1.0/default/vendor.lineage.livedisplay@1.0-service-legacymm.rc deleted file mode 100644 index 586f6a8..0000000 --- a/livedisplay/1.0/default/vendor.lineage.livedisplay@1.0-service-legacymm.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.livedisplay-hal-1-0 /vendor/bin/hw/vendor.lineage.livedisplay@1.0-service-legacymm - class hal - user system - group system diff --git a/livedisplay/1.0/default/vendor.lineage.livedisplay@1.0-service-sdm.rc b/livedisplay/1.0/default/vendor.lineage.livedisplay@1.0-service-sdm.rc deleted file mode 100644 index b5ceaf1..0000000 --- a/livedisplay/1.0/default/vendor.lineage.livedisplay@1.0-service-sdm.rc +++ /dev/null @@ -1,4 +0,0 @@ -service vendor.livedisplay-hal-1-0 /vendor/bin/hw/vendor.lineage.livedisplay@1.0-service-sdm - class hal - user system - group system diff --git a/livedisplay/1.0/types.hal b/livedisplay/1.0/types.hal deleted file mode 100644 index 637e197..0000000 --- a/livedisplay/1.0/types.hal +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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. - */ - -package vendor.lineage.livedisplay@1.0; - -struct Range { - int32_t max; - int32_t min; - uint32_t step; -}; - -struct FloatRange { - float max; - float min; - float step; -}; - -struct HSIC { - int32_t hue; - float saturation; - float intensity; - float contrast; - float saturationThreshold; -}; - -struct DisplayMode { - int32_t id; - string name; -}; - -enum Feature : uint32_t { - DISPLAY_MODES = 0x1, - COLOR_BALANCE = 0x2, - OUTDOOR_MODE = 0x4, - ADAPTIVE_BACKLIGHT = 0x8, - PICTURE_ADJUSTMENT = 0x10, - MAX = PICTURE_ADJUSTMENT -}; -typedef bitfield<Feature> Features; |
