diff options
author | Long Ling <longling@google.com> | 2020-07-23 13:34:46 -0700 |
---|---|---|
committer | Long Ling <longling@google.com> | 2020-07-31 10:15:51 -0700 |
commit | 26f2471bcbd4c929d337a7240168f4108f6f113e (patch) | |
tree | 27c92fd8f921f3c42e5cb5dcdcb29bee8a3d77cc /include | |
parent | 192f4589fd779b8ea41ab1c3280f9774472a65ab (diff) |
libhwc2.1: add displaycolor common header file
Move displaycololr.h from vendor folder to here to remove hwc
compile dependecy on vendor.
Bug: 158048652
Change-Id: I1feec8df6b1a6ef63e781950d91912eaf9568485
Signed-off-by: Long Ling <longling@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/displaycolor/displaycolor.h | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/include/displaycolor/displaycolor.h b/include/displaycolor/displaycolor.h new file mode 100644 index 0000000..af1576a --- /dev/null +++ b/include/displaycolor/displaycolor.h @@ -0,0 +1,208 @@ +/* + * Copyright (C) 2020 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. + */ + +#ifndef DISPLAYCOLOR_H_ +#define DISPLAYCOLOR_H_ + +#include <android/hardware/graphics/common/1.1/types.h> +#include <android/hardware/graphics/common/1.2/types.h> + +#include <string> + +namespace displaycolor { + +namespace hwc { +using android::hardware::graphics::common::V1_1::RenderIntent; +using android::hardware::graphics::common::V1_2::ColorMode; +using android::hardware::graphics::common::V1_2::Dataspace; +} // namespace hwc + +/// A map associating supported RenderIntents for each supported ColorMode +using ColorModesMap = std::map<hwc::ColorMode, std::vector<hwc::RenderIntent>>; + +/// Image data bit depths. +enum class BitDepth { kEight, kTen }; + +struct LayerColorData { + bool operator==(const LayerColorData &rhs) const { + return dataspace == rhs.dataspace && matrix == rhs.matrix && + static_metadata == rhs.static_metadata && + dynamic_metadata == rhs.dynamic_metadata; + } + + /** + * @brief HDR static metadata. + * + * See HWC v2.2 (IComposerClient::PerFrameMetadataKey) + * for more information. + */ + struct HdrStaticMetadata { + private: + std::array<int32_t, 13> data; + + public: + HdrStaticMetadata() = default; + HdrStaticMetadata(const HdrStaticMetadata &other) + : data(other.data), is_valid(other.is_valid) {} + HdrStaticMetadata(const HdrStaticMetadata &&other) = delete; + HdrStaticMetadata &operator=(const HdrStaticMetadata &other) { + data = other.data; + is_valid = other.is_valid; + return *this; + } + HdrStaticMetadata &operator=(HdrStaticMetadata &&other) = delete; + ~HdrStaticMetadata() = default; + + bool operator==(const HdrStaticMetadata &rhs) const { + return data == rhs.data && is_valid == rhs.is_valid; + } + + /// Indicator for whether the data in this struct should be used. + bool is_valid = false; + /// This device's display's peak luminance, in nits. + int32_t &device_max_luminance = data[0]; + + // Mastering display properties + int32_t &display_red_primary_x = data[1]; + int32_t &display_red_primary_y = data[2]; + int32_t &display_green_primary_x = data[3]; + int32_t &display_green_primary_y = data[4]; + int32_t &display_blue_primary_x = data[5]; + int32_t &display_blue_primary_y = data[6]; + int32_t &white_point_x = data[7]; + int32_t &white_point_y = data[8]; + int32_t &max_luminance = data[9]; + int32_t &min_luminance = data[10]; + + // Content properties + int32_t &max_content_light_level = data[11]; + int32_t &max_frame_average_light_level = data[12]; + }; + + /** + * @brief HDR dynamic metadata. + * + * The members defined here are a subset of metadata define in + * SMPTE ST 2094-40:2016. + * Also see module videoapi information. + */ + struct HdrDynamicMetadata { + bool operator==(const HdrDynamicMetadata &rhs) const { + return is_valid == rhs.is_valid && + display_maximum_luminance == rhs.display_maximum_luminance && + maxscl == rhs.maxscl && + maxrgb_percentages == rhs.maxrgb_percentages && + maxrgb_percentiles == rhs.maxrgb_percentiles && + tm_flag == rhs.tm_flag && tm_knee_x == rhs.tm_knee_x && + tm_knee_y == rhs.tm_knee_y && + bezier_curve_anchors == rhs.bezier_curve_anchors; + } + + /// Indicator for whether the data in this struct should be used. + bool is_valid = false; + + uint32_t display_maximum_luminance; + std::array<uint32_t, 3> maxscl; + std::vector<uint8_t> maxrgb_percentages; + std::vector<uint32_t> maxrgb_percentiles; + uint16_t tm_flag; + uint16_t tm_knee_x; + uint16_t tm_knee_y; + std::vector<uint16_t> bezier_curve_anchors; + }; + + /// This layer's dataspace (color gamut, transfer function, and range). + hwc::Dataspace dataspace = hwc::Dataspace::UNKNOWN; + /// Color transform for this layer. See SET_LAYER_COLOR_TRANSFORM HWC v2.3. + // clang-format off + std::array<float, 16> matrix { + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 + }; + // clang-format on + /** + * @brief This layer's HDR static metadata. Only applicable when dataspace + * indicates this is an HDR layer. + */ + HdrStaticMetadata static_metadata; + /** + * @brief This layer's HDR dynamic metadata. Only applicable when dataspace + * indicates this is an HDR layer. + */ + HdrDynamicMetadata dynamic_metadata; +}; + +/** + * @brief DisplayScene holds all the information required for libdisplaycolor to + * return correct data. + */ +struct DisplayScene { + bool operator==(const DisplayScene &rhs) const { + return dpu_bit_depth == rhs.dpu_bit_depth && + color_mode == rhs.color_mode && + render_intent == rhs.render_intent; + } + + /// A vector of layer color data. + std::vector<LayerColorData> layer_data; + /// The bit depth the DPU is currently outputting + BitDepth dpu_bit_depth = BitDepth::kEight; + /// The current ColorMode (typically set by SurfaceFlinger) + hwc::ColorMode color_mode = hwc::ColorMode::NATIVE; + /// The current RenderIntent (typically set by SurfaceFlinger) + hwc::RenderIntent render_intent = hwc::RenderIntent::COLORIMETRIC; + /// Color transform for this layer. See SET_COLOR_TRANSFORM HWC v2.1. + // clang-format off + std::array<float, 16> matrix { + 1.0, 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0, 0.0, + 0.0, 0.0, 1.0, 0.0, + 0.0, 0.0, 0.0, 1.0 + }; + // clang-format on +}; + +/// An interface specifying functions that are HW-agnostic. +class IDisplayColorGeneric { + public: + /// A generic stage in the display pipeline. + struct DisplayStage { + bool enable = false; + }; + + virtual ~IDisplayColorGeneric() {} + + /** + * @brief Update display color data. This function is expected to be called + * before querying display color data, if the display scene has changed. + * + * @param scene Display scene data to use during the update. + * @return OK if successful, error otherwise. + */ + virtual int Update(const DisplayScene &scene) = 0; + + /** + * @brief Get a map of supported ColorModes, and supported RenderIntents for + * each ColorMode. + */ + virtual const ColorModesMap &ColorModesAndRenderIntents() const = 0; +}; + +} // namespace displaycolor + +#endif // DISPLAYCOLOR_H_ |