Skip to content

Commit

Permalink
reset static items only if item changes visibility
Browse files Browse the repository at this point in the history
decreases cpu load with wraplists (they're not deleting/recreating extra items each frame)
  • Loading branch information
pieh committed Jul 27, 2012
1 parent 566dc10 commit eaed915
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
32 changes: 23 additions & 9 deletions xbmc/guilib/GUIBaseContainer.cpp
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions xbmc/guilib/GUIBaseContainer.h
Expand Up @@ -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;
Expand Down

0 comments on commit eaed915

Please sign in to comment.