Skip to content

Commit

Permalink
Updated libraries versions.
Browse files Browse the repository at this point in the history
Added check for gl texture limit and some refactoring.
  • Loading branch information
shliama committed Sep 8, 2016
1 parent b2b7690 commit fa825c0
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 336 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.android.tools.build:gradle:2.1.3'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
buildToolsVersion "24.0.2"

defaultConfig {
applicationId "com.yalantis.ucrop.sample"
Expand All @@ -28,7 +28,7 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:appcompat-v7:24.2.0'

compile project (':ucrop')
}
6 changes: 3 additions & 3 deletions ucrop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply from: '../mavenpush.gradle'

android {
compileSdkVersion 24
buildToolsVersion '24.0.0'
buildToolsVersion '24.0.2'

defaultConfig {
minSdkVersion 14
Expand Down Expand Up @@ -36,6 +36,6 @@ android {
}

dependencies {
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
}
22 changes: 20 additions & 2 deletions ucrop/src/main/java/com/yalantis/ucrop/util/BitmapLoadUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,28 @@ public static int calculateMaxBitmapSize(@NonNull Context context) {
height = display.getHeight();
}

int screenDiagonal = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
// Twice the device screen diagonal as default
int maxBitmapSize = (int) Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
Log.d(TAG, "2 DIAGONAL SIZE: " + maxBitmapSize);

// Check for max texture size via Canvas
Canvas canvas = new Canvas();
return Math.min(screenDiagonal * 2, Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight()));
final int maxCanvasSize = Math.min(canvas.getMaximumBitmapWidth(), canvas.getMaximumBitmapHeight());
Log.d(TAG, "MAX CANVAS SIZE: " + maxCanvasSize);
if (maxCanvasSize > 0) {
maxBitmapSize = Math.min(maxBitmapSize, maxCanvasSize);
}

// Check for max texture size via GL
final int maxTextureSize = EglUtils.getMaxTextureSize();
Log.d(TAG, "MAX TEXTURE SIZE: " + maxTextureSize);
if (maxTextureSize > 0) {
maxBitmapSize = Math.min(maxBitmapSize, maxTextureSize);
}

Log.d(TAG, "MAX BITMAP SIZE: " + maxBitmapSize);

return maxBitmapSize;
}

@SuppressWarnings("ConstantConditions")
Expand Down
134 changes: 134 additions & 0 deletions ucrop/src/main/java/com/yalantis/ucrop/util/EglUtils.java
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];
}
}
Loading

0 comments on commit fa825c0

Please sign in to comment.