-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check for gl texture limit and some refactoring.
- Loading branch information
Showing
8 changed files
with
170 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Jan 15 00:55:26 EET 2016 | ||
#Thu Sep 08 12:21:35 EEST 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
ucrop/src/main/java/com/yalantis/ucrop/util/EglUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package com.yalantis.ucrop.util; | ||
|
||
import android.annotation.TargetApi; | ||
import android.opengl.EGL14; | ||
import android.opengl.EGLConfig; | ||
import android.opengl.EGLContext; | ||
import android.opengl.EGLDisplay; | ||
import android.opengl.EGLSurface; | ||
import android.opengl.GLES10; | ||
import android.opengl.GLES20; | ||
import android.os.Build; | ||
import android.util.Log; | ||
|
||
import javax.microedition.khronos.egl.EGL10; | ||
|
||
/** | ||
* Created by Oleksii Shliama [https://github.com/shliama] on 9/8/16. | ||
*/ | ||
public class EglUtils { | ||
|
||
private static final String TAG = "EglUtils"; | ||
|
||
private EglUtils() { | ||
|
||
} | ||
|
||
public static int getMaxTextureSize() { | ||
try { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { | ||
return getMaxTextureEgl14(); | ||
} else { | ||
return getMaxTextureEgl10(); | ||
} | ||
} catch (Exception e) { | ||
Log.d(TAG, "getMaxTextureSize: ", e); | ||
return 0; | ||
} | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) | ||
private static int getMaxTextureEgl14() { | ||
EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); | ||
int[] vers = new int[2]; | ||
EGL14.eglInitialize(dpy, vers, 0, vers, 1); | ||
|
||
int[] configAttr = { | ||
EGL14.EGL_COLOR_BUFFER_TYPE, EGL14.EGL_RGB_BUFFER, | ||
EGL14.EGL_LEVEL, 0, | ||
EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, | ||
EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT, | ||
EGL14.EGL_NONE | ||
}; | ||
EGLConfig[] configs = new EGLConfig[1]; | ||
int[] numConfig = new int[1]; | ||
EGL14.eglChooseConfig(dpy, configAttr, 0, | ||
configs, 0, 1, numConfig, 0); | ||
if (numConfig[0] == 0) { | ||
return 0; | ||
} | ||
EGLConfig config = configs[0]; | ||
|
||
int[] surfAttr = { | ||
EGL14.EGL_WIDTH, 64, | ||
EGL14.EGL_HEIGHT, 64, | ||
EGL14.EGL_NONE | ||
}; | ||
EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0); | ||
|
||
int[] ctxAttrib = { | ||
EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, | ||
EGL14.EGL_NONE | ||
}; | ||
EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0); | ||
|
||
EGL14.eglMakeCurrent(dpy, surf, surf, ctx); | ||
|
||
int[] maxSize = new int[1]; | ||
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0); | ||
|
||
EGL14.eglMakeCurrent(dpy, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, | ||
EGL14.EGL_NO_CONTEXT); | ||
EGL14.eglDestroySurface(dpy, surf); | ||
EGL14.eglDestroyContext(dpy, ctx); | ||
EGL14.eglTerminate(dpy); | ||
|
||
return maxSize[0]; | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) | ||
private static int getMaxTextureEgl10() { | ||
EGL10 egl = (EGL10) javax.microedition.khronos.egl.EGLContext.getEGL(); | ||
|
||
javax.microedition.khronos.egl.EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); | ||
int[] vers = new int[2]; | ||
egl.eglInitialize(dpy, vers); | ||
|
||
int[] configAttr = { | ||
EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RGB_BUFFER, | ||
EGL10.EGL_LEVEL, 0, | ||
EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT, | ||
EGL10.EGL_NONE | ||
}; | ||
javax.microedition.khronos.egl.EGLConfig[] configs = new javax.microedition.khronos.egl.EGLConfig[1]; | ||
int[] numConfig = new int[1]; | ||
egl.eglChooseConfig(dpy, configAttr, configs, 1, numConfig); | ||
if (numConfig[0] == 0) { | ||
return 0; | ||
} | ||
javax.microedition.khronos.egl.EGLConfig config = configs[0]; | ||
|
||
int[] surfAttr = { | ||
EGL10.EGL_WIDTH, 64, | ||
EGL10.EGL_HEIGHT, 64, | ||
EGL10.EGL_NONE | ||
}; | ||
javax.microedition.khronos.egl.EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr); | ||
final int EGL_CONTEXT_CLIENT_VERSION = 0x3098; // missing in EGL10 | ||
int[] ctxAttrib = { | ||
EGL_CONTEXT_CLIENT_VERSION, 1, | ||
EGL10.EGL_NONE | ||
}; | ||
javax.microedition.khronos.egl.EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttrib); | ||
egl.eglMakeCurrent(dpy, surf, surf, ctx); | ||
int[] maxSize = new int[1]; | ||
GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0); | ||
egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, | ||
EGL10.EGL_NO_CONTEXT); | ||
egl.eglDestroySurface(dpy, surf); | ||
egl.eglDestroyContext(dpy, ctx); | ||
egl.eglTerminate(dpy); | ||
|
||
return maxSize[0]; | ||
} | ||
} |
Oops, something went wrong.