Skip to content

Commit

Permalink
Bug 1945602 - Apply mozilla patches for libyuv r=ng
Browse files Browse the repository at this point in the history
  • Loading branch information
updatebot-ci committed Feb 25, 2025
1 parent 58bdae1 commit 4490f68
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 22 deletions.
10 changes: 6 additions & 4 deletions media/libyuv/libyuv/include/libyuv/row.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ extern "C" {

// The following functions fail on gcc/clang 32 bit with fpic and framepointer.
// caveat: clangcl uses row_win.cc which works.
#if defined(__x86_64__) || !defined(__pic__) || defined(__clang__) || \
defined(_MSC_VER)
#if !defined(MOZ_PROFILING) && \
(defined(__x86_64__) || !defined(__pic__) || defined(__clang__) || \
defined(_MSC_VER))
// TODO(fbarchard): fix build error on android_full_debug=1
// https://code.google.com/p/libyuv/issues/detail?id=517
#define HAS_I422ALPHATOARGBROW_SSSE3
Expand Down Expand Up @@ -192,8 +193,9 @@ extern "C" {
#define HAS_ARGBSUBTRACTROW_AVX2
#define HAS_BLENDPLANEROW_AVX2

#if defined(__x86_64__) || !defined(__pic__) || defined(__clang__) || \
defined(_MSC_VER)
#if !defined(MOZ_PROFILING) && \
(defined(__x86_64__) || !defined(__pic__) || defined(__clang__) || \
defined(_MSC_VER))
// TODO(fbarchard): fix build error on android_full_debug=1
// https://code.google.com/p/libyuv/issues/detail?id=517
#define HAS_I422ALPHATOARGBROW_AVX2
Expand Down
126 changes: 117 additions & 9 deletions media/libyuv/libyuv/libyuv.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'mips_msa%': 0, # Default to msa off.
'build_neon': 0,
'build_msa': 0,
'build_lsx': 0,
'conditions': [
['(target_arch == "armv7" or target_arch == "armv7s" or \
(target_arch == "arm" and arm_version >= 7) or target_arch == "arm64")\
Expand All @@ -52,7 +53,7 @@
'optimize': 'max', # enable O2 and ltcg.
},
# Allows libyuv.a redistributable library without external dependencies.
'standalone_static_library': 1,
# 'standalone_static_library': 1,
'conditions': [
# Disable -Wunused-parameter
['clang == 1', {
Expand All @@ -70,6 +71,9 @@
'-mfpu=vfpv3-d16',
# '-mthumb', # arm32 not thumb
],
'cflags_mozilla!': [
'<@(moz_neon_cflags_block_list)',
],
'conditions': [
# Disable LTO in libyuv_neon target due to gcc 4.9 compiler bug.
['clang == 0 and use_lto == 1', {
Expand All @@ -78,21 +82,31 @@
'-ffat-lto-objects',
],
}],
# arm64 does not need -mfpu=neon option as neon is not optional
['target_arch != "arm64"', {
'cflags': [
'-mfpu=neon',
# '-marm', # arm32 not thumb
],
}],
],
}],
['build_msa != 0', {
'defines': [
'LIBYUV_MSA',
],
}],
['OS != "ios" and libyuv_disable_jpeg != 1', {
['build_lsx == 0', {
'conditions': [
['target_arch == "loongarch64"', {
'cflags_mozilla': [
'-mno-lsx',
],
}],
],
}],
['build_with_mozilla == 1', {
'defines': [
'HAVE_JPEG'
],
'cflags_mozilla': [
'$(MOZ_JPEG_CFLAGS)',
],
}],
['OS != "ios" and libyuv_disable_jpeg != 1 and build_with_mozilla != 1', {
'defines': [
'HAVE_JPEG'
],
Expand All @@ -118,6 +132,7 @@
}],
], #conditions
'defines': [
'LIBYUV_DISABLE_SME',
# Enable the following 3 macros to turn off assembly for specified CPU.
# 'LIBYUV_DISABLE_X86',
# 'LIBYUV_DISABLE_NEON',
Expand Down Expand Up @@ -146,12 +161,105 @@
'-Wl,--dynamic-linker,/system/bin/linker',
],
}],
['target_arch == "armv7" or target_arch == "arm64" and moz_have_arm_i8mm_and_dot_prod == 1 and build_with_mozilla == 1', {
'dependencies': [
':libyuv_neon',
],
}],
['target_arch == "arm64" and moz_have_arm_sve2 == 1 and build_with_mozilla == 1', {
'dependencies': [
':libyuv_sve',
],
'defines' :[
'LIBYUV_SVE',
]
}],
['target_arch == "arm64" and moz_have_arm_sve2 == 1 and build_with_mozilla == 1', {
'dependencies': [
':libyuv_sve',
],
'defines' :[
'LIBYUV_SVE',
]
}],
], #conditions
},
'sources': [
'<@(libyuv_sources)',
],
},
{
'target_name': 'libyuv_neon',
'type': 'static_library',
'variables': {
'optimize': 'max', # enable O2 and ltcg.
},
'conditions': [
['target_arch == "arm64" and moz_have_arm_i8mm_and_dot_prod == 1 and build_with_mozilla == 1', {
'cflags_mozilla': [
'-march=armv8.2-a+dotprod+i8mm',
],
}],
# arm64 does not need -mfpu=neon option as neon is not optional
['target_arch != "arm64"', {
'cflags': [
'-mfpu=neon',
# '-marm', # arm32 not thumb
],
'cflags_mozilla': [
'-mfpu=neon',
],
}],
['build_neon != 0', {
'cflags_mozilla!': [
'<@(moz_neon_cflags_block_list)',
],
'sources': [
'<@(libyuv_neon_sources)',
],
}],
], #conditions
'include_dirs': [
'include',
'.',
],
'direct_dependent_settings': {
'include_dirs': [
'include',
'.',
], #conditions
},
},
{
'target_name': 'libyuv_sve',
'type': 'static_library',
'variables': {
'optimize': 'max', # enable O2 and ltcg.
},
'conditions': [
['target_arch == "arm64" and moz_have_arm_sve2 == 1 and build_with_mozilla == 1', {
'cflags_mozilla!': [
'<@(moz_neon_cflags_block_list)',
],
'cflags_mozilla': [
'-march=armv9-a+dotprod+sve2+i8mm',
],
'sources': [
'<@(libyuv_sve_sources)',
],
}],
], #conditions
'include_dirs': [
'include',
'.',
],
'direct_dependent_settings': {
'include_dirs': [
'include',
'.',
], #conditions
},
},
], # targets.
}

