mirror of
https://github.com/moonlight-stream/moonlight-qt
synced 2024-11-10 13:44:17 +00:00
OverlayManager now manages font size for the overlays
This commit is contained in:
parent
d5f7b20be3
commit
f83853c2fb
5 changed files with 57 additions and 49 deletions
|
@ -27,7 +27,7 @@ DXVA2Renderer::DXVA2Renderer() :
|
||||||
m_ProcService(nullptr),
|
m_ProcService(nullptr),
|
||||||
m_Processor(nullptr),
|
m_Processor(nullptr),
|
||||||
m_FrameIndex(0),
|
m_FrameIndex(0),
|
||||||
m_OverlayFont(nullptr),
|
m_DebugOverlayFont(nullptr),
|
||||||
m_BlockingPresent(false)
|
m_BlockingPresent(false)
|
||||||
{
|
{
|
||||||
RtlZeroMemory(m_DecSurfaces, sizeof(m_DecSurfaces));
|
RtlZeroMemory(m_DecSurfaces, sizeof(m_DecSurfaces));
|
||||||
|
@ -47,7 +47,7 @@ DXVA2Renderer::~DXVA2Renderer()
|
||||||
SAFE_COM_RELEASE(m_RenderTarget);
|
SAFE_COM_RELEASE(m_RenderTarget);
|
||||||
SAFE_COM_RELEASE(m_ProcService);
|
SAFE_COM_RELEASE(m_ProcService);
|
||||||
SAFE_COM_RELEASE(m_Processor);
|
SAFE_COM_RELEASE(m_Processor);
|
||||||
SAFE_COM_RELEASE(m_OverlayFont);
|
SAFE_COM_RELEASE(m_DebugOverlayFont);
|
||||||
|
|
||||||
for (int i = 0; i < ARRAYSIZE(m_DecSurfaces); i++) {
|
for (int i = 0; i < ARRAYSIZE(m_DecSurfaces); i++) {
|
||||||
SAFE_COM_RELEASE(m_DecSurfaces[i]);
|
SAFE_COM_RELEASE(m_DecSurfaces[i]);
|
||||||
|
@ -324,32 +324,6 @@ bool DXVA2Renderer::initializeRenderer()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DXVA2Renderer::initializeOverlay()
|
|
||||||
{
|
|
||||||
HRESULT hr;
|
|
||||||
|
|
||||||
hr = D3DXCreateFontA(m_Device,
|
|
||||||
20,
|
|
||||||
0,
|
|
||||||
FW_HEAVY,
|
|
||||||
1,
|
|
||||||
false,
|
|
||||||
ANSI_CHARSET,
|
|
||||||
OUT_DEFAULT_PRECIS,
|
|
||||||
DEFAULT_QUALITY,
|
|
||||||
DEFAULT_PITCH | FF_DONTCARE,
|
|
||||||
"",
|
|
||||||
&m_OverlayFont);
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"D3DXCreateFontA() failed: %x",
|
|
||||||
hr);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DXVA2Renderer::isDXVideoProcessorAPIBlacklisted()
|
bool DXVA2Renderer::isDXVideoProcessorAPIBlacklisted()
|
||||||
{
|
{
|
||||||
IDirect3D9* d3d9;
|
IDirect3D9* d3d9;
|
||||||
|
@ -706,9 +680,6 @@ bool DXVA2Renderer::initialize(SDL_Window* window, int videoFormat, int width, i
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// It's okay if this fails
|
|
||||||
initializeOverlay();
|
|
||||||
|
|
||||||
// For some reason, using Direct3D9Ex breaks this with multi-monitor setups.
|
// For some reason, using Direct3D9Ex breaks this with multi-monitor setups.
|
||||||
// When focus is lost, the window is minimized then immediately restored without
|
// When focus is lost, the window is minimized then immediately restored without
|
||||||
// input focus. This glitches out the renderer and a bunch of other stuff.
|
// input focus. This glitches out the renderer and a bunch of other stuff.
|
||||||
|
@ -736,6 +707,33 @@ IFFmpegRenderer::FramePacingConstraint DXVA2Renderer::getFramePacingConstraint()
|
||||||
return PACING_ANY;
|
return PACING_ANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DXVA2Renderer::notifyOverlayUpdated(Overlay::OverlayType)
|
||||||
|
{
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
// Initialize the overlay font if it's not already created
|
||||||
|
if (m_DebugOverlayFont == nullptr) {
|
||||||
|
hr = D3DXCreateFontA(m_Device,
|
||||||
|
Session::get()->getOverlayManager().getOverlayFontSize(Overlay::OverlayDebug),
|
||||||
|
0,
|
||||||
|
FW_HEAVY,
|
||||||
|
1,
|
||||||
|
false,
|
||||||
|
ANSI_CHARSET,
|
||||||
|
OUT_DEFAULT_PRECIS,
|
||||||
|
DEFAULT_QUALITY,
|
||||||
|
DEFAULT_PITCH | FF_DONTCARE,
|
||||||
|
"",
|
||||||
|
&m_DebugOverlayFont);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"D3DXCreateFontA() failed: %x",
|
||||||
|
hr);
|
||||||
|
m_DebugOverlayFont = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DXVA2Renderer::renderFrameAtVsync(AVFrame *frame)
|
void DXVA2Renderer::renderFrameAtVsync(AVFrame *frame)
|
||||||
{
|
{
|
||||||
IDirect3DSurface9* surface = reinterpret_cast<IDirect3DSurface9*>(frame->data[3]);
|
IDirect3DSurface9* surface = reinterpret_cast<IDirect3DSurface9*>(frame->data[3]);
|
||||||
|
@ -919,15 +917,15 @@ void DXVA2Renderer::renderFrameAtVsync(AVFrame *frame)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_OverlayFont != nullptr) {
|
if (m_DebugOverlayFont != nullptr) {
|
||||||
if (Session::get()->getOverlayManager().isOverlayEnabled(Overlay::OverlayDebug)) {
|
if (Session::get()->getOverlayManager().isOverlayEnabled(Overlay::OverlayDebug)) {
|
||||||
SDL_Color color = Session::get()->getOverlayManager().getOverlayColor(Overlay::OverlayDebug);
|
SDL_Color color = Session::get()->getOverlayManager().getOverlayColor(Overlay::OverlayDebug);
|
||||||
m_OverlayFont->DrawTextA(nullptr,
|
m_DebugOverlayFont->DrawTextA(nullptr,
|
||||||
Session::get()->getOverlayManager().getOverlayText(Overlay::OverlayDebug),
|
Session::get()->getOverlayManager().getOverlayText(Overlay::OverlayDebug),
|
||||||
-1,
|
-1,
|
||||||
&sample.DstRect,
|
&sample.DstRect,
|
||||||
DT_LEFT | DT_NOCLIP,
|
DT_LEFT | DT_NOCLIP,
|
||||||
D3DCOLOR_ARGB(color.a, color.r, color.g, color.b));
|
D3DCOLOR_ARGB(color.a, color.r, color.g, color.b));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,12 +27,12 @@ public:
|
||||||
virtual bool needsTestFrame();
|
virtual bool needsTestFrame();
|
||||||
virtual int getDecoderCapabilities();
|
virtual int getDecoderCapabilities();
|
||||||
virtual FramePacingConstraint getFramePacingConstraint();
|
virtual FramePacingConstraint getFramePacingConstraint();
|
||||||
|
virtual void notifyOverlayUpdated(Overlay::OverlayType) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool initializeDecoder();
|
bool initializeDecoder();
|
||||||
bool initializeRenderer();
|
bool initializeRenderer();
|
||||||
bool initializeDevice(SDL_Window* window, bool enableVsync);
|
bool initializeDevice(SDL_Window* window, bool enableVsync);
|
||||||
bool initializeOverlay();
|
|
||||||
bool isDecoderBlacklisted();
|
bool isDecoderBlacklisted();
|
||||||
bool isDXVideoProcessorAPIBlacklisted();
|
bool isDXVideoProcessorAPIBlacklisted();
|
||||||
|
|
||||||
|
@ -70,6 +70,6 @@ private:
|
||||||
DXVA2_ValueRange m_SaturationRange;
|
DXVA2_ValueRange m_SaturationRange;
|
||||||
DXVA2_VideoDesc m_Desc;
|
DXVA2_VideoDesc m_Desc;
|
||||||
REFERENCE_TIME m_FrameIndex;
|
REFERENCE_TIME m_FrameIndex;
|
||||||
LPD3DXFONT m_OverlayFont;
|
LPD3DXFONT m_DebugOverlayFont;
|
||||||
bool m_BlockingPresent;
|
bool m_BlockingPresent;
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,13 +18,6 @@ SdlRenderer::SdlRenderer()
|
||||||
TTF_GetError());
|
TTF_GetError());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_DebugOverlayFont = TTF_OpenFont("ModeSeven.ttf", 20);
|
|
||||||
if (m_DebugOverlayFont == nullptr) {
|
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"TTF_OpenFont() failed: %s",
|
|
||||||
TTF_GetError());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SdlRenderer::~SdlRenderer()
|
SdlRenderer::~SdlRenderer()
|
||||||
|
@ -85,8 +78,16 @@ void SdlRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
|
||||||
{
|
{
|
||||||
if (type == Overlay::OverlayDebug) {
|
if (type == Overlay::OverlayDebug) {
|
||||||
if (m_DebugOverlayFont == nullptr) {
|
if (m_DebugOverlayFont == nullptr) {
|
||||||
// Can't proceed without a font
|
m_DebugOverlayFont = TTF_OpenFont("ModeSeven.ttf",
|
||||||
return;
|
Session::get()->getOverlayManager().getOverlayFontSize(Overlay::OverlayDebug));
|
||||||
|
if (m_DebugOverlayFont == nullptr) {
|
||||||
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"TTF_OpenFont() failed: %s",
|
||||||
|
TTF_GetError());
|
||||||
|
|
||||||
|
// Can't proceed without a font
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface* oldSurface = (SDL_Surface*)SDL_AtomicGetPtr((void**)&m_DebugOverlaySurface);
|
SDL_Surface* oldSurface = (SDL_Surface*)SDL_AtomicGetPtr((void**)&m_DebugOverlaySurface);
|
||||||
|
|
|
@ -8,17 +8,24 @@ OverlayManager::OverlayManager() :
|
||||||
memset(m_Overlays, 0, sizeof(m_Overlays));
|
memset(m_Overlays, 0, sizeof(m_Overlays));
|
||||||
|
|
||||||
m_Overlays[OverlayType::OverlayDebug].color = {0xFF, 0xFF, 0xFF, 0xFF};
|
m_Overlays[OverlayType::OverlayDebug].color = {0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
|
m_Overlays[OverlayType::OverlayDebug].fontSize = 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OverlayManager::isOverlayEnabled(OverlayType type)
|
bool OverlayManager::isOverlayEnabled(OverlayType type)
|
||||||
{
|
{
|
||||||
return m_Overlays[type].enabled;
|
return m_Overlays[type].enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* OverlayManager::getOverlayText(OverlayType type)
|
char* OverlayManager::getOverlayText(OverlayType type)
|
||||||
{
|
{
|
||||||
return m_Overlays[type].text;
|
return m_Overlays[type].text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int OverlayManager::getOverlayFontSize(OverlayType type)
|
||||||
|
{
|
||||||
|
return m_Overlays[type].fontSize;
|
||||||
|
}
|
||||||
|
|
||||||
void OverlayManager::setOverlayTextUpdated(OverlayType type)
|
void OverlayManager::setOverlayTextUpdated(OverlayType type)
|
||||||
{
|
{
|
||||||
// Only update the overlay state if it's enabled. If it's not enabled,
|
// Only update the overlay state if it's enabled. If it's not enabled,
|
||||||
|
|
|
@ -31,11 +31,13 @@ public:
|
||||||
void setOverlayTextUpdated(OverlayType type);
|
void setOverlayTextUpdated(OverlayType type);
|
||||||
void setOverlayState(OverlayType type, bool enabled);
|
void setOverlayState(OverlayType type, bool enabled);
|
||||||
SDL_Color getOverlayColor(OverlayType type);
|
SDL_Color getOverlayColor(OverlayType type);
|
||||||
|
int getOverlayFontSize(OverlayType type);
|
||||||
|
|
||||||
void setOverlayRenderer(IOverlayRenderer* renderer);
|
void setOverlayRenderer(IOverlayRenderer* renderer);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool enabled;
|
bool enabled;
|
||||||
|
int fontSize;
|
||||||
SDL_Color color;
|
SDL_Color color;
|
||||||
char text[512];
|
char text[512];
|
||||||
} m_Overlays[OverlayMax];
|
} m_Overlays[OverlayMax];
|
||||||
|
|
Loading…
Reference in a new issue