Strengthen dataspace guarantees in SurfaceFlinger.
Correctly converting from yuv to rgb in RenderEngine requires that the
buffer dataspace is accurate. So, if the dataspace on a layer differs
from the buffer then update the dataspace in the buffer's metadata to be
consistent.
Moreover, some GPU drivers do not perform yuv2rgb in a reasonable way
when the dataspace is UNKNOWN. In that case, reauthor the dataspace to
be sRGB so that there is consistent behavior for an UNKNOWN dataspace.
Finally, some GPU drivers cache gralloc metadata on creation of GPU
resources, which is not compliant with gralloc expectations. So that
vendors have some time to fix the drivers and so that GSI tests pass,
recreate GPU resources when the vendor partition is old and the buffer
is a YCbCr format.
Bug: 247826480
Test: SurfaceControlTest
Change-Id: Iee2641acce3926c826e96c56ececb431868d8598
diff --git a/libs/renderengine/ExternalTexture.cpp b/libs/renderengine/ExternalTexture.cpp
index 210dca5..9eb42cd 100644
--- a/libs/renderengine/ExternalTexture.cpp
+++ b/libs/renderengine/ExternalTexture.cpp
@@ -14,17 +14,17 @@
* limitations under the License.
*/
+#include <log/log.h>
#include <renderengine/RenderEngine.h>
#include <renderengine/impl/ExternalTexture.h>
#include <ui/GraphicBuffer.h>
-
-#include "log/log_main.h"
+#include <utils/Trace.h>
namespace android::renderengine::impl {
ExternalTexture::ExternalTexture(const sp<GraphicBuffer>& buffer,
renderengine::RenderEngine& renderEngine, uint32_t usage)
- : mBuffer(buffer), mRenderEngine(renderEngine) {
+ : mBuffer(buffer), mRenderEngine(renderEngine), mWritable(usage & WRITEABLE) {
LOG_ALWAYS_FATAL_IF(buffer == nullptr,
"Attempted to bind a null buffer to an external texture!");
// GLESRenderEngine has a separate texture cache for output buffers,
@@ -35,11 +35,20 @@
renderengine::RenderEngine::RenderEngineType::THREADED)) {
return;
}
- mRenderEngine.mapExternalTextureBuffer(mBuffer, usage & WRITEABLE);
+ mRenderEngine.mapExternalTextureBuffer(mBuffer, mWritable);
}
ExternalTexture::~ExternalTexture() {
mRenderEngine.unmapExternalTextureBuffer(std::move(mBuffer));
}
+void ExternalTexture::remapBuffer() {
+ ATRACE_CALL();
+ {
+ auto buf = mBuffer;
+ mRenderEngine.unmapExternalTextureBuffer(std::move(buf));
+ }
+ mRenderEngine.mapExternalTextureBuffer(mBuffer, mWritable);
+}
+
} // namespace android::renderengine::impl