Paul Keith | 7193ce2 | 2018-08-12 20:05:57 +0200 | [diff] [blame] | 1 | /* |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 2 | * Copyright (C) 2019-2020 The LineageOS Project |
Paul Keith | 7193ce2 | 2018-08-12 20:05:57 +0200 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 17 | #ifdef LIVES_IN_SYSTEM |
| 18 | #define LOG_TAG "lineage.livedisplay@2.0-impl-sdm" |
| 19 | #else |
| 20 | #define LOG_TAG "vendor.lineage.livedisplay@2.0-impl-sdm" |
| 21 | #endif |
| 22 | |
dianlujitao | 44e1a1f | 2020-06-24 22:51:34 +0800 | [diff] [blame] | 23 | #include "livedisplay/sdm/PictureAdjustment.h" |
LuK1337 | 588974a | 2020-01-07 14:15:27 +0100 | [diff] [blame] | 24 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 25 | #include <android-base/logging.h> |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 26 | |
dianlujitao | 44e1a1f | 2020-06-24 22:51:34 +0800 | [diff] [blame] | 27 | #include "livedisplay/sdm/Utils.h" |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 28 | |
| 29 | namespace vendor { |
| 30 | namespace lineage { |
| 31 | namespace livedisplay { |
| 32 | namespace V2_0 { |
Paul Keith | 986bd64 | 2019-01-19 16:35:57 +0100 | [diff] [blame] | 33 | namespace sdm { |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 34 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 35 | using ::android::OK; |
dianlujitao | 4afd662 | 2020-06-24 22:09:13 +0800 | [diff] [blame] | 36 | using ::android::hardware::Void; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 37 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 38 | PictureAdjustment::PictureAdjustment(std::shared_ptr<SDMController> controller) |
| 39 | : controller_(std::move(controller)) { |
dianlujitao | a15a1f3 | 2020-06-23 23:42:05 +0800 | [diff] [blame] | 40 | if (!isReady()) { |
| 41 | LOG(FATAL) << "PictureAdjustment backend not ready, exiting."; |
| 42 | } |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 43 | } |
| 44 | |
dianlujitao | a15a1f3 | 2020-06-23 23:42:05 +0800 | [diff] [blame] | 45 | bool PictureAdjustment::isReady() { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 46 | static int supported = -1; |
| 47 | |
| 48 | if (supported >= 0) { |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 49 | return supported; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 50 | } |
| 51 | |
dianlujitao | bb5ff4a | 2020-06-24 19:07:04 +0800 | [diff] [blame] | 52 | if (utils::CheckFeatureVersion(controller_, utils::FEATURE_VER_SW_PA_API) != OK) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 53 | supported = 0; |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 54 | return false; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 55 | } |
| 56 | |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 57 | HsicRanges r{}; |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 58 | if (controller_->getGlobalPaRange(&r) != OK) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 59 | supported = 0; |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 60 | return false; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | supported = r.hue.max != 0 && r.hue.min != 0 && r.saturation.max != 0.f && |
| 64 | r.saturation.min != 0.f && r.intensity.max != 0.f && r.intensity.min != 0.f && |
| 65 | r.contrast.max != 0.f && r.contrast.min != 0.f; |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 66 | |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 67 | return supported; |
| 68 | } |
| 69 | |
| 70 | HSIC PictureAdjustment::getPictureAdjustmentInternal() { |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 71 | HsicConfig config{}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 72 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 73 | if (controller_->getGlobalPaConfig(&config) == OK) { |
| 74 | return HSIC{static_cast<float>(config.data.hue), config.data.saturation, |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 75 | config.data.intensity, config.data.contrast, config.data.saturation_threshold}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | return HSIC{}; |
| 79 | } |
| 80 | |
| 81 | void PictureAdjustment::updateDefaultPictureAdjustment() { |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 82 | default_pa_ = getPictureAdjustmentInternal(); |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 83 | } |
| 84 | |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 85 | // Methods from ::vendor::lineage::livedisplay::V2_0::IPictureAdjustment follow. |
| 86 | Return<void> PictureAdjustment::getHueRange(getHueRange_cb _hidl_cb) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 87 | FloatRange range{}; |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 88 | HsicRanges r{}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 89 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 90 | if (controller_->getGlobalPaRange(&r) == OK) { |
| 91 | range.max = r.hue.max; |
| 92 | range.min = r.hue.min; |
| 93 | range.step = r.hue.step; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | _hidl_cb(range); |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 97 | return Void(); |
| 98 | } |
| 99 | |
| 100 | Return<void> PictureAdjustment::getSaturationRange(getSaturationRange_cb _hidl_cb) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 101 | FloatRange range{}; |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 102 | HsicRanges r{}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 103 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 104 | if (controller_->getGlobalPaRange(&r) == OK) { |
| 105 | range.max = r.saturation.max; |
| 106 | range.min = r.saturation.min; |
| 107 | range.step = r.saturation.step; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | _hidl_cb(range); |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 111 | return Void(); |
| 112 | } |
| 113 | |
| 114 | Return<void> PictureAdjustment::getIntensityRange(getIntensityRange_cb _hidl_cb) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 115 | FloatRange range{}; |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 116 | HsicRanges r{}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 117 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 118 | if (controller_->getGlobalPaRange(&r) == OK) { |
| 119 | range.max = r.intensity.max; |
| 120 | range.min = r.intensity.min; |
| 121 | range.step = r.intensity.step; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | _hidl_cb(range); |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 125 | return Void(); |
| 126 | } |
| 127 | |
| 128 | Return<void> PictureAdjustment::getContrastRange(getContrastRange_cb _hidl_cb) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 129 | FloatRange range{}; |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 130 | HsicRanges r{}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 131 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 132 | if (controller_->getGlobalPaRange(&r) == OK) { |
| 133 | range.max = r.contrast.max; |
| 134 | range.min = r.contrast.min; |
| 135 | range.step = r.contrast.step; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | _hidl_cb(range); |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 139 | return Void(); |
| 140 | } |
| 141 | |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 142 | Return<void> PictureAdjustment::getSaturationThresholdRange( |
LuK1337 | 588974a | 2020-01-07 14:15:27 +0100 | [diff] [blame] | 143 | getSaturationThresholdRange_cb _hidl_cb) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 144 | FloatRange range{}; |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 145 | HsicRanges r{}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 146 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 147 | if (controller_->getGlobalPaRange(&r) == OK) { |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 148 | range.max = r.saturation_threshold.max; |
| 149 | range.min = r.saturation_threshold.min; |
| 150 | range.step = r.saturation_threshold.step; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | _hidl_cb(range); |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 154 | return Void(); |
| 155 | } |
| 156 | |
| 157 | Return<void> PictureAdjustment::getPictureAdjustment(getPictureAdjustment_cb _hidl_cb) { |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 158 | _hidl_cb(getPictureAdjustmentInternal()); |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 159 | return Void(); |
| 160 | } |
| 161 | |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 162 | Return<void> PictureAdjustment::getDefaultPictureAdjustment( |
LuK1337 | 588974a | 2020-01-07 14:15:27 +0100 | [diff] [blame] | 163 | getDefaultPictureAdjustment_cb _hidl_cb) { |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 164 | _hidl_cb(default_pa_); |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 165 | return Void(); |
| 166 | } |
| 167 | |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 168 | Return<bool> PictureAdjustment::setPictureAdjustment( |
LuK1337 | 588974a | 2020-01-07 14:15:27 +0100 | [diff] [blame] | 169 | const ::vendor::lineage::livedisplay::V2_0::HSIC& hsic) { |
dianlujitao | 143150e | 2020-06-24 17:41:07 +0800 | [diff] [blame] | 170 | HsicConfig config = {0, |
| 171 | {static_cast<int32_t>(hsic.hue), hsic.saturation, hsic.intensity, |
| 172 | hsic.contrast, hsic.saturationThreshold}}; |
Paul Keith | 7a5da24 | 2019-01-20 04:24:30 +0100 | [diff] [blame] | 173 | |
dianlujitao | 7468c41 | 2020-06-23 22:16:50 +0800 | [diff] [blame] | 174 | return controller_->setGlobalPaConfig(&config) == OK; |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 175 | } |
| 176 | |
Paul Keith | 986bd64 | 2019-01-19 16:35:57 +0100 | [diff] [blame] | 177 | } // namespace sdm |
Paul Keith | 3f26562 | 2018-08-12 19:56:29 +0200 | [diff] [blame] | 178 | } // namespace V2_0 |
| 179 | } // namespace livedisplay |
| 180 | } // namespace lineage |
| 181 | } // namespace vendor |