Expand Down
31 changes: 23 additions & 8 deletions media/libyuv/libyuv/libyuv.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@

{
'variables': {
'moz_have_arm_sve2%': '<(moz_have_arm_sve2)',
'moz_have_arm_i8mm_and_dot_prod%': '<(moz_have_arm_i8mm_and_dot_prod)',
'moz_neon_cflags_block_list': [
'-mfpu=vfp',
'-mfpu=vfpv3',
'-mfpu=vfpv3-d16',
],
# Needs to be reflected in upstream gyp file.
'libyuv_sve_sources': [
# sources.
'source/row_sve.cc',
],
'libyuv_neon_sources': [
# ARM Source Files
"source/compare_neon.cc",
"source/compare_neon64.cc",
"source/rotate_neon.cc",
"source/rotate_neon64.cc",
"source/row_neon.cc",
"source/row_neon64.cc",
"source/scale_neon.cc",
"source/scale_neon64.cc",
],
'libyuv_sources': [
# includes.
'include/libyuv.h',
Expand Down Expand Up @@ -40,8 +63,6 @@
'source/compare_common.cc',
'source/compare_gcc.cc',
'source/compare_msa.cc',
'source/compare_neon.cc',
'source/compare_neon64.cc',
'source/compare_win.cc',
'source/convert.cc',
'source/convert_argb.cc',
Expand All @@ -60,24 +81,18 @@
'source/rotate_common.cc',
'source/rotate_gcc.cc',
'source/rotate_msa.cc',
'source/rotate_neon.cc',
'source/rotate_neon64.cc',
'source/rotate_win.cc',
'source/row_any.cc',
'source/row_common.cc',
'source/row_gcc.cc',
'source/row_msa.cc',
'source/row_neon.cc',
'source/row_neon64.cc',
'source/row_win.cc',
'source/scale.cc',
'source/scale_any.cc',
'source/scale_argb.cc',
'source/scale_common.cc',
'source/scale_gcc.cc',
'source/scale_msa.cc',
'source/scale_neon.cc',
'source/scale_neon64.cc',
'source/scale_rgb.cc',
'source/scale_uv.cc',
'source/scale_win.cc',
Expand Down
5 changes: 4 additions & 1 deletion media/libyuv/libyuv/source/mjpeg_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ MJpegDecoder::MJpegDecoder()
decompress_struct_->err = jpeg_std_error(&error_mgr_->base);
// Override standard exit()-based error handler.
error_mgr_->base.error_exit = &ErrorHandler;
#ifndef DEBUG_MJPEG
error_mgr_->base.output_message = &OutputHandler;
#endif
#endif
decompress_struct_->client_data = NULL;
source_mgr_->init_source = &init_source;
Expand Down Expand Up @@ -462,11 +464,12 @@ void ErrorHandler(j_common_ptr cinfo) {
longjmp(mgr->setjmp_buffer, 1);
}

#ifndef DEBUG_MJPEG
// Suppress fprintf warnings.
void OutputHandler(j_common_ptr cinfo) {
(void)cinfo;
}

#endif
#endif // HAVE_SETJMP

void MJpegDecoder::AllocOutputBuffers(int num_outbufs) {
Expand Down

0 comments on commit 4490f68

Please sign in to comment.