1 /* 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 27 namespace android::compositionengine { 28 29 class CompositionEngine; 30 class Display; 31 32 namespace impl { 33 34 class DisplayColorProfile : public compositionengine::DisplayColorProfile { 35 public: 36 DisplayColorProfile(const DisplayColorProfileCreationArgs&); 37 ~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; 57 bool isDataspaceSupported(ui::Dataspace) const override; 58 59 void dump(std::string&) const override; 60 61 private: 62 void populateColorModes(const DisplayColorProfileCreationArgs::HwcColorModes& hwcColorModes); 63 void addColorMode(const DisplayColorProfileCreationArgs::HwcColorModes& hwcColorModes, 64 const ui::ColorMode mode, const ui::RenderIntent intent); 65 66 // Mappings from desired Dataspace/RenderIntent to the supported 67 // Dataspace/ColorMode/RenderIntent. 68 using ColorModeKey = uint64_t; 69 struct ColorModeValue { 70 ui::Dataspace dataspace; 71 ui::ColorMode colorMode; 72 ui::RenderIntent renderIntent; 73 }; 74 getColorModeKey(ui::Dataspace dataspace,ui::RenderIntent intent)75 static ColorModeKey getColorModeKey(ui::Dataspace dataspace, ui::RenderIntent intent) { 76 return (static_cast<uint64_t>(dataspace) << 32) | static_cast<uint32_t>(intent); 77 } 78 79 // Need to know if display is wide-color capable or not. 80 // Initialized by SurfaceFlinger when the DisplayDevice is created. 81 // Fed to RenderEngine during composition. 82 bool mHasWideColorGamut{false}; 83 int32_t mSupportedPerFrameMetadata{0}; 84 bool mHasHdr10Plus{false}; 85 bool mHasHdr10{false}; 86 bool mHasHLG{false}; 87 bool mHasDolbyVision{false}; 88 HdrCapabilities mHdrCapabilities; 89 std::unordered_map<ColorModeKey, ColorModeValue> mColorModes; 90 }; 91 92 std::unique_ptr<compositionengine::DisplayColorProfile> createDisplayColorProfile( 93 const DisplayColorProfileCreationArgs&); 94 95 } // namespace impl 96 } // namespace android::compositionengine 97