OverlayManager now manages font size for the overlays

This commit is contained in:
Cameron Gutman 2019-02-12 22:36:56 -08:00
parent d5f7b20be3
commit f83853c2fb
5 changed files with 57 additions and 49 deletions

View file

@ -27,7 +27,7 @@ DXVA2Renderer::DXVA2Renderer() :
m_ProcService(nullptr),
m_Processor(nullptr),
m_FrameIndex(0),
m_OverlayFont(nullptr),
m_DebugOverlayFont(nullptr),
m_BlockingPresent(false)
{
RtlZeroMemory(m_DecSurfaces, sizeof(m_DecSurfaces));
@ -47,7 +47,7 @@ DXVA2Renderer::~DXVA2Renderer()
SAFE_COM_RELEASE(m_RenderTarget);
SAFE_COM_RELEASE(m_ProcService);
SAFE_COM_RELEASE(m_Processor);
SAFE_COM_RELEASE(m_OverlayFont);
SAFE_COM_RELEASE(m_DebugOverlayFont);
for (int i = 0; i < ARRAYSIZE(m_DecSurfaces); i++) {
SAFE_COM_RELEASE(m_DecSurfaces[i]);
@ -324,32 +324,6 @@ bool DXVA2Renderer::initializeRenderer()
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()
{
IDirect3D9* d3d9;
@ -706,9 +680,6 @@ bool DXVA2Renderer::initialize(SDL_Window* window, int videoFormat, int width, i
return false;
}
// It's okay if this fails
initializeOverlay();
// For some reason, using Direct3D9Ex breaks this with multi-monitor setups.
// 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.
@ -736,6 +707,33 @@ IFFmpegRenderer::FramePacingConstraint DXVA2Renderer::getFramePacingConstraint()
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)
{
IDirect3DSurface9* surface = reinterpret_cast<IDirect3DSurface9*>(frame->data[3]);
@ -919,10 +917,10 @@ void DXVA2Renderer::renderFrameAtVsync(AVFrame *frame)
}
}
if (m_OverlayFont != nullptr) {
if (m_DebugOverlayFont != nullptr) {
if (Session::get()->getOverlayManager().isOverlayEnabled(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),
-1,
&sample.DstRect,

View file

@ -27,12 +27,12 @@ public:
virtual bool needsTestFrame();
virtual int getDecoderCapabilities();
virtual FramePacingConstraint getFramePacingConstraint();
virtual void notifyOverlayUpdated(Overlay::OverlayType) override;
private:
bool initializeDecoder();
bool initializeRenderer();
bool initializeDevice(SDL_Window* window, bool enableVsync);
bool initializeOverlay();
bool isDecoderBlacklisted();
bool isDXVideoProcessorAPIBlacklisted();
@ -70,6 +70,6 @@ private:
DXVA2_ValueRange m_SaturationRange;
DXVA2_VideoDesc m_Desc;
REFERENCE_TIME m_FrameIndex;
LPD3DXFONT m_OverlayFont;
LPD3DXFONT m_DebugOverlayFont;
bool m_BlockingPresent;
};

View file

@ -18,13 +18,6 @@ SdlRenderer::SdlRenderer()
TTF_GetError());
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()
@ -85,9 +78,17 @@ void SdlRenderer::notifyOverlayUpdated(Overlay::OverlayType type)
{
if (type == Overlay::OverlayDebug) {
if (m_DebugOverlayFont == nullptr) {
m_DebugOverlayFont = TTF_OpenFont("ModeSeven.ttf",
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);

View file

@ -8,17 +8,24 @@ OverlayManager::OverlayManager() :
memset(m_Overlays, 0, sizeof(m_Overlays));
m_Overlays[OverlayType::OverlayDebug].color = {0xFF, 0xFF, 0xFF, 0xFF};
m_Overlays[OverlayType::OverlayDebug].fontSize = 20;
}
bool OverlayManager::isOverlayEnabled(OverlayType type)
{
return m_Overlays[type].enabled;
}
char* OverlayManager::getOverlayText(OverlayType type)
{
return m_Overlays[type].text;
}
int OverlayManager::getOverlayFontSize(OverlayType type)
{
return m_Overlays[type].fontSize;
}
void OverlayManager::setOverlayTextUpdated(OverlayType type)
{
// Only update the overlay state if it's enabled. If it's not enabled,

View file

@ -31,11 +31,13 @@ public:
void setOverlayTextUpdated(OverlayType type);
void setOverlayState(OverlayType type, bool enabled);
SDL_Color getOverlayColor(OverlayType type);
int getOverlayFontSize(OverlayType type);
void setOverlayRenderer(IOverlayRenderer* renderer);
struct {
bool enabled;
int fontSize;
SDL_Color color;
char text[512];
} m_Overlays[OverlayMax];