diff options
author | James Zern <jzern@google.com> | 2022-10-26 20:56:42 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-10-26 20:56:42 +0000 |
commit | 9ba800a7451d431e1afd0f593514c177a80169ba (patch) | |
tree | 72dd7db3f7607a1bba040cbbd47e50d398ea6044 | |
parent | 8bab09a4a890ca7c3e04c8724af6efb8774b24d8 (diff) | |
parent | 979c0ebbcd95c06acc8b46a693e544b859cee0de (diff) | |
download | libwebp-9ba800a7451d431e1afd0f593514c177a80169ba.tar.gz |
Merge changes Id72fbf3b,Ic59d23a2 into main
* changes:
sharpyuv: add SharpYuvGetCPUInfo
cpu.c,cosmetics: fix a typo
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 8 | ||||
-rw-r--r-- | Makefile.vc | 1 | ||||
-rw-r--r-- | build.gradle | 1 | ||||
-rw-r--r-- | makefile.unix | 4 | ||||
-rw-r--r-- | sharpyuv/Makefile.am | 2 | ||||
-rw-r--r-- | sharpyuv/sharpyuv.c | 29 | ||||
-rw-r--r-- | sharpyuv/sharpyuv_cpu.c | 14 | ||||
-rw-r--r-- | sharpyuv/sharpyuv_cpu.h | 22 | ||||
-rw-r--r-- | sharpyuv/sharpyuv_dsp.c | 17 | ||||
-rw-r--r-- | sharpyuv/sharpyuv_dsp.h | 3 | ||||
-rw-r--r-- | src/dsp/cpu.c | 2 |
12 files changed, 74 insertions, 30 deletions
@@ -35,6 +35,7 @@ endif sharpyuv_srcs := \ sharpyuv/sharpyuv.c \ + sharpyuv/sharpyuv_cpu.c \ sharpyuv/sharpyuv_csp.c \ sharpyuv/sharpyuv_dsp.c \ sharpyuv/sharpyuv_gamma.c \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 1a2793d6..9383c213 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,7 @@ if(WEBP_BUILD_WEBP_JS) endif() set(SHARPYUV_DEP_LIBRARIES) +set(SHARPYUV_DEP_INCLUDE_DIRS) set(WEBP_DEP_LIBRARIES) set(WEBP_DEP_INCLUDE_DIRS) @@ -151,9 +152,12 @@ if(ANDROID) ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c) list(APPEND INSTALLED_LIBRARIES cpufeatures-webp) target_link_libraries(cpufeatures-webp dl) + set(SHARPYUV_DEP_LIBRARIES ${SHARPYUV_DEP_LIBRARIES} cpufeatures-webp) set(WEBP_DEP_LIBRARIES ${WEBP_DEP_LIBRARIES} cpufeatures-webp) - set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS} - ${ANDROID_NDK}/sources/android/cpufeatures) + set(cpufeatures_include_dir ${ANDROID_NDK}/sources/android/cpufeatures) + set(SHARPYUV_DEP_INCLUDE_DIRS ${SHARPYUV_DEP_INCLUDE_DIRS} + ${cpufeatures_include_dir}) + set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS} ${cpufeatures_include_dir}) add_definitions(-DHAVE_CPU_FEATURES_H=1) set(HAVE_CPU_FEATURES_H 1) else() diff --git a/Makefile.vc b/Makefile.vc index 5881adc4..8e3aed45 100644 --- a/Makefile.vc +++ b/Makefile.vc @@ -180,6 +180,7 @@ CFLAGS = $(CFLAGS) /D_UNICODE /DUNICODE SHARPYUV_OBJS = \ $(DIROBJ)\sharpyuv\sharpyuv.obj \ + $(DIROBJ)\sharpyuv\sharpyuv_cpu.obj \ $(DIROBJ)\sharpyuv\sharpyuv_csp.obj \ $(DIROBJ)\sharpyuv\sharpyuv_dsp.obj \ $(DIROBJ)\sharpyuv\sharpyuv_gamma.obj \ diff --git a/build.gradle b/build.gradle index 13202a85..c25314c0 100644 --- a/build.gradle +++ b/build.gradle @@ -107,6 +107,7 @@ model { source { srcDir "sharpyuv" include "sharpyuv.c" + include "sharpyuv_cpu.c" include "sharpyuv_csp.c" include "sharpyuv_dsp.c" include "sharpyuv_gamma.c" diff --git a/makefile.unix b/makefile.unix index 854f3342..8348d108 100644 --- a/makefile.unix +++ b/makefile.unix @@ -128,6 +128,7 @@ ANIM_UTIL_OBJS = \ SHARPYUV_OBJS = \ sharpyuv/sharpyuv.o \ + sharpyuv/sharpyuv_cpu.o \ sharpyuv/sharpyuv_csp.o \ sharpyuv/sharpyuv_dsp.o \ sharpyuv/sharpyuv_gamma.o \ @@ -308,7 +309,8 @@ HDRS_INSTALLED = \ SHARPYUV_HDRS_INSTALLED = \ sharpyuv/sharpyuv.h \ - sharpyuv/sharpyuv_csp.h + sharpyuv/sharpyuv_cpu.h \ + sharpyuv/sharpyuv_csp.h \ HDRS = \ src/dec/alphai_dec.h \ diff --git a/sharpyuv/Makefile.am b/sharpyuv/Makefile.am index 48801e06..b6b46758 100644 --- a/sharpyuv/Makefile.am +++ b/sharpyuv/Makefile.am @@ -11,6 +11,7 @@ libsharpyuvinclude_HEADERS = libsharpyuvinclude_HEADERS += sharpyuv.h libsharpyuvinclude_HEADERS += sharpyuv_csp.h noinst_HEADERS = +noinst_HEADERS += ../src/dsp/cpu.c noinst_HEADERS += ../src/dsp/cpu.h noinst_HEADERS += ../src/webp/types.h @@ -25,6 +26,7 @@ libsharpyuv_neon_la_CPPFLAGS = $(libsharpyuv_la_CPPFLAGS) libsharpyuv_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_FLAGS) libsharpyuv_la_SOURCES = +libsharpyuv_la_SOURCES += sharpyuv_cpu.c sharpyuv_cpu.h libsharpyuv_la_SOURCES += sharpyuv_csp.c sharpyuv_csp.h libsharpyuv_la_SOURCES += sharpyuv_dsp.c sharpyuv_dsp.h libsharpyuv_la_SOURCES += sharpyuv_gamma.c sharpyuv_gamma.h diff --git a/sharpyuv/sharpyuv.c b/sharpyuv/sharpyuv.c index 5ff02225..6585041e 100644 --- a/sharpyuv/sharpyuv.c +++ b/sharpyuv/sharpyuv.c @@ -20,7 +20,7 @@ #include <string.h> #include "src/webp/types.h" -#include "src/dsp/cpu.h" +#include "sharpyuv/sharpyuv_cpu.h" #include "sharpyuv/sharpyuv_dsp.h" #include "sharpyuv/sharpyuv_gamma.h" @@ -431,26 +431,23 @@ static int DoSharpArgbToYuv(const uint8_t* r_ptr, const uint8_t* g_ptr, #endif // defined(WEBP_USE_THREAD) && !defined(_WIN32) // Hidden exported init function. -// By default SharpYuvConvert calls it with NULL. If needed, users can declare -// it as extern and call it with a VP8CPUInfo function. +// By default SharpYuvConvert calls it with SharpYuvGetCPUInfo. If needed, +// users can declare it as extern and call it with an alternate VP8CPUInfo +// function. SHARPYUV_EXTERN void SharpYuvInit(VP8CPUInfo cpu_info_func); void SharpYuvInit(VP8CPUInfo cpu_info_func) { static volatile VP8CPUInfo sharpyuv_last_cpuinfo_used = (VP8CPUInfo)&sharpyuv_last_cpuinfo_used; LOCK_ACCESS; - { - const int initialized = - (sharpyuv_last_cpuinfo_used != (VP8CPUInfo)&sharpyuv_last_cpuinfo_used); - if (cpu_info_func == NULL && initialized) UNLOCK_ACCESS_AND_RETURN; - if (sharpyuv_last_cpuinfo_used == cpu_info_func) UNLOCK_ACCESS_AND_RETURN; - - SharpYuvInitDsp(cpu_info_func); - if (!initialized) { - SharpYuvInitGammaTables(); - } - - sharpyuv_last_cpuinfo_used = cpu_info_func; + SharpYuvGetCPUInfo = cpu_info_func; + if (sharpyuv_last_cpuinfo_used == SharpYuvGetCPUInfo) { + UNLOCK_ACCESS_AND_RETURN; } + + SharpYuvInitDsp(); + SharpYuvInitGammaTables(); + + sharpyuv_last_cpuinfo_used = SharpYuvGetCPUInfo; UNLOCK_ACCESS_AND_RETURN; } @@ -487,7 +484,7 @@ int SharpYuvConvert(const void* r_ptr, const void* g_ptr, // Stride should be even for uint16_t buffers. return 0; } - SharpYuvInit(NULL); + SharpYuvInit(SharpYuvGetCPUInfo); // Add scaling factor to go from rgb_bit_depth to yuv_bit_depth, to the // rgb->yuv conversion matrix. diff --git a/sharpyuv/sharpyuv_cpu.c b/sharpyuv/sharpyuv_cpu.c new file mode 100644 index 00000000..29425a0c --- /dev/null +++ b/sharpyuv/sharpyuv_cpu.c @@ -0,0 +1,14 @@ +// Copyright 2022 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +#include "sharpyuv/sharpyuv_cpu.h" + +// Include src/dsp/cpu.c to create SharpYuvGetCPUInfo from VP8GetCPUInfo. The +// function pointer is renamed in sharpyuv_cpu.h. +#include "src/dsp/cpu.c" diff --git a/sharpyuv/sharpyuv_cpu.h b/sharpyuv/sharpyuv_cpu.h new file mode 100644 index 00000000..176ca3eb --- /dev/null +++ b/sharpyuv/sharpyuv_cpu.h @@ -0,0 +1,22 @@ +// Copyright 2022 Google Inc. All Rights Reserved. +// +// Use of this source code is governed by a BSD-style license +// that can be found in the COPYING file in the root of the source +// tree. An additional intellectual property rights grant can be found +// in the file PATENTS. All contributing project authors may +// be found in the AUTHORS file in the root of the source tree. +// ----------------------------------------------------------------------------- +// +#ifndef WEBP_SHARPYUV_SHARPYUV_CPU_H_ +#define WEBP_SHARPYUV_SHARPYUV_CPU_H_ + +#include "sharpyuv/sharpyuv.h" + +// Avoid exporting SharpYuvGetCPUInfo in shared object / DLL builds. +// SharpYuvInit() replaces the use of the function pointer. +#undef WEBP_EXTERN +#define WEBP_EXTERN extern +#define VP8GetCPUInfo SharpYuvGetCPUInfo +#include "src/dsp/cpu.h" + +#endif // WEBP_SHARPYUV_SHARPYUV_CPU_H_ diff --git a/sharpyuv/sharpyuv_dsp.c b/sharpyuv/sharpyuv_dsp.c index 956fa7ce..31c272c4 100644 --- a/sharpyuv/sharpyuv_dsp.c +++ b/sharpyuv/sharpyuv_dsp.c @@ -16,7 +16,7 @@ #include <assert.h> #include <stdlib.h> -#include "src/dsp/cpu.h" +#include "sharpyuv/sharpyuv_cpu.h" //----------------------------------------------------------------------------- @@ -75,23 +75,24 @@ void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len, extern void InitSharpYuvSSE2(void); extern void InitSharpYuvNEON(void); -void SharpYuvInitDsp(VP8CPUInfo cpu_info_func) { - (void)cpu_info_func; - +void SharpYuvInitDsp(void) { #if !WEBP_NEON_OMIT_C_CODE SharpYuvUpdateY = SharpYuvUpdateY_C; SharpYuvUpdateRGB = SharpYuvUpdateRGB_C; SharpYuvFilterRow = SharpYuvFilterRow_C; #endif + if (SharpYuvGetCPUInfo != NULL) { #if defined(WEBP_HAVE_SSE2) - if (cpu_info_func == NULL || cpu_info_func(kSSE2)) { - InitSharpYuvSSE2(); - } + if (SharpYuvGetCPUInfo(kSSE2)) { + InitSharpYuvSSE2(); + } #endif // WEBP_HAVE_SSE2 + } #if defined(WEBP_HAVE_NEON) - if (WEBP_NEON_OMIT_C_CODE || cpu_info_func == NULL || cpu_info_func(kNEON)) { + if (WEBP_NEON_OMIT_C_CODE || + (SharpYuvGetCPUInfo != NULL && SharpYuvGetCPUInfo(kNEON))) { InitSharpYuvNEON(); } #endif // WEBP_HAVE_NEON diff --git a/sharpyuv/sharpyuv_dsp.h b/sharpyuv/sharpyuv_dsp.h index c7755b97..18e8de38 100644 --- a/sharpyuv/sharpyuv_dsp.h +++ b/sharpyuv/sharpyuv_dsp.h @@ -12,7 +12,6 @@ #ifndef WEBP_SHARPYUV_SHARPYUV_DSP_H_ #define WEBP_SHARPYUV_SHARPYUV_DSP_H_ -#include "src/dsp/cpu.h" #include "src/webp/types.h" extern uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref, @@ -23,6 +22,6 @@ extern void (*SharpYuvFilterRow)(const int16_t* A, const int16_t* B, int len, const uint16_t* best_y, uint16_t* out, int bit_depth); -void SharpYuvInitDsp(VP8CPUInfo cpu_info_func); +void SharpYuvInitDsp(void); #endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_ diff --git a/src/dsp/cpu.c b/src/dsp/cpu.c index a4ba7f2c..62de73f7 100644 --- a/src/dsp/cpu.c +++ b/src/dsp/cpu.c @@ -212,7 +212,7 @@ VP8CPUInfo VP8GetCPUInfo = wasmCPUInfo; #elif defined(WEBP_HAVE_NEON) // In most cases this function doesn't check for NEON support (it's assumed by // the configuration), but enables turning off NEON at runtime, for testing -// purposes, by setting VP8DecGetCPUInfo = NULL. +// purposes, by setting VP8GetCPUInfo = NULL. static int armCPUInfo(CPUFeature feature) { if (feature != kNEON) return 0; #if defined(__linux__) && defined(WEBP_HAVE_NEON_RTCD) |