Skip to content
Browse files

reset static items only if item changes visibility

decreases cpu load with wraplists (they're not deleting/recreating extra items each frame)
  • Loading branch information...
1 parent 566dc10 commit eaed915f5401fe5d8bcc263f1a98be74009b84d7 @pieh pieh committed
Showing with 24 additions and 9 deletions.
  1. +23 −9 xbmc/guilib/GUIBaseContainer.cpp
  2. +1 −0 xbmc/guilib/GUIBaseContainer.h
View
32 xbmc/guilib/GUIBaseContainer.cpp
@@ -826,36 +826,50 @@ void CGUIBaseContainer::UpdateVisibility(const CGUIListItem *item)
SelectItem(itemIndex);
}
+ UpdateStaticItems();
+}
+
+void CGUIBaseContainer::UpdateStaticItems(bool refreshItems)
+{
if (m_staticContent)
{ // update our item list with our new content, but only add those items that should
// be visible. Save the previous item and keep it if we are adding that one.
+ std::vector<CGUIListItemPtr> items;
+ int reselect = -1;
int selected = GetSelectedItem();
CGUIListItem* selectedItem = (selected >= 0 && (unsigned int)selected < m_items.size()) ? m_items[selected].get() : NULL;
- Reset();
- bool updateItems = false;
+ bool updateItemsProperties = false;
if (!m_staticUpdateTime)
m_staticUpdateTime = CTimeUtils::GetFrameTime();
if (CTimeUtils::GetFrameTime() - m_staticUpdateTime > 1000)
{
m_staticUpdateTime = CTimeUtils::GetFrameTime();
- updateItems = true;
+ updateItemsProperties = true;
}
for (unsigned int i = 0; i < m_staticItems.size(); ++i)
{
CGUIStaticItemPtr staticItem = boost::static_pointer_cast<CGUIStaticItem>(m_staticItems[i]);
if (staticItem->UpdateVisibility(GetParentID()))
- MarkDirtyRegion();
+ refreshItems = true;
if (staticItem->IsVisible())
{
- m_items.push_back(staticItem);
+ items.push_back(staticItem);
// if item is selected and it changed position, re-select it
- if (staticItem.get() == selectedItem && selected != (int)m_items.size() - 1)
- SelectItem(m_items.size() - 1);
+ if (staticItem.get() == selectedItem && selected != (int)items.size() - 1)
+ reselect = items.size() - 1;
}
// update any properties
- if (updateItems)
+ if (updateItemsProperties)
staticItem->UpdateProperties(GetParentID());
}
+ if (refreshItems)
+ {
+ Reset();
+ m_items = items;
+ if (reselect >= 0 && reselect < (int)m_items.size())
+ SelectItem(reselect);
+ MarkDirtyRegion();
+ }
UpdateScrollByLetter();
}
}
@@ -1019,7 +1033,7 @@ void CGUIBaseContainer::SetStaticContent(const vector<CGUIListItemPtr> &items)
m_staticUpdateTime = 0;
m_staticItems.clear();
m_staticItems.assign(items.begin(), items.end());
- UpdateVisibility();
+ UpdateStaticItems(true);
}
void CGUIBaseContainer::SetRenderOffset(const CPoint &offset)
View
1 xbmc/guilib/GUIBaseContainer.h
@@ -124,6 +124,7 @@ class CGUIBaseContainer : public CGUIControl
virtual int GetCurrentPage() const;
bool InsideLayout(const CGUIListItemLayout *layout, const CPoint &point) const;
virtual void OnFocus();
+ void UpdateStaticItems(bool refreshItems = false);
int ScrollCorrectionRange() const;
inline float Size() const;

0 comments on commit eaed915

Please sign in to comment.
Something went wrong with that request. Please try again.