summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-11-16 13:48:51 +0000
committerRobin Watts <robin.watts@artifex.com>2012-11-19 16:49:27 +0000
commit6ac6f0b873cffea1817a361764e868e93f043af2 (patch)
tree0a656b41aa316918a745d64e42af1e0dffd53d0c /android
parentbc3ce65fce7b41270933395f1c7d2aa935b2cc11 (diff)
downloadmupdf-6ac6f0b873cffea1817a361764e868e93f043af2.tar.xz
Enable android profiler build.
Requires android-ndk-profiler to be copied into android and android/jni. Also requires r8c of the NDK.
Diffstat (limited to 'android')
-rw-r--r--android/AndroidManifest.xml1
-rw-r--r--android/jni/Android.mk12
-rw-r--r--android/jni/Application.mk19
-rw-r--r--android/jni/Core.mk5
-rw-r--r--android/jni/ThirdParty.mk3
-rw-r--r--android/jni/mupdf.c16
6 files changed, 51 insertions, 5 deletions
diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml
index a4daa50c..f4c0bc7d 100644
--- a/android/AndroidManifest.xml
+++ b/android/AndroidManifest.xml
@@ -3,6 +3,7 @@
package="com.artifex.mupdf"
android:versionCode="1"
android:versionName="@string/version">
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
diff --git a/android/jni/Android.mk b/android/jni/Android.mk
index 91fface9..882404fa 100644
--- a/android/jni/Android.mk
+++ b/android/jni/Android.mk
@@ -3,6 +3,11 @@ TOP_LOCAL_PATH := $(LOCAL_PATH)
MUPDF_ROOT := ..
+ifdef NDK_PROFILER
+include android-ndk-profiler.mk
+endif
+
+include $(TOP_LOCAL_PATH)/Core2.mk
include $(TOP_LOCAL_PATH)/Core.mk
include $(TOP_LOCAL_PATH)/ThirdParty.mk
@@ -15,7 +20,12 @@ LOCAL_C_INCLUDES := \
LOCAL_CFLAGS :=
LOCAL_MODULE := mupdf
LOCAL_SRC_FILES := mupdf.c
-LOCAL_STATIC_LIBRARIES := mupdfcore mupdfthirdparty
+LOCAL_STATIC_LIBRARIES := mupdfcore mupdfcore2 mupdfthirdparty
+ifdef NDK_PROFILER
+LOCAL_CFLAGS += -pg -DNDK_PROFILER
+LOCAL_STATIC_LIBRARIES += andprof
+else
+endif
LOCAL_LDLIBS := -lm -llog -ljnigraphics
ifdef V8_BUILD
diff --git a/android/jni/Application.mk b/android/jni/Application.mk
index 441243d8..4acb1d30 100644
--- a/android/jni/Application.mk
+++ b/android/jni/Application.mk
@@ -1,10 +1,25 @@
# The ARMv7 is significanly faster due to the use of the hardware FPU
APP_PLATFORM=android-8
APP_ABI := armeabi armeabi-v7a
+ifdef NDK_PROFILER
+# The profiler doesn't seem to receive ticks when run on release code.
+# Accordingly, we need to build as debug - but this turns optimisations
+# off, which is less than ideal. We COULD force them back on by using
+# APP_CFLAGS = -O2, but this then triggers bugs in the compiler when it
+# builds a couple of our source files. Accordingly, we have moved
+# those files into Core2, and we have some flag hackery to make just that
+# module without optimisation.
APP_OPTIM := debug
+APP_CFLAGS :=
+else
+APP_OPTIM := release
+endif
ifdef V8_BUILD
APP_STL := stlport_static
endif
-# Workaround bug in the ndk
-NDK_TOOLCHAIN_VERSION=4.4.3
+# If the ndk is r8b then workaround bug by uncommenting the following line
+#NDK_TOOLCHAIN_VERSION=4.4.3
+
+# If the ndk is newer than r8c, try using clang.
+#NDK_TOOLCHAIN_VERSION=clang3.1
diff --git a/android/jni/Core.mk b/android/jni/Core.mk
index 917ec2c0..a549640a 100644
--- a/android/jni/Core.mk
+++ b/android/jni/Core.mk
@@ -11,6 +11,9 @@ FREETYPE := freetype
V8 := v8-3.9
LOCAL_CFLAGS += -DARCH_ARM -DARCH_THUMB -DARCH_ARM_CAN_LOAD_UNALIGNED
+ifdef NDK_PROFILER
+LOCAL_CFLAGS += -pg -DNDK_PROFILER -O2
+endif
LOCAL_C_INCLUDES := \
../thirdparty/jbig2dec \
@@ -68,7 +71,6 @@ LOCAL_SRC_FILES := \
$(MY_ROOT)/fitz/res_font.c \
$(MY_ROOT)/fitz/res_path.c \
$(MY_ROOT)/fitz/res_pixmap.c \
- $(MY_ROOT)/fitz/res_shade.c \
$(MY_ROOT)/fitz/res_store.c \
$(MY_ROOT)/fitz/res_text.c \
$(MY_ROOT)/fitz/stm_buffer.c \
@@ -83,7 +85,6 @@ LOCAL_SRC_FILES := \
$(MY_ROOT)/draw/draw_mesh.c \
$(MY_ROOT)/draw/draw_paint.c \
$(MY_ROOT)/draw/draw_path.c \
- $(MY_ROOT)/draw/draw_simple_scale.c \
$(MY_ROOT)/draw/draw_unpack.c \
$(MY_ROOT)/pdf/pdf_annot.c \
$(MY_ROOT)/pdf/pdf_cmap.c \
diff --git a/android/jni/ThirdParty.mk b/android/jni/ThirdParty.mk
index e028c49d..660c8e9e 100644
--- a/android/jni/ThirdParty.mk
+++ b/android/jni/ThirdParty.mk
@@ -21,6 +21,9 @@ LOCAL_CFLAGS := \
-DFT2_BUILD_LIBRARY -DDARWIN_NO_CARBON -DHAVE_STDINT_H \
'-DFT_CONFIG_MODULES_H="slimftmodules.h"' \
'-DFT_CONFIG_OPTIONS_H="slimftoptions.h"'
+ifdef NDK_PROFILER
+LOCAL_CFLAGS += -pg -DNDK_PROFILER -O2
+endif
LOCAL_MODULE := mupdfthirdparty
LOCAL_SRC_FILES := \
diff --git a/android/jni/mupdf.c b/android/jni/mupdf.c
index a24be98a..fe392b75 100644
--- a/android/jni/mupdf.c
+++ b/android/jni/mupdf.c
@@ -8,6 +8,10 @@
#include <stdlib.h>
#include <math.h>
+#ifdef NDK_PROFILER
+#include "prof.h"
+#endif
+
#include "fitz.h"
#include "mupdf.h"
@@ -206,6 +210,10 @@ Java_com_artifex_mupdf_MuPDFCore_openFile(JNIEnv * env, jobject thiz, jstring jf
const char *filename;
int result = 0;
+#ifdef NDK_PROFILER
+ monstartup("libmupdf.so");
+#endif
+
filename = (*env)->GetStringUTFChars(env, jfilename, NULL);
if (filename == NULL)
{
@@ -943,6 +951,14 @@ Java_com_artifex_mupdf_MuPDFCore_destroying(JNIEnv * env, jobject thiz)
fz_close_document(doc);
doc = NULL;
+#ifdef NDK_PROFILER
+ // Apparently we should really be writing to whatever path we get
+ // from calling getFilesDir() in the java part, which supposedly
+ // gives /sdcard/data/data/com.artifex.MuPDF/gmon.out, but that's
+ // unfriendly.
+ setenv("CPUPROFILE", "/sdcard/gmon.out", 1);
+ moncleanup();
+#endif
}
JNIEXPORT jobjectArray JNICALL