Use the NDK's cpu-features library when building skia for Chromium/Android.
This patch ensures that when Skia is built for Chromium, it will
always use the Android NDK's cpu-features helper library to detect
NEON at runtime.
This is needed because sandboxed Chromium renderer processes cannot
access /proc, and the probing performed in SkUtilsArm.cpp will never
work. As such, the NEON code paths will never be used even when the
device supports them.
Chromium has special code that ensures that the browser process
passes the CPU features flags to every renderer process, but
Skia needs to use android_getCpuFeatures() to get them.
See http://crbug.com/164154 for full details.
Review URL: https://codereview.appspot.com/7102045
git-svn-id: http://skia.googlecode.com/svn/trunk@7149 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkPreConfig.h b/include/core/SkPreConfig.h
index 393a348..4f977ea 100644
--- a/include/core/SkPreConfig.h
+++ b/include/core/SkPreConfig.h
@@ -55,6 +55,12 @@
#define SK_BUILD_FOR_ANDROID
#endif
+// USE_CHROMIUM_SKIA is defined when building Skia for the Chromium
+// browser.
+#if defined(USE_CHROMIUM_SKIA)
+ #define SK_BUILD_FOR_CHROMIUM
+#endif
+
//////////////////////////////////////////////////////////////////////
#if !defined(SK_DEBUG) && !defined(SK_RELEASE)
diff --git a/src/core/SkUtilsArm.cpp b/src/core/SkUtilsArm.cpp
index 1c49316..b0eaac0 100644
--- a/src/core/SkUtilsArm.cpp
+++ b/src/core/SkUtilsArm.cpp
@@ -16,6 +16,20 @@
#include <string.h>
#include <pthread.h>
+// Set USE_ANDROID_NDK_CPU_FEATURES to use the Android NDK's
+// cpu-features helper library to detect NEON at runtime. See
+// http://crbug.com/164154 to see why this is needed in Chromium
+// for Android.
+#if defined(SK_BUILD_FOR_ANDROID) && defined(SK_BUILD_FOR_CHROMIUM)
+# define USE_ANDROID_NDK_CPU_FEATURES 1
+#else
+# define USE_ANDROID_NDK_CPU_FEATURES 0
+#endif
+
+#if USE_ANDROID_NDK_CPU_FEATURES
+# include <cpu-features.h>
+#endif
+
// Set NEON_DEBUG to 1 to allow debugging of the CPU features probing.
// For now, we always set it for SK_DEBUG builds.
#ifdef SK_DEBUG
@@ -62,6 +76,12 @@
SkDebugf("Running dynamic CPU feature detection\n");
#endif
+#if USE_ANDROID_NDK_CPU_FEATURES
+
+ result = (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;
+
+#else // USE_ANDROID_NDK_CPU_FEATURES
+
// There is no user-accessible CPUID instruction on ARM that we can use.
// Instead, we must parse /proc/cpuinfo and look for the 'neon' feature.
// For example, here's a typical output (Nexus S running ICS 4.0.3):
@@ -151,6 +171,8 @@
} while (0);
+#endif // USE_ANDROID_NDK_CPU_FEATURES
+
if (result) {
SkDebugf("Device supports ARM NEON instructions!\n");
} else {