Put GPU priority to low for all rendering contexts

Our live wallpapers that use libgdx need to have lower GPU priority
so they don't preempt GPU tasks from the foreground windows. Ideally,
we'd add an option for this but since libgdx is exclusively used for
live wallpapers, we can just set the option statically.

Bug: 29639773
Change-Id: I0f5fae4af7d45267c69e22e31a23e58d0d771bc2
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java
index 32ba11f..ce924e2 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20.java
@@ -44,6 +44,9 @@
 	static String TAG = "GL2JNIView";

 	private static final boolean DEBUG = false;

 

+	final static int EGL_CONTEXT_PRIORITY_LEVEL_IMG = 0x3100;

+	final static int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;

+

 	final ResolutionStrategy resolutionStrategy;

 	static int targetGLESVersion;

 

@@ -140,7 +143,8 @@
 		public EGLContext createContext (EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {

 			Log.w(TAG, "creating OpenGL ES " + GLSurfaceView20.targetGLESVersion + ".0 context");

 			checkEglError("Before eglCreateContext "+targetGLESVersion, egl);

-			int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, GLSurfaceView20.targetGLESVersion, EGL10.EGL_NONE};

+			int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, GLSurfaceView20.targetGLESVersion,

+					EGL_CONTEXT_PRIORITY_LEVEL_IMG, EGL_CONTEXT_PRIORITY_LOW_IMG, EGL10.EGL_NONE};

 			EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);

 			boolean success = checkEglError("After eglCreateContext "+targetGLESVersion, egl);

 

diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20API18.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20API18.java
index b1239ce..84a456a 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20API18.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceView20API18.java
@@ -135,7 +135,9 @@
 		public EGLContext createContext (EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
 			Log.w(TAG, "creating OpenGL ES 2.0 context");
 			checkEglError("Before eglCreateContext", egl);
-			int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE};
+			int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2,
+					GLSurfaceView20.EGL_CONTEXT_PRIORITY_LEVEL_IMG, GLSurfaceView20.EGL_CONTEXT_PRIORITY_LOW_IMG,
+					EGL10.EGL_NONE};
 			EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
 			checkEglError("After eglCreateContext", egl);
 			return context;
diff --git a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewAPI18.java b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewAPI18.java
index dfac62a..58d130b 100644
--- a/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewAPI18.java
+++ b/backends/gdx-backend-android/src/com/badlogic/gdx/backends/android/surfaceview/GLSurfaceViewAPI18.java
@@ -778,8 +778,11 @@
         private int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
 
         public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
+            final int EGL_CONTEXT_PRIORITY_LEVEL_IMG = 0x3100;
+            final int EGL_CONTEXT_PRIORITY_LOW_IMG = 0x3103;
             int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, mEGLContextClientVersion,
-                    EGL10.EGL_NONE };
+                    GLSurfaceView20.EGL_CONTEXT_PRIORITY_LEVEL_IMG, GLSurfaceView20.EGL_CONTEXT_PRIORITY_LOW_IMG,
+                    EGL10.EGL_NONE};
 
             return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT,
                     mEGLContextClientVersion != 0 ? attrib_list : null);