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

Commit 9a89d83d authored by Jaesung Chung's avatar Jaesung Chung
Browse files

Avoid a race condition on reading qemu.gles property

The qemu.gles property will be ready after the SurfaceFlinger service is
initializing. Once the all required variable is set, it caches the
result for the future calls.

Bug: 37759781
Test: Test with imx6ul and imx7d pico boards.
Change-Id: Ib9f11a51ec8a0707be854f67fc8591149ab7fd49
parent 7f75a7fc
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.os.Trace;
import android.util.Log;
import android.view.Surface.OutOfResourcesException;
@@ -188,6 +189,11 @@ public final class ThreadedRenderer {
    public static final String DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY =
            "debug.hwui.show_non_rect_clip";

    static {
        // Try to check OpenGL support early if possible.
        isAvailable();
    }

    /**
     * A process can set this flag to false to prevent the use of threaded
     * rendering.
@@ -227,8 +233,7 @@ public final class ThreadedRenderer {
        sTrimForeground = true;
    }

    private static native boolean nSupportsOpenGL();
    private static boolean sSupportsOpenGL = nSupportsOpenGL();
    private static Boolean sSupportsOpenGL;

    /**
     * Indicates whether threaded rendering is available under any form for
@@ -238,7 +243,24 @@ public final class ThreadedRenderer {
     *         false otherwise
     */
    public static boolean isAvailable() {
        return sSupportsOpenGL;
        if (sSupportsOpenGL != null) {
            return sSupportsOpenGL.booleanValue();
        }
        if (SystemProperties.getInt("ro.kernel.qemu", 0) == 0) {
            // Device is not an emulator.
            sSupportsOpenGL = true;
            return true;
        }
        int qemu_gles = SystemProperties.getInt("qemu.gles", -1);
        if (qemu_gles == -1) {
            // In this case, the value of the qemu.gles property is not ready
            // because the SurfaceFlinger service may not start at this point.
            return false;
        }
        // In the emulator this property will be set > 0 when OpenGL ES 2.0 is
        // enabled, 0 otherwise. On old emulator versions it will be undefined.
        sSupportsOpenGL = qemu_gles > 0;
        return sSupportsOpenGL.booleanValue();
    }

    /**
+0 −13
Original line number Diff line number Diff line
@@ -570,18 +570,6 @@ void NotifyHandler::handleMessage(const Message& message) {
    mObserver->decStrong(nullptr);
}

static jboolean android_view_ThreadedRenderer_supportsOpenGL(JNIEnv* env, jobject clazz) {
    char prop[PROPERTY_VALUE_MAX];
    if (property_get("ro.kernel.qemu", prop, NULL) == 0) {
        // not in the emulator
        return JNI_TRUE;
    }
    // In the emulator this property will be set > 0 when OpenGL ES 2.0 is
    // enabled, 0 otherwise. On old emulator versions it will be undefined.
    property_get("qemu.gles", prop, "0");
    return atoi(prop) > 0 ? JNI_TRUE : JNI_FALSE;
}

static void android_view_ThreadedRenderer_rotateProcessStatsBuffer(JNIEnv* env, jobject clazz) {
    RenderProxy::rotateProcessStatsBuffer();
}
@@ -898,7 +886,6 @@ static void android_view_ThreadedRenderer_setupShadersDiskCache(JNIEnv* env, job
const char* const kClassPathName = "android/view/ThreadedRenderer";

static const JNINativeMethod gMethods[] = {
    { "nSupportsOpenGL", "()Z", (void*) android_view_ThreadedRenderer_supportsOpenGL },
    { "nRotateProcessStatsBuffer", "()V", (void*) android_view_ThreadedRenderer_rotateProcessStatsBuffer },
    { "nSetProcessStatsBuffer", "(I)V", (void*) android_view_ThreadedRenderer_setProcessStatsBuffer },
    { "nGetRenderThreadTid", "(J)I", (void*) android_view_ThreadedRenderer_getRenderThreadTid },