हमारा सुझाव है कि 27 मार्च, 2025 से AOSP को बनाने और उसमें योगदान देने के लिए, aosp-main
के बजाय android-latest-release
का इस्तेमाल करें. ज़्यादा जानकारी के लिए, AOSP में हुए बदलाव लेख पढ़ें.
क्लाइंट फ़्रेमबफ़र मैनेजमेंट
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
Android 13 से, डिसप्ले रिज़ॉल्यूशन बदलने पर, क्लाइंट कॉम्पोज़िशन के दौरान इस्तेमाल किए जाने वाले नए फ़्रेमबफ़र को असाइन किया जाता है. रिज़ॉल्यूशन में बदलाव होने के बाद, SurfaceFlinger अगले अमान्य साइकल में यह ऐलोकेशन करता है.
रिज़ॉल्यूशन स्विच करने के दौरान फ़्रेमबफ़र मैनेजमेंट
रिज़ॉल्यूशन में बदलाव, इनमें से किसी एक वजह से होता है:
hotplug इवेंट, हार्डवेयर कंपोजर (एचडब्ल्यूसी) से शुरू होता है. यह तब होता है, जब किसी बाहरी डिसप्ले को किसी ऐसे दूसरे बाहरी डिसप्ले से बदला जाता है जिसका डिफ़ॉल्ट रिज़ॉल्यूशन अलग होता है.
hotplug इवेंट के दौरान, पुराने डिसप्ले डेटा को डिएलोकेट करने पर, पुराने फ़्रेमबफ़र के हैंडल रिलीज़ कर दिए जाते हैं.
SurfaceFlinger की ओर से शुरू किया गया डिसप्ले मोड स्विच. ऐसा तब होता है, जब उपयोगकर्ता उपयोगकर्ता सेटिंग की मदद से रिज़ॉल्यूशन बदलता है या कोई ऐप्लिकेशन preferredDisplayModeId
की मदद से रिज़ॉल्यूशन बदलता है.
डिसप्ले मोड स्विच करने के दौरान, SurfaceFlinger, setActiveConfig
या setActiveConfigWithConstraints
को कॉल करने से पहले, मौजूदा क्लाइंट फ़्रेमबफ़र के हैंडल रिलीज़ कर देता है.
जिन डिवाइसों में पुराने और नए फ़्रेमबफ़र के लिए ज़रूरत के मुताबिक मेमोरी नहीं होती उन पर मेमोरी फ़्रैगमेंटेशन जैसी गंभीर समस्याओं से बचने के लिए, यह ज़रूरी है कि एचडब्ल्यूसी पुराने फ़्रेमबफ़र का इस्तेमाल बंद कर दे और इन फ़्रेमबफ़र के सभी हैंडल रिलीज़ कर दे. ऐसा इन मामलों में किया जाता है:
हैंडल रिलीज़ करने पर, नए फ़्रेमबफ़र के लिए मेमोरी को पूरी तरह से डिएलोकेट किया जा सकता है. SurfaceFlinger, अगले अमान्य साइकल के दौरान ऐसा करता है.
फ़्रेमबफ़र मैनेजमेंट के लिए सुझाव
अगर HWC, पुराने फ़्रेमबफ़र के हैंडल को समय पर रिलीज़ नहीं करता है, तो पुराने फ़्रेमबफ़र के डिएलोकेशन से पहले, नया फ़्रेमबफ़र ऐलोकेशन हो जाता है. फ़्रैगमेंटेशन या अन्य समस्याओं की वजह से, नया ऐलोकेशन न होने पर, गंभीर समस्याएं हो सकती हैं. इससे भी बुरा यह हो सकता है कि एचडब्ल्यूसी इन हैंडल को रिलीज़ न करे. ऐसा होने पर, मेमोरी लीक हो सकती है.
ऐलोकेशन में होने वाली गड़बड़ियों से बचने के लिए, ये सुझाव अपनाएं:
अगर नए क्लाइंट फ़्रेमबफ़र उपलब्ध कराए जाने तक, एचडब्ल्यूसी को पुराने क्लाइंट फ़्रेमबफ़र का इस्तेमाल करना जारी रखना है, तो पुराने और नए, दोनों फ़्रेमबफ़र के लिए ज़रूरत के मुताबिक मेमोरी रिज़र्व करना ज़रूरी है. साथ ही, फ़्रेमबफ़र मेमोरी स्पेस पर, डेफ़्रैग्मेंटेशन एल्गोरिदम चलाया जा सकता है.
फ़्रेमबफ़र के लिए, अलग से मेमोरी पूल तय करें. यह पूल, बाकी ग्राफ़िक बफ़र मेमोरी से अलग होना चाहिए. यह ज़रूरी है, क्योंकि फ़्रेमबफ़र को डिएलोकेट करने और फिर से लोकेट करने के बीच, तीसरे पक्ष की कोई प्रोसेस ग्राफ़िक मेमोरी को लोकेट करने की कोशिश कर सकती है. अगर फ़्रेमबफ़र में उसी ग्राफ़िक मेमोरी पूल का इस्तेमाल किया जाता है और ग्राफ़िक मेमोरी भरी हुई है, तो तीसरे पक्ष की प्रोसेस, फ़्रेमबफ़र से पहले से तय की गई ग्राफ़िक मेमोरी का इस्तेमाल कर सकती है. इससे, फ़्रेमबफ़र को फिर से तय करने के लिए मेमोरी कम रह जाती है या मेमोरी स्पेस फ़्रैगमेंट हो सकता है.
फ़्रेमबफ़र मैनेजमेंट की जांच करना
OEM को सलाह दी जाती है कि वे अपने डिवाइस के लिए, रिज़ॉल्यूशन स्विच करने पर क्लाइंट फ़्रेमबफ़र मेमोरी के सही मैनेजमेंट की जांच करें. इसके लिए, यह तरीका अपनाएं:
हॉटप्लग इवेंट के लिए, बस दो अलग-अलग डिसप्ले को अलग-अलग रिज़ॉल्यूशन के साथ अनप्लग और फिर से कनेक्ट करें.
फ़्रेमबफ़र मेमोरी के व्यवहार की जांच करने के लिए, मोड स्विच शुरू करने के लिए ModeSwitchingTestActivity
सीटीएस पुष्टि करने वाले टूल का इस्तेमाल करें.
इस टेस्ट से, उन समस्याओं का पता लगाया जा सकता है जिन्हें प्रोग्राम के हिसाब से पता लगाना मुश्किल होता है.
इस पेज पर मौजूद कॉन्टेंट और कोड सैंपल कॉन्टेंट के लाइसेंस में बताए गए लाइसेंस के हिसाब से हैं. Java और OpenJDK, Oracle और/या इससे जुड़ी हुई कंपनियों के ट्रेडमार्क या रजिस्टर किए हुए ट्रेडमार्क हैं.
आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया.
[[["समझने में आसान है","easyToUnderstand","thumb-up"],["मेरी समस्या हल हो गई","solvedMyProblem","thumb-up"],["अन्य","otherUp","thumb-up"]],[["वह जानकारी मौजूद नहीं है जो मुझे चाहिए","missingTheInformationINeed","thumb-down"],["बहुत मुश्किल है / बहुत सारे चरण हैं","tooComplicatedTooManySteps","thumb-down"],["पुराना","outOfDate","thumb-down"],["अनुवाद से जुड़ी समस्या","translationIssue","thumb-down"],["सैंपल / कोड से जुड़ी समस्या","samplesCodeIssue","thumb-down"],["अन्य","otherDown","thumb-down"]],["आखिरी बार 2025-07-27 (UTC) को अपडेट किया गया."],[],[],null,["# Client framebuffer management\n\nStarting with Android 13, new framebuffers, used during\n[client](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/graphics/composer/aidl/android/hardware/graphics/composer3/DisplayCommand.aidl#113)\ncomposition, are allocated whenever the display resolution changes. This\nallocation is performed by SurfaceFlinger on the next *invalidate* cycle\nafter a resolution change.\n\nFramebuffer management during resolution switches\n-------------------------------------------------\n\nResolution changes occur due to one of the following\ntwo scenarios:\n\n- A [hotplug event](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/graphics/composer/aidl/android/hardware/graphics/composer3/IComposerCallback.aidl#41),\n initiated by Hardware Composer (HWC), which occurs when swapping from one external\n display to a different external display that has a different default resolution.\n\n During a hotplug event, the handles to the old framebuffers are released\n when the old display data is deallocated.\n- A display mode switch initiated by SurfaceFlinger, which occurs when the\n user changes the resolution with [user settings](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/core/java/android/hardware/display/DisplayManager.java#1209),\n or an app changes the resolution with [`preferredDisplayModeId`](https://developer.android.com/reference/android/view/WindowManager.LayoutParams#preferredDisplayModeId).\n\n During a display mode switch, the handles to existing client framebuffers\n are released by SurfaceFlinger before calling [`setActiveConfig`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/graphics/composer/aidl/android/hardware/graphics/composer3/IComposerClient.aidl#550)\n or [`setActiveConfigWithConstraints`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/graphics/composer/aidl/android/hardware/graphics/composer3/IComposerClient.aidl#577).\n\nTo avoid catastrophic problems, such as memory fragmentation, on devices that\ndon't reserve enough memory for the old and new framebuffers, it's critical\nthat HWC ceases to use the old framebuffers and releases any\nhandles to these framebuffers as shown in the following cases:\n\n- For hotplug events, immediately before calling [`onHotplug`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/graphics/composer/aidl/android/hardware/graphics/composer3/IComposerCallback.aidl#41).\n\n- For mode switches, immediately after the call to [`setActiveConfig`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/graphics/composer/aidl/android/hardware/graphics/composer3/IComposerClient.aidl#550)\n or [`setActiveConfigWithConstraints`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/graphics/composer/aidl/android/hardware/graphics/composer3/IComposerClient.aidl#577).\n\nReleasing the handles allows the framebuffer memory to be fully deallocated\nprior to the allocation of new framebuffers that SurfaceFlinger performs\nduring the next *invalidate* cycle.\n\n### Recommendations for framebuffer management\n\nIf HWC doesn't release handles to old framebuffers in time,\nthe new framebuffer allocation takes place before the old framebuffer\ndeallocation. This can cause catastrophic problems when the new allocation fails\ndue to fragmentation or other issues. Even worse, if\nHWC doesn't release these handles at all, a memory leak can\noccur.\n\nTo avoid catastrophic allocation failures, follow these recommendations:\n\n- If HWC needs to continue using the old client framebuffers until the new\n client framebuffers are provided, then it's critical to reserve enough memory\n for both the old and new framebuffers, and possibly run defragmentation\n algorithms on the framebuffer memory space.\n\n- Allocate a dedicated memory pool for the framebuffers that's separate from\n the rest of the graphic buffer memory. This is important because between\n deallocation and reallocation of the framebuffers, a third-party process can\n attempt to allocate graphics memory. If the same graphics memory pool is\n used by the framebuffer and if the graphics memory is full, the third-party\n process can occupy the graphics memory previously allocated by a framebuffer,\n thus leaving insufficient memory for the framebuffer reallocation or, possibly\n fragmenting the memory space.\n\nTest framebuffer management\n---------------------------\n\nOEMs are advised to test for proper client framebuffer memory management across\nresolution switches for their device, described as follows:\n\n- For hotplug events, simply unplug and reconnect two different displays with\n different resolutions.\n\n- For mode switches, use the [`ModeSwitchingTestActivity`](https://cs.android.com/android/platform/superproject/+/android-latest-release:cts/apps/CtsVerifier/src/com/android/cts/verifier/tv/display/ModeSwitchingTestActivity.java;l=47-53;drc=c80d948aff1e7df5c2dc0ddba0d1cd63a90e4d9c) CTS\n Verifier test to initiate a mode switch for testing framebuffer memory behavior.\n This test can visually identify problems that are hard to detect\n programmatically."]]