Skip to content

Instantly share code, notes, and snippets.

@Sakura286
Last active May 6, 2025 03:40
Show Gist options
  • Select an option

  • Save Sakura286/bc6503dc2954f1ad51175118adb7647a to your computer and use it in GitHub Desktop.

Select an option

Save Sakura286/bc6503dc2954f1ad51175118adb7647a to your computer and use it in GitHub Desktop.
From 3a3a58ff7bfe5027164425eba79f7feac98666a2 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Thu, 24 Apr 2025 02:46:01 +0000
Subject: [PATCH 1/2] add hw decode detect logic
---
.../platforms/ffmpeg/FFmpegVideoDecoder.cpp | 2 +-
widget/gtk/GfxInfo.cpp | 34 +++++++++++++++++--
widget/gtk/GfxInfo.h | 3 ++
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
index f32e0e4266..06d4ccc3cd 100644
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -636,7 +636,7 @@ FFmpegVideoDecoder<LIBAV_VER>::FFmpegVideoDecoder(
mVAAPIDeviceContext(nullptr),
mUsingV4L2(false),
mUsingEsmpp(false),
- mEnableHardwareDecoding(true), //(!aDisableHardwareDecoding),
+ mEnableHardwareDecoding(!aDisableHardwareDecoding),
mDisplay(nullptr),
#endif
mImageAllocator(aAllocator),
diff --git a/widget/gtk/GfxInfo.cpp b/widget/gtk/GfxInfo.cpp
index baf3fb452a..3d2e020742 100644
--- a/widget/gtk/GfxInfo.cpp
+++ b/widget/gtk/GfxInfo.cpp
@@ -41,10 +41,12 @@
#define GFX_TEST_TIMEOUT 4000
#define VAAPI_TEST_TIMEOUT 2000
#define V4L2_TEST_TIMEOUT 2000
+#define ESMPP_TEST_TIMEOUT 2000
#define GLX_PROBE_BINARY u"glxtest"_ns
#define VAAPI_PROBE_BINARY u"vaapitest"_ns
#define V4L2_PROBE_BINARY u"v4l2test"_ns
+#define ESMPP_PROBE_BINARY u"esmpptest"_ns
namespace mozilla::widget {
@@ -652,6 +654,12 @@ void GfxInfo::GetDataVAAPI() {
}
mIsVAAPISupported = Some(false);
+ // mVAAPISupportedCodecs = CODEC_HW_H264;
+ // media::MCSInfo:mIsV4L2Supported:AddSupport(
+ // media::MediaCodecsSupport::H264HardwareDecode);
+
+ // mIsVAAPISupported = Some(true);
+ // return;
#ifdef MOZ_ENABLE_VAAPI
char* vaapiData = nullptr;
auto free = mozilla::MakeScopeExit([&] { g_free((void*)vaapiData); });
@@ -831,6 +839,25 @@ void GfxInfo::V4L2ProbeDevice(nsCString& dev) {
}
}
+void GfxInfo::GetDataESMPP() {
+ if (mIsESMPPSupported.isSome()) {
+ return;
+ }
+ mIsESMPPSupported = Some(true);
+
+
+ mVAAPISupportedCodecs = CODEC_HW_H264 | CODEC_HW_VP8 | CODEC_HW_VP9 | CODEC_HW_AV1;
+
+ media::MCSInfo::AddSupport(
+ media::MediaCodecsSupport::H264HardwareDecode);
+ media::MCSInfo::AddSupport(
+ media::MediaCodecsSupport::VP8HardwareDecode);
+ media::MCSInfo::AddSupport(
+ media::MediaCodecsSupport::VP9HardwareDecode);
+ media::MCSInfo::AddSupport(
+ media::MediaCodecsSupport::AV1HardwareDecode);
+}
+
const nsTArray<GfxDriverInfo>& GfxInfo::GetGfxDriverInfo() {
if (!sDriverInfo->Length()) {
// Mesa 10.0 provides the GLX_MESA_query_renderer extension, which allows us
@@ -1280,7 +1307,8 @@ nsresult GfxInfo::GetFeatureStatusImpl(
continue;
}
if ((mVAAPISupportedCodecs & pair.mCodec) ||
- (mV4L2SupportedCodecs & pair.mCodec)) {
+ (mV4L2SupportedCodecs & pair.mCodec) ||
+ (mESMPPSupportedCodecs & pair.mCodec)) {
*aStatus = nsIGfxInfo::FEATURE_STATUS_OK;
} else {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_PLATFORM_TEST;
@@ -1305,11 +1333,13 @@ nsresult GfxInfo::GetFeatureStatusImpl(
if (probeHWDecode) {
GetDataVAAPI();
GetDataV4L2();
+ GetDataESMPP();
} else {
mIsVAAPISupported = Some(false);
mIsV4L2Supported = Some(false);
+ mIsESMPPSupported = Some(false);
}
- if (!mIsVAAPISupported.value() && !mIsV4L2Supported.value()) {
+ if (!mIsVAAPISupported.value() && !mIsV4L2Supported.value() && !mIsESMPPSupported.value()) {
*aStatus = nsIGfxInfo::FEATURE_BLOCKED_PLATFORM_TEST;
aFailureId = "FEATURE_FAILURE_VIDEO_DECODING_TEST_FAILED";
}
diff --git a/widget/gtk/GfxInfo.h b/widget/gtk/GfxInfo.h
index 26b4554b4a..a72a1d09d7 100644
--- a/widget/gtk/GfxInfo.h
+++ b/widget/gtk/GfxInfo.h
@@ -121,12 +121,15 @@ class GfxInfo final : public GfxInfoBase {
int mVAAPISupportedCodecs = 0;
mozilla::Maybe<bool> mIsV4L2Supported;
int mV4L2SupportedCodecs = 0;
+ mozilla::Maybe<bool> mIsESMPPSupported;
+ int mESMPPSupportedCodecs = 0;
static int sGLXTestPipe;
static pid_t sGLXTestPID;
void GetDataVAAPI();
void GetDataV4L2();
+ void GetDataESMPP();
void V4L2ProbeDevice(nsCString& dev);
void AddCrashReportAnnotations();
};
--
2.43.0
From 3d3cc2155ecf6201e48391ed66fe4bb5fbc9adbf Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Sun, 4 May 2025 09:05:09 +0000
Subject: [PATCH 2/2] comment cs_border_solid and ps_text_run
---
gfx/wr/webrender/res/cs_border_solid.glsl | 177 +++++++++++-----------
gfx/wr/webrender/res/ps_text_run.glsl | 108 ++++++-------
2 files changed, 147 insertions(+), 138 deletions(-)
diff --git a/gfx/wr/webrender/res/cs_border_solid.glsl b/gfx/wr/webrender/res/cs_border_solid.glsl
index 460646e21b..baf9aea635 100644
--- a/gfx/wr/webrender/res/cs_border_solid.glsl
+++ b/gfx/wr/webrender/res/cs_border_solid.glsl
@@ -82,97 +82,100 @@ vec2 get_outer_corner_scale(int segment) {
}
void main(void) {
- int segment = aFlags & 0xff;
- bool do_aa = ((aFlags >> 24) & 0xf0) != 0;
-
- vec2 outer_scale = get_outer_corner_scale(segment);
- vec2 size = aRect.zw - aRect.xy;
- vec2 outer = outer_scale * size;
- vec2 clip_sign = 1.0 - 2.0 * outer_scale;
-
- int mix_colors;
- switch (segment) {
- case SEGMENT_TOP_LEFT:
- case SEGMENT_TOP_RIGHT:
- case SEGMENT_BOTTOM_RIGHT:
- case SEGMENT_BOTTOM_LEFT: {
- mix_colors = do_aa ? MIX_AA : MIX_NO_AA;
- break;
- }
- default:
- mix_colors = DONT_MIX;
- break;
- }
-
- vMixColors.x = mix_colors;
- vPos = size * aPosition.xy;
-
- vColor0 = aColor0;
- vColor1 = aColor1;
- vClipCenter_Sign = vec4(outer + clip_sign * aRadii, clip_sign);
- vClipRadii = vec4(aRadii, max(aRadii - aWidths, 0.0));
- vColorLine = vec4(outer, aWidths.y * -clip_sign.y, aWidths.x * clip_sign.x);
-
- vec2 horizontal_clip_sign = vec2(-clip_sign.x, clip_sign.y);
- vHorizontalClipCenter_Sign = vec4(aClipParams1.xy +
- horizontal_clip_sign * aClipParams1.zw,
- horizontal_clip_sign);
- vHorizontalClipRadii = aClipParams1.zw;
-
- vec2 vertical_clip_sign = vec2(clip_sign.x, -clip_sign.y);
- vVerticalClipCenter_Sign = vec4(aClipParams2.xy +
- vertical_clip_sign * aClipParams2.zw,
- vertical_clip_sign);
- vVerticalClipRadii = aClipParams2.zw;
-
- gl_Position = uTransform * vec4(aTaskOrigin + aRect.xy + vPos, 0.0, 1.0);
+ // int segment = aFlags & 0xff;
+ // bool do_aa = ((aFlags >> 24) & 0xf0) != 0;
+
+ // vec2 outer_scale = get_outer_corner_scale(segment);
+ // vec2 size = aRect.zw - aRect.xy;
+ // vec2 outer = outer_scale * size;
+ // vec2 clip_sign = 1.0 - 2.0 * outer_scale;
+
+ // int mix_colors;
+ // switch (segment) {
+ // case SEGMENT_TOP_LEFT:
+ // case SEGMENT_TOP_RIGHT:
+ // case SEGMENT_BOTTOM_RIGHT:
+ // case SEGMENT_BOTTOM_LEFT: {
+ // mix_colors = do_aa ? MIX_AA : MIX_NO_AA;
+ // break;
+ // }
+ // default:
+ // mix_colors = DONT_MIX;
+ // break;
+ // }
+
+ // vMixColors.x = mix_colors;
+ // vPos = size * aPosition.xy;
+
+ // vColor0 = aColor0;
+ // vColor1 = aColor1;
+ // vClipCenter_Sign = vec4(outer + clip_sign * aRadii, clip_sign);
+ // vClipRadii = vec4(aRadii, max(aRadii - aWidths, 0.0));
+ // vColorLine = vec4(outer, aWidths.y * -clip_sign.y, aWidths.x * clip_sign.x);
+
+ // vec2 horizontal_clip_sign = vec2(-clip_sign.x, clip_sign.y);
+ // vHorizontalClipCenter_Sign = vec4(aClipParams1.xy +
+ // horizontal_clip_sign * aClipParams1.zw,
+ // horizontal_clip_sign);
+ // vHorizontalClipRadii = aClipParams1.zw;
+
+ // vec2 vertical_clip_sign = vec2(clip_sign.x, -clip_sign.y);
+ // vVerticalClipCenter_Sign = vec4(aClipParams2.xy +
+ // vertical_clip_sign * aClipParams2.zw,
+ // vertical_clip_sign);
+ // vVerticalClipRadii = aClipParams2.zw;
+
+ // gl_Position = uTransform * vec4(aTaskOrigin + aRect.xy + vPos, 0.0, 1.0);
+
+ gl_Position = vec4(0.0);
}
#endif
#ifdef WR_FRAGMENT_SHADER
void main(void) {
- float aa_range = compute_aa_range(vPos);
- bool do_aa = vMixColors.x != MIX_NO_AA;
-
- float mix_factor = 0.0;
- if (vMixColors.x != DONT_MIX) {
- float d_line = distance_to_line(vColorLine.xy, vColorLine.zw, vPos);
- if (do_aa) {
- mix_factor = distance_aa(aa_range, -d_line);
- } else {
- mix_factor = d_line + EPSILON >= 0. ? 1.0 : 0.0;
- }
- }
-
- // Check if inside main corner clip-region
- vec2 clip_relative_pos = vPos - vClipCenter_Sign.xy;
- bool in_clip_region = all(lessThan(vClipCenter_Sign.zw * clip_relative_pos, vec2(0.0)));
-
- float d = -1.0;
- if (in_clip_region) {
- float d_radii_a = distance_to_ellipse(clip_relative_pos, vClipRadii.xy);
- float d_radii_b = distance_to_ellipse(clip_relative_pos, vClipRadii.zw);
- d = max(d_radii_a, -d_radii_b);
- }
-
- // And again for horizontally-adjacent corner
- clip_relative_pos = vPos - vHorizontalClipCenter_Sign.xy;
- in_clip_region = all(lessThan(vHorizontalClipCenter_Sign.zw * clip_relative_pos, vec2(0.0)));
- if (in_clip_region) {
- float d_radii = distance_to_ellipse(clip_relative_pos, vHorizontalClipRadii.xy);
- d = max(d_radii, d);
- }
-
- // And finally for vertically-adjacent corner
- clip_relative_pos = vPos - vVerticalClipCenter_Sign.xy;
- in_clip_region = all(lessThan(vVerticalClipCenter_Sign.zw * clip_relative_pos, vec2(0.0)));
- if (in_clip_region) {
- float d_radii = distance_to_ellipse(clip_relative_pos, vVerticalClipRadii.xy);
- d = max(d_radii, d);
- }
-
- float alpha = do_aa ? distance_aa(aa_range, d) : 1.0;
- vec4 color = mix(vColor0, vColor1, mix_factor);
- oFragColor = color * alpha;
+ // float aa_range = compute_aa_range(vPos);
+ // bool do_aa = vMixColors.x != MIX_NO_AA;
+
+ // float mix_factor = 0.0;
+ // if (vMixColors.x != DONT_MIX) {
+ // float d_line = distance_to_line(vColorLine.xy, vColorLine.zw, vPos);
+ // if (do_aa) {
+ // mix_factor = distance_aa(aa_range, -d_line);
+ // } else {
+ // mix_factor = d_line + EPSILON >= 0. ? 1.0 : 0.0;
+ // }
+ // }
+
+ // // Check if inside main corner clip-region
+ // vec2 clip_relative_pos = vPos - vClipCenter_Sign.xy;
+ // bool in_clip_region = all(lessThan(vClipCenter_Sign.zw * clip_relative_pos, vec2(0.0)));
+
+ // float d = -1.0;
+ // if (in_clip_region) {
+ // float d_radii_a = distance_to_ellipse(clip_relative_pos, vClipRadii.xy);
+ // float d_radii_b = distance_to_ellipse(clip_relative_pos, vClipRadii.zw);
+ // d = max(d_radii_a, -d_radii_b);
+ // }
+
+ // // And again for horizontally-adjacent corner
+ // clip_relative_pos = vPos - vHorizontalClipCenter_Sign.xy;
+ // in_clip_region = all(lessThan(vHorizontalClipCenter_Sign.zw * clip_relative_pos, vec2(0.0)));
+ // if (in_clip_region) {
+ // float d_radii = distance_to_ellipse(clip_relative_pos, vHorizontalClipRadii.xy);
+ // d = max(d_radii, d);
+ // }
+
+ // // And finally for vertically-adjacent corner
+ // clip_relative_pos = vPos - vVerticalClipCenter_Sign.xy;
+ // in_clip_region = all(lessThan(vVerticalClipCenter_Sign.zw * clip_relative_pos, vec2(0.0)));
+ // if (in_clip_region) {
+ // float d_radii = distance_to_ellipse(clip_relative_pos, vVerticalClipRadii.xy);
+ // d = max(d_radii, d);
+ // }
+
+ // float alpha = do_aa ? distance_aa(aa_range, d) : 1.0;
+ // vec4 color = mix(vColor0, vColor1, mix_factor);
+ // oFragColor = color * alpha;
+ oFragColor = vec4(0.0);
}
#endif
diff --git a/gfx/wr/webrender/res/ps_text_run.glsl b/gfx/wr/webrender/res/ps_text_run.glsl
index 9faac99620..712b3c823f 100644
--- a/gfx/wr/webrender/res/ps_text_run.glsl
+++ b/gfx/wr/webrender/res/ps_text_run.glsl
@@ -96,6 +96,7 @@ vec2 get_snap_bias(int subpx_dir) {
}
void main() {
+/*
Instance instance = decode_instance_attributes();
PrimitiveHeader ph = fetch_prim_header(instance.prim_header_address);
Transform transform = fetch_transform(ph.transform_id);
@@ -269,72 +270,77 @@ void main() {
v_uv = mix(st0, st1, f);
v_uv_bounds = (res.uv_rect + vec4(0.5, 0.5, -0.5, -0.5)) / texture_size.xyxy;
+*/
+ v_uv = vec2(0.0);
+ v_uv_bounds = vec4(0.0);
+ v_color = vec4(1.0);
}
#endif // WR_VERTEX_SHADER
#ifdef WR_FRAGMENT_SHADER
-Fragment text_fs(void) {
- Fragment frag;
+// Fragment text_fs(void) {
+// Fragment frag;
- vec2 tc = clamp(v_uv, v_uv_bounds.xy, v_uv_bounds.zw);
- vec4 mask = texture(sColor0, tc);
- // v_mask_swizzle.z != 0 means we are using an R8 texture as alpha,
- // and therefore must swizzle from the r channel to all channels.
- mask = mix(mask, mask.rrrr, bvec4(v_mask_swizzle.z != 0.0));
- #ifndef WR_FEATURE_DUAL_SOURCE_BLENDING
- mask.rgb = mask.rgb * v_mask_swizzle.x + mask.aaa * v_mask_swizzle.y;
- #endif
+// vec2 tc = clamp(v_uv, v_uv_bounds.xy, v_uv_bounds.zw);
+// vec4 mask = texture(sColor0, tc);
+// // v_mask_swizzle.z != 0 means we are using an R8 texture as alpha,
+// // and therefore must swizzle from the r channel to all channels.
+// mask = mix(mask, mask.rrrr, bvec4(v_mask_swizzle.z != 0.0));
+// #ifndef WR_FEATURE_DUAL_SOURCE_BLENDING
+// mask.rgb = mask.rgb * v_mask_swizzle.x + mask.aaa * v_mask_swizzle.y;
+// #endif
- #if defined(WR_FEATURE_GLYPH_TRANSFORM) && !defined(SWGL_CLIP_DIST)
- mask *= float(all(greaterThanEqual(v_uv_clip, vec4(0.0))));
- #endif
+// #if defined(WR_FEATURE_GLYPH_TRANSFORM) && !defined(SWGL_CLIP_DIST)
+// mask *= float(all(greaterThanEqual(v_uv_clip, vec4(0.0))));
+// #endif
- frag.color = v_color * mask;
+// frag.color = v_color * mask;
- #if defined(WR_FEATURE_DUAL_SOURCE_BLENDING) && !defined(SWGL_BLEND)
- frag.blend = mask * v_mask_swizzle.x + mask.aaaa * v_mask_swizzle.y;
- #endif
+// #if defined(WR_FEATURE_DUAL_SOURCE_BLENDING) && !defined(SWGL_BLEND)
+// frag.blend = mask * v_mask_swizzle.x + mask.aaaa * v_mask_swizzle.y;
+// #endif
- return frag;
-}
+// return frag;
+// }
void main() {
- Fragment frag = text_fs();
-
- float clip_mask = do_clip();
- frag.color *= clip_mask;
-
- #if defined(WR_FEATURE_DEBUG_OVERDRAW)
- oFragColor = WR_DEBUG_OVERDRAW_COLOR;
- #elif defined(WR_FEATURE_DUAL_SOURCE_BLENDING) && !defined(SWGL_BLEND)
- oFragColor = frag.color;
- oFragBlend = frag.blend * clip_mask;
- #else
- write_output(frag.color);
- #endif
+ // Fragment frag = text_fs();
+
+ // float clip_mask = do_clip();
+ // frag.color *= clip_mask;
+
+ // #if defined(WR_FEATURE_DEBUG_OVERDRAW)
+ // oFragColor = WR_DEBUG_OVERDRAW_COLOR;
+ // #elif defined(WR_FEATURE_DUAL_SOURCE_BLENDING) && !defined(SWGL_BLEND)
+ // oFragColor = frag.color;
+ // oFragBlend = frag.blend * clip_mask;
+ // #else
+ // write_output(frag.color);
+ // #endif
+ oFragColor = vec4(0.0);
}
-#if defined(SWGL_DRAW_SPAN) && defined(SWGL_BLEND) && defined(SWGL_CLIP_DIST)
-void swgl_drawSpanRGBA8() {
- // Only support simple swizzles for now. More complex swizzles must either
- // be handled by blend overrides or the slow path.
- if (v_mask_swizzle.x != 0.0 && v_mask_swizzle.x != 1.0) {
- return;
- }
-
- #ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
- swgl_commitTextureLinearRGBA8(sColor0, v_uv, v_uv_bounds);
- #else
- if (swgl_isTextureR8(sColor0)) {
- swgl_commitTextureLinearColorR8ToRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
- } else {
- swgl_commitTextureLinearColorRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
- }
- #endif
-}
-#endif
+// #if defined(SWGL_DRAW_SPAN) && defined(SWGL_BLEND) && defined(SWGL_CLIP_DIST)
+// void swgl_drawSpanRGBA8() {
+// // Only support simple swizzles for now. More complex swizzles must either
+// // be handled by blend overrides or the slow path.
+// if (v_mask_swizzle.x != 0.0 && v_mask_swizzle.x != 1.0) {
+// return;
+// }
+
+// #ifdef WR_FEATURE_DUAL_SOURCE_BLENDING
+// swgl_commitTextureLinearRGBA8(sColor0, v_uv, v_uv_bounds);
+// #else
+// if (swgl_isTextureR8(sColor0)) {
+// swgl_commitTextureLinearColorR8ToRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
+// } else {
+// swgl_commitTextureLinearColorRGBA8(sColor0, v_uv, v_uv_bounds, v_color);
+// }
+// #endif
+// }
+// #endif
#endif // WR_FRAGMENT_SHADER
--
2.43.0
From 653e93d41f8fda27eb34d44db45073a7c4ae0faa Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: Tue, 6 May 2025 03:20:08 +0000
Subject: [PATCH] limit framepool to 2
---
dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
index 06d4ccc3cd..e21356c8d1 100644
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -1743,7 +1743,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImageEsmpp(
MOZ_ASSERT(mTaskQueue->IsOnCurrentThread());
if (!mVideoFramePool) {
- mVideoFramePool = MakeUnique<VideoFramePool<LIBAV_VER>>(20);
+ mVideoFramePool = MakeUnique<VideoFramePool<LIBAV_VER>>(2);
}
auto surface = mVideoFramePool->GetVideoFrameSurface(
--
2.43.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment