summaryrefslogtreecommitdiff
path: root/sdm/libs/hwc2/hwc_display.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sdm/libs/hwc2/hwc_display.cpp')
-rw-r--r--sdm/libs/hwc2/hwc_display.cpp128
1 files changed, 122 insertions, 6 deletions
diff --git a/sdm/libs/hwc2/hwc_display.cpp b/sdm/libs/hwc2/hwc_display.cpp
index 4d292632..03e4cc36 100644
--- a/sdm/libs/hwc2/hwc_display.cpp
+++ b/sdm/libs/hwc2/hwc_display.cpp
@@ -54,6 +54,8 @@ HWCColorMode::HWCColorMode(DisplayInterface *display_intf) : display_intf_(displ
HWC2::Error HWCColorMode::Init() {
PopulateColorModes();
+ if (GetWhitePointCompensatedCoefficients())
+ white_point_compensated_ = PaserWhitePointCompensatedData();
return ApplyDefaultColorMode();
}
@@ -121,11 +123,13 @@ HWC2::Error HWCColorMode::SetColorModeWithRenderIntent(ColorMode mode, RenderInt
DLOGE("failed for mode = %d intent = %d name = %s", mode, intent, mode_string.c_str());
return HWC2::Error::Unsupported;
}
- // The mode does not have the PCC configured, restore the transform
- RestoreColorTransform();
current_color_mode_ = mode;
current_render_intent_ = intent;
+
+ // The mode does not have the PCC configured, restore the transform
+ RestoreColorTransform();
+
DLOGV_IF(kTagClient, "Successfully applied mode = %d intent = %d name = %s", mode, intent,
mode_string.c_str());
return HWC2::Error::None;
@@ -141,8 +145,23 @@ HWC2::Error HWCColorMode::SetColorModeById(int32_t color_mode_id) {
return HWC2::Error::None;
}
+HWC2::Error HWCColorMode::SetWhitePointCompensation(bool enabled) {
+ white_point_compensated_ = enabled;
+ if (white_point_compensated_) {
+ PaserWhitePointCompensatedData();
+ ApplyWhitePointCompensationToMatrix(white_point_compensated_color_matrix_, color_matrix_);
+ }
+
+ RestoreColorTransform();
+
+ DLOGI("Set White Point Compensation: %d", enabled);
+ return HWC2::Error::None;
+}
+
HWC2::Error HWCColorMode::RestoreColorTransform() {
- DisplayError error = display_intf_->SetColorTransform(kColorTransformMatrixCount, color_matrix_);
+
+ DisplayError error = display_intf_->SetColorTransform(kColorTransformMatrixCount,
+ GetTransferMatrix());
if (error != kErrorNone) {
DLOGE("Failed to set Color Transform");
return HWC2::Error::BadParameter;
@@ -151,19 +170,106 @@ HWC2::Error HWCColorMode::RestoreColorTransform() {
return HWC2::Error::None;
}
+bool HWCColorMode::PaserWhitePointCompensatedData() {
+ static constexpr char kWhitePointCalibrationDataPath[] = "/persist/display/calibrated_rgb";
+ FILE *fp = fopen(kWhitePointCalibrationDataPath, "r");
+ int compensated_red = 0;
+ int compensated_green = 0;
+ int compensated_blue = 0;
+
+ if (!fp) {
+ compensated_red_ratio_ = 1.0;
+ compensated_green_ratio_ = 1.0;
+ compensated_blue_ratio_ = 1.0;
+ return false;
+ }
+
+ fscanf(fp, "%d %d %d", &compensated_red, &compensated_green, &compensated_blue);
+
+ fclose(fp);
+
+ // r = r_coeffient2 * R^2 + r_coeffient1 * R + r_coeffient0
+ // g = g_coeffient2 * G^2 + g_coeffient1 * G + g_coeffient0
+ // b = b_coeffient2 * B^2 + b_coeffient1 * B + b_coeffient0
+ // r_ratio = r/kCompensatedMaxRGB
+ // g_ratio = g/kCompensatedMaxRGB
+ // b_ratio = b/kCompensatedMaxRGB
+ auto rgb_ratio = [=](int rgb, float c2, float c1, float c0) {
+ return ((c2 * rgb * rgb + c1 * rgb + c0) / kCompensatedMaxRGB);};
+
+ compensated_red_ratio_ = rgb_ratio(CheckCompensatedRGB(compensated_red), white_point_compensated_Coefficients_[0],
+ white_point_compensated_Coefficients_[1], white_point_compensated_Coefficients_[2]);
+ compensated_green_ratio_ = rgb_ratio(CheckCompensatedRGB(compensated_green), white_point_compensated_Coefficients_[3],
+ white_point_compensated_Coefficients_[4], white_point_compensated_Coefficients_[5]);
+ compensated_blue_ratio_ = rgb_ratio(CheckCompensatedRGB(compensated_blue), white_point_compensated_Coefficients_[6],
+ white_point_compensated_Coefficients_[7], white_point_compensated_Coefficients_[8]);
+ return true;
+}
+
+bool HWCColorMode::GetWhitePointCompensatedCoefficients() {
+ char value[kPropertyMax] = {};
+ if (Debug::Get()->GetProperty(WHITE_POINT_COMPENSATED_COEFFICIENT_PROP, value) != kErrorNone) {
+ DLOGW("Undefined Compensated Coefficients");
+ return false;
+ }
+
+ std::string value_string(value);
+ std::size_t start = 0, end = 0;
+ int index = 0;
+ // We need 9 coneffients, 3 for red, 3 for green, 3 for blue.
+ float CompensatedCoefficients[kCompensatedCoefficientElements] = { 1.0, 1.0, 1.0, \
+ 1.0, 1.0, 1.0, \
+ 1.0, 1.0, 1.0 };
+
+ // The property must have kCompensatedCoefficientElements delimited by commas
+ while ((end = value_string.find(",", start)) != std::string::npos) {
+ CompensatedCoefficients[index] = std::stof(value_string.substr(start, end - start));
+ start = end + 1;
+ index++;
+ if (index > kCompensatedCoefficientElements - 1) {
+ DLOGW("Over Compensated Coefficients defined");
+ return false;
+ }
+ }
+
+ if (index < kCompensatedCoefficientElements - 1) {
+ DLOGW("Less Compensated Coefficients defined");
+ return false;
+ }
+
+ CompensatedCoefficients[index] = std::stof(value_string.substr(start, end - start));
+
+ for (int32_t i = 0; i < kCompensatedCoefficientElements; i++) {
+ white_point_compensated_Coefficients_[i] = CompensatedCoefficients[i];
+ DLOGD("CompensatedCoefficients[%d]=%f",i, CompensatedCoefficients[i]);
+ }
+ return true;
+}
+
HWC2::Error HWCColorMode::SetColorTransform(const float *matrix,
android_color_transform_t /*hint*/) {
DTRACE_SCOPED();
auto status = HWC2::Error::None;
double color_matrix[kColorTransformMatrixCount] = {0};
+ double white_point_compensated_color_matrix[kColorTransformMatrixCount] = {0};
CopyColorTransformMatrix(matrix, color_matrix);
- DisplayError error = display_intf_->SetColorTransform(kColorTransformMatrixCount, color_matrix);
+ if (white_point_compensated_)
+ ApplyWhitePointCompensationToMatrix(white_point_compensated_color_matrix, color_matrix);
+
+ DisplayError error = display_intf_->SetColorTransform(kColorTransformMatrixCount,
+ NeedWhitePointCompensated() ?
+ white_point_compensated_color_matrix :
+ color_matrix);
if (error != kErrorNone) {
DLOGE("Failed to set Color Transform Matrix");
status = HWC2::Error::Unsupported;
}
CopyColorTransformMatrix(matrix, color_matrix_);
+
+ if (white_point_compensated_)
+ CopyColorTransformMatrix(white_point_compensated_color_matrix, white_point_compensated_color_matrix_);
+
return status;
}
@@ -312,13 +418,23 @@ void HWCColorMode::Dump(std::ostringstream* os) {
}
*os << "current mode: " << static_cast<uint32_t>(current_color_mode_) << std::endl;
*os << "current render_intent: " << static_cast<uint32_t>(current_render_intent_) << std::endl;
+ *os << "Need white point compensated: " << NeedWhitePointCompensated() << ",RGB:["
+ << std::fixed << std::setprecision(4)
+ << compensated_red_ratio_ << ","
+ << compensated_green_ratio_ << ","
+ << compensated_blue_ratio_ << "] "<< std::endl;
+
*os << "current transform: ";
+ double color_matrix[kColorTransformMatrixCount] = {0};
+
+ CopyColorTransformMatrix(GetTransferMatrix(), color_matrix);
+
for (uint32_t i = 0; i < kColorTransformMatrixCount; i++) {
if (i % 4 == 0) {
*os << std::endl;
}
- *os << std::fixed << std::setprecision(2) << std::setw(6) << std::setfill(' ')
- << color_matrix_[i] << " ";
+ *os << std::fixed << std::setprecision(4) << std::setw(8) << std::setfill(' ')
+ << color_matrix[i] << " ";
}
*os << std::endl;
}