Skip to content

Commit

Permalink
Gxm: fix video mirror filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Feb 15, 2025
1 parent 65a4de0 commit 5487bd0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
8 changes: 7 additions & 1 deletion wiliwili/include/view/mpv_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ class MPVCore : public brls::Singleton<MPVCore> {

int getHue() const;

/**
* 设置硬解码模式
* @param value 为真时将硬解码设置为 auto-copy, 为假时将硬解码设置为 各个平台默认值
*/
void setHwdecCopyMode(bool value);

/**
* 禁用系统锁屏
*/
Expand Down Expand Up @@ -358,7 +364,7 @@ class MPVCore : public brls::Singleton<MPVCore> {
inline static bool HARDWARE_DEC = false;

// 硬解方式
#ifdef __SWITCH__
#if defined(__SWITCH__) || defined(BOREALIS_USE_GXM)
inline static std::string PLAYER_HWDEC_METHOD = "auto";
#elif defined(__PSV__)
inline static std::string PLAYER_HWDEC_METHOD = "vita-copy";
Expand Down
15 changes: 2 additions & 13 deletions wiliwili/source/fragment/player_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,8 @@ void PlayerSetting::setupCustomShaders() {
}

#ifdef BOREALIS_USE_D3D11
// 如果正在使用硬解,那么将硬解更新为 auto-copy,避免直接硬解因为不经过 cpu 处理导致滤镜无效
if (MPVCore::HARDWARE_DEC) {
std::string hwdec = value ? "auto-copy" : MPVCore::PLAYER_HWDEC_METHOD;
MPVCore::instance().command_async("set", "hwdec", hwdec);
brls::Logger::info("MPV hardware decode: {}", hwdec);
}
// D3D11 下硬解需要开启 copy 模式,才能正常使用着色器
MPVCore::instance().setHwdecCopyMode(value);
#endif

GA("player_setting", {{"shader", cell->title->getFullText()}});
Expand Down Expand Up @@ -194,13 +190,6 @@ void PlayerSetting::setupCommonSetting() {
btnMirror->init("wiliwili/player/setting/common/mirror"_i18n, MPVCore::VIDEO_MIRROR, [](bool value) {
MPVCore::instance().setMirror(!MPVCore::VIDEO_MIRROR);
GA("player_setting", {{"mirror", value ? "true" : "false"}});

// 如果正在使用硬解,那么将硬解更新为 auto-copy,避免直接硬解因为不经过 cpu 处理导致镜像翻转无效
if (MPVCore::HARDWARE_DEC) {
std::string hwdec = MPVCore::VIDEO_MIRROR ? "auto-copy" : MPVCore::PLAYER_HWDEC_METHOD;
MPVCore::instance().command_async("set", "hwdec", hwdec);
brls::Logger::info("MPV hardware decode: {}", hwdec);
}
});

/// Player aspect
Expand Down
20 changes: 20 additions & 0 deletions wiliwili/source/view/mpv_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,12 +794,20 @@ void MPVCore::draw(brls::Rect area, float alpha) {
#elif defined(BOREALIS_USE_GXM)
auto *vg = brls::Application::getNVGContext();

if (MPVCore::VIDEO_MIRROR) {
nvgSave(vg);
nvgTranslate(vg, area.getWidth() + area.getMinX() * 2, 0);
nvgScale(vg, -1, 1);
}
NVGpaint img = nvgImagePattern(vg, 0, 0, brls::Application::contentWidth, brls::Application::contentHeight, 0,
nvg_image, alpha);
nvgBeginPath(vg);
nvgRect(vg, area.getMinX(), area.getMinY(), area.getWidth(), area.getHeight());
nvgFillPaint(vg, img);
nvgFill(vg);
if (MPVCore::VIDEO_MIRROR) {
nvgRestore(vg);
}
#elif defined(MPV_NO_FB) || defined(BOREALIS_USE_DEKO3D) || defined(BOREALIS_USE_D3D11)
// 只在非透明时绘制视频,可以避免退出页面时视频画面残留
if (alpha >= 1) {
Expand Down Expand Up @@ -1219,7 +1227,19 @@ void MPVCore::setAspect(const std::string &value) {

void MPVCore::setMirror(bool value) {
MPVCore::VIDEO_MIRROR = value;
#ifndef BOREALIS_USE_GXM
command_async("set", "vf", value ? "hflip" : "");
setHwdecCopyMode(value);
#endif
}

void MPVCore::setHwdecCopyMode(bool value) {
// 如果正在使用硬解,那么将硬解更新为 auto-copy,避免直接硬解因为不经过 cpu 处理导致镜像翻转、滤镜无效
if (MPVCore::HARDWARE_DEC) {
std::string hwdec = value ? "auto-copy" : MPVCore::PLAYER_HWDEC_METHOD;
command_async("set", "hwdec", hwdec);
brls::Logger::info("MPV hardware decode: {}", hwdec);
}
}

void MPVCore::setBrightness(int value) {
Expand Down

0 comments on commit 5487bd0

Please sign in to comment.