diff --git a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerClient.h b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerClient.h index 86525b87ce..095189f91b 100644 --- a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerClient.h +++ b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerClient.h @@ -102,6 +102,7 @@ class ComposerClientImpl : public Interface { } void onRefresh(Display display) { + mResources->setDisplayMustValidateState(display, true); auto ret = mCallback->onRefresh(display); ALOGE_IF(!ret.isOk(), "failed to send onRefresh: %s", ret.description().c_str()); } diff --git a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h index 36aa64ef05..d87110a014 100644 --- a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h +++ b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerCommandEngine.h @@ -258,6 +258,7 @@ class ComposerCommandEngine : protected CommandReaderBase { auto err = mHal->validateDisplay(mCurrentDisplay, &changedLayers, &compositionTypes, &displayRequestMask, &requestedLayers, &requestMasks); + mResources->setDisplayMustValidateState(mCurrentDisplay, false); if (err == Error::NONE) { mWriter.setChangedCompositionTypes(changedLayers, compositionTypes); mWriter.setDisplayRequests(displayRequestMask, requestedLayers, requestMasks); @@ -278,7 +279,9 @@ class ComposerCommandEngine : protected CommandReaderBase { int presentFence = -1; std::vector layers; std::vector fences; - auto err = mHal->presentDisplay(mCurrentDisplay, &presentFence, &layers, &fences); + auto err = mResources->mustValidateDisplay(mCurrentDisplay) + ? Error::NOT_VALIDATED + : mHal->presentDisplay(mCurrentDisplay, &presentFence, &layers, &fences); if (err == Error::NONE) { mWriter.setPresentOrValidateResult(1); mWriter.setPresentFence(presentFence); @@ -296,6 +299,7 @@ class ComposerCommandEngine : protected CommandReaderBase { auto err = mHal->validateDisplay(mCurrentDisplay, &changedLayers, &compositionTypes, &displayRequestMask, &requestedLayers, &requestMasks); + mResources->setDisplayMustValidateState(mCurrentDisplay, false); if (err == Error::NONE) { mWriter.setPresentOrValidateResult(0); mWriter.setChangedCompositionTypes(changedLayers, compositionTypes); diff --git a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h index 7bb369296c..2cbf044604 100644 --- a/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h +++ b/graphics/composer/2.1/utils/hal/include/composer-hal/2.1/ComposerResources.h @@ -216,7 +216,8 @@ class ComposerDisplayResource { : mType(type), mClientTargetCache(importer), mOutputBufferCache(importer, ComposerHandleCache::HandleType::BUFFER, - outputBufferCacheSize) {} + outputBufferCacheSize), + mMustValidate(true) {} bool initClientTargetCache(uint32_t cacheSize) { return mClientTargetCache.initCache(ComposerHandleCache::HandleType::BUFFER, cacheSize); @@ -263,10 +264,15 @@ class ComposerDisplayResource { return layers; } + void setMustValidateState(bool mustValidate) { mMustValidate = mustValidate; } + + bool mustValidate() const { return mMustValidate; } + protected: const DisplayType mType; ComposerHandleCache mClientTargetCache; ComposerHandleCache mOutputBufferCache; + bool mMustValidate; std::unordered_map> mLayerResources; }; @@ -389,6 +395,23 @@ class ComposerResources { outStreamHandle, outReplacedStream); } + void setDisplayMustValidateState(Display display, bool mustValidate) { + std::lock_guard lock(mDisplayResourcesMutex); + auto* displayResource = findDisplayResourceLocked(display); + if (displayResource) { + displayResource->setMustValidateState(mustValidate); + } + } + + bool mustValidateDisplay(Display display) { + std::lock_guard lock(mDisplayResourcesMutex); + auto* displayResource = findDisplayResourceLocked(display); + if (displayResource) { + return displayResource->mustValidate(); + } + return false; + } + protected: virtual std::unique_ptr createDisplayResource( ComposerDisplayResource::DisplayType type, uint32_t outputBufferCacheSize) { diff --git a/graphics/composer/2.1/utils/passthrough/include/composer-passthrough/2.1/HwcHal.h b/graphics/composer/2.1/utils/passthrough/include/composer-passthrough/2.1/HwcHal.h index 964e75bdc5..436e4612bb 100644 --- a/graphics/composer/2.1/utils/passthrough/include/composer-passthrough/2.1/HwcHal.h +++ b/graphics/composer/2.1/utils/passthrough/include/composer-passthrough/2.1/HwcHal.h @@ -111,7 +111,6 @@ class HwcHalImpl : public Hal { } void registerEventCallback(hal::ComposerHal::EventCallback* callback) override { - mMustValidateDisplay = true; mEventCallback = callback; mDispatch.registerCallback(mDevice, HWC2_CALLBACK_HOTPLUG, this, @@ -331,7 +330,6 @@ class HwcHalImpl : public Hal { uint32_t typesCount = 0; uint32_t reqsCount = 0; int32_t err = mDispatch.validateDisplay(mDevice, display, &typesCount, &reqsCount); - mMustValidateDisplay = false; if (err != HWC2_ERROR_NONE && err != HWC2_ERROR_HAS_CHANGES) { return static_cast(err); @@ -384,10 +382,6 @@ class HwcHalImpl : public Hal { Error presentDisplay(Display display, int32_t* outPresentFence, std::vector* outLayers, std::vector* outReleaseFences) override { - if (mMustValidateDisplay) { - return Error::NOT_VALIDATED; - } - *outPresentFence = -1; int32_t err = mDispatch.presentDisplay(mDevice, display, outPresentFence); if (err != HWC2_ERROR_NONE) { @@ -593,7 +587,6 @@ class HwcHalImpl : public Hal { static void refreshHook(hwc2_callback_data_t callbackData, hwc2_display_t display) { auto hal = static_cast(callbackData); - hal->mMustValidateDisplay = true; hal->mEventCallback->onRefresh(display); } @@ -654,8 +647,6 @@ class HwcHalImpl : public Hal { } mDispatch = {}; hal::ComposerHal::EventCallback* mEventCallback = nullptr; - - std::atomic mMustValidateDisplay{true}; }; } // namespace detail