Skip to content

Commit 4406345

Browse files
committed
Disable GLES20Canvas on emu w/o native GL
When the emulator is run without '-gpu on', GLES20 isn't supported, so claiming GLES20Canvas is available will lead to catastrophic failure. This change makes GLES20Canvas available when compiled in and either not running on the emulator, or running on the emulator with native GL acceleration enabled. Change-Id: I89c944f9e3c9585224f5aa0877335ea48ea4a468
1 parent 335c4e6 commit 4406345

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/jni/android_view_GLES20Canvas.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <nativehelper/JNIHelp.h>
2424
#include <android_runtime/AndroidRuntime.h>
2525
#include <android_runtime/android_graphics_SurfaceTexture.h>
26+
#include <cutils/properties.h>
2627
#include <utils/ResourceTypes.h>
2728

2829
#include <gui/SurfaceTexture.h>
@@ -736,7 +737,15 @@ static jboolean android_view_GLES20Canvas_copyLayer(JNIEnv* env, jobject clazz,
736737

737738
static jboolean android_view_GLES20Canvas_isAvailable(JNIEnv* env, jobject clazz) {
738739
#ifdef USE_OPENGL_RENDERER
739-
return JNI_TRUE;
740+
char prop[PROPERTY_VALUE_MAX];
741+
if (property_get("ro.kernel.qemu", prop, NULL) == 0) {
742+
// not in the emulator
743+
return JNI_TRUE;
744+
}
745+
// In the emulator this property will be set to 1 when hardware GLES is
746+
// enabled, 0 otherwise. On old emulator versions it will be undefined.
747+
property_get("ro.kernel.qemu.gles", prop, "0");
748+
return atoi(prop) == 1 ? JNI_TRUE : JNI_FALSE;
740749
#else
741750
return JNI_FALSE;
742751
#endif

0 commit comments

Comments
 (0)