diff options
9 files changed, 85 insertions, 40 deletions
diff --git a/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java new file mode 100644 index 000000000000..7c8f808eb5a2 --- /dev/null +++ b/android/Bootstrap/src/org/libreoffice/kit/DirectBufferAllocator.java @@ -0,0 +1,52 @@ +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +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; + +public class DirectBufferAllocator { + + private DirectBufferAllocator() { + } + + private static native ByteBuffer allocateDirectBufferNative(int size); + + private static native void freeDirectBufferNative(ByteBuffer aBuffer); + + public static ByteBuffer allocate(int size) { + if (size <= 0) { + throw new IllegalArgumentException("Invalid size " + size); + } + + ByteBuffer directBuffer = allocateDirectBufferNative(size); + if (directBuffer == null) { + throw new OutOfMemoryError("allocateDirectBuffer() returned null"); + } else if (!directBuffer.isDirect()) { + throw new AssertionError("allocateDirectBuffer() did not return a direct buffer"); + } + + return directBuffer; + } + + public static ByteBuffer free(ByteBuffer buffer) { + if (buffer == null) { + return null; + } + + if (!buffer.isDirect()) { + throw new IllegalArgumentException("buffer must be direct"); + } + + freeDirectBufferNative(buffer); + return null; + } +}
\ No newline at end of file diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/DirectBufferAllocator.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/DirectBufferAllocator.java deleted file mode 100644 index 902d94ae0ecf..000000000000 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/DirectBufferAllocator.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.libreoffice; - -import java.nio.ByteBuffer; - -public class DirectBufferAllocator { - public static ByteBuffer allocate(int size) { - if (size <= 0) { - throw new IllegalArgumentException("Invalid size " + size); - } - - ByteBuffer directBuffer = ByteBuffer.allocateDirect(size); - //ByteBuffer directBuffer = nativeAllocateDirectBuffer(size); - if (directBuffer == null) { - throw new OutOfMemoryError("allocateDirectBuffer() returned null"); - } else if (!directBuffer.isDirect()) { - throw new AssertionError("allocateDirectBuffer() did not return a direct buffer"); - } - - return directBuffer; - } - - public static ByteBuffer free(ByteBuffer buffer) { - if (buffer == null) { - return null; - } - - if (!buffer.isDirect()) { - throw new IllegalArgumentException("buffer must be direct"); - } - //nativeFreeDirectBuffer(buffer); - return buffer; - } -} diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java index de431d70d8ab..a616fcc4da43 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/BufferedCairoImage.java @@ -9,7 +9,7 @@ package org.mozilla.gecko.gfx; import android.graphics.Bitmap; import android.util.Log; -import org.libreoffice.DirectBufferAllocator; +import org.libreoffice.kit.DirectBufferAllocator; import java.nio.ByteBuffer; diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java index bf1cab7cae10..13437330818c 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/CheckerboardImage.java @@ -7,7 +7,7 @@ package org.mozilla.gecko.gfx; import android.graphics.Color; -import org.libreoffice.DirectBufferAllocator; +import org.libreoffice.kit.DirectBufferAllocator; import java.nio.ByteBuffer; import java.nio.ShortBuffer; diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java index c82bab8b5cf7..90be6d0753e1 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/LayerRenderer.java @@ -52,7 +52,7 @@ import android.opengl.GLSurfaceView; import android.os.SystemClock; import android.util.Log; -import org.libreoffice.DirectBufferAllocator; +import org.libreoffice.kit.DirectBufferAllocator; import org.mozilla.gecko.gfx.Layer.RenderContext; import java.nio.ByteBuffer; diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScreenshotLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScreenshotLayer.java index 5d8f4544584a..4552e3662bcd 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScreenshotLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScreenshotLayer.java @@ -12,7 +12,7 @@ import android.graphics.Paint; import android.graphics.Rect; import android.opengl.GLES20; -import org.libreoffice.DirectBufferAllocator; +import org.libreoffice.kit.DirectBufferAllocator; import java.nio.ByteBuffer; import java.nio.FloatBuffer; diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java index d3e00e16c74a..51ba946e6f52 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/ScrollbarLayer.java @@ -14,7 +14,7 @@ import android.graphics.Rect; import android.graphics.RectF; import android.opengl.GLES20; -import org.libreoffice.DirectBufferAllocator; +import org.libreoffice.kit.DirectBufferAllocator; import org.mozilla.gecko.util.FloatUtils; import java.nio.ByteBuffer; diff --git a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java index 5ac7c976f70f..023433a888c3 100644 --- a/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java +++ b/android/experimental/LOAndroid3/src/java/org/mozilla/gecko/gfx/TextLayer.java @@ -11,7 +11,7 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Typeface; -import org.libreoffice.DirectBufferAllocator; +import org.libreoffice.kit.DirectBufferAllocator; import java.nio.ByteBuffer; diff --git a/desktop/source/lib/lokandroid.cxx b/desktop/source/lib/lokandroid.cxx index bc9a8b0b1274..6a0ba2a41648 100644 --- a/desktop/source/lib/lokandroid.cxx +++ b/desktop/source/lib/lokandroid.cxx @@ -80,6 +80,7 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Office_document } /* Document */ + extern "C" SAL_JNI_EXPORT void JNICALL Java_org_libreoffice_kit_Document_destroy (JNIEnv* pEnv, jobject aObject) { @@ -164,7 +165,8 @@ extern "C" SAL_JNI_EXPORT jlong JNICALL Java_org_libreoffice_kit_Document_getDoc return nWidth; } -extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs(JNIEnv* pEnv, jobject aObject, jstring sUrl, jstring sFormat, jstring sOptions) +extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs + (JNIEnv* pEnv, jobject aObject, jstring sUrl, jstring sFormat, jstring sOptions) { LibreOfficeKitDocument* pDocument = getHandle<LibreOfficeKitDocument>(pEnv, aObject); @@ -181,4 +183,28 @@ extern "C" SAL_JNI_EXPORT jint JNICALL Java_org_libreoffice_kit_Office_saveAs(JN return result; } +/* DirectBufferAllocator */ + +extern "C" SAL_JNI_EXPORT jobject JNICALL Java_org_libreoffice_kit_DirectBufferAllocator_allocateDirectBufferNative + (JNIEnv* pEnv, jclass /*aClass*/, jlong nSize) +{ + jobject aBuffer = NULL; + void* pMemory = malloc(nSize); + if (pMemory != NULL) + { + aBuffer = pEnv->NewDirectByteBuffer(pMemory, nSize); + if (!aBuffer) + { + 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: */ |