Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da355968 authored by John Reck's avatar John Reck
Browse files

Delete RenderProxy off of the cleaner thread

Speculation for the cause of an ANR. HardwareRenderer's
cleaner can block on RenderThread, which in turn blocks ART's
cleaner thread. This can potentially cause other blockages, but
it's also poor behavior to have such a long-running Cleaner anyway.

Avoid this by putting cleanup to CommonPool.

Bug: 191514384
Test: make, CtsUiRenderingTestCases still passes

Change-Id: I8190f7862528c3ac39ce636f6fca229322480968
parent a02615b9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -247,7 +247,7 @@ static jlong android_view_ThreadedRenderer_createProxy(JNIEnv* env, jobject claz
static void android_view_ThreadedRenderer_deleteProxy(JNIEnv* env, jobject clazz,
        jlong proxyPtr) {
    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
    delete proxy;
    RenderProxy::asyncDelete(proxy);
}

static jboolean android_view_ThreadedRenderer_loadSystemProperties(JNIEnv* env, jobject clazz,
+12 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@
#include "renderthread/CanvasContext.h"
#include "renderthread/RenderTask.h"
#include "renderthread/RenderThread.h"
#include "thread/CommonPool.h"
#include "utils/Macros.h"
#include "utils/TimeUtils.h"

@@ -42,6 +43,17 @@ RenderProxy::RenderProxy(bool translucent, RenderNode* rootRenderNode,
    mDrawFrameTask.setContext(&mRenderThread, mContext, rootRenderNode);
}

void RenderProxy::asyncDelete(RenderProxy* proxy) {
    if (!proxy) return;

    if (proxy->mContext) {
        // Use the common pool because ~RenderProxy blocks on calling into RenderThread
        CommonPool::post([proxy]() { delete proxy; });
    } else {
        delete proxy;
    }
}

RenderProxy::~RenderProxy() {
    destroyContext();
}
+6 −2
Original line number Diff line number Diff line
@@ -62,10 +62,14 @@ enum {
 * references RenderProxy fields. This is safe as RenderProxy cannot
 * be deleted if it is blocked inside a call.
 */
class RenderProxy {
class RenderProxy final {
public:
    RenderProxy(bool opaque, RenderNode* rootNode, IContextFactory* contextFactory);
    virtual ~RenderProxy();
    ~RenderProxy();

    // Schedules a delete of the RenderProxy at a later date. Avoids blocking the current thread
    // on destruction which ~RenderProxy does by default.
    static void asyncDelete(RenderProxy*);

    // Won't take effect until next EGLSurface creation
    void setSwapBehavior(SwapBehavior swapBehavior);