Fix deadlock in render thread when Bitmap.prepareToDraw is invoked

Fix a deadlock with Skia pipelines, caused by calling
Bitmap::getSkBitmap from render thread.

Test: built and booted an image. Ran recent apps activity.
bug: 35060578
bug: 34926691
Change-Id: Iaf7957b955d938b722b153d72ad832ae5d50e86f
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index fb79272..11614fa 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -667,11 +667,17 @@
 }
 
 int RenderProxy::copyGraphicBufferInto(GraphicBuffer* buffer, SkBitmap* bitmap) {
-    SETUP_TASK(copyGraphicBufferInto);
-    args->thread = &RenderThread::getInstance();
-    args->bitmap = bitmap;
-    args->buffer = buffer;
-    return static_cast<int>(reinterpret_cast<intptr_t>(staticPostAndWait(task)));
+    RenderThread& thread = RenderThread::getInstance();
+    if (Properties::isSkiaEnabled() && gettid() == thread.getTid()) {
+        //TODO: fix everything that hits this. We should never be triggering a readback ourselves.
+        return (int) thread.readback().copyGraphicBufferInto(buffer, bitmap);
+    } else {
+        SETUP_TASK(copyGraphicBufferInto);
+        args->thread = &thread;
+        args->bitmap = bitmap;
+        args->buffer = buffer;
+        return static_cast<int>(reinterpret_cast<intptr_t>(staticPostAndWait(task)));
+    }
 }
 
 void RenderProxy::post(RenderTask* task) {
@@ -690,6 +696,7 @@
 
 void* RenderProxy::staticPostAndWait(MethodInvokeRenderTask* task) {
     RenderThread& thread = RenderThread::getInstance();
+    LOG_ALWAYS_FATAL_IF(gettid() == thread.getTid());
     void* retval;
     task->setReturnPtr(&retval);
     thread.queueAndWait(task);