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
This commit is contained in:
digit@google.com 2013-01-14 14:58:22 +00:00
parent 61be7946ed
commit 47ebbcc7ab
2 changed files with 28 additions and 0 deletions

View File

@ -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)

View File

@ -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 {