From 80d3874ed0add377a93e5d6334a1fce11f6a6a2e Mon Sep 17 00:00:00 2001 From: rachytski Date: Mon, 20 Aug 2012 12:39:03 +0300 Subject: [PATCH] refactored guy::Controller to accept yg::gl::Screen for caching, updating elements on every frame and purging them when renderPolicy is reseted. --- gui/controller.cpp | 31 +++++++++++++++++++++++++++++-- gui/controller.hpp | 16 ++++++++++++++-- gui/element.cpp | 6 ++++++ gui/element.hpp | 6 ++++++ map/framework.cpp | 4 +++- 5 files changed, 58 insertions(+), 5 deletions(-) diff --git a/gui/controller.cpp b/gui/controller.cpp index 5d8cb73e37..b0a09dbd77 100644 --- a/gui/controller.cpp +++ b/gui/controller.cpp @@ -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(); + } } diff --git a/gui/controller.hpp b/gui/controller.hpp index 2ef10978a1..79439bac7a 100644 --- a/gui/controller.hpp +++ b/gui/controller.hpp @@ -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(); }; } diff --git a/gui/element.cpp b/gui/element.cpp index 24e411937c..acc3d10928 100644 --- a/gui/element.cpp +++ b/gui/element.cpp @@ -66,6 +66,12 @@ namespace gui void Element::cache() {} + void Element::purge() + {} + + void Element::update() + {} + void Element::checkDirtyDrawing() const { if (isDirtyDrawing()) diff --git a/gui/element.hpp b/gui/element.hpp index 8efbbae5d3..7a1f55a8b2 100644 --- a/gui/element.hpp +++ b/gui/element.hpp @@ -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); diff --git a/map/framework.cpp b/map/framework.cpp index e32a1f3627..0a8fc52df0 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -600,6 +600,7 @@ void Framework::DrawAdditionalInfo(shared_ptr 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);