Skip to content

Commit

Permalink
Add commandline arg for debug
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonflylee committed Dec 1, 2023
1 parent b912783 commit 887e2c6
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 43 deletions.
2 changes: 1 addition & 1 deletion library/borealis
Submodule borealis updated 27 files
+10 −2 demo/main.cpp
+7 −4 library/CMakeLists.txt
+1 −0 library/cmake/commonOption.cmake
+6 −1 library/cmake/toolchain.cmake
+12 −16 library/include/borealis/core/logger.hpp
+2 −0 library/include/borealis/extern/nanovg/nanovg.h
+1,566 −0 library/include/borealis/extern/nanovg/nanovg_d3d11.h
+630 −0 library/include/borealis/extern/nanovg/nvg_shader/D3D11PixelShader.h
+107 −0 library/include/borealis/extern/nanovg/nvg_shader/D3D11PixelShader.hlsl
+688 −0 library/include/borealis/extern/nanovg/nvg_shader/D3D11PixelShaderAA.h
+2 −0 library/include/borealis/extern/nanovg/nvg_shader/D3D11PixelShaderAA.hlsl
+2 −0 library/include/borealis/extern/nanovg/nvg_shader/D3D11PixelShaderNoAA.hlsl
+242 −0 library/include/borealis/extern/nanovg/nvg_shader/D3D11VertexShader.h
+25 −0 library/include/borealis/extern/nanovg/nvg_shader/D3D11VertexShader.hlsl
+6 −0 library/include/borealis/extern/nanovg/nvg_shader/d3d_shaders.bat
+11 −0 library/include/borealis/extern/nanovg/nvg_shader/d3d_shaders.ps1
+48 −45 library/include/borealis/platforms/driver/d3d11.hpp
+0 −7 library/include/borealis/platforms/driver/winrt.hpp
+1 −1 library/lib/core/application.cpp
+5 −0 library/lib/core/logger.cpp
+12 −0 library/lib/platforms/desktop/desktop_winrt.cpp
+251 −277 library/lib/platforms/driver/d3d11.cpp
+0 −26 library/lib/platforms/driver/winrt.cpp
+26 −35 library/lib/platforms/glfw/glfw_video.cpp
+24 −23 library/lib/platforms/sdl/sdl_video.cpp
+7 −10 library/lib/views/debug_layer.cpp
+0 −1 xmake.lua
58 changes: 35 additions & 23 deletions wiliwili/include/view/mpv_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#if defined(MPV_SW_RENDER)
#elif defined(BOREALIS_USE_DEKO3D)
#include <mpv/render_dk3d.h>
#else
#elif defined(BOREALIS_USE_OPENGL)
#include <mpv/render_gl.h>
#if defined(__PSV__) || defined(PS4)
#include <GLES2/gl2.h>
Expand All @@ -25,14 +25,17 @@
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#endif
#include <nanovg_gl.h>
#if !defined(MPV_NO_FB) && !defined(MPV_SW_RENDER) && !defined(USE_GL2)
// 将视频绘制到独立的 framebuffer
#define MPV_USE_FB
struct GLShader {
GLuint prog;
GLuint vao;
GLuint vbo;
GLuint ebo;
};
#endif
#endif

typedef enum MpvEventEnum {
MPV_LOADED,
Expand Down Expand Up @@ -242,6 +245,9 @@ class MPVCore : public brls::Singleton<MPVCore> {
// 视频缓存(是否使用内存缓存视频,值为缓存的大小,单位MB)
inline static int INMEMORY_CACHE = 0;

// 开启 Terminal 日志
inline static bool TERMINAL = false;

// 硬件解码
inline static bool HARDWARE_DEC = false;
inline static std::string PLAYER_HWDEC_METHOD = "auto-safe";
Expand Down Expand Up @@ -275,36 +281,42 @@ class MPVCore : public brls::Singleton<MPVCore> {
{MPV_RENDER_PARAM_SW_FORMAT, (void *)sw_format},
{MPV_RENDER_PARAM_SW_STRIDE, &pitch},
{MPV_RENDER_PARAM_SW_POINTER, pixels},
{ MPV_RENDER_PARAM_INVALID,
nullptr }};
{MPV_RENDER_PARAM_INVALID, nullptr},
};
#elif defined(BOREALIS_USE_DEKO3D)
DkFence doneFence;
DkFence readyFence;
mpv_deko3d_fbo mpv_fbo{nullptr, &readyFence, &doneFence,
1280, 720, DkImageFormat_RGBA8_Unorm};
mpv_render_param mpv_params[3] = {{MPV_RENDER_PARAM_DEKO3D_FBO, &mpv_fbo},
{ MPV_RENDER_PARAM_INVALID,
nullptr }};
#elif defined(MPV_NO_FB)
mpv_opengl_fbo mpv_fbo{0, 1920, 1080};
int flip_y{1};
mpv_render_param mpv_params[3] = {{MPV_RENDER_PARAM_OPENGL_FBO, &mpv_fbo},
{MPV_RENDER_PARAM_FLIP_Y, &flip_y},
{ MPV_RENDER_PARAM_INVALID,
nullptr }};
#else
mpv_deko3d_fbo mpv_fbo{
nullptr, &readyFence, &doneFence, 1280, 720, DkImageFormat_RGBA8_Unorm,
};
mpv_render_param mpv_params[3] = {
{MPV_RENDER_PARAM_DEKO3D_FBO, &mpv_fbo},
{MPV_RENDER_PARAM_INVALID, nullptr},
};
#elif defined(MPV_USE_FB)
GLuint media_framebuffer = 0;
GLuint media_texture = 0;
GLShader shader{0};
mpv_opengl_fbo mpv_fbo{0, 1920, 1080};
int flip_y{1};
bool redraw = false;
mpv_render_param mpv_params[3] = {{MPV_RENDER_PARAM_OPENGL_FBO, &mpv_fbo},
{MPV_RENDER_PARAM_FLIP_Y, &flip_y},
{MPV_RENDER_PARAM_INVALID, nullptr}};
float vertices[20] = {1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f,
0.0f, 1.0f, 0.0f, -1.0f, -1.0f, 0.0f, 0.0f,
0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f};
mpv_render_param mpv_params[3] = {
{MPV_RENDER_PARAM_OPENGL_FBO, &mpv_fbo},
{MPV_RENDER_PARAM_FLIP_Y, &flip_y},
{MPV_RENDER_PARAM_INVALID, nullptr},
};
float vertices[20] = {
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
};
#else
mpv_opengl_fbo mpv_fbo{0, 1920, 1080};
int flip_y{1};
mpv_render_param mpv_params[3] = {
{MPV_RENDER_PARAM_OPENGL_FBO, &mpv_fbo},
{MPV_RENDER_PARAM_FLIP_Y, &flip_y},
{MPV_RENDER_PARAM_INVALID, nullptr},
};
#endif

// MPV 内部事件,传递内容为: 事件类型
Expand Down
15 changes: 13 additions & 2 deletions wiliwili/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,25 @@

#include "utils/config_helper.hpp"
#include "utils/activity_helper.hpp"
#include "view/mpv_core.hpp"

#ifdef IOS
#include <SDL2/SDL_main.h>
#endif

int main(int argc, char* argv[]) {
// Set log level
brls::Logger::setLogLevel(brls::LogLevel::LOG_INFO);
for (int i = 1; i < argc; i++) {
if (std::strcmp(argv[i], "-d") == 0) {
brls::Logger::setLogLevel(brls::LogLevel::LOG_DEBUG);
} else if (std::strcmp(argv[i], "-v") == 0) {
brls::Application::enableDebuggingView(true);
} else if (std::strcmp(argv[i], "-t") == 0) {
MPVCore::TERMINAL = true;
} else if (std::strcmp(argv[i], "-o") == 0) {
const char* path = (i + 1 < argc) ? argv[++i] : "wiliwili.log";
brls::Logger::setLogOutput(std::fopen(path, "w+"));
}
}

// Load cookies and settings
ProgramConfig::instance().init();
Expand Down
28 changes: 11 additions & 17 deletions wiliwili/source/view/mpv_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
#include "utils/config_helper.hpp"
#include "utils/number_helper.hpp"

#if !defined(MPV_NO_FB) && !defined(MPV_SW_RENDER) && \
!defined(BOREALIS_USE_DEKO3D)
#ifdef MPV_USE_FB
const char *vertexShaderSource =
"#version 150 core\n"
"in vec3 aPos;\n"
Expand Down Expand Up @@ -60,7 +59,7 @@ void MPVCore::on_update(void *self) {
brls::sync([]() {
uint64_t flags =
mpv_render_context_update(MPVCore::instance().getContext());
#if defined(MPV_NO_FB) || defined(BOREALIS_USE_DEKO3D)
#if defined(MPV_NO_FB) || defined(BOREALIS_USE_DEKO3D) || defined(USE_GL2)
(void)flags;
#else
MPVCore::instance().redraw = flags & MPV_RENDER_UPDATE_FRAME;
Expand Down Expand Up @@ -113,7 +112,6 @@ void MPVCore::init() {
mpv_set_option_string(mpv, "config-dir",
ProgramConfig::instance().getConfigDir().c_str());
mpv_set_option_string(mpv, "ytdl", "no");
mpv_set_option_string(mpv, "terminal", "yes");
mpv_set_option_string(mpv, "audio-channels", "stereo");
mpv_set_option_string(mpv, "idle", "yes");
mpv_set_option_string(mpv, "loop-file", "no");
Expand Down Expand Up @@ -180,10 +178,12 @@ void MPVCore::init() {
// log
// mpv_set_option_string(mpv, "msg-level", "ffmpeg=trace");
// mpv_set_option_string(mpv, "msg-level", "all=no");

if (MPVCore::TERMINAL) {
mpv_set_option_string(mpv, "terminal", "yes");
#ifdef _DEBUG
mpv_set_option_string(mpv, "msg-level", "all=v");
mpv_set_option_string(mpv, "msg-level", "all=v");
#endif
}

if (mpv_initialize(mpv) < 0) {
mpv_terminate_destroy(mpv);
Expand Down Expand Up @@ -322,9 +322,7 @@ void MPVCore::restart() {
}

void MPVCore::deleteFrameBuffer() {
#if defined(MPV_NO_FB) || defined(MPV_SW_RENDER)
#elif defined(BOREALIS_USE_DEKO3D)
#else
#ifdef MPV_USE_FB
if (this->media_framebuffer != 0) {
glDeleteFramebuffers(1, &this->media_framebuffer);
this->media_framebuffer = 0;
Expand All @@ -337,9 +335,7 @@ void MPVCore::deleteFrameBuffer() {
}

void MPVCore::deleteShader() {
#if defined(MPV_NO_FB) || defined(MPV_SW_RENDER)
#elif defined(BOREALIS_USE_DEKO3D)
#else
#ifdef MPV_USE_FB
if (shader.vao != 0) glDeleteVertexArrays(1, &shader.vao);
if (shader.vbo != 0) glDeleteBuffers(1, &shader.vbo);
if (shader.ebo != 0) glDeleteBuffers(1, &shader.ebo);
Expand All @@ -352,9 +348,7 @@ void MPVCore::initializeGL() {
#if defined(IOS)
mpv_fbo.fbo = 1;
#endif
#elif defined(MPV_SW_RENDER)
#elif defined(BOREALIS_USE_DEKO3D)
#else
#elif defined(MPV_USE_FB)
if (media_framebuffer != 0) return;
brls::Logger::debug("initializeGL");

Expand Down Expand Up @@ -499,7 +493,7 @@ void MPVCore::setFrameSize(brls::Rect r) {
// 在视频暂停时调整纹理尺寸,视频画面会被清空为黑色,强制重新绘制一次,避免这个问题
mpv_render_context_render(mpv_context, mpv_params);
mpv_render_context_report_swap(mpv_context);
#elif defined(MPV_NO_FB) || defined(BOREALIS_USE_DEKO3D)
#elif !defined(MPV_USE_FB)
// Using default framebuffer
this->mpv_fbo.w = brls::Application::windowWidth;
this->mpv_fbo.h = brls::Application::windowHeight;
Expand Down Expand Up @@ -579,7 +573,7 @@ void MPVCore::draw(brls::Rect area, float alpha) {
nvgFillPaint(vg, nvgImagePattern(vg, 0, 0, rect.getWidth(),
rect.getHeight(), 0, nvg_image, alpha));
nvgFill(vg);
#elif defined(MPV_NO_FB) || defined(BOREALIS_USE_DEKO3D)
#elif !defined(MPV_USE_FB)
// 只在非透明时绘制视频,可以避免退出页面时视频画面残留
if (alpha >= 1) {
#ifdef BOREALIS_USE_DEKO3D
Expand Down

0 comments on commit 887e2c6

Please sign in to comment.