Loading core/jni/android/opengl/util.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -599,6 +599,44 @@ static int getInternalFormat(SkBitmap::Config config) } } static int getType(SkBitmap::Config config) { switch(config) { case SkBitmap::kA8_Config: return GL_UNSIGNED_BYTE; case SkBitmap::kARGB_4444_Config: return GL_UNSIGNED_SHORT_4_4_4_4; case SkBitmap::kARGB_8888_Config: return GL_UNSIGNED_BYTE; case SkBitmap::kIndex8_Config: return -1; // No type for compressed data. case SkBitmap::kRGB_565_Config: return GL_UNSIGNED_SHORT_5_6_5; default: return -1; } } static jint util_getInternalFormat(JNIEnv *env, jclass clazz, jobject jbitmap) { SkBitmap const * nativeBitmap = (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); return getInternalFormat(config); } static jint util_getType(JNIEnv *env, jclass clazz, jobject jbitmap) { SkBitmap const * nativeBitmap = (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); return getType(config); } static jint util_texImage2D(JNIEnv *env, jclass clazz, jint target, jint level, jint internalformat, jobject jbitmap, jint type, jint border) Loading @@ -610,6 +648,9 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz, if (internalformat < 0) { internalformat = getInternalFormat(config); } if (type < 0) { type = getType(config); } int err = checkFormat(config, internalformat, type); if (err) return err; Loading Loading @@ -694,6 +735,8 @@ static JNINativeMethod gVisiblityMethods[] = { static JNINativeMethod gUtilsMethods[] = { {"nativeClassInit", "()V", (void*)nativeUtilsClassInit }, { "native_getInternalFormat", "(Landroid/graphics/Bitmap;)I", (void*) util_getInternalFormat }, { "native_getType", "(Landroid/graphics/Bitmap;)I", (void*) util_getType }, { "native_texImage2D", "(IIILandroid/graphics/Bitmap;II)I", (void*)util_texImage2D }, { "native_texSubImage2D", "(IIIILandroid/graphics/Bitmap;II)I", (void*)util_texSubImage2D }, }; Loading opengl/java/android/opengl/GLUtils.java +23 −31 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ public final class GLUtils { /** * return the internal format as defined by OpenGL ES of the supplied bitmap. * * @param bitmap * @return the internal format of the bitmap. */ Loading @@ -48,40 +47,30 @@ public final class GLUtils { if (bitmap == null) { throw new NullPointerException("getInternalFormat can't be used with a null Bitmap"); } switch (bitmap.getConfig()) { case ALPHA_8: return GL10.GL_ALPHA; case ARGB_4444: case ARGB_8888: return GL10.GL_RGBA; case RGB_565: return GL10.GL_RGB; } int result = native_getInternalFormat(bitmap); if (result < 0) { throw new IllegalArgumentException("Unknown internalformat"); } return result; } /** * Return the type as defined by OpenGL ES of the supplied bitmap. * Return the type as defined by OpenGL ES of the supplied bitmap, if there * is one. If the bitmap is stored in a compressed format, it may not have * a valid OpenGL ES type. * @throws IllegalArgumentException if the bitmap does not have a type. * @param bitmap * @return the OpenGL ES type of the bitmap. */ public static int getType(Bitmap bitmap) { if (bitmap == null) { throw new NullPointerException("getType can't be used with a null Bitmap"); } int type; switch(bitmap.getConfig()) { case ARGB_4444: type = GL10.GL_UNSIGNED_SHORT_4_4_4_4; break; case RGB_565: type = GL10.GL_UNSIGNED_SHORT_5_6_5; break; case ALPHA_8: case ARGB_8888: default: type = GL10.GL_UNSIGNED_BYTE; break; } return type; int result = native_getType(bitmap); if (result < 0) { throw new IllegalArgumentException("Unknown type"); } return result; } /** Loading Loading @@ -111,15 +100,16 @@ public final class GLUtils { if (bitmap == null) { throw new NullPointerException("texImage2D can't be used with a null Bitmap"); } int type = getType(bitmap); if (native_texImage2D(target, level, internalformat, bitmap, type, border)!=0) { if (native_texImage2D(target, level, internalformat, bitmap, -1, border)!=0) { throw new IllegalArgumentException("invalid Bitmap format"); } } /** * A version of texImage2D() that takes an explicit type parameter * as defined by the OpenGL ES specification. * as defined by the OpenGL ES specification. The actual type and * internalformat of the bitmap must be compatible with the specified * type and internalformat parameters. * * @param target * @param level Loading @@ -139,7 +129,8 @@ public final class GLUtils { } /** * A version of texImage2D that determines the internalFormat automatically. * A version of texImage2D that determines the internalFormat and type * automatically. * * @param target * @param level Loading @@ -151,8 +142,7 @@ public final class GLUtils { if (bitmap == null) { throw new NullPointerException("texImage2D can't be used with a null Bitmap"); } int type = getType(bitmap); if (native_texImage2D(target, level, -1, bitmap, type, border)!=0) { if (native_texImage2D(target, level, -1, bitmap, -1, border)!=0) { throw new IllegalArgumentException("invalid Bitmap format"); } } Loading Loading @@ -213,6 +203,8 @@ public final class GLUtils { native private static void nativeClassInit(); native private static int native_getInternalFormat(Bitmap bitmap); native private static int native_getType(Bitmap bitmap); native private static int native_texImage2D(int target, int level, int internalformat, Bitmap bitmap, int type, int border); native private static int native_texSubImage2D(int target, int level, int xoffset, int yoffset, Loading Loading
core/jni/android/opengl/util.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -599,6 +599,44 @@ static int getInternalFormat(SkBitmap::Config config) } } static int getType(SkBitmap::Config config) { switch(config) { case SkBitmap::kA8_Config: return GL_UNSIGNED_BYTE; case SkBitmap::kARGB_4444_Config: return GL_UNSIGNED_SHORT_4_4_4_4; case SkBitmap::kARGB_8888_Config: return GL_UNSIGNED_BYTE; case SkBitmap::kIndex8_Config: return -1; // No type for compressed data. case SkBitmap::kRGB_565_Config: return GL_UNSIGNED_SHORT_5_6_5; default: return -1; } } static jint util_getInternalFormat(JNIEnv *env, jclass clazz, jobject jbitmap) { SkBitmap const * nativeBitmap = (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); return getInternalFormat(config); } static jint util_getType(JNIEnv *env, jclass clazz, jobject jbitmap) { SkBitmap const * nativeBitmap = (SkBitmap const *)env->GetIntField(jbitmap, nativeBitmapID); const SkBitmap& bitmap(*nativeBitmap); SkBitmap::Config config = bitmap.getConfig(); return getType(config); } static jint util_texImage2D(JNIEnv *env, jclass clazz, jint target, jint level, jint internalformat, jobject jbitmap, jint type, jint border) Loading @@ -610,6 +648,9 @@ static jint util_texImage2D(JNIEnv *env, jclass clazz, if (internalformat < 0) { internalformat = getInternalFormat(config); } if (type < 0) { type = getType(config); } int err = checkFormat(config, internalformat, type); if (err) return err; Loading Loading @@ -694,6 +735,8 @@ static JNINativeMethod gVisiblityMethods[] = { static JNINativeMethod gUtilsMethods[] = { {"nativeClassInit", "()V", (void*)nativeUtilsClassInit }, { "native_getInternalFormat", "(Landroid/graphics/Bitmap;)I", (void*) util_getInternalFormat }, { "native_getType", "(Landroid/graphics/Bitmap;)I", (void*) util_getType }, { "native_texImage2D", "(IIILandroid/graphics/Bitmap;II)I", (void*)util_texImage2D }, { "native_texSubImage2D", "(IIIILandroid/graphics/Bitmap;II)I", (void*)util_texSubImage2D }, }; Loading
opengl/java/android/opengl/GLUtils.java +23 −31 Original line number Diff line number Diff line Loading @@ -40,7 +40,6 @@ public final class GLUtils { /** * return the internal format as defined by OpenGL ES of the supplied bitmap. * * @param bitmap * @return the internal format of the bitmap. */ Loading @@ -48,40 +47,30 @@ public final class GLUtils { if (bitmap == null) { throw new NullPointerException("getInternalFormat can't be used with a null Bitmap"); } switch (bitmap.getConfig()) { case ALPHA_8: return GL10.GL_ALPHA; case ARGB_4444: case ARGB_8888: return GL10.GL_RGBA; case RGB_565: return GL10.GL_RGB; } int result = native_getInternalFormat(bitmap); if (result < 0) { throw new IllegalArgumentException("Unknown internalformat"); } return result; } /** * Return the type as defined by OpenGL ES of the supplied bitmap. * Return the type as defined by OpenGL ES of the supplied bitmap, if there * is one. If the bitmap is stored in a compressed format, it may not have * a valid OpenGL ES type. * @throws IllegalArgumentException if the bitmap does not have a type. * @param bitmap * @return the OpenGL ES type of the bitmap. */ public static int getType(Bitmap bitmap) { if (bitmap == null) { throw new NullPointerException("getType can't be used with a null Bitmap"); } int type; switch(bitmap.getConfig()) { case ARGB_4444: type = GL10.GL_UNSIGNED_SHORT_4_4_4_4; break; case RGB_565: type = GL10.GL_UNSIGNED_SHORT_5_6_5; break; case ALPHA_8: case ARGB_8888: default: type = GL10.GL_UNSIGNED_BYTE; break; } return type; int result = native_getType(bitmap); if (result < 0) { throw new IllegalArgumentException("Unknown type"); } return result; } /** Loading Loading @@ -111,15 +100,16 @@ public final class GLUtils { if (bitmap == null) { throw new NullPointerException("texImage2D can't be used with a null Bitmap"); } int type = getType(bitmap); if (native_texImage2D(target, level, internalformat, bitmap, type, border)!=0) { if (native_texImage2D(target, level, internalformat, bitmap, -1, border)!=0) { throw new IllegalArgumentException("invalid Bitmap format"); } } /** * A version of texImage2D() that takes an explicit type parameter * as defined by the OpenGL ES specification. * as defined by the OpenGL ES specification. The actual type and * internalformat of the bitmap must be compatible with the specified * type and internalformat parameters. * * @param target * @param level Loading @@ -139,7 +129,8 @@ public final class GLUtils { } /** * A version of texImage2D that determines the internalFormat automatically. * A version of texImage2D that determines the internalFormat and type * automatically. * * @param target * @param level Loading @@ -151,8 +142,7 @@ public final class GLUtils { if (bitmap == null) { throw new NullPointerException("texImage2D can't be used with a null Bitmap"); } int type = getType(bitmap); if (native_texImage2D(target, level, -1, bitmap, type, border)!=0) { if (native_texImage2D(target, level, -1, bitmap, -1, border)!=0) { throw new IllegalArgumentException("invalid Bitmap format"); } } Loading Loading @@ -213,6 +203,8 @@ public final class GLUtils { native private static void nativeClassInit(); native private static int native_getInternalFormat(Bitmap bitmap); native private static int native_getType(Bitmap bitmap); native private static int native_texImage2D(int target, int level, int internalformat, Bitmap bitmap, int type, int border); native private static int native_texSubImage2D(int target, int level, int xoffset, int yoffset, Loading