Kaydet (Commit) c8dcec92 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

android: remove the native DirectBufferAllocator

Change-Id: I41d25d288253f1b35c268ba70b8384812fa567e5
üst 03089170
...@@ -5,14 +5,12 @@ ...@@ -5,14 +5,12 @@
package org.libreoffice.kit; 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; 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 { public final class DirectBufferAllocator {
private static final String LOGTAG = DirectBufferAllocator.class.getSimpleName(); private static final String LOGTAG = DirectBufferAllocator.class.getSimpleName();
...@@ -20,46 +18,7 @@ public final class DirectBufferAllocator { ...@@ -20,46 +18,7 @@ public final class DirectBufferAllocator {
private DirectBufferAllocator() { private DirectBufferAllocator() {
} }
private static native ByteBuffer allocateDirectBufferNative(int size);
private static native void freeDirectBufferNative(ByteBuffer aBuffer);
public static ByteBuffer allocate(int size) { 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); ByteBuffer directBuffer = ByteBuffer.allocateDirect(size);
if (directBuffer == null) { if (directBuffer == null) {
if (size <= 0) { if (size <= 0) {
...@@ -74,7 +33,7 @@ public final class DirectBufferAllocator { ...@@ -74,7 +33,7 @@ public final class DirectBufferAllocator {
return directBuffer; return directBuffer;
} }
private static ByteBuffer freeVM(ByteBuffer buffer) { public static ByteBuffer free(ByteBuffer buffer) {
if (buffer == null) { if (buffer == null) {
return null; return null;
} }
......
...@@ -316,32 +316,4 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_resetSe ...@@ -316,32 +316,4 @@ extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_resetSe
pDocument->pClass->resetSelection(pDocument); 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment