forked from organicmaps/organicmaps
refactored guy::Controller to accept yg::gl::Screen for caching, updating elements on every frame and purging them when renderPolicy is reseted.
This commit is contained in:
parent
e00411fd42
commit
80d3874ed0
5 changed files with 58 additions and 5 deletions
|
@ -19,10 +19,12 @@ namespace gui
|
|||
|
||||
Controller::RenderParams::RenderParams(double visualScale,
|
||||
TInvalidateFn invalidateFn,
|
||||
yg::GlyphCache * glyphCache)
|
||||
yg::GlyphCache * glyphCache,
|
||||
yg::gl::Screen * cacheScreen)
|
||||
: m_VisualScale(visualScale),
|
||||
m_InvalidateFn(invalidateFn),
|
||||
m_GlyphCache(glyphCache)
|
||||
m_GlyphCache(glyphCache),
|
||||
m_CacheScreen(cacheScreen)
|
||||
{}
|
||||
|
||||
Controller::~Controller()
|
||||
|
@ -124,6 +126,7 @@ namespace gui
|
|||
m_GlyphCache = p.m_GlyphCache;
|
||||
m_InvalidateFn = p.m_InvalidateFn;
|
||||
m_VisualScale = p.m_VisualScale;
|
||||
m_CacheScreen = p.m_CacheScreen;
|
||||
}
|
||||
|
||||
void Controller::ResetRenderParams()
|
||||
|
@ -131,6 +134,9 @@ namespace gui
|
|||
m_GlyphCache = 0;
|
||||
m_VisualScale = 0;
|
||||
m_InvalidateFn.clear();
|
||||
m_CacheScreen = 0;
|
||||
|
||||
PurgeElements();
|
||||
}
|
||||
|
||||
void Controller::DrawFrame(yg::gl::Screen * screen)
|
||||
|
@ -175,4 +181,25 @@ namespace gui
|
|||
{
|
||||
return m_bundle;
|
||||
}
|
||||
|
||||
yg::gl::Screen * Controller::GetCacheScreen() const
|
||||
{
|
||||
return m_CacheScreen;
|
||||
}
|
||||
|
||||
void Controller::UpdateElements()
|
||||
{
|
||||
for (elem_list_t::const_iterator it = m_Elements.begin();
|
||||
it != m_Elements.end();
|
||||
++it)
|
||||
(*it)->update();
|
||||
}
|
||||
|
||||
void Controller::PurgeElements()
|
||||
{
|
||||
for (elem_list_t::const_iterator it = m_Elements.begin();
|
||||
it != m_Elements.end();
|
||||
++it)
|
||||
(*it)->purge();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,6 +57,9 @@ namespace gui
|
|||
/// Localized strings for GUI.
|
||||
StringsBundle const * m_bundle;
|
||||
|
||||
/// Screen, which is used to cache gui::Elements into display lists.
|
||||
yg::gl::Screen * m_CacheScreen;
|
||||
|
||||
public:
|
||||
|
||||
/// Constructor with GestureDetector to route events from.
|
||||
|
@ -77,10 +80,12 @@ namespace gui
|
|||
double m_VisualScale;
|
||||
TInvalidateFn m_InvalidateFn;
|
||||
yg::GlyphCache * m_GlyphCache;
|
||||
yg::gl::Screen * m_CacheScreen;
|
||||
RenderParams();
|
||||
RenderParams(double visualScale,
|
||||
TInvalidateFn invalidateFn,
|
||||
yg::GlyphCache * glyphCache);
|
||||
yg::GlyphCache * glyphCache,
|
||||
yg::gl::Screen * cacheScreen);
|
||||
};
|
||||
|
||||
/// Attach GUI Controller to the renderer
|
||||
|
@ -99,9 +104,16 @@ namespace gui
|
|||
double GetVisualScale() const;
|
||||
/// Get localized strings bundle
|
||||
StringsBundle const * GetStringsBundle() const;
|
||||
/// Get GLyphCache
|
||||
/// Get GlyphCache
|
||||
yg::GlyphCache * GetGlyphCache() const;
|
||||
/// Get yg::gl::Screen, which is used to cache gui::Element's
|
||||
/// into display lists.
|
||||
yg::gl::Screen * GetCacheScreen() const;
|
||||
/// Redraw GUI
|
||||
void DrawFrame(yg::gl::Screen * screen);
|
||||
/// Calling gui::Element::update for every element.
|
||||
void UpdateElements();
|
||||
/// Calling gui::Element::purge for every element.
|
||||
void PurgeElements();
|
||||
};
|
||||
}
|
||||
|
|
|
@ -66,6 +66,12 @@ namespace gui
|
|||
void Element::cache()
|
||||
{}
|
||||
|
||||
void Element::purge()
|
||||
{}
|
||||
|
||||
void Element::update()
|
||||
{}
|
||||
|
||||
void Element::checkDirtyDrawing() const
|
||||
{
|
||||
if (isDirtyDrawing())
|
||||
|
|
|
@ -72,6 +72,12 @@ namespace gui
|
|||
int visualRank() const;
|
||||
|
||||
virtual void cache();
|
||||
/// this method is called upon renderPolicy destruction and should clean
|
||||
/// all rendering-related resources, p.e. displayLists.
|
||||
virtual void purge();
|
||||
/// this method is called in each frame and should be overriden if the
|
||||
/// element wants to update it's internal state.
|
||||
virtual void update();
|
||||
|
||||
virtual void setController(Controller * controller);
|
||||
|
||||
|
|
|
@ -600,6 +600,7 @@ void Framework::DrawAdditionalInfo(shared_ptr<PaintEvent> const & e)
|
|||
|
||||
pScreen->endFrame();
|
||||
|
||||
m_guiController->UpdateElements();
|
||||
m_guiController->DrawFrame(pScreen);
|
||||
}
|
||||
|
||||
|
@ -1078,7 +1079,8 @@ void Framework::SetRenderPolicy(RenderPolicy * renderPolicy)
|
|||
gui::Controller::RenderParams rp(m_renderPolicy->VisualScale(),
|
||||
bind(&WindowHandle::invalidate,
|
||||
renderPolicy->GetWindowHandle().get()),
|
||||
m_renderPolicy->GetGlyphCache());
|
||||
m_renderPolicy->GetGlyphCache(),
|
||||
m_renderPolicy->GetDrawer()->screen().get());
|
||||
|
||||
m_guiController->SetRenderParams(rp);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue