Defer deleting ExternalTextures that go out of scope during DrawLayers
Some buffers (e.g. protected content) are not pre-mapped into a
texture. Their textures are created in drawLayers and go out of scope
at the end of drawLayers drawLayers when those temporary textures are
sent to the GPU.
This CL ensures that in those cases we defer unbinding and deleting the
temporary texture until the cleanupPostRender method is called. Also to
avoid unecessary thread hops into cleanupPostRender this CL also adds a
thread-safe check to see if cleanup is necessary. Finally, we also make
the threaded variant asynchronous to further improve the availability of
SurfaceFlinger.
Bug: 190628682
Bug: 191132989
Test: atest librenderengine_test and perfetto traces
Change-Id: Ic2f4384cd1957c928a0ef656a98eb0041e29622c
diff --git a/libs/renderengine/gl/GLESRenderEngine.cpp b/libs/renderengine/gl/GLESRenderEngine.cpp
index 18eb7b5..b5dd8ac 100644
--- a/libs/renderengine/gl/GLESRenderEngine.cpp
+++ b/libs/renderengine/gl/GLESRenderEngine.cpp
@@ -970,37 +970,17 @@
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
-bool GLESRenderEngine::cleanupPostRender(CleanupMode mode) {
+bool GLESRenderEngine::canSkipPostRenderCleanup() const {
+ return mPriorResourcesCleaned ||
+ (mLastDrawFence != nullptr && mLastDrawFence->getStatus() != Fence::Status::Signaled);
+}
+
+void GLESRenderEngine::cleanupPostRender() {
ATRACE_CALL();
- if (mPriorResourcesCleaned ||
- (mLastDrawFence != nullptr && mLastDrawFence->getStatus() != Fence::Status::Signaled)) {
+ if (canSkipPostRenderCleanup()) {
// If we don't have a prior frame needing cleanup, then don't do anything.
- return false;
- }
-
- // This is a bit of a band-aid fix for FrameCaptureProcessor, as we should
- // not need to keep memory around if we don't need to do so.
- if (mode == CleanupMode::CLEAN_ALL) {
- // TODO: SurfaceFlinger memory utilization may benefit from resetting
- // texture bindings as well. Assess if it does and there's no performance regression
- // when rebinding the same image data to the same texture, and if so then its mode
- // behavior can be tweaked.
- if (mPlaceholderImage != EGL_NO_IMAGE_KHR) {
- for (auto [textureName, bufferId] : mTextureView) {
- if (bufferId && mPlaceholderImage != EGL_NO_IMAGE_KHR) {
- glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureName);
- glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES,
- static_cast<GLeglImageOES>(mPlaceholderImage));
- mTextureView[textureName] = std::nullopt;
- checkErrors();
- }
- }
- }
- {
- std::lock_guard<std::mutex> lock(mRenderingMutex);
- mImageCache.clear();
- }
+ return;
}
// Bind the texture to placeholder so that backing image data can be freed.
@@ -1011,7 +991,6 @@
// we could no-op repeated calls of this method instead.
mLastDrawFence = nullptr;
mPriorResourcesCleaned = true;
- return true;
}
void GLESRenderEngine::cleanFramebufferCache() {