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