mirror of
https://github.com/webmproject/libwebp.git
synced 2024-12-26 13:48:21 +01:00
sharpyuv: add SharpYuvGetCPUInfo
This gives a similar structure to libwebp and fixes a bug where passing NULL to SharpYuvInit() would unconditionally set optimized function pointers. SharpYuvInit() is left as an undocumented public function and SharpYuvGetCPUInfo is kept private to serialize updates to the pointer. Change-Id: Id72fbf3ba5b396367510e3bcd1ee2e4e11b95b8c
This commit is contained in:
parent
769387c54a
commit
979c0ebbcd
@ -35,6 +35,7 @@ endif
|
|||||||
|
|
||||||
sharpyuv_srcs := \
|
sharpyuv_srcs := \
|
||||||
sharpyuv/sharpyuv.c \
|
sharpyuv/sharpyuv.c \
|
||||||
|
sharpyuv/sharpyuv_cpu.c \
|
||||||
sharpyuv/sharpyuv_csp.c \
|
sharpyuv/sharpyuv_csp.c \
|
||||||
sharpyuv/sharpyuv_dsp.c \
|
sharpyuv/sharpyuv_dsp.c \
|
||||||
sharpyuv/sharpyuv_gamma.c \
|
sharpyuv/sharpyuv_gamma.c \
|
||||||
|
@ -87,6 +87,7 @@ if(WEBP_BUILD_WEBP_JS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(SHARPYUV_DEP_LIBRARIES)
|
set(SHARPYUV_DEP_LIBRARIES)
|
||||||
|
set(SHARPYUV_DEP_INCLUDE_DIRS)
|
||||||
set(WEBP_DEP_LIBRARIES)
|
set(WEBP_DEP_LIBRARIES)
|
||||||
set(WEBP_DEP_INCLUDE_DIRS)
|
set(WEBP_DEP_INCLUDE_DIRS)
|
||||||
|
|
||||||
@ -151,9 +152,12 @@ if(ANDROID)
|
|||||||
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
|
${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c)
|
||||||
list(APPEND INSTALLED_LIBRARIES cpufeatures-webp)
|
list(APPEND INSTALLED_LIBRARIES cpufeatures-webp)
|
||||||
target_link_libraries(cpufeatures-webp dl)
|
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_LIBRARIES ${WEBP_DEP_LIBRARIES} cpufeatures-webp)
|
||||||
set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS}
|
set(cpufeatures_include_dir ${ANDROID_NDK}/sources/android/cpufeatures)
|
||||||
${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)
|
add_definitions(-DHAVE_CPU_FEATURES_H=1)
|
||||||
set(HAVE_CPU_FEATURES_H 1)
|
set(HAVE_CPU_FEATURES_H 1)
|
||||||
else()
|
else()
|
||||||
|
@ -180,6 +180,7 @@ CFLAGS = $(CFLAGS) /D_UNICODE /DUNICODE
|
|||||||
|
|
||||||
SHARPYUV_OBJS = \
|
SHARPYUV_OBJS = \
|
||||||
$(DIROBJ)\sharpyuv\sharpyuv.obj \
|
$(DIROBJ)\sharpyuv\sharpyuv.obj \
|
||||||
|
$(DIROBJ)\sharpyuv\sharpyuv_cpu.obj \
|
||||||
$(DIROBJ)\sharpyuv\sharpyuv_csp.obj \
|
$(DIROBJ)\sharpyuv\sharpyuv_csp.obj \
|
||||||
$(DIROBJ)\sharpyuv\sharpyuv_dsp.obj \
|
$(DIROBJ)\sharpyuv\sharpyuv_dsp.obj \
|
||||||
$(DIROBJ)\sharpyuv\sharpyuv_gamma.obj \
|
$(DIROBJ)\sharpyuv\sharpyuv_gamma.obj \
|
||||||
|
@ -107,6 +107,7 @@ model {
|
|||||||
source {
|
source {
|
||||||
srcDir "sharpyuv"
|
srcDir "sharpyuv"
|
||||||
include "sharpyuv.c"
|
include "sharpyuv.c"
|
||||||
|
include "sharpyuv_cpu.c"
|
||||||
include "sharpyuv_csp.c"
|
include "sharpyuv_csp.c"
|
||||||
include "sharpyuv_dsp.c"
|
include "sharpyuv_dsp.c"
|
||||||
include "sharpyuv_gamma.c"
|
include "sharpyuv_gamma.c"
|
||||||
|
@ -128,6 +128,7 @@ ANIM_UTIL_OBJS = \
|
|||||||
|
|
||||||
SHARPYUV_OBJS = \
|
SHARPYUV_OBJS = \
|
||||||
sharpyuv/sharpyuv.o \
|
sharpyuv/sharpyuv.o \
|
||||||
|
sharpyuv/sharpyuv_cpu.o \
|
||||||
sharpyuv/sharpyuv_csp.o \
|
sharpyuv/sharpyuv_csp.o \
|
||||||
sharpyuv/sharpyuv_dsp.o \
|
sharpyuv/sharpyuv_dsp.o \
|
||||||
sharpyuv/sharpyuv_gamma.o \
|
sharpyuv/sharpyuv_gamma.o \
|
||||||
@ -308,7 +309,8 @@ HDRS_INSTALLED = \
|
|||||||
|
|
||||||
SHARPYUV_HDRS_INSTALLED = \
|
SHARPYUV_HDRS_INSTALLED = \
|
||||||
sharpyuv/sharpyuv.h \
|
sharpyuv/sharpyuv.h \
|
||||||
sharpyuv/sharpyuv_csp.h
|
sharpyuv/sharpyuv_cpu.h \
|
||||||
|
sharpyuv/sharpyuv_csp.h \
|
||||||
|
|
||||||
HDRS = \
|
HDRS = \
|
||||||
src/dec/alphai_dec.h \
|
src/dec/alphai_dec.h \
|
||||||
|
@ -11,6 +11,7 @@ libsharpyuvinclude_HEADERS =
|
|||||||
libsharpyuvinclude_HEADERS += sharpyuv.h
|
libsharpyuvinclude_HEADERS += sharpyuv.h
|
||||||
libsharpyuvinclude_HEADERS += sharpyuv_csp.h
|
libsharpyuvinclude_HEADERS += sharpyuv_csp.h
|
||||||
noinst_HEADERS =
|
noinst_HEADERS =
|
||||||
|
noinst_HEADERS += ../src/dsp/cpu.c
|
||||||
noinst_HEADERS += ../src/dsp/cpu.h
|
noinst_HEADERS += ../src/dsp/cpu.h
|
||||||
noinst_HEADERS += ../src/webp/types.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_neon_la_CFLAGS = $(AM_CFLAGS) $(NEON_FLAGS)
|
||||||
|
|
||||||
libsharpyuv_la_SOURCES =
|
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_csp.c sharpyuv_csp.h
|
||||||
libsharpyuv_la_SOURCES += sharpyuv_dsp.c sharpyuv_dsp.h
|
libsharpyuv_la_SOURCES += sharpyuv_dsp.c sharpyuv_dsp.h
|
||||||
libsharpyuv_la_SOURCES += sharpyuv_gamma.c sharpyuv_gamma.h
|
libsharpyuv_la_SOURCES += sharpyuv_gamma.c sharpyuv_gamma.h
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "src/webp/types.h"
|
#include "src/webp/types.h"
|
||||||
#include "src/dsp/cpu.h"
|
#include "sharpyuv/sharpyuv_cpu.h"
|
||||||
#include "sharpyuv/sharpyuv_dsp.h"
|
#include "sharpyuv/sharpyuv_dsp.h"
|
||||||
#include "sharpyuv/sharpyuv_gamma.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)
|
#endif // defined(WEBP_USE_THREAD) && !defined(_WIN32)
|
||||||
|
|
||||||
// Hidden exported init function.
|
// Hidden exported init function.
|
||||||
// By default SharpYuvConvert calls it with NULL. If needed, users can declare
|
// By default SharpYuvConvert calls it with SharpYuvGetCPUInfo. If needed,
|
||||||
// it as extern and call it with a VP8CPUInfo function.
|
// users can declare it as extern and call it with an alternate VP8CPUInfo
|
||||||
|
// function.
|
||||||
SHARPYUV_EXTERN void SharpYuvInit(VP8CPUInfo cpu_info_func);
|
SHARPYUV_EXTERN void SharpYuvInit(VP8CPUInfo cpu_info_func);
|
||||||
void SharpYuvInit(VP8CPUInfo cpu_info_func) {
|
void SharpYuvInit(VP8CPUInfo cpu_info_func) {
|
||||||
static volatile VP8CPUInfo sharpyuv_last_cpuinfo_used =
|
static volatile VP8CPUInfo sharpyuv_last_cpuinfo_used =
|
||||||
(VP8CPUInfo)&sharpyuv_last_cpuinfo_used;
|
(VP8CPUInfo)&sharpyuv_last_cpuinfo_used;
|
||||||
LOCK_ACCESS;
|
LOCK_ACCESS;
|
||||||
{
|
SharpYuvGetCPUInfo = cpu_info_func;
|
||||||
const int initialized =
|
if (sharpyuv_last_cpuinfo_used == SharpYuvGetCPUInfo) {
|
||||||
(sharpyuv_last_cpuinfo_used != (VP8CPUInfo)&sharpyuv_last_cpuinfo_used);
|
UNLOCK_ACCESS_AND_RETURN;
|
||||||
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);
|
SharpYuvInitDsp();
|
||||||
if (!initialized) {
|
|
||||||
SharpYuvInitGammaTables();
|
SharpYuvInitGammaTables();
|
||||||
}
|
|
||||||
|
|
||||||
sharpyuv_last_cpuinfo_used = cpu_info_func;
|
sharpyuv_last_cpuinfo_used = SharpYuvGetCPUInfo;
|
||||||
}
|
|
||||||
UNLOCK_ACCESS_AND_RETURN;
|
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.
|
// Stride should be even for uint16_t buffers.
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
SharpYuvInit(NULL);
|
SharpYuvInit(SharpYuvGetCPUInfo);
|
||||||
|
|
||||||
// Add scaling factor to go from rgb_bit_depth to yuv_bit_depth, to the
|
// Add scaling factor to go from rgb_bit_depth to yuv_bit_depth, to the
|
||||||
// rgb->yuv conversion matrix.
|
// rgb->yuv conversion matrix.
|
||||||
|
14
sharpyuv/sharpyuv_cpu.c
Normal file
14
sharpyuv/sharpyuv_cpu.c
Normal file
@ -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"
|
22
sharpyuv/sharpyuv_cpu.h
Normal file
22
sharpyuv/sharpyuv_cpu.h
Normal file
@ -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_
|
@ -16,7 +16,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.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 InitSharpYuvSSE2(void);
|
||||||
extern void InitSharpYuvNEON(void);
|
extern void InitSharpYuvNEON(void);
|
||||||
|
|
||||||
void SharpYuvInitDsp(VP8CPUInfo cpu_info_func) {
|
void SharpYuvInitDsp(void) {
|
||||||
(void)cpu_info_func;
|
|
||||||
|
|
||||||
#if !WEBP_NEON_OMIT_C_CODE
|
#if !WEBP_NEON_OMIT_C_CODE
|
||||||
SharpYuvUpdateY = SharpYuvUpdateY_C;
|
SharpYuvUpdateY = SharpYuvUpdateY_C;
|
||||||
SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;
|
SharpYuvUpdateRGB = SharpYuvUpdateRGB_C;
|
||||||
SharpYuvFilterRow = SharpYuvFilterRow_C;
|
SharpYuvFilterRow = SharpYuvFilterRow_C;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (SharpYuvGetCPUInfo != NULL) {
|
||||||
#if defined(WEBP_HAVE_SSE2)
|
#if defined(WEBP_HAVE_SSE2)
|
||||||
if (cpu_info_func == NULL || cpu_info_func(kSSE2)) {
|
if (SharpYuvGetCPUInfo(kSSE2)) {
|
||||||
InitSharpYuvSSE2();
|
InitSharpYuvSSE2();
|
||||||
}
|
}
|
||||||
#endif // WEBP_HAVE_SSE2
|
#endif // WEBP_HAVE_SSE2
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(WEBP_HAVE_NEON)
|
#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();
|
InitSharpYuvNEON();
|
||||||
}
|
}
|
||||||
#endif // WEBP_HAVE_NEON
|
#endif // WEBP_HAVE_NEON
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#ifndef WEBP_SHARPYUV_SHARPYUV_DSP_H_
|
#ifndef WEBP_SHARPYUV_SHARPYUV_DSP_H_
|
||||||
#define WEBP_SHARPYUV_SHARPYUV_DSP_H_
|
#define WEBP_SHARPYUV_SHARPYUV_DSP_H_
|
||||||
|
|
||||||
#include "src/dsp/cpu.h"
|
|
||||||
#include "src/webp/types.h"
|
#include "src/webp/types.h"
|
||||||
|
|
||||||
extern uint64_t (*SharpYuvUpdateY)(const uint16_t* src, const uint16_t* ref,
|
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,
|
const uint16_t* best_y, uint16_t* out,
|
||||||
int bit_depth);
|
int bit_depth);
|
||||||
|
|
||||||
void SharpYuvInitDsp(VP8CPUInfo cpu_info_func);
|
void SharpYuvInitDsp(void);
|
||||||
|
|
||||||
#endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_
|
#endif // WEBP_SHARPYUV_SHARPYUV_DSP_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user