aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkUtilsArm.cpp
diff options
context:
space:
mode:
authorGravatar digit@google.com <digit@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-14 14:58:22 +0000
committerGravatar digit@google.com <digit@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-14 14:58:22 +0000
commit47ebbcc7abf90c943b2d5e05fcedb42913e917e0 (patch)
treeb519c624c82eebcdf30a10bc5f4ba90398566ff7 /src/core/SkUtilsArm.cpp
parent61be7946ed4c351fa3f71a407243d3cd024d9924 (diff)
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
Diffstat (limited to 'src/core/SkUtilsArm.cpp')
-rw-r--r--src/core/SkUtilsArm.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/core/SkUtilsArm.cpp b/src/core/SkUtilsArm.cpp
index 1c49316d9e..b0eaac00bb 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 @@ static bool sk_cpu_arm_check_neon(void) {
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 @@ static bool sk_cpu_arm_check_neon(void) {
} while (0);
+#endif // USE_ANDROID_NDK_CPU_FEATURES
+
if (result) {
SkDebugf("Device supports ARM NEON instructions!\n");
} else {