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 ui::Dataspace getTargetDataspace(ui::ColorMode, ui::Dataspace, ui::Dataspace) const override; 59 60 void dump(std::string&) const override; 61 62 private: 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 getColorModeKey(ui::Dataspace dataspace,ui::RenderIntent intent)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 93 std::unique_ptr<compositionengine::DisplayColorProfile> createDisplayColorProfile( 94 const DisplayColorProfileCreationArgs&); 95 96 } // namespace impl 97 } // namespace android::compositionengine 98