[Aidl] Add LUT HAL

A Look-Up Table(LUT) provides either the platform or apps ways to
control tonemapping for specific content, more specifically HDR
contents.

LutProperties HAL is also exposed to OverlayProperties API.

Bug: 329472100
Test: builds
Change-Id: Ia25fb21b57c924a9f5a6b4424661a4e152db96f4
This commit is contained in:
Sally Qi
2024-04-22 11:43:05 -07:00
parent b0a523945d
commit ac6824fb33
16 changed files with 337 additions and 6 deletions

View File

@@ -249,7 +249,7 @@
</hal>
<hal format="aidl">
<name>android.hardware.graphics.composer3</name>
<version>3</version>
<version>4</version>
<interface>
<name>IComposer</name>
<instance>default</instance>

View File

@@ -53,13 +53,13 @@ cc_defaults {
cc_defaults {
name: "android.hardware.graphics.composer3-ndk_static",
static_libs: [
"android.hardware.graphics.composer3-V3-ndk",
"android.hardware.graphics.composer3-V4-ndk",
],
}
cc_defaults {
name: "android.hardware.graphics.composer3-ndk_shared",
shared_libs: [
"android.hardware.graphics.composer3-V3-ndk",
"android.hardware.graphics.composer3-V4-ndk",
],
}

View File

@@ -29,7 +29,7 @@ aidl_interface {
host_supported: true,
vendor_available: true,
double_loadable: true,
frozen: true,
frozen: false,
srcs: [
"android/hardware/graphics/composer3/*.aidl",
],

View File

@@ -41,4 +41,5 @@ union CommandResultPayload {
android.hardware.graphics.composer3.ReleaseFences releaseFences;
android.hardware.graphics.composer3.PresentOrValidate presentOrValidateResult;
android.hardware.graphics.composer3.ClientTargetPropertyWithBrightness clientTargetProperty;
android.hardware.graphics.composer3.DisplayLuts displayLuts;
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2024 The Android Open Source 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.
*/
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
///////////////////////////////////////////////////////////////////////////////
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
// the interface (from the latest frozen version), the build system will
// prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
// with such a backward incompatible change, it has a high risk of breaking
// later when a module using the interface is updated, e.g., Mainline modules.
package android.hardware.graphics.composer3;
@VintfStability
parcelable DisplayLuts {
long display;
android.hardware.graphics.composer3.Lut[] luts;
}

View File

@@ -57,4 +57,5 @@ parcelable LayerCommand {
@nullable int[] bufferSlotsToClear;
android.hardware.graphics.composer3.LayerLifecycleBatchCommandType layerLifecycleBatchCommandType;
int newBufferSlotCount;
@nullable android.hardware.graphics.composer3.Lut[] luts;
}

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2024 The Android Open Source 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.
*/
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
///////////////////////////////////////////////////////////////////////////////
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
// the interface (from the latest frozen version), the build system will
// prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
// with such a backward incompatible change, it has a high risk of breaking
// later when a module using the interface is updated, e.g., Mainline modules.
package android.hardware.graphics.composer3;
@VintfStability
parcelable Lut {
long layer;
@nullable ParcelFileDescriptor pfd;
android.hardware.graphics.composer3.LutProperties lutProperties;
}

View File

@@ -0,0 +1,50 @@
/*
* Copyright (C) 2024 The Android Open Source 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.
*/
///////////////////////////////////////////////////////////////////////////////
// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. //
///////////////////////////////////////////////////////////////////////////////
// This file is a snapshot of an AIDL file. Do not edit it manually. There are
// two cases:
// 1). this is a frozen version file - do not edit this in any case.
// 2). this is a 'current' file. If you make a backwards compatible change to
// the interface (from the latest frozen version), the build system will
// prompt you to update this file with `m <name>-update-api`.
//
// You must not make a backward incompatible change to any AIDL file built
// with the aidl_interface module type with versions property set. The module
// type is used to build AIDL files in a way that they can be used across
// independently updatable components of the system. If a device is shipped
// with such a backward incompatible change, it has a high risk of breaking
// later when a module using the interface is updated, e.g., Mainline modules.
package android.hardware.graphics.composer3;
@VintfStability
parcelable LutProperties {
android.hardware.graphics.composer3.LutProperties.Dimension dimension;
long size;
android.hardware.graphics.composer3.LutProperties.SamplingKey[] samplingKeys;
@VintfStability
enum Dimension {
ONE_D = 1,
THREE_D = 3,
}
@VintfStability
enum SamplingKey {
RGB,
MAX_RGB,
}
}

View File

@@ -36,6 +36,7 @@ package android.hardware.graphics.composer3;
parcelable OverlayProperties {
android.hardware.graphics.composer3.OverlayProperties.SupportedBufferCombinations[] combinations;
boolean supportMixedColorSpaces;
@nullable android.hardware.graphics.composer3.LutProperties[] lutProperties;
parcelable SupportedBufferCombinations {
android.hardware.graphics.common.PixelFormat[] pixelFormats;
android.hardware.graphics.common.Dataspace[] standards;

View File

@@ -19,6 +19,7 @@ package android.hardware.graphics.composer3;
import android.hardware.graphics.composer3.ChangedCompositionTypes;
import android.hardware.graphics.composer3.ClientTargetPropertyWithBrightness;
import android.hardware.graphics.composer3.CommandError;
import android.hardware.graphics.composer3.DisplayLuts;
import android.hardware.graphics.composer3.DisplayRequest;
import android.hardware.graphics.composer3.PresentFence;
import android.hardware.graphics.composer3.PresentOrValidate;
@@ -96,4 +97,13 @@ union CommandResultPayload {
* the SDR buffers when an HDR layer is simultaneously device-composited.
*/
ClientTargetPropertyWithBrightness clientTargetProperty;
/**
* Sets the Lut(s) for the layers.
*
* HWC should only request Lut(s) if SurfaceFlinger does not send the Lut(s) to the HWC.
* The main use-case is like HDR10+ or Dolby Vision where there is no Lut to send from
* SurfaceFlinger.
*/
DisplayLuts displayLuts;
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2024 The Android Open Source 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.
*/
package android.hardware.graphics.composer3;
import android.hardware.graphics.composer3.Lut;
/**
* LUT (Look-Up Table) Interface for Color Transformation.
*
* This interface allows the HWC (Hardware Composer) to define and communicate Luts
* to SurfaceFlinger.
*/
@VintfStability
parcelable DisplayLuts {
/**
* The display which this commands refers to.
*/
long display;
/**
* A Lut list specified by the HWC for given HDR layers that don't have Luts provided.
*/
Lut[] luts;
}

View File

@@ -24,6 +24,7 @@ import android.hardware.graphics.composer3.Buffer;
import android.hardware.graphics.composer3.Color;
import android.hardware.graphics.composer3.LayerBrightness;
import android.hardware.graphics.composer3.LayerLifecycleBatchCommandType;
import android.hardware.graphics.composer3.Lut;
import android.hardware.graphics.composer3.ParcelableBlendMode;
import android.hardware.graphics.composer3.ParcelableComposition;
import android.hardware.graphics.composer3.ParcelableDataspace;
@@ -279,4 +280,9 @@ parcelable LayerCommand {
* Specifies the number of buffer slot to be reserved.
*/
int newBufferSlotCount;
/**
* Sets the lut(s) for the layer.
*/
@nullable Lut[] luts;
}

View File

@@ -0,0 +1,61 @@
/*
* Copyright (C) 2024 The Android Open Source 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.
*/
package android.hardware.graphics.composer3;
import android.hardware.graphics.composer3.LutProperties;
/**
* LUT (Look-Up Table) Interface for Color Transformation.
*
* This interface allows the HWC (Hardware Composer) to define and communicate LUTs
* with SurfaceFlinger.
*/
@VintfStability
parcelable Lut {
/**
* The layer which this commands refer to.
*/
long layer;
/**
* A handle to a memory region.
* If the file descriptor is not set, this means that the HWC doesn't specify a Lut.
*
* When specifying a Lut, the HWC is required to follow the instructions as below:
* 1. use `memfd_create` to create a shared memory segment
* with the size specified in lutProperties.
* 2. use `mmap` to map the shared memory segment into its own virtual address space.
* PROT_READ/PROT_WRITE recommended for prot argument.
*
* For data precision, 32-bit float is used to specify a Lut by both the HWC and
* the platform.
*
* For unflattening/flattening 3D Lut(s), the algorithm below should be observed
* by both the HWC and the platform.
* Assuming that we have a 3D array `ORIGINAL[WIDTH, HEIGHT, DEPTH]`, we would turn it into
* `FLAT[WIDTH * HEIGHT * DEPTH]` by
*
* `FLAT[z + DEPTH * (y + HEIGHT * x)] = ORIGINAL[x, y, z]`
*/
@nullable ParcelFileDescriptor pfd;
/**
* The properties of the Lut.
*/
LutProperties lutProperties;
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (C) 2024 The Android Open Source 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.
*/
package android.hardware.graphics.composer3;
/**
* The properties of the LUT (Look-Up Table).
*/
@VintfStability
parcelable LutProperties {
/**
* The dimension of the Lut.
* Either 1d or 3d.
*/
@VintfStability enum Dimension { ONE_D = 1, THREE_D = 3 }
Dimension dimension;
/**
* The size of the Lut.
* This refers to the length of a 1D Lut, or the grid size of a 3D one.
*/
long size;
/**
* SamplingKey is about how a Lut can be sampled.
* A Lut can be sampled in more than one way,
* but only one sampling method is used at one time.
*
* The implementations should use a sampling strategy
* at least as good as linear sampling.
*/
// TODO(b/358422255): add sampling ways
@VintfStability enum SamplingKey { RGB, MAX_RGB }
SamplingKey[] samplingKeys;
}

View File

@@ -16,6 +16,8 @@
package android.hardware.graphics.composer3;
import android.hardware.graphics.composer3.LutProperties;
@VintfStability
parcelable OverlayProperties {
parcelable SupportedBufferCombinations {
@@ -42,4 +44,8 @@ parcelable OverlayProperties {
// True if the DPU is able to color manage at least two overlays
// with different input colorspaces, false otherwise.
boolean supportMixedColorSpaces;
// Array of lut properties in order that the HWC supports.
// The list accepts 1D lut(s) and 3D lut(s).
@nullable LutProperties[] lutProperties;
}

View File

@@ -27,9 +27,8 @@
#include <string.h>
#include <aidl/android/hardware/graphics/composer3/ClientTargetProperty.h>
#include <aidl/android/hardware/graphics/composer3/Composition.h>
#include <aidl/android/hardware/graphics/composer3/CommandResultPayload.h>
#include <aidl/android/hardware/graphics/composer3/Composition.h>
#include <log/log.h>
#include <sync/sync.h>
@@ -84,6 +83,10 @@ class ComposerClientReader {
parseSetClientTargetProperty(std::move(
result.get<CommandResultPayload::Tag::clientTargetProperty>()));
break;
case CommandResultPayload::Tag::displayLuts:
parseSetDisplayLuts(
std::move(result.get<CommandResultPayload::Tag::displayLuts>()));
break;
}
}
}
@@ -182,6 +185,20 @@ class ComposerClientReader {
return std::move(data.clientTargetProperty);
}
// Get the lut(s) requested by hardware composer.
std::vector<Lut> takeLuts(int64_t display) {
LOG_ALWAYS_FATAL_IF(mDisplay && display != *mDisplay);
auto found = mReturnData.find(display);
// If not found, return the empty vector
if (found == mReturnData.end()) {
return {};
}
ReturnData& data = found->second;
return std::move(data.luts);
}
private:
void resetData() {
mErrors.clear();
@@ -227,6 +244,18 @@ class ComposerClientReader {
data.clientTargetProperty = std::move(clientTargetProperty);
}
void parseSetDisplayLuts(DisplayLuts&& displayLuts) {
LOG_ALWAYS_FATAL_IF(mDisplay && displayLuts.display != *mDisplay);
auto& data = mReturnData[displayLuts.display];
for (auto& lut : displayLuts.luts) {
if (lut.pfd.get() >= 0) {
data.luts.push_back({lut.layer,
std::move(ndk::ScopedFileDescriptor(lut.pfd.release())),
lut.lutProperties});
}
}
}
struct ReturnData {
DisplayRequest displayRequests;
std::vector<ChangedCompositionLayer> changedLayers;
@@ -238,6 +267,7 @@ class ComposerClientReader {
.clientTargetProperty = {common::PixelFormat::RGBA_8888, Dataspace::UNKNOWN},
.brightness = 1.f,
};
std::vector<Lut> luts;
};
std::vector<CommandError> mErrors;