diff options
-rw-r--r-- | android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java | 51 | ||||
-rw-r--r-- | desktop/source/lib/lokandroid.cxx | 28 |
2 files changed, 5 insertions, 74 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java index de90303d9eba..99cb3a48620f 100644 --- a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java +++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java @@ -5,14 +5,12 @@ package org.libreoffice.kit; -// -// We must manually allocate direct buffers in JNI to work around a bug where Honeycomb's -// ByteBuffer.allocateDirect() grossly overallocates the direct buffer size. -// https://code.google.com/p/android/issues/detail?id=16941 -// - import java.nio.ByteBuffer; +/** + * This is the common code for allocation and freeing of memory. For this direct ByteBuffer is used but + * in the past it was possible to use a JNI version of allocation because of a bug in old Android version. + */ public final class DirectBufferAllocator { private static final String LOGTAG = DirectBufferAllocator.class.getSimpleName(); @@ -20,46 +18,7 @@ public final class DirectBufferAllocator { private DirectBufferAllocator() { } - private static native ByteBuffer allocateDirectBufferNative(int size); - - private static native void freeDirectBufferNative(ByteBuffer aBuffer); - public static ByteBuffer allocate(int size) { - return allocateVM(size); - } - - public static ByteBuffer free(ByteBuffer buffer) { - return freeVM(buffer); - } - - private static ByteBuffer allocateJNI(int size) { - ByteBuffer directBuffer = allocateDirectBufferNative(size); - if (directBuffer == null) { - if (size <= 0) { - throw new IllegalArgumentException("Invalid allocation size: " + size); - } else { - throw new OutOfMemoryError("allocateDirectBuffer() returned null"); - } - } else if (!directBuffer.isDirect()) { - throw new AssertionError("allocateDirectBuffer() did not return a direct buffer"); - } - return directBuffer; - } - - private static ByteBuffer freeJNI(ByteBuffer buffer) { - if (buffer == null) { - return null; - } - - if (!buffer.isDirect()) { - throw new IllegalArgumentException("ByteBuffer must be direct"); - } - - freeDirectBufferNative(buffer); - return null; - } - - private static ByteBuffer allocateVM(int size) { ByteBuffer directBuffer = ByteBuffer.allocateDirect(size); if (directBuffer == null) { if (size <= 0) { @@ -74,7 +33,7 @@ public final class DirectBufferAllocator { return directBuffer; } - private static ByteBuffer freeVM(ByteBuffer buffer) { + public static ByteBuffer free(ByteBuffer buffer) { if (buffer == null) { return null; } diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx index 1db794539a69..6142f5ab9885 100644 --- a/desktop/source/lib/lokandroid.cxx +++ b/desktop/source/lib/lokandroid.cxx @@ -316,32 +316,4 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_resetSe pDocument->pClass->resetSelection(pDocument); } -/* DirectBufferAllocator */ - -extern "C" SAL_JNI_EXPORT jobject JNICALL Java_org_libreoffice_kit_DirectBufferAllocator_allocateDirectBufferNative - (JNIEnv* pEnv, jclass /*aClass*/, jint nSize) -{ - jobject aBuffer = NULL; - - if (nSize > 0) - { - void* pMemory = malloc(nSize); - if (pMemory != NULL) - { - aBuffer = pEnv->NewDirectByteBuffer(pMemory, nSize); - if (aBuffer == NULL) - { - free(pMemory); - } - } - } - return aBuffer; -} - -extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_DirectBufferAllocator_freeDirectBufferNative - (JNIEnv* pEnv, jclass, jobject aBuffer) -{ - free(pEnv->GetDirectBufferAddress(aBuffer)); -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |