From 2daef3c6ba72f364f9ac3859efc1cf2782fff67f Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Fri, 2 Apr 2021 16:29:27 -0700 Subject: Add ExternalTexture class into RenderEngine interface ExternalTexture is an RAII structure that wraps raw GraphicBuffers that are passed into RenderEngine. ExternalTexture's role is to help with managing GPU resources of GraphicBuffers by mapping buffers into textures, EGLImages, or AutoBackendTextures depending on the RenderEngine backend. Under the hood, mapExternalTextureBuffer and unmapExternalTextureBuffer (renamed from cacheExternalTextureBuffer and unbindExternalTextureBuffer respectively) are used to help tie resource management to the ExternalTexture lifetime. The main motivation for this is that currently managing buffer lifecycle has historically been errorprone and caused memory leaks, so this improves code health. As part of this: * mapExternalTextureBuffer and unmapExternalTextureBuffer are now protected methods, and are never called outside of RenderEngine with the exception of creating and destroying ExternalTextures. * Because GLESRenderEngine's output buffers are cached differently from Skia RenderEngine, if there are output-only buffers then disable the mapExternalTextureBuffer calls whenever GLESRenderEngine is used. * Custom RAII classes in the Planner and in BufferLayerConsumer are now removed since they're subsumed by ExternalTexture * RenderSurface now controls its own management of ExternalTextures in a small queue * cleanFramebufferCache is now unimplemented for Skia, because ExternalTextures are now deleted whenever a RenderSurface is deleted. Bug: 180767535 Test: libsurfaceflinger_unittest Test: libcompositionengine_test Test: librenderengine_test Test: Simulate virtual displays Test: Screen reotation Test: Movie playback on Google TV Test: Force GPU composition Test: screenshot Change-Id: I222c71e6e1c67485cdeac49e2cb829289af9efec --- services/surfaceflinger/ClientCache.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'services/surfaceflinger/ClientCache.cpp') diff --git a/services/surfaceflinger/ClientCache.cpp b/services/surfaceflinger/ClientCache.cpp index 44b33ef43d..f310738423 100644 --- a/services/surfaceflinger/ClientCache.cpp +++ b/services/surfaceflinger/ClientCache.cpp @@ -102,7 +102,12 @@ bool ClientCache::add(const client_cache_t& cacheId, const sp& bu return false; } - processBuffers[id].buffer = buffer; + LOG_ALWAYS_FATAL_IF(mRenderEngine == nullptr, + "Attempted to build the ClientCache before a RenderEngine instance was " + "ready!"); + processBuffers[id].buffer = std::make_shared< + renderengine::ExternalTexture>(buffer, *mRenderEngine, + renderengine::ExternalTexture::Usage::READABLE); return true; } @@ -132,7 +137,7 @@ void ClientCache::erase(const client_cache_t& cacheId) { } } -sp ClientCache::get(const client_cache_t& cacheId) { +std::shared_ptr ClientCache::get(const client_cache_t& cacheId) { std::lock_guard lock(mMutex); ClientCacheBuffer* buf = nullptr; @@ -213,8 +218,8 @@ void ClientCache::dump(std::string& result) { auto &buffers = i.second.second; for (auto& [id, clientCacheBuffer] : buffers) { StringAppendF(&result, "\t ID: %d, Width/Height: %d,%d\n", (int)id, - (int)clientCacheBuffer.buffer->getWidth(), - (int)clientCacheBuffer.buffer->getHeight()); + (int)clientCacheBuffer.buffer->getBuffer()->getWidth(), + (int)clientCacheBuffer.buffer->getBuffer()->getHeight()); } } } -- cgit v1.2.3-59-g8ed1b