diff options
author | Wiwit Rifa'i <wiwitrifai@google.com> | 2023-09-14 17:14:18 +0800 |
---|---|---|
committer | Wiwit Rifa'i <wiwitrifai@google.com> | 2023-09-18 21:00:09 +0800 |
commit | e67fb287bacdb0ba9666d8f773cae4b1d6bcb52c (patch) | |
tree | ca6789e145115acce8d98134acb43fa4d7f198c8 | |
parent | 578af9e67c4bcc533d0d741c7e9d2054cdfb03bb (diff) | |
download | zuma-e67fb287bacdb0ba9666d8f773cae4b1d6bcb52c.tar.gz |
libhwc2.1: avoid finding std::map element twice
We should not use std::map::at() after calling std::map::find() for the
same key. Otherwise, it would find the same element twice and it's
unnecessary.
Bug: 295892886
Test: trigger assignResource using hwc-tester & check simpleperf
Change-Id: I971965a8b2a84120c989e55b87e223225ea32456
-rw-r--r-- | libhwc2.1/libresource/ExynosResourceManagerModule.cpp | 51 |
1 files changed, 15 insertions, 36 deletions
diff --git a/libhwc2.1/libresource/ExynosResourceManagerModule.cpp b/libhwc2.1/libresource/ExynosResourceManagerModule.cpp index 859eb48..79653b4 100644 --- a/libhwc2.1/libresource/ExynosResourceManagerModule.cpp +++ b/libhwc2.1/libresource/ExynosResourceManagerModule.cpp @@ -280,6 +280,11 @@ uint32_t ExynosResourceManagerModule::initDisplaysTDMInfo() return 0; } +uint32_t getSramAmount(tdm_attr_t attr, uint32_t formatProperty, lbWidthIndex_t widthIndex) { + auto it = sramAmountMap.find(sramAmountParams(attr, formatProperty, widthIndex)); + return (it != sramAmountMap.end()) ? it->second : 0; +} + uint32_t ExynosResourceManagerModule::calculateHWResourceAmount(ExynosDisplay *display, ExynosMPPSource *mppSrc) { @@ -316,7 +321,7 @@ uint32_t ExynosResourceManagerModule::calculateHWResourceAmount(ExynosDisplay *d /** To find index **/ uint32_t formatIndex = 0; - lbWidthIndex_t widthIndex; + lbWidthIndex_t widthIndex = LB_W_3073_INF; auto findWidthIndex = [&](int32_t w) -> lbWidthIndex_t { for (auto it = LB_WIDTH_INDEX_MAP.begin(); it != LB_WIDTH_INDEX_MAP.end(); it++) { @@ -336,27 +341,13 @@ uint32_t ExynosResourceManagerModule::calculateHWResourceAmount(ExynosDisplay *d int32_t width_y = pixel_align(width + kSramSBWCRotWidthAlign, kSramSBWCRotWidthAlign); int32_t width_c = pixel_align(width / 2 + kSramSBWCRotWidthAlign, kSramSBWCRotWidthAlign); - widthIndex = findWidthIndex(width_y); - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_ROT_90, SBWC_Y, widthIndex)) != - sramAmountMap.end()) - SRAMtotal += - sramAmountMap.at(sramAmountParams(TDM_ATTR_ROT_90, SBWC_Y, widthIndex)); - widthIndex = findWidthIndex(width_c * 2); - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_ROT_90, SBWC_UV, widthIndex)) != - sramAmountMap.end()) - SRAMtotal += - sramAmountMap.at(sramAmountParams(TDM_ATTR_ROT_90, SBWC_UV, widthIndex)); + SRAMtotal += getSramAmount(TDM_ATTR_ROT_90, SBWC_Y, findWidthIndex(width_y)); + SRAMtotal += getSramAmount(TDM_ATTR_ROT_90, SBWC_UV, findWidthIndex(width_c * 2)); } else { /* sramAmountMap has SRAM for both Y and UV */ widthIndex = findWidthIndex(width); - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_ROT_90, NON_SBWC_Y | formatBPP, - widthIndex)) != sramAmountMap.end()) - SRAMtotal += sramAmountMap.at( - sramAmountParams(TDM_ATTR_ROT_90, NON_SBWC_Y | formatBPP, widthIndex)); - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_ROT_90, NON_SBWC_UV | formatBPP, - widthIndex)) != sramAmountMap.end()) - SRAMtotal += sramAmountMap.at( - sramAmountParams(TDM_ATTR_ROT_90, NON_SBWC_UV | formatBPP, widthIndex)); + SRAMtotal += getSramAmount(TDM_ATTR_ROT_90, NON_SBWC_Y | formatBPP, widthIndex); + SRAMtotal += getSramAmount(TDM_ATTR_ROT_90, NON_SBWC_UV | formatBPP, widthIndex); } HDEBUGLOGD(eDebugTDM, "+ rotation : %d", SRAMtotal); } else { @@ -376,21 +367,14 @@ uint32_t ExynosResourceManagerModule::calculateHWResourceAmount(ExynosDisplay *d /* AFBC amount */ if (compressType == COMP_TYPE_AFBC) { formatIndex = (isFormatRgb(format) ? RGB : 0) | formatBPP; - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_AFBC, formatIndex, widthIndex)) != - sramAmountMap.end()) - SRAMtotal += - sramAmountMap.at(sramAmountParams(TDM_ATTR_AFBC, formatIndex, widthIndex)); + SRAMtotal += getSramAmount(TDM_ATTR_AFBC, formatIndex, widthIndex); HDEBUGLOGD(eDebugTDM, "+ AFBC : %d", SRAMtotal); } /* SBWC amount */ if (compressType == COMP_TYPE_SBWC) { - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_SBWC, SBWC_Y, widthIndex)) != - sramAmountMap.end()) - SRAMtotal += sramAmountMap.at(sramAmountParams(TDM_ATTR_SBWC, SBWC_Y, widthIndex)); - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_SBWC, SBWC_UV, widthIndex)) != - sramAmountMap.end()) - SRAMtotal += sramAmountMap.at(sramAmountParams(TDM_ATTR_SBWC, SBWC_UV, widthIndex)); + SRAMtotal += getSramAmount(TDM_ATTR_SBWC, SBWC_Y, widthIndex); + SRAMtotal += getSramAmount(TDM_ATTR_SBWC, SBWC_UV, widthIndex); HDEBUGLOGD(eDebugTDM, "+ SBWC : %d", SRAMtotal); } } @@ -398,9 +382,7 @@ uint32_t ExynosResourceManagerModule::calculateHWResourceAmount(ExynosDisplay *d /* ITP (CSC) amount */ if (isFormatYUV(format)) { /** ITP has no size difference, Use width index as LB_W_3073_INF **/ - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_ITP, formatBPP, LB_W_3073_INF)) != - sramAmountMap.end()) - SRAMtotal += sramAmountMap.at(sramAmountParams(TDM_ATTR_ITP, formatBPP, LB_W_3073_INF)); + SRAMtotal += getSramAmount(TDM_ATTR_ITP, formatBPP, LB_W_3073_INF); HDEBUGLOGD(eDebugTDM, "+ YUV : %d", SRAMtotal); } @@ -425,10 +407,7 @@ uint32_t ExynosResourceManagerModule::calculateHWResourceAmount(ExynosDisplay *d formatIndex = FORMAT_YUV_MASK; /** Scale has no size difference, Use width index as LB_W_3073_INF **/ - if (sramAmountMap.find(sramAmountParams(TDM_ATTR_SCALE, formatIndex, LB_W_3073_INF)) != - sramAmountMap.end()) - SRAMtotal += - sramAmountMap.at(sramAmountParams(TDM_ATTR_SCALE, formatIndex, LB_W_3073_INF)); + SRAMtotal += getSramAmount(TDM_ATTR_SCALE, formatIndex, LB_W_3073_INF); HDEBUGLOGD(eDebugTDM, "+ Scale : %d", SRAMtotal); } |