1 /* 2 * Copyright (C) 2024 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 #include <displaycolor/displaycolor.h> 18 19 #include "ExynosDisplayContextProvider.h" 20 #include "libdevice/BrightnessController.h" 21 22 namespace android::hardware::graphics::composer { 23 24 // Implement DisplayContextProvider getBrightnessMode() const25BrightnessMode ExynosDisplayContextProvider::getBrightnessMode() const { 26 if (!mDisplay || !(mDisplay->mBrightnessController)) { 27 return BrightnessMode::kInvalidBrightnessMode; 28 } 29 auto res = mDisplay->mBrightnessController->getBrightnessNitsAndMode(); 30 if (res == std::nullopt) { 31 return BrightnessMode::kInvalidBrightnessMode; 32 } 33 auto brightnessMode = std::get<displaycolor::BrightnessMode>(res.value()); 34 switch (brightnessMode) { 35 case displaycolor::BrightnessMode::BM_NOMINAL: { 36 return BrightnessMode::kNormalBrightnessMode; 37 } 38 case displaycolor::BrightnessMode::BM_HBM: { 39 return BrightnessMode::kHighBrightnessMode; 40 } 41 default: { 42 return BrightnessMode::kInvalidBrightnessMode; 43 } 44 } 45 } 46 getBrightnessNits() const47int ExynosDisplayContextProvider::getBrightnessNits() const { 48 if (!mDisplay || !(mDisplay->mBrightnessController)) { 49 return -1; 50 } 51 auto res = mDisplay->mBrightnessController->getBrightnessNitsAndMode(); 52 if (res == std::nullopt) { 53 return -1; 54 } 55 return std::round(std::get<float>(res.value())); 56 } 57 getDisplayFileNodePath() const58const char* ExynosDisplayContextProvider::getDisplayFileNodePath() const { 59 return mDisplayFileNodePath.c_str(); 60 } 61 getAmbientLightSensorOutput() const62int ExynosDisplayContextProvider::getAmbientLightSensorOutput() const { 63 return -1; 64 } 65 isProximityThrottlingEnabled() const66bool ExynosDisplayContextProvider::isProximityThrottlingEnabled() const { 67 return false; 68 } 69 // End of DisplayContextProvider implementation. 70 getDisplayConfigs() const71const std::map<uint32_t, displayConfigs_t>* ExynosDisplayContextProvider::getDisplayConfigs() 72 const { 73 if (!mDisplay) return nullptr; 74 return &(mDisplay->mDisplayConfigs); 75 } 76 getDisplayConfig(hwc2_config_t id) const77const displayConfigs_t* ExynosDisplayContextProvider::getDisplayConfig(hwc2_config_t id) const { 78 const auto configs = getDisplayConfigs(); 79 if ((!configs) || configs->count(id) == 0) { 80 return nullptr; 81 } 82 const auto& config = configs->find(id); 83 return &(config->second); 84 } 85 isHsMode(hwc2_config_t id) const86bool ExynosDisplayContextProvider::isHsMode(hwc2_config_t id) const { 87 auto config = getDisplayConfig(id); 88 return config ? (!config->isNsMode) : false; 89 } 90 getTeFrequency(hwc2_config_t id) const91int ExynosDisplayContextProvider::getTeFrequency(hwc2_config_t id) const { 92 auto config = getDisplayConfig(id); 93 return config ? durationNsToFreq(config->vsyncPeriod) : -1; 94 } 95 getMaxFrameRate(hwc2_config_t id) const96int ExynosDisplayContextProvider::getMaxFrameRate(hwc2_config_t id) const { 97 auto config = getDisplayConfig(id); 98 return config ? durationNsToFreq(config->refreshRate) : -1; 99 } 100 getWidth(hwc2_config_t id) const101int ExynosDisplayContextProvider::getWidth(hwc2_config_t id) const { 102 auto config = getDisplayConfig(id); 103 return config ? config->width : -1; 104 } 105 getHeight(hwc2_config_t id) const106int ExynosDisplayContextProvider::getHeight(hwc2_config_t id) const { 107 auto config = getDisplayConfig(id); 108 return config ? config->height : -1; 109 } 110 111 } // namespace android::hardware::graphics::composer 112