diff --git a/third_party/libwebp/BUILD.gn b/third_party/libwebp/BUILD.gn index 94c0d145a8b7..4d6acade4e7e 100644 --- a/third_party/libwebp/BUILD.gn +++ b/third_party/libwebp/BUILD.gn @@ -43,6 +43,9 @@ libwebp_lib("libwebp_dsp_dec_common") { ":libwebp_dsp_dec_sse2", ":libwebp_dsp_dec_sse41", ] + if (is_starboard) { + deps += [ "//starboard:starboard_headers_only" ] + } } libwebp_lib("libwebp_dsp_dec_msa") { @@ -87,6 +90,31 @@ libwebp_lib("libwebp_utils_enc") { config("libwebp_direct_config") { include_dirs = [ "." ] + if (is_starboard) { + if (current_cpu == "x64" || current_cpu == "x86") { + cflags = [ + "-msse2", + "-msse4.1", + ] + defines = [ + "WEBP_HAVE_SSE2", + "WEBP_HAVE_SSE41", + ] + } + + # This crashes on x86/Atom, enable on 64-bit only. + if (current_cpu == "x64") { + cflags += [ + "-mavx", + "-mavx2", + ] + defines += [ "WEBP_HAVE_AVX2" ] + } + if (current_cpu == "arm" || current_cpu == "arm64") { + defines = [ "WEBP_HAVE_NEON" ] + cflags = [ "-mfpu=neon" ] + } + } } group("libwebp") { diff --git a/third_party/libwebp/src/dsp/cpu.c b/third_party/libwebp/src/dsp/cpu.c index 8b40feed2928..cba945579341 100644 --- a/third_party/libwebp/src/dsp/cpu.c +++ b/third_party/libwebp/src/dsp/cpu.c @@ -13,6 +13,51 @@ #include "src/dsp/dsp.h" +#if defined(STARBOARD) + +#include "starboard/cpu_features.h" +#include "starboard/log.h" +#include "starboard/system.h" + +bool warn_if_not_enabled(const char* name, bool value) { + if (!value) { + SbLogFormatF("LibWebP optimization not enabled: %s\n", name); + SbLogFlush(); + } + return value; +} + +static int StarboardGetCPUInfo(CPUFeature feature) { + SbCPUFeatures features; + if (SbCPUFeaturesGet(&features)) { + switch (feature) { + case kSSE2: + return warn_if_not_enabled("sse2", features.x86.has_sse2); + case kSSE3: + return warn_if_not_enabled("sse3", features.x86.has_sse3); + case kSSE4_1: + return warn_if_not_enabled("sse41", features.x86.has_sse41); + case kAVX: + return warn_if_not_enabled("avx", features.x86.has_avx); + case kAVX2: + return warn_if_not_enabled("avx2", features.x86.has_avx2); + case kNEON: { + return warn_if_not_enabled("neon", features.arm.has_neon); + } + default: + return 0; + } + } else { + SbLogFormatF("LibWebP CPU feature detection failed\n"); + SbLogFlush(); + } + return 0; +} + +VP8CPUInfo VP8GetCPUInfo = StarboardGetCPUInfo; + +#else // STARBOARD + #if defined(WEBP_HAVE_NEON_RTCD) #include #include @@ -220,3 +265,5 @@ VP8CPUInfo VP8GetCPUInfo = mipsCPUInfo; #else VP8CPUInfo VP8GetCPUInfo = NULL; #endif + +#endif // STARBOARD