blob: 9bc0e681c71ee0bcd2c3b3212be63bf617d7f583 [file] [log] [blame]
Lloyd Pique3d0c02e2018-10-19 18:38:12 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <cstdint>
20#include <unordered_map>
21#include <vector>
22
23#include <compositionengine/DisplayColorProfile.h>
24#include <compositionengine/DisplayColorProfileCreationArgs.h>
25#include <ui/HdrCapabilities.h>
26
27namespace android::compositionengine {
28
29class CompositionEngine;
30class Display;
31
32namespace impl {
33
34class DisplayColorProfile : public compositionengine::DisplayColorProfile {
35public:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070036 DisplayColorProfile(const DisplayColorProfileCreationArgs&);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070037 ~DisplayColorProfile() override;
38
39 bool isValid() const override;
40
41 bool hasRenderIntent(ui::RenderIntent intent) const override;
42 bool hasLegacyHdrSupport(ui::Dataspace dataspace) const override;
43 void getBestColorMode(ui::Dataspace dataspace, ui::RenderIntent intent,
44 ui::Dataspace* outDataspace, ui::ColorMode* outMode,
45 ui::RenderIntent* outIntent) const override;
46
47 bool hasWideColorGamut() const override;
48 int32_t getSupportedPerFrameMetadata() const override;
49
50 // Whether h/w composer has native support for specific HDR type.
51 bool hasHDR10PlusSupport() const override;
52 bool hasHDR10Support() const override;
53 bool hasHLGSupport() const override;
54 bool hasDolbyVisionSupport() const override;
55
56 const HdrCapabilities& getHdrCapabilities() const override;
Lloyd Piquef5275482019-01-29 18:42:42 -080057 bool isDataspaceSupported(ui::Dataspace) const override;
58 ui::Dataspace getTargetDataspace(ui::ColorMode, ui::Dataspace, ui::Dataspace) const override;
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070059
60 void dump(std::string&) const override;
61
62private:
63 void populateColorModes(const DisplayColorProfileCreationArgs::HwcColorModes& hwcColorModes);
64 void addColorMode(const DisplayColorProfileCreationArgs::HwcColorModes& hwcColorModes,
65 const ui::ColorMode mode, const ui::RenderIntent intent);
66
67 // Mappings from desired Dataspace/RenderIntent to the supported
68 // Dataspace/ColorMode/RenderIntent.
69 using ColorModeKey = uint64_t;
70 struct ColorModeValue {
71 ui::Dataspace dataspace;
72 ui::ColorMode colorMode;
73 ui::RenderIntent renderIntent;
74 };
75
76 static ColorModeKey getColorModeKey(ui::Dataspace dataspace, ui::RenderIntent intent) {
77 return (static_cast<uint64_t>(dataspace) << 32) | static_cast<uint32_t>(intent);
78 }
79
80 // Need to know if display is wide-color capable or not.
81 // Initialized by SurfaceFlinger when the DisplayDevice is created.
82 // Fed to RenderEngine during composition.
83 bool mHasWideColorGamut{false};
84 int32_t mSupportedPerFrameMetadata{0};
85 bool mHasHdr10Plus{false};
86 bool mHasHdr10{false};
87 bool mHasHLG{false};
88 bool mHasDolbyVision{false};
89 HdrCapabilities mHdrCapabilities;
90 std::unordered_map<ColorModeKey, ColorModeValue> mColorModes;
91};
92
93std::unique_ptr<compositionengine::DisplayColorProfile> createDisplayColorProfile(
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070094 const DisplayColorProfileCreationArgs&);
Lloyd Pique3d0c02e2018-10-19 18:38:12 -070095
96} // namespace impl
97} // namespace android::compositionengine