summaryrefslogtreecommitdiff
path: root/libs/hwui/SkiaCanvas.cpp
diff options
context:
space:
mode:
author Alex Strelnikov <strel@google.com> 2024-03-07 20:38:10 +0000
committer Alex Strelnikov <strel@google.com> 2024-03-10 03:07:27 +0000
commitb58afe6dab72f08f19111448633354bb69c4d14b (patch)
treead29a901ce0c96ac268fc0b29986f05a0c819654 /libs/hwui/SkiaCanvas.cpp
parentd2a2fae7eb0a46d6ed2d7afbd7127f00dcf0da54 (diff)
Fix Mesh UAF, uniform handling, and performance bug.
Prior to this change, the render thread would only receive a non-owning pointer or reference to a Mesh. Also because the Mesh itself was passed by pointer, the refcount in its uniform sk_sp<SkData> would not be incremented until an SkMesh was updated on the render thread, causing uniform setting calls on the UI thread to impact prior draw calls with the same mesh. The dirty flag used for the uniforms was also signaling a reupload of vertex and index data to the GPU. This fix adds a MeshBufferData class to handle keeping Skia buffers up-to-date, and a Mesh::Snapshot class that carries shared ownership of all pieces needed to construct an SkMesh. The snapshot is stored on the render thread by value and increments the refcount of the uniform sk_sp<SkData>. Because the current Android Mesh API does not support partial buffer updates, there is no need for a dirty flag, as comparing the DirectContextID and checking if the buffers have been created is sufficient. Creating an SkMesh is performed lazily inside the SkMesh getter of the snapshot. BUG: 328507000 Test: atest CtsUiRenderingTestCases:MeshTest Change-Id: Iabe83dca462d4526c118047621b131009032d35b
Diffstat (limited to 'libs/hwui/SkiaCanvas.cpp')
-rw-r--r--libs/hwui/SkiaCanvas.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/libs/hwui/SkiaCanvas.cpp b/libs/hwui/SkiaCanvas.cpp
index 0b739c361d64..72e83afbd96f 100644
--- a/libs/hwui/SkiaCanvas.cpp
+++ b/libs/hwui/SkiaCanvas.cpp
@@ -596,8 +596,8 @@ void SkiaCanvas::drawMesh(const Mesh& mesh, sk_sp<SkBlender> blender, const Pain
if (recordingContext) {
context = recordingContext->asDirectContext();
}
- mesh.updateSkMesh(context);
- mCanvas->drawMesh(mesh.getSkMesh(), blender, paint);
+ mesh.refBufferData()->updateBuffers(context);
+ mCanvas->drawMesh(mesh.takeSnapshot().getSkMesh(), blender, paint);
}
// ----------------------------------------------------------------------------