blob: 3758b52f0a43e7ca501312eaa0e1854fba156acc [file] [log] [blame]
Paul Keith7193ce22018-08-12 20:05:57 +02001/*
dianlujitao7468c412020-06-23 22:16:50 +08002 * Copyright (C) 2019-2020 The LineageOS Project
Paul Keith7193ce22018-08-12 20:05:57 +02003 *
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
dianlujitao7468c412020-06-23 22:16:50 +080017#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
dianlujitao44e1a1f2020-06-24 22:51:34 +080023#include "livedisplay/sdm/PictureAdjustment.h"
LuK1337588974a2020-01-07 14:15:27 +010024
dianlujitao7468c412020-06-23 22:16:50 +080025#include <android-base/logging.h>
Paul Keith7a5da242019-01-20 04:24:30 +010026
dianlujitao44e1a1f2020-06-24 22:51:34 +080027#include "livedisplay/sdm/Utils.h"
Paul Keith3f265622018-08-12 19:56:29 +020028
29namespace vendor {
30namespace lineage {
31namespace livedisplay {
32namespace V2_0 {
Paul Keith986bd642019-01-19 16:35:57 +010033namespace sdm {
Paul Keith3f265622018-08-12 19:56:29 +020034
dianlujitao7468c412020-06-23 22:16:50 +080035using ::android::OK;
dianlujitao4afd6622020-06-24 22:09:13 +080036using ::android::hardware::Void;
Paul Keith7a5da242019-01-20 04:24:30 +010037
dianlujitao7468c412020-06-23 22:16:50 +080038PictureAdjustment::PictureAdjustment(std::shared_ptr<SDMController> controller)
39 : controller_(std::move(controller)) {
dianlujitaoa15a1f32020-06-23 23:42:05 +080040 if (!isReady()) {
41 LOG(FATAL) << "PictureAdjustment backend not ready, exiting.";
42 }
Paul Keith7a5da242019-01-20 04:24:30 +010043}
44
dianlujitaoa15a1f32020-06-23 23:42:05 +080045bool PictureAdjustment::isReady() {
Paul Keith7a5da242019-01-20 04:24:30 +010046 static int supported = -1;
47
48 if (supported >= 0) {
dianlujitao7468c412020-06-23 22:16:50 +080049 return supported;
Paul Keith7a5da242019-01-20 04:24:30 +010050 }
51
dianlujitaobb5ff4a2020-06-24 19:07:04 +080052 if (utils::CheckFeatureVersion(controller_, utils::FEATURE_VER_SW_PA_API) != OK) {
Paul Keith7a5da242019-01-20 04:24:30 +010053 supported = 0;
dianlujitao7468c412020-06-23 22:16:50 +080054 return false;
Paul Keith7a5da242019-01-20 04:24:30 +010055 }
56
dianlujitao143150e2020-06-24 17:41:07 +080057 HsicRanges r{};
dianlujitao7468c412020-06-23 22:16:50 +080058 if (controller_->getGlobalPaRange(&r) != OK) {
Paul Keith7a5da242019-01-20 04:24:30 +010059 supported = 0;
dianlujitao7468c412020-06-23 22:16:50 +080060 return false;
Paul Keith7a5da242019-01-20 04:24:30 +010061 }
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;
dianlujitao7468c412020-06-23 22:16:50 +080066
Paul Keith7a5da242019-01-20 04:24:30 +010067 return supported;
68}
69
70HSIC PictureAdjustment::getPictureAdjustmentInternal() {
dianlujitao143150e2020-06-24 17:41:07 +080071 HsicConfig config{};
Paul Keith7a5da242019-01-20 04:24:30 +010072
dianlujitao7468c412020-06-23 22:16:50 +080073 if (controller_->getGlobalPaConfig(&config) == OK) {
74 return HSIC{static_cast<float>(config.data.hue), config.data.saturation,
dianlujitao143150e2020-06-24 17:41:07 +080075 config.data.intensity, config.data.contrast, config.data.saturation_threshold};
Paul Keith7a5da242019-01-20 04:24:30 +010076 }
77
78 return HSIC{};
79}
80
81void PictureAdjustment::updateDefaultPictureAdjustment() {
dianlujitao143150e2020-06-24 17:41:07 +080082 default_pa_ = getPictureAdjustmentInternal();
Paul Keith7a5da242019-01-20 04:24:30 +010083}
84
Paul Keith3f265622018-08-12 19:56:29 +020085// Methods from ::vendor::lineage::livedisplay::V2_0::IPictureAdjustment follow.
86Return<void> PictureAdjustment::getHueRange(getHueRange_cb _hidl_cb) {
Paul Keith7a5da242019-01-20 04:24:30 +010087 FloatRange range{};
dianlujitao143150e2020-06-24 17:41:07 +080088 HsicRanges r{};
Paul Keith7a5da242019-01-20 04:24:30 +010089
dianlujitao7468c412020-06-23 22:16:50 +080090 if (controller_->getGlobalPaRange(&r) == OK) {
91 range.max = r.hue.max;
92 range.min = r.hue.min;
93 range.step = r.hue.step;
Paul Keith7a5da242019-01-20 04:24:30 +010094 }
95
96 _hidl_cb(range);
Paul Keith3f265622018-08-12 19:56:29 +020097 return Void();
98}
99
100Return<void> PictureAdjustment::getSaturationRange(getSaturationRange_cb _hidl_cb) {
Paul Keith7a5da242019-01-20 04:24:30 +0100101 FloatRange range{};
dianlujitao143150e2020-06-24 17:41:07 +0800102 HsicRanges r{};
Paul Keith7a5da242019-01-20 04:24:30 +0100103
dianlujitao7468c412020-06-23 22:16:50 +0800104 if (controller_->getGlobalPaRange(&r) == OK) {
105 range.max = r.saturation.max;
106 range.min = r.saturation.min;
107 range.step = r.saturation.step;
Paul Keith7a5da242019-01-20 04:24:30 +0100108 }
109
110 _hidl_cb(range);
Paul Keith3f265622018-08-12 19:56:29 +0200111 return Void();
112}
113
114Return<void> PictureAdjustment::getIntensityRange(getIntensityRange_cb _hidl_cb) {
Paul Keith7a5da242019-01-20 04:24:30 +0100115 FloatRange range{};
dianlujitao143150e2020-06-24 17:41:07 +0800116 HsicRanges r{};
Paul Keith7a5da242019-01-20 04:24:30 +0100117
dianlujitao7468c412020-06-23 22:16:50 +0800118 if (controller_->getGlobalPaRange(&r) == OK) {
119 range.max = r.intensity.max;
120 range.min = r.intensity.min;
121 range.step = r.intensity.step;
Paul Keith7a5da242019-01-20 04:24:30 +0100122 }
123
124 _hidl_cb(range);
Paul Keith3f265622018-08-12 19:56:29 +0200125 return Void();
126}
127
128Return<void> PictureAdjustment::getContrastRange(getContrastRange_cb _hidl_cb) {
Paul Keith7a5da242019-01-20 04:24:30 +0100129 FloatRange range{};
dianlujitao143150e2020-06-24 17:41:07 +0800130 HsicRanges r{};
Paul Keith7a5da242019-01-20 04:24:30 +0100131
dianlujitao7468c412020-06-23 22:16:50 +0800132 if (controller_->getGlobalPaRange(&r) == OK) {
133 range.max = r.contrast.max;
134 range.min = r.contrast.min;
135 range.step = r.contrast.step;
Paul Keith7a5da242019-01-20 04:24:30 +0100136 }
137
138 _hidl_cb(range);
Paul Keith3f265622018-08-12 19:56:29 +0200139 return Void();
140}
141
Paul Keith7a5da242019-01-20 04:24:30 +0100142Return<void> PictureAdjustment::getSaturationThresholdRange(
LuK1337588974a2020-01-07 14:15:27 +0100143 getSaturationThresholdRange_cb _hidl_cb) {
Paul Keith7a5da242019-01-20 04:24:30 +0100144 FloatRange range{};
dianlujitao143150e2020-06-24 17:41:07 +0800145 HsicRanges r{};
Paul Keith7a5da242019-01-20 04:24:30 +0100146
dianlujitao7468c412020-06-23 22:16:50 +0800147 if (controller_->getGlobalPaRange(&r) == OK) {
dianlujitao143150e2020-06-24 17:41:07 +0800148 range.max = r.saturation_threshold.max;
149 range.min = r.saturation_threshold.min;
150 range.step = r.saturation_threshold.step;
Paul Keith7a5da242019-01-20 04:24:30 +0100151 }
152
153 _hidl_cb(range);
Paul Keith3f265622018-08-12 19:56:29 +0200154 return Void();
155}
156
157Return<void> PictureAdjustment::getPictureAdjustment(getPictureAdjustment_cb _hidl_cb) {
Paul Keith7a5da242019-01-20 04:24:30 +0100158 _hidl_cb(getPictureAdjustmentInternal());
Paul Keith3f265622018-08-12 19:56:29 +0200159 return Void();
160}
161
Paul Keith7a5da242019-01-20 04:24:30 +0100162Return<void> PictureAdjustment::getDefaultPictureAdjustment(
LuK1337588974a2020-01-07 14:15:27 +0100163 getDefaultPictureAdjustment_cb _hidl_cb) {
dianlujitao143150e2020-06-24 17:41:07 +0800164 _hidl_cb(default_pa_);
Paul Keith3f265622018-08-12 19:56:29 +0200165 return Void();
166}
167
Paul Keith7a5da242019-01-20 04:24:30 +0100168Return<bool> PictureAdjustment::setPictureAdjustment(
LuK1337588974a2020-01-07 14:15:27 +0100169 const ::vendor::lineage::livedisplay::V2_0::HSIC& hsic) {
dianlujitao143150e2020-06-24 17:41:07 +0800170 HsicConfig config = {0,
171 {static_cast<int32_t>(hsic.hue), hsic.saturation, hsic.intensity,
172 hsic.contrast, hsic.saturationThreshold}};
Paul Keith7a5da242019-01-20 04:24:30 +0100173
dianlujitao7468c412020-06-23 22:16:50 +0800174 return controller_->setGlobalPaConfig(&config) == OK;
Paul Keith3f265622018-08-12 19:56:29 +0200175}
176
Paul Keith986bd642019-01-19 16:35:57 +0100177} // namespace sdm
Paul Keith3f265622018-08-12 19:56:29 +0200178} // namespace V2_0
179} // namespace livedisplay
180} // namespace lineage
181} // namespace vendor