From 9bad0d7e726e6b264c528a3dd13d0c58fd92c0e1 Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Tue, 19 Dec 2017 12:34:34 -0700 Subject: Add plumbing for HDR metadata Allow a ANativeWindow client to send HDR metadata to SurfaceFlinger. The metadata can be queried with BufferLayerConsumer::getCurrentHdrMetadata. Written by Courtney. Updated by olv@. Bug: 63710530 Test: builds Change-Id: I23192d4750950664b57863a533bffd72397255b4 --- libs/gui/HdrMetadata.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 libs/gui/HdrMetadata.cpp (limited to 'libs/gui/HdrMetadata.cpp') diff --git a/libs/gui/HdrMetadata.cpp b/libs/gui/HdrMetadata.cpp new file mode 100644 index 0000000000..299bdfa381 --- /dev/null +++ b/libs/gui/HdrMetadata.cpp @@ -0,0 +1,69 @@ +/* + * Copyright 2018 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. + */ + +#include + +namespace android { + +size_t HdrMetadata::getFlattenedSize() const { + size_t size = sizeof(validTypes); + if (validTypes & SMPTE2086) { + size += sizeof(smpte2086); + } + if (validTypes & CTA861_3) { + size += sizeof(cta8613); + } + return size; +} + +status_t HdrMetadata::flatten(void* buffer, size_t size) const { + if (size < getFlattenedSize()) { + return NO_MEMORY; + } + + FlattenableUtils::write(buffer, size, validTypes); + if (validTypes & SMPTE2086) { + FlattenableUtils::write(buffer, size, smpte2086); + } + if (validTypes & CTA861_3) { + FlattenableUtils::write(buffer, size, cta8613); + } + + return NO_ERROR; +} + +status_t HdrMetadata::unflatten(void const* buffer, size_t size) { + if (size < sizeof(validTypes)) { + return NO_MEMORY; + } + FlattenableUtils::read(buffer, size, validTypes); + if (validTypes & SMPTE2086) { + if (size < sizeof(smpte2086)) { + return NO_MEMORY; + } + FlattenableUtils::read(buffer, size, smpte2086); + } + if (validTypes & CTA861_3) { + if (size < sizeof(cta8613)) { + return NO_MEMORY; + } + FlattenableUtils::read(buffer, size, cta8613); + } + + return NO_ERROR; +} + +} // namespace android -- cgit v1.2.3-59-g8ed1b From 39a0788cf6d728bd356700bb5b0a1d31cce10356 Mon Sep 17 00:00:00 2001 From: Courtney Goeltzenleuchter Date: Mon, 12 Feb 2018 07:12:38 -0700 Subject: Add equality operator for state checking Bug: 63710530 Test: compile Change-Id: I8e9f875def10ad09dae1d647fca078f0243c6b96 --- libs/gui/HdrMetadata.cpp | 28 ++++++++++++++++++++++++++++ libs/gui/include/gui/HdrMetadata.h | 2 ++ 2 files changed, 30 insertions(+) (limited to 'libs/gui/HdrMetadata.cpp') diff --git a/libs/gui/HdrMetadata.cpp b/libs/gui/HdrMetadata.cpp index 299bdfa381..b715e431d5 100644 --- a/libs/gui/HdrMetadata.cpp +++ b/libs/gui/HdrMetadata.cpp @@ -66,4 +66,32 @@ status_t HdrMetadata::unflatten(void const* buffer, size_t size) { return NO_ERROR; } +bool HdrMetadata::operator==(const HdrMetadata& rhs) const { + if (validTypes != rhs.validTypes) return false; + + if ((validTypes & SMPTE2086) == SMPTE2086) { + if (smpte2086.displayPrimaryRed.x != rhs.smpte2086.displayPrimaryRed.x || + smpte2086.displayPrimaryRed.y != rhs.smpte2086.displayPrimaryRed.y || + smpte2086.displayPrimaryGreen.x != rhs.smpte2086.displayPrimaryGreen.x || + smpte2086.displayPrimaryGreen.y != rhs.smpte2086.displayPrimaryGreen.y || + smpte2086.displayPrimaryBlue.x != rhs.smpte2086.displayPrimaryBlue.x || + smpte2086.displayPrimaryBlue.y != rhs.smpte2086.displayPrimaryBlue.y || + smpte2086.whitePoint.x != rhs.smpte2086.whitePoint.x || + smpte2086.whitePoint.y != rhs.smpte2086.whitePoint.y || + smpte2086.maxLuminance != rhs.smpte2086.maxLuminance || + smpte2086.minLuminance != rhs.smpte2086.minLuminance) { + return false; + } + } + + if ((validTypes & CTA861_3) == CTA861_3) { + if (cta8613.maxFrameAverageLightLevel != rhs.cta8613.maxFrameAverageLightLevel || + cta8613.maxContentLightLevel != rhs.cta8613.maxContentLightLevel) { + return false; + } + } + + return true; +} + } // namespace android diff --git a/libs/gui/include/gui/HdrMetadata.h b/libs/gui/include/gui/HdrMetadata.h index cd01952005..9800602d6c 100644 --- a/libs/gui/include/gui/HdrMetadata.h +++ b/libs/gui/include/gui/HdrMetadata.h @@ -38,6 +38,8 @@ struct HdrMetadata : public LightFlattenable { size_t getFlattenedSize() const; status_t flatten(void* buffer, size_t size) const; status_t unflatten(void const* buffer, size_t size); + + bool operator==(const HdrMetadata& rhs) const; }; } // namespace android -- cgit v1.2.3-59-g8ed1b