1 /* 2 * Copyright (C) 2012 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 /** 18 * Project HWC 2.0 Design 19 */ 20 21 #ifndef _EXYNOSRESOURCEMANAGER_H 22 #define _EXYNOSRESOURCEMANAGER_H 23 24 #include <unordered_map> 25 #include "ExynosDevice.h" 26 #include "ExynosDisplay.h" 27 #include "ExynosHWCHelper.h" 28 #include "ExynosMPPModule.h" 29 #include "ExynosResourceRestriction.h" 30 31 using namespace android; 32 33 class ExynosDevice; 34 class ExynosDisplay; 35 class ExynosMPP; 36 37 #define ASSIGN_RESOURCE_TRY_COUNT 100 38 39 #define MAX_OVERLAY_LAYER_NUM 20 40 41 const std::map<mpp_phycal_type_t, uint64_t> sw_feature_table = 42 { 43 {MPP_DPP_G, MPP_ATTR_DIM}, 44 {MPP_DPP_GF, MPP_ATTR_DIM}, 45 {MPP_DPP_GFS, MPP_ATTR_DIM}, 46 {MPP_DPP_VG, MPP_ATTR_DIM}, 47 {MPP_DPP_VGS, MPP_ATTR_DIM}, 48 {MPP_DPP_VGF, MPP_ATTR_DIM}, 49 {MPP_DPP_VGFS, MPP_ATTR_DIM}, 50 {MPP_DPP_VGRFS, MPP_ATTR_DIM}, 51 }; 52 53 #ifndef USE_MODULE_DPU_ATTR_MAP 54 const dpu_attr_map_t dpu_attr_map_table [] = 55 { 56 {DPP_ATTR_AFBC, MPP_ATTR_AFBC}, 57 {DPP_ATTR_BLOCK, MPP_ATTR_BLOCK_MODE}, 58 {DPP_ATTR_FLIP, MPP_ATTR_FLIP_H | MPP_ATTR_FLIP_V}, 59 {DPP_ATTR_ROT, MPP_ATTR_ROT_90}, 60 {DPP_ATTR_SCALE, MPP_ATTR_SCALE}, 61 {DPP_ATTR_HDR, MPP_ATTR_HDR10}, 62 {DPP_ATTR_C_HDR, MPP_ATTR_HDR10}, 63 {DPP_ATTR_C_HDR10_PLUS, MPP_ATTR_HDR10PLUS}, 64 {DPP_ATTR_WCG, MPP_ATTR_WCG}, 65 }; 66 #endif 67 68 /* Based on multi-resolution feature */ 69 enum dst_realloc_state { 70 DST_REALLOC_DONE = 0, 71 DST_REALLOC_START, 72 DST_REALLOC_GOING, 73 }; 74 75 class ExynosMPPVector : public android::SortedVector< ExynosMPP* > { 76 public: 77 ExynosMPPVector(); 78 ExynosMPPVector(const ExynosMPPVector& rhs); 79 virtual int do_compare(const void* lhs, const void* rhs) const; 80 }; 81 82 class ExynosResourceManager { 83 private: 84 class DstBufMgrThread: public Thread { 85 private: 86 ExynosResourceManager *mExynosResourceManager; 87 Condition mCondition; 88 public: 89 bool mRunning; 90 Mutex mMutex; 91 Mutex mStateMutex; 92 Mutex mResInfoMutex; 93 uint32_t mBufXres; 94 uint32_t mBufYres; 95 void reallocDstBufs(uint32_t Xres, uint32_t Yres); 96 bool needDstRealloc(uint32_t Xres, uint32_t Yres, ExynosMPP *m2mMPP); 97 DstBufMgrThread(ExynosResourceManager *exynosResourceManager); 98 ~DstBufMgrThread(); 99 virtual bool threadLoop(); 100 }; 101 102 public: 103 uint32_t mForceReallocState; 104 ExynosDevice *mDevice; 105 bool hasHdrLayer; 106 bool hasDrmLayer; 107 bool isHdrExternal; 108 109 uint32_t mFormatRestrictionCnt; 110 uint32_t mSizeRestrictionCnt[RESTRICTION_MAX]; 111 restriction_key_t mFormatRestrictions[RESTRICTION_CNT_MAX]; 112 restriction_size_element_t mSizeRestrictions[RESTRICTION_MAX][RESTRICTION_CNT_MAX]; 113 114 std::unordered_map<uint32_t /* physical type */, uint64_t /* attribute */> mMPPAttrs; 115 116 ExynosResourceManager(ExynosDevice *device); 117 virtual ~ExynosResourceManager(); 118 void reloadResourceForHWFC(); 119 void setTargetDisplayLuminance(uint16_t min, uint16_t max); 120 void setTargetDisplayDevice(int device); 121 int32_t doPreProcessing(); 122 void doReallocDstBufs(uint32_t Xres, uint32_t Yres); 123 int32_t doAllocDstBufs(uint32_t mXres, uint32_t mYres); 124 int32_t assignResource(ExynosDisplay *display); 125 int32_t assignResourceInternal(ExynosDisplay *display); 126 static ExynosMPP* getExynosMPP(uint32_t type); 127 static ExynosMPP* getExynosMPP(uint32_t physicalType, uint32_t physicalIndex); 128 static void enableMPP(uint32_t physicalType, uint32_t physicalIndex, uint32_t logicalIndex, uint32_t enable); 129 static void setScaleDownRatio(uint32_t physicalType, 130 uint32_t physicalIndex, uint32_t logicalIndex, 131 uint32_t scaleDownRatio); 132 int32_t updateSupportedMPPFlag(ExynosDisplay * display); 133 int32_t resetResources(); 134 int32_t preAssignResources(); 135 void preAssignWindows(ExynosDisplay *display); 136 int32_t preProcessLayer(ExynosDisplay *display); 137 int32_t resetAssignedResources(ExynosDisplay *display, bool forceReset = false); 138 virtual int32_t assignCompositionTarget(ExynosDisplay *display, uint32_t targetType); 139 int32_t validateLayer(uint32_t index, ExynosDisplay *display, ExynosLayer *layer); 140 int32_t assignLayers(ExynosDisplay *display, uint32_t priority); otfMppReordering(ExynosDisplay * __unused display,ExynosMPPVector __unused & otfMPPs,struct exynos_image __unused & src,struct exynos_image __unused & dst)141 virtual int32_t otfMppReordering(ExynosDisplay *__unused display, 142 ExynosMPPVector __unused &otfMPPs, 143 struct exynos_image __unused &src, 144 struct exynos_image __unused &dst) { 145 return 0; 146 } 147 virtual int32_t assignLayer(ExynosDisplay *display, ExynosLayer *layer, uint32_t layer_index, 148 exynos_image &m2m_out_img, ExynosMPP **m2mMPP, ExynosMPP **otfMPP, uint32_t &overlayInfo); 149 virtual int32_t assignWindow(ExynosDisplay *display); 150 virtual int32_t checkScenario(ExynosDisplay *display); 151 int32_t updateResourceState(); 152 static float getResourceUsedCapa(ExynosMPP &mpp); 153 int32_t updateExynosComposition(ExynosDisplay *display); 154 int32_t updateClientComposition(ExynosDisplay *display); 155 int32_t getCandidateM2mMPPOutImages(ExynosDisplay *display, 156 ExynosLayer *layer, std::vector<exynos_image> &image_lists); 157 int32_t setResourcePriority(ExynosDisplay *display); 158 int32_t deliverPerformanceInfo(); 159 int32_t prepareResources(const int32_t willOnDispId = -1); 160 int32_t finishAssignResourceWork(); 161 int32_t initResourcesState(ExynosDisplay *display); 162 getOtfMPPSize()163 uint32_t getOtfMPPSize() {return (uint32_t)mOtfMPPs.size();}; getOtfMPP(uint32_t index)164 ExynosMPP* getOtfMPP(uint32_t index) {return mOtfMPPs[index];}; 165 getM2mMPPSize()166 uint32_t getM2mMPPSize() {return (uint32_t)mM2mMPPs.size();}; getM2mMPP(uint32_t index)167 ExynosMPP* getM2mMPP(uint32_t index) {return mM2mMPPs[index];}; 168 169 virtual void makeAcrylRestrictions(mpp_phycal_type_t type); 170 void makeSizeRestrictions(uint32_t mppId, const restriction_size_t &size, 171 restriction_classification_t format); 172 void makeFormatRestrictions(restriction_key_t table); 173 174 void updateRestrictions(); 175 176 mpp_phycal_type_t getPhysicalType(int ch) const; 177 ExynosMPP* getOtfMPPWithChannel(int ch); 178 uint32_t getFeatureTableSize() const; getOtfMPPs()179 const static ExynosMPPVector& getOtfMPPs() { return mOtfMPPs; }; 180 float getM2MCapa(uint32_t physicalType); 181 virtual bool hasHDR10PlusMPP(); 182 float getAssignedCapacity(uint32_t physicalType); 183 184 void dump(String8 &result) const; 185 void setM2MCapa(uint32_t physicalType, uint32_t capa); 186 virtual bool isAssignable(ExynosMPP* candidateMPP, ExynosDisplay* display, 187 struct exynos_image& src, struct exynos_image& dst, 188 ExynosMPPSource* mppSrc); 189 190 private: 191 int32_t changeLayerFromClientToDevice(ExynosDisplay* display, ExynosLayer* layer, 192 uint32_t layer_index, const exynos_image& m2m_out_img, 193 ExynosMPP* m2mMPP, ExynosMPP* otfMPP); 194 void dump(const restriction_classification_t, String8 &result) const; 195 196 sp<DstBufMgrThread> mDstBufMgrThread; 197 198 protected: 199 virtual void setFrameRateForPerformance(ExynosMPP &mpp, AcrylicPerformanceRequestFrame *frame); 200 void getCandidateScalingM2mMPPOutImages(const ExynosDisplay *display, 201 const exynos_image &src_img, 202 const exynos_image &dst_img, 203 std::vector<exynos_image> &image_lists); 204 exynos_image getAlignedImage(exynos_image image, const ExynosMPP *m2mMpp, 205 const ExynosMPP *otfMpp) const; 206 int32_t validateRCDLayer(const ExynosDisplay &display, const ExynosLayer &layer, 207 const uint32_t layerIndex, const exynos_image &srcImg, 208 const exynos_image &dstImg); 209 static ExynosMPPVector mOtfMPPs; 210 static ExynosMPPVector mM2mMPPs; 211 uint32_t mResourceReserved; /* Set MPP logical type for bit operation */ 212 float mMinimumSdrDimRatio; 213 214 android::Vector<ExynosDisplay *> mDisplays; 215 std::map<uint32_t, ExynosDisplay *> mDisplayMap; 216 217 protected: 218 bool mDeviceSupportWCG = false; 219 220 public: initDisplays(android::Vector<ExynosDisplay * > displays,std::map<uint32_t,ExynosDisplay * > displayMap)221 void initDisplays(android::Vector<ExynosDisplay *> displays, 222 std::map<uint32_t, ExynosDisplay *> displayMap) { 223 mDisplays = displays; 224 mDisplayMap = displayMap; 225 } getDisplay(uint32_t displayId)226 ExynosDisplay *getDisplay(uint32_t displayId) { return mDisplayMap[displayId]; } 227 228 virtual void updateSupportWCG(); deviceSupportWCG()229 virtual bool deviceSupportWCG() { return mDeviceSupportWCG; } 230 231 /* return 1 if it's needed */ 232 bool needHdrProcessing(ExynosDisplay *display, exynos_image &srcImg, exynos_image &dstImg); 233 uint32_t needHWResource(ExynosDisplay *display, exynos_image &srcImg, exynos_image &dstImg, 234 tdm_attr_t attr); 235 236 /* TDM (Time-Division Multiplexing) based Resource Management */ isHWResourceAvailable(ExynosDisplay __unused * display,ExynosMPP __unused * currentMPP,ExynosMPPSource __unused * mppSrc)237 virtual bool isHWResourceAvailable(ExynosDisplay __unused *display, 238 ExynosMPP __unused *currentMPP, 239 ExynosMPPSource __unused *mppSrc) { 240 return true; 241 } setDisplaysTDMInfo(__unused ExynosDisplay * mainDisp,__unused ExynosDisplay * minorDisp)242 virtual uint32_t setDisplaysTDMInfo(__unused ExynosDisplay* mainDisp, 243 __unused ExynosDisplay* minorDisp) { 244 return 0; 245 } calculateHWResourceAmount(ExynosDisplay __unused * display,ExynosMPPSource __unused * mppSrc)246 virtual uint32_t calculateHWResourceAmount(ExynosDisplay __unused *display, 247 ExynosMPPSource __unused *mppSrc) { 248 return 0; 249 } 250 251 std::pair<ExynosDisplay*, ExynosDisplay*> decideMainAndMinorDisplay( 252 const int32_t willOnDispId) const; 253 void updatePreAssignDisplayList(const ExynosDisplay* mainDisp, 254 const ExynosDisplay* minorDisp); 255 }; 256 257 #endif //_EXYNOSRESOURCEMANAGER_H 258