1 /* 2 * Copyright (C) 2023 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 #ifndef EXYNOS_DISPLAY_MODULE_ZUMAPRO_H 18 #define EXYNOS_DISPLAY_MODULE_ZUMAPRO_H 19 20 #include "../../zuma/libhwc2.1/libmaindisplay/ExynosPrimaryDisplayModule.h" 21 #include "HistogramController.h" 22 #include "worker.h" 23 24 namespace zumapro { 25 26 using namespace displaycolor; 27 28 class ExynosPrimaryDisplayModule : public gs201::ExynosPrimaryDisplayModule { 29 public: 30 ExynosPrimaryDisplayModule(uint32_t index, ExynosDevice* device, 31 const std::string& displayName); 32 ~ExynosPrimaryDisplayModule(); 33 int32_t validateWinConfigData() override; 34 void checkPreblendingRequirement() override; 35 36 protected: 37 class OperationRateManager : public gs201::ExynosPrimaryDisplayModule::OperationRateManager { 38 public: 39 OperationRateManager(ExynosPrimaryDisplay* display, int32_t hsHz, int32_t nsHz); 40 virtual ~OperationRateManager(); 41 42 int32_t onLowPowerMode(bool enabled) override; 43 int32_t onPeakRefreshRate(uint32_t rate) override; 44 int32_t onConfig(hwc2_config_t cfg) override; 45 int32_t onBrightness(uint32_t dbv) override; 46 int32_t onPowerMode(int32_t mode) override; 47 int32_t getTargetOperationRate() const override; 48 49 protected: 50 class HistogramQueryWorker : public Worker { 51 public: 52 HistogramQueryWorker(OperationRateManager* op, float deltaThreshold); 53 ~HistogramQueryWorker(); 54 55 bool isRuntimeResolutionConfig() const; 56 void updateConfig(uint32_t xres, uint32_t yres); 57 void startQuery(); 58 void stopQuery(); 59 60 protected: 61 void Routine() override; 62 63 private: 64 void prepare(); 65 void unprepare(); 66 67 OperationRateManager* mOpRateManager; 68 ndk::SpAIBinder mSpAIBinder; 69 HistogramDevice::HistogramConfig mConfig; 70 bool mReady; 71 bool mQueryMode; 72 float mHistogramLumaDeltaThreshold; 73 float mPrevHistogramLuma; 74 75 // Use the fixed weights from sensor team's measurement (b/286330225). These values 76 // can be used for all devices since we just need a fix set then the DTE team can 77 // determine the threshold of luma delta after evaluations. 78 static constexpr uint32_t kHistogramConfigWeightR = 186; 79 static constexpr uint32_t kHistogramConfigWeightG = 766; 80 static constexpr uint32_t kHistogramConfigWeightB = 72; 81 }; 82 83 private: 84 enum class DispOpCondition : uint32_t { 85 PANEL_SET_POWER = 0, 86 SET_CONFIG, 87 SET_DBV, 88 HISTOGRAM_DELTA, 89 MAX, 90 }; 91 92 int32_t onHistogram(); 93 int32_t updateOperationRateLocked(const DispOpCondition cond); 94 95 ExynosPrimaryDisplay* mDisplay; 96 const int32_t mDisplayHsOperationRate; 97 const int32_t mDisplayNsOperationRate; 98 int32_t mDisplayTargetOperationRate; 99 int32_t mDisplayNsMinDbv; 100 int32_t mDisplayPeakRefreshRate; 101 int32_t mDisplayRefreshRate; 102 int32_t mDisplayLastDbv; 103 int32_t mDisplayDbv; 104 int32_t mDisplayHsSwitchMinDbv; 105 std::optional<hwc2_power_mode_t> mDisplayPowerMode; 106 bool mDisplayLowBatteryModeEnabled; 107 Mutex mLock; 108 109 static constexpr uint32_t kBrightnessDeltaThreshold = 10; 110 static constexpr uint32_t kLowPowerOperationRate = 30; 111 112 std::unique_ptr<HistogramQueryWorker> mHistogramQueryWorker; 113 }; 114 }; 115 116 } // namespace zumapro 117 118 #endif // EXYNOS_DISPLAY_MODULE_ZUMAPRO_H 119