Refactor for asynchronous fontcache load

This commit is contained in:
Jack Andersen 2015-12-12 16:26:41 -10:00
parent cb2df22ec2
commit 6dde3e6003
5 changed files with 53 additions and 21 deletions

View File

@ -65,6 +65,7 @@ public:
View* setContentView(View* view);
void resetTooltip(ViewResources& res);
void displayTooltip(const std::string& name, const std::string& help);
private:

View File

@ -6,6 +6,8 @@
#include "Toolbar.hpp"
#include "Button.hpp"
#include <thread>
namespace Specter
{
class ThemeData
@ -22,6 +24,9 @@ class ThemeData
Zeus::CColor m_button1Disabled = {0.2823, 0.2823, 0.2823, 0.5};
Zeus::CColor m_button2Disabled = {0.1725, 0.1725, 0.1725, 0.5};
Zeus::CColor m_tooltipBg = {0.0, 0.0, 0.0, 0.65};
Zeus::CColor m_splashBg = {0.1, 0.1, 0.1, 0.65};
Zeus::CColor m_splash1 = {1.0, 1.0, 1.0, 1.0};
Zeus::CColor m_splash2 = {0.3, 0.3, 0.3, 1.0};
public:
virtual const Zeus::CColor& viewportBackground() const {return m_vpBg;}
virtual const Zeus::CColor& toolbarBackground() const {return m_tbBg;}
@ -35,12 +40,15 @@ public:
virtual const Zeus::CColor& button1Disabled() const {return m_button1Disabled;}
virtual const Zeus::CColor& button2Disabled() const {return m_button2Disabled;}
virtual const Zeus::CColor& tooltipBackground() const {return m_tooltipBg;}
virtual const Zeus::CColor& splashBackground() const {return m_splashBg;}
virtual const Zeus::CColor& splash1() const {return m_splash1;}
virtual const Zeus::CColor& splash2() const {return m_splash2;}
};
class ViewResources
{
template <class Factory>
void init(Factory* factory, FontCache* fcache, const ThemeData& theme)
void init(Factory* factory, const ThemeData& theme, FontCache* fcache)
{
m_viewRes.init(factory, theme);
m_textRes.init(factory, fcache);
@ -65,8 +73,12 @@ public:
Specter::FontTag m_heading14;
Specter::FontTag m_heading18;
Specter::FontTag m_titleFont;
Specter::FontTag m_curveFont;
std::thread m_fcacheThread;
bool m_fcacheReady = false;
ViewResources() = default;
ViewResources(const ViewResources& other) = delete;
ViewResources(ViewResources&& other) = default;
@ -74,6 +86,9 @@ public:
ViewResources& operator=(ViewResources&& other) = default;
void init(boo::IGraphicsDataFactory* factory, FontCache* fcache, const ThemeData& theme, float pixelFactor);
void prepFontCacheSync();
void prepFontCacheAsync(boo::IWindow* window);
bool fontCacheReady() const {return m_fcacheReady;}
void resetPixelFactor(float pixelFactor);
void resetTheme(const ThemeData& theme);
void resetLanguage(const ThemeData& theme);

View File

@ -14,8 +14,6 @@ RootView::RootView(IViewManager& viewMan, ViewResources& res, boo::IWindow* wind
m_renderTex = res.m_factory->newRenderTexture(rect.size[0], rect.size[1], 1);
commitResources(res);
resized(rect, rect);
m_tooltip.reset(new Tooltip(res, *this, "Test", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi hendrerit nisl quis lobortis mattis. Mauris efficitur, est a vestibulum iaculis, leo orci pellentesque nunc, non rutrum ipsum lectus eget nisl. Aliquam accumsan vestibulum turpis. Duis id lacus ac lectus sollicitudin posuere vel sit amet metus. Aenean nec tortor id enim efficitur accumsan vitae eu ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce magna eros, lacinia a leo eget, volutpat rhoncus urna."));
}
void RootView::destroyed()
@ -130,6 +128,11 @@ View* RootView::setContentView(View* view)
return ret;
}
void RootView::resetTooltip(ViewResources& res)
{
m_tooltip.reset(new Tooltip(res, *this, "Test", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi hendrerit nisl quis lobortis mattis. Mauris efficitur, est a vestibulum iaculis, leo orci pellentesque nunc, non rutrum ipsum lectus eget nisl. Aliquam accumsan vestibulum turpis. Duis id lacus ac lectus sollicitudin posuere vel sit amet metus. Aenean nec tortor id enim efficitur accumsan vitae eu ante. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce magna eros, lacinia a leo eget, volutpat rhoncus urna."));
}
void RootView::displayTooltip(const std::string& name, const std::string& help)
{
}

View File

@ -438,9 +438,9 @@ void TextView::think()
{
}
void TextView::resized(const boo::SWindowRect &rootView, const boo::SWindowRect& sub)
void TextView::resized(const boo::SWindowRect &root, const boo::SWindowRect& sub)
{
View::resized(rootView, sub);
View::resized(root, sub);
}
void TextView::draw(boo::IGraphicsCommandQueue* gfxQ)

View File

@ -8,47 +8,60 @@ void ViewResources::init(boo::IGraphicsDataFactory* factory, FontCache* fcache,
const ThemeData& theme, float pf)
{
m_pixelFactor = pf;
unsigned dpi = 72.f * pf;
m_theme = theme;
m_factory = factory;
m_fcache = fcache;
m_mainFont = fcache->prepMainFont(factory, AllCharFilter, false, 10.f, dpi);
m_monoFont = fcache->prepMonoFont(factory, AllCharFilter, false, 10.f, dpi);
m_heading14 = fcache->prepMainFont(factory, LatinAndJapaneseCharFilter, false, 14.f, dpi);
m_heading18 = fcache->prepMainFont(factory, LatinAndJapaneseCharFilter, false, 18.f, dpi);
m_curveFont = fcache->prepCurvesFont(factory, AllCharFilter, false, 8.f, dpi);
unsigned dpi = 72.f * m_pixelFactor;
m_curveFont = fcache->prepCurvesFont(m_factory, AllCharFilter, false, 8.f, dpi);
switch (factory->platform())
{
case boo::IGraphicsDataFactory::Platform::OGL:
init<boo::GLDataFactory>(static_cast<boo::GLDataFactory*>(factory), fcache, theme);
init<boo::GLDataFactory>(static_cast<boo::GLDataFactory*>(factory), theme, fcache);
break;
#if _WIN32
case boo::IGraphicsDataFactory::Platform::D3D11:
case boo::IGraphicsDataFactory::Platform::D3D12:
init<boo::ID3DDataFactory>(static_cast<boo::ID3DDataFactory*>(factory), fcache, theme);
init<boo::ID3DDataFactory>(static_cast<boo::ID3DDataFactory*>(factory), theme, fcache);
break;
#elif BOO_HAS_METAL
case boo::IGraphicsDataFactory::Platform::Metal:
init<boo::MetalDataFactory>(static_cast<boo::MetalDataFactory*>(factory), fcache, theme);
init<boo::MetalDataFactory>(static_cast<boo::MetalDataFactory*>(factory), theme, fcache);
break;
#endif
default:
Log.report(LogVisor::FatalError, _S("unable to init view system for %s"), factory->platformName());
}
fcache->closeBuiltinFonts();
m_resData = factory->commit();
}
void ViewResources::prepFontCacheSync()
{
unsigned dpi = 72.f * m_pixelFactor;
m_mainFont = m_fcache->prepMainFont(m_factory, AllCharFilter, false, 10.f, dpi);
m_monoFont = m_fcache->prepMonoFont(m_factory, AllCharFilter, false, 10.f, dpi);
m_heading14 = m_fcache->prepMainFont(m_factory, LatinAndJapaneseCharFilter, false, 14.f, dpi);
m_heading18 = m_fcache->prepMainFont(m_factory, LatinAndJapaneseCharFilter, false, 18.f, dpi);
m_titleFont = m_fcache->prepMainFont(m_factory, LatinCharFilter, false, 36.f, dpi);
m_fcache->closeBuiltinFonts();
m_fcacheReady = true;
}
void ViewResources::prepFontCacheAsync(boo::IWindow* window)
{
m_fcacheReady = false;
m_fcacheThread = std::thread([this, window]()
{
window->getLoadContextDataFactory();
prepFontCacheSync();
});
}
void ViewResources::resetPixelFactor(float pf)
{
m_pixelFactor = pf;
unsigned dpi = 72.f * pf;
m_mainFont = m_fcache->prepMainFont(m_factory, AllCharFilter, false, 10.f, dpi);
m_monoFont = m_fcache->prepMonoFont(m_factory, AllCharFilter, false, 10.f, dpi);
m_heading14 = m_fcache->prepMainFont(m_factory, LatinAndJapaneseCharFilter, false, 14.f, dpi);
m_heading18 = m_fcache->prepMainFont(m_factory, LatinAndJapaneseCharFilter, false, 18.f, dpi);
unsigned dpi = 72.f * m_pixelFactor;
m_curveFont = m_fcache->prepCurvesFont(m_factory, AllCharFilter, false, 8.f, dpi);
m_fcache->closeBuiltinFonts();
prepFontCacheSync();
}
void ViewResources::resetTheme(const ThemeData& theme)