1
0
Fork 0

drm_hwcomposer: Remove SetColorTransform HWC2 API

Instead, reuse generic API SetColorTransformMatrix. The only valid hints
are abitrary and identity. Convert color_transform_hint_ member variable
to a bool.

Change-Id: Iac05c54394bee67637caa3edd3cde4e2097f6e1f
Signed-off-by: Sasha McIntosh <sashamcintosh@google.com>
This commit is contained in:
Sasha McIntosh 2025-05-06 11:07:03 -04:00
parent 574a22f721
commit 9624a8ea11
5 changed files with 67 additions and 71 deletions

View file

@ -43,11 +43,6 @@ namespace {
constexpr int kCtmRows = 3;
constexpr int kCtmCols = 3;
constexpr std::array<float, 16> kIdentityMatrix = {
1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F,
0.0F, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F,
};
bool float_equals(float a, float b) {
const float epsilon = 0.001F;
return std::abs(a - b) < epsilon;
@ -127,26 +122,30 @@ HwcDisplay::HwcDisplay(hwc2_display_t handle, bool is_virtual, DrmHwc *hwc)
void HwcDisplay::SetColorTransformMatrix(
const std::array<float, 16> &color_transform_matrix) {
const bool is_identity = std::equal(color_transform_matrix.begin(),
color_transform_matrix.end(),
kIdentityMatrix.begin(), float_equals);
color_transform_hint_ = is_identity ? HAL_COLOR_TRANSFORM_IDENTITY
: HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX;
color_transform_is_identity_ = std::equal(color_transform_matrix.begin(),
color_transform_matrix.end(),
kIdentityMatrix.begin(),
float_equals);
ctm_has_offset_ = false;
if (color_transform_hint_ == is_identity) {
SetColorMatrixToIdentity();
} else {
if (TransformHasOffsetValue(color_transform_matrix.data()))
ctm_has_offset_ = true;
if (IsInHeadlessMode())
return;
color_matrix_ = ToColorTransform(color_transform_matrix);
if (color_transform_is_identity_) {
SetColorMatrixToIdentity();
return;
}
if (TransformHasOffsetValue(color_transform_matrix.data()))
ctm_has_offset_ = true;
color_matrix_ = ToColorTransform(color_transform_matrix);
}
void HwcDisplay::SetColorMatrixToIdentity() {
ctm_has_offset_ = false;
color_matrix_ = identity_color_matrix_;
color_transform_hint_ = HAL_COLOR_TRANSFORM_IDENTITY;
color_transform_is_identity_ = true;
}
HwcDisplay::~HwcDisplay() {
@ -942,47 +941,8 @@ bool HwcDisplay::CreateComposition(AtomicCommitArgs &a_args) {
return true;
}
HWC2::Error HwcDisplay::SetColorTransform(const float *matrix, int32_t hint) {
if (hint < HAL_COLOR_TRANSFORM_IDENTITY ||
hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA)
return HWC2::Error::BadParameter;
if (!matrix && hint == HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX)
return HWC2::Error::BadParameter;
color_transform_hint_ = static_cast<android_color_transform_t>(hint);
ctm_has_offset_ = false;
if (IsInHeadlessMode())
return HWC2::Error::None;
if (!GetPipe().crtc->Get()->GetCtmProperty())
return HWC2::Error::None;
switch (color_transform_hint_) {
case HAL_COLOR_TRANSFORM_IDENTITY:
SetColorMatrixToIdentity();
break;
case HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX:
// Without HW support, we cannot correctly process matrices with an offset.
{
if (TransformHasOffsetValue(matrix))
ctm_has_offset_ = true;
std::array<float, 16> aidl_matrix = kIdentityMatrix;
memcpy(aidl_matrix.data(), matrix, aidl_matrix.size() * sizeof(float));
color_matrix_ = ToColorTransform(aidl_matrix);
}
break;
default:
return HWC2::Error::Unsupported;
}
return HWC2::Error::None;
}
bool HwcDisplay::CtmByGpu() {
if (color_transform_hint_ == HAL_COLOR_TRANSFORM_IDENTITY)
if (color_transform_is_identity_)
return false;
if (GetPipe().crtc->Get()->GetCtmProperty() && !ctm_has_offset_)

View file

@ -159,7 +159,6 @@ class HwcDisplay {
float *max_luminance,
float *max_average_luminance,
float *min_luminance);
HWC2::Error SetColorTransform(const float *matrix, int32_t hint);
bool IsWritebackSupported();
bool SetWritebackEnabled(bool enabled);
@ -262,7 +261,7 @@ class HwcDisplay {
uint16_t virtual_disp_height_{};
std::shared_ptr<drm_color_ctm> color_matrix_;
std::shared_ptr<drm_color_ctm> identity_color_matrix_;
android_color_transform_t color_transform_hint_{};
bool color_transform_is_identity_{};
bool ctm_has_offset_ = false;
ContentType content_type_ = ContentType::kNoData;
Colorspace colorspace_{};

View file

@ -29,6 +29,7 @@
#include "DrmHwcTwo.h"
#include "backend/Backend.h"
#include "compositor/DisplayInfo.h"
#include "hwc2_device/HwcLayer.h"
#include "utils/log.h"
@ -622,6 +623,38 @@ static int32_t SetColorMode(hwc2_device_t *device, hwc2_display_t display, int32
return 0;
}
static int32_t SetColorTransform(hwc2_device_t *device, hwc2_display_t display,
const float *matrix, int32_t hint) {
ALOGV("SetColorTransform");
if (hint < HAL_COLOR_TRANSFORM_IDENTITY ||
hint > HAL_COLOR_TRANSFORM_CORRECT_TRITANOPIA) {
return static_cast<int32_t>(HWC2::Error::BadParameter);
}
if (hint != HAL_COLOR_TRANSFORM_ARBITRARY_MATRIX &&
hint != HAL_COLOR_TRANSFORM_IDENTITY) {
return static_cast<int32_t>(HWC2::Error::Unsupported);
}
LOCK_COMPOSER(device);
GET_DISPLAY(display);
if (matrix == nullptr) {
if (hint == HAL_COLOR_TRANSFORM_IDENTITY) {
idisplay->SetColorTransformMatrix(kIdentityMatrix);
return 0;
}
return static_cast<int32_t>(HWC2::Error::BadParameter);
}
std::array<float, kColorMatrixSize> aidl_matrix = kIdentityMatrix;
memcpy(aidl_matrix.data(), matrix, aidl_matrix.size() * sizeof(float));
idisplay->SetColorTransformMatrix(aidl_matrix);
return 0;
}
static int32_t SetOutputBuffer(hwc2_device_t *device, hwc2_display_t display,
buffer_handle_t buffer, int32_t release_fence) {
ALOGV("SetOutputBuffer");
@ -1320,9 +1353,7 @@ static hwc2_function_pointer_t HookDevGetFunction(struct hwc2_device * /*dev*/,
case HWC2::FunctionDescriptor::SetColorMode:
return (hwc2_function_pointer_t)SetColorMode;
case HWC2::FunctionDescriptor::SetColorTransform:
return ToHook<HWC2_PFN_SET_COLOR_TRANSFORM>(
DisplayHook<decltype(&HwcDisplay::SetColorTransform),
&HwcDisplay::SetColorTransform, const float *, int32_t>);
return (hwc2_function_pointer_t)SetColorTransform;
case HWC2::FunctionDescriptor::SetOutputBuffer:
return (hwc2_function_pointer_t)SetOutputBuffer;
case HWC2::FunctionDescriptor::SetPowerMode: