diff --git a/livedisplay/Android.bp b/livedisplay/Android.bp index 9d7cb12..87957f1 100644 --- a/livedisplay/Android.bp +++ b/livedisplay/Android.bp @@ -19,8 +19,9 @@ cc_binary { defaults: ["hidl_defaults"], relative_install_path: "hw", srcs: [ + ":vendor.lineage.livedisplay@2.0-sdm-pa", + ":vendor.lineage.livedisplay@2.0-sdm-utils", "DisplayModes.cpp", - "PictureAdjustment.cpp", "SunlightEnhancement.cpp", "service.cpp", ], @@ -32,4 +33,8 @@ cc_binary { "libutils", "vendor.lineage.livedisplay@2.0", ], + header_libs: [ + "vendor.lineage.livedisplay@2.0-sdm-headers", + ], + cflags: ["-DLIVES_IN_SYSTEM"], } diff --git a/livedisplay/Constants.h b/livedisplay/Constants.h deleted file mode 100644 index c7589ef..0000000 --- a/livedisplay/Constants.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2019 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V2_0_CONSTANTS_H -#define VENDOR_LINEAGE_LIVEDISPLAY_V2_0_CONSTANTS_H - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V2_0 { -namespace implementation { - -#define DPPS_BUF_SIZE 64 - -#define FOSS_PROPERTY "ro.vendor.display.foss" -#define FOSS_ON "foss:on" -#define FOSS_OFF "foss:off" - -#define COLOR_BALANCE_FEATURE 3 -#define DISPLAY_MODES_FEATURE 4 -#define PICTURE_ADJUSTMENT_FEATURE 1 - -} // namespace implementation -} // namespace V2_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V2_0_CONSTANTS_H diff --git a/livedisplay/PictureAdjustment.cpp b/livedisplay/PictureAdjustment.cpp deleted file mode 100644 index 95f243c..0000000 --- a/livedisplay/PictureAdjustment.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (C) 2019 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "PictureAdjustment.h" - -#include - -#include "Constants.h" -#include "Types.h" - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V2_0 { -namespace implementation { - -static sp sInstance; - -PictureAdjustment::PictureAdjustment(void* libHandle, uint64_t cookie) { - sInstance = this; - - mLibHandle = libHandle; - mCookie = cookie; - disp_api_get_feature_version = - reinterpret_cast( - dlsym(mLibHandle, "disp_api_get_feature_version")); - disp_api_get_global_pa_range = reinterpret_cast( - dlsym(mLibHandle, "disp_api_get_global_pa_range")); - disp_api_get_global_pa_config = - reinterpret_cast( - dlsym(mLibHandle, "disp_api_get_global_pa_config")); - disp_api_set_global_pa_config = - reinterpret_cast( - dlsym(mLibHandle, "disp_api_set_global_pa_config")); - memset(&mDefaultPictureAdjustment, 0, sizeof(HSIC)); -} - -bool PictureAdjustment::isSupported() { - sdm_feature_version version{}; - hsic_ranges r{}; - uint32_t flags = 0; - static int supported = -1; - - if (supported >= 0) { - goto out; - } - - if (disp_api_get_feature_version == nullptr || - disp_api_get_feature_version(mCookie, PICTURE_ADJUSTMENT_FEATURE, &version, &flags) != 0) { - supported = 0; - goto out; - } - - if (version.x <= 0 && version.y <= 0 && version.z <= 0) { - supported = 0; - goto out; - } - - if (disp_api_get_global_pa_range == nullptr || - disp_api_get_global_pa_range(mCookie, 0, &r) != 0) { - supported = 0; - goto out; - } - - supported = r.hue.max != 0 && r.hue.min != 0 && r.saturation.max != 0.f && - r.saturation.min != 0.f && r.intensity.max != 0.f && r.intensity.min != 0.f && - r.contrast.max != 0.f && r.contrast.min != 0.f; -out: - return supported; -} - -HSIC PictureAdjustment::getPictureAdjustmentInternal() { - hsic_config config{}; - uint32_t enable = 0; - - if (disp_api_get_global_pa_config != nullptr) { - if (disp_api_get_global_pa_config(mCookie, 0, &enable, &config) == 0) { - return HSIC{static_cast(config.data.hue), config.data.saturation, - config.data.intensity, config.data.contrast, - config.data.saturationThreshold}; - } - } - - return HSIC{}; -} - -void PictureAdjustment::updateDefaultPictureAdjustment() { - if (sInstance != nullptr) { - sInstance->mDefaultPictureAdjustment = sInstance->getPictureAdjustmentInternal(); - } -} - -// Methods from ::vendor::lineage::livedisplay::V2_0::IPictureAdjustment follow. -Return PictureAdjustment::getHueRange(getHueRange_cb _hidl_cb) { - FloatRange range{}; - hsic_ranges r{}; - - if (disp_api_get_global_pa_range != nullptr) { - if (disp_api_get_global_pa_range(mCookie, 0, &r) == 0) { - range.max = r.hue.max; - range.min = r.hue.min; - range.step = r.hue.step; - } - } - - _hidl_cb(range); - return Void(); -} - -Return PictureAdjustment::getSaturationRange(getSaturationRange_cb _hidl_cb) { - FloatRange range{}; - hsic_ranges r{}; - - if (disp_api_get_global_pa_range != nullptr) { - if (disp_api_get_global_pa_range(mCookie, 0, &r) == 0) { - range.max = r.saturation.max; - range.min = r.saturation.min; - range.step = r.saturation.step; - } - } - - _hidl_cb(range); - return Void(); -} - -Return PictureAdjustment::getIntensityRange(getIntensityRange_cb _hidl_cb) { - FloatRange range{}; - hsic_ranges r{}; - - if (disp_api_get_global_pa_range != nullptr) { - if (disp_api_get_global_pa_range(mCookie, 0, &r) == 0) { - range.max = r.intensity.max; - range.min = r.intensity.min; - range.step = r.intensity.step; - } - } - - _hidl_cb(range); - return Void(); -} - -Return PictureAdjustment::getContrastRange(getContrastRange_cb _hidl_cb) { - FloatRange range{}; - hsic_ranges r{}; - - if (disp_api_get_global_pa_range != nullptr) { - if (disp_api_get_global_pa_range(mCookie, 0, &r) == 0) { - range.max = r.contrast.max; - range.min = r.contrast.min; - range.step = r.contrast.step; - } - } - - _hidl_cb(range); - return Void(); -} - -Return PictureAdjustment::getSaturationThresholdRange( - getSaturationThresholdRange_cb _hidl_cb) { - FloatRange range{}; - hsic_ranges r{}; - - if (disp_api_get_global_pa_range != nullptr) { - if (disp_api_get_global_pa_range(mCookie, 0, &r) == 0) { - range.max = r.saturationThreshold.max; - range.min = r.saturationThreshold.min; - range.step = r.saturationThreshold.step; - } - } - - _hidl_cb(range); - return Void(); -} - -Return PictureAdjustment::getPictureAdjustment(getPictureAdjustment_cb _hidl_cb) { - _hidl_cb(getPictureAdjustmentInternal()); - return Void(); -} - -Return PictureAdjustment::getDefaultPictureAdjustment( - getDefaultPictureAdjustment_cb _hidl_cb) { - _hidl_cb(mDefaultPictureAdjustment); - return Void(); -} - -Return PictureAdjustment::setPictureAdjustment( - const ::vendor::lineage::livedisplay::V2_0::HSIC& hsic) { - hsic_config config = {0, - {static_cast(hsic.hue), hsic.saturation, hsic.intensity, - hsic.contrast, hsic.saturationThreshold}}; - - if (disp_api_set_global_pa_config != nullptr) { - return disp_api_set_global_pa_config(mCookie, 0, 1, &config) == 0; - } - - return false; -} - -} // namespace implementation -} // namespace V2_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor diff --git a/livedisplay/PictureAdjustment.h b/livedisplay/PictureAdjustment.h deleted file mode 100644 index a1c82c3..0000000 --- a/livedisplay/PictureAdjustment.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (C) 2019 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V2_0_PICTUREADJUSTMENT_H -#define VENDOR_LINEAGE_LIVEDISPLAY_V2_0_PICTUREADJUSTMENT_H - -#include - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V2_0 { -namespace implementation { - -using ::android::sp; -using ::android::hardware::Return; -using ::android::hardware::Void; - -class PictureAdjustment : public IPictureAdjustment { - public: - PictureAdjustment(void* libHandle, uint64_t cookie); - - bool isSupported(); - - // Methods from ::vendor::lineage::livedisplay::V2_0::IPictureAdjustment follow. - 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; - Return getPictureAdjustment(getPictureAdjustment_cb _hidl_cb) override; - Return getDefaultPictureAdjustment(getDefaultPictureAdjustment_cb _hidl_cb) override; - Return setPictureAdjustment( - const ::vendor::lineage::livedisplay::V2_0::HSIC& hsic) override; - - static void updateDefaultPictureAdjustment(); - - private: - void* mLibHandle; - uint64_t mCookie; - - int32_t (*disp_api_get_feature_version)(uint64_t, uint32_t, void*, uint32_t*); - int32_t (*disp_api_get_global_pa_range)(uint64_t, uint32_t, void*); - int32_t (*disp_api_get_global_pa_config)(uint64_t, uint32_t, uint32_t*, void*); - int32_t (*disp_api_set_global_pa_config)(uint64_t, uint32_t, uint32_t, void*); - - HSIC getPictureAdjustmentInternal(); - - HSIC mDefaultPictureAdjustment; -}; - -} // namespace implementation -} // namespace V2_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V2_0_PICTUREADJUSTMENT_H diff --git a/livedisplay/Types.h b/livedisplay/Types.h deleted file mode 100644 index 72399c0..0000000 --- a/livedisplay/Types.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2019 The LineageOS Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef VENDOR_LINEAGE_LIVEDISPLAY_V2_0_TYPES_H -#define VENDOR_LINEAGE_LIVEDISPLAY_V2_0_TYPES_H - -namespace vendor { -namespace lineage { -namespace livedisplay { -namespace V2_0 { -namespace implementation { - -struct sdm_feature_version { - uint8_t x, y; - uint16_t z; -}; - -struct sdm_disp_mode { - int32_t id; - int32_t type; - int32_t len; - char* name; -}; - -struct hsic_data { - int32_t hue; - float saturation; - float intensity; - float contrast; - float saturationThreshold; -}; - -struct hsic_config { - uint32_t unused; - hsic_data data; -}; - -struct hsic_int_range { - int32_t max; - int32_t min; - uint32_t step; -}; - -struct hsic_float_range { - float max; - float min; - float step; -}; - -struct hsic_ranges { - uint32_t unused; - 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; -}; - -} // namespace implementation -} // namespace V2_0 -} // namespace livedisplay -} // namespace lineage -} // namespace vendor - -#endif // VENDOR_LINEAGE_LIVEDISPLAY_V2_0_TYPES_H diff --git a/livedisplay/service.cpp b/livedisplay/service.cpp index 6f21363..d9ae82a 100644 --- a/livedisplay/service.cpp +++ b/livedisplay/service.cpp @@ -14,18 +14,14 @@ * limitations under the License. */ -#include - #define LOG_TAG "lineage.livedisplay@2.0-service.oneplus_kona" -#define SDM_DISP_LIB "libsdm-disp-apis.qti.so" - #include #include #include +#include #include "DisplayModes.h" -#include "PictureAdjustment.h" #include "SunlightEnhancement.h" using android::OK; @@ -38,53 +34,21 @@ using ::vendor::lineage::livedisplay::V2_0::IDisplayModes; using ::vendor::lineage::livedisplay::V2_0::IPictureAdjustment; using ::vendor::lineage::livedisplay::V2_0::ISunlightEnhancement; using ::vendor::lineage::livedisplay::V2_0::implementation::DisplayModes; -using ::vendor::lineage::livedisplay::V2_0::implementation::PictureAdjustment; using ::vendor::lineage::livedisplay::V2_0::implementation::SunlightEnhancement; +using ::vendor::lineage::livedisplay::V2_0::sdm::PictureAdjustment; +using ::vendor::lineage::livedisplay::V2_0::sdm::SDMController; int main() { - // Vendor backend - void* libHandle = nullptr; - const char* libName = nullptr; - int32_t (*disp_api_init)(uint64_t*, uint32_t) = nullptr; - int32_t (*disp_api_deinit)(uint64_t, uint32_t) = nullptr; - uint64_t cookie = 0; - - // HIDL frontend - sp dm; - sp pa; - sp se; - status_t status = OK; android::ProcessState::initWithDriver("/dev/binder"); LOG(INFO) << "LiveDisplay HAL service is starting."; - libHandle = dlopen(SDM_DISP_LIB, RTLD_NOW); - if (libHandle == nullptr) { - LOG(ERROR) << "Failed to load SDM display lib, exiting."; - goto shutdown; - } - - disp_api_init = - reinterpret_cast(dlsym(libHandle, "disp_api_init")); - if (disp_api_init == nullptr) { - LOG(ERROR) << "Can not get disp_api_init from " << libName << " (" << dlerror() << ")"; - goto shutdown; - } - - disp_api_deinit = - reinterpret_cast(dlsym(libHandle, "disp_api_deinit")); - if (disp_api_deinit == nullptr) { - LOG(ERROR) << "Can not get disp_api_deinit from " << libName << " (" << dlerror() << ")"; - goto shutdown; - } - - status = disp_api_init(&cookie, 0); - if (status != OK) { - LOG(ERROR) << "Can not initialize " << libName << " (" << status << ")"; - goto shutdown; - } + std::shared_ptr controller = std::make_shared(); + sp dm; + sp pa; + sp se; dm = new DisplayModes(); if (dm == nullptr) { @@ -92,7 +56,7 @@ int main() { goto shutdown; } - pa = new PictureAdjustment(libHandle, cookie); + pa = new PictureAdjustment(controller); if (pa == nullptr) { LOG(ERROR) << "Can not create an instance of LiveDisplay HAL PictureAdjustment Iface, " "exiting."; @@ -106,11 +70,6 @@ int main() { goto shutdown; } - if (!pa->isSupported()) { - // Backend isn't ready yet, so restart and try again - goto shutdown; - } - configureRpcThreadpool(1, true /*callerWillJoin*/); status = dm->registerAsService(); @@ -120,13 +79,11 @@ int main() { goto shutdown; } - if (pa->isSupported()) { - status = pa->registerAsService(); - if (status != OK) { - LOG(ERROR) << "Could not register service for LiveDisplay HAL PictureAdjustment Iface (" - << status << ")"; - goto shutdown; - } + status = pa->registerAsService(); + if (status != OK) { + LOG(ERROR) << "Could not register service for LiveDisplay HAL PictureAdjustment Iface (" + << status << ")"; + goto shutdown; } status = se->registerAsService(); @@ -141,15 +98,6 @@ int main() { // Should not pass this line shutdown: - // Cleanup what we started - if (disp_api_deinit != nullptr) { - disp_api_deinit(cookie, 0); - } - - if (libHandle != nullptr) { - dlclose(libHandle); - } - // In normal operation, we don't expect the thread pool to shutdown LOG(ERROR) << "LiveDisplay HAL service is shutting down."; return 1;