Skip to content

Commit

Permalink
allow not to free memory (destroy controls objects) when exiting window
Browse files Browse the repository at this point in the history
added additional checks in AllocResources - we have to load .xml file if:
 - load type is set to LOAD_EVERY_TIME (all windows use it by default)
 - window is loaded and any of include condition have changed value
 - window isn't loaded

we have to unload window before loading if window wasn't unloaded before and include conditions have change value(s)
  • Loading branch information
pieh committed Sep 8, 2012
1 parent 5671a6a commit afffab0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
42 changes: 32 additions & 10 deletions xbmc/guilib/GUIWindow.cpp
Expand Up @@ -60,7 +60,7 @@ CGUIWindow::CGUIWindow(int id, const CStdString &xmlFile)
m_isDialog = false;
m_needsScaling = true;
m_windowLoaded = false;
m_loadType = LOAD_ON_DEMAND;
m_loadType = LOAD_EVERY_TIME;
m_closing = false;
m_active = false;
m_renderOrder = 0;
Expand Down Expand Up @@ -685,13 +685,29 @@ void CGUIWindow::AllocResources(bool forceLoad /*= FALSE */)
int64_t start;
start = CurrentHostCounter();
#endif
// load skin xml fil
CStdString xmlFile = GetProperty("xmlfile").asString();
bool bHasPath=false;
if (xmlFile.Find("\\") > -1 || xmlFile.Find("/") > -1 )
bHasPath = true;
if (xmlFile.size() && (forceLoad || m_loadType == LOAD_ON_DEMAND || !m_windowLoaded))
Load(xmlFile,bHasPath);
// use forceLoad to determine if xml file needs loading
forceLoad |= (m_loadType == LOAD_EVERY_TIME);

// if window is loaded (not cleared before) and we aren't forced to load
// we will have to load it only if include conditions values were changed
if (m_windowLoaded && !forceLoad)
forceLoad = g_infoManager.ConditionsChangedValues(m_xmlIncludeConditions);

// if window is loaded and load is forced we have to free window resources first
if (m_windowLoaded && forceLoad)
FreeResources(true);

// load skin xml file only if we are forced to load or window isn't loaded yet
forceLoad |= !m_windowLoaded;
if (forceLoad)
{
CStdString xmlFile = GetProperty("xmlfile").asString();
if (xmlFile.size())
{
bool bHasPath = xmlFile.Find("\\") > -1 || xmlFile.Find("/") > -1;
Load(xmlFile,bHasPath);
}
}

int64_t slend;
slend = CurrentHostCounter();
Expand All @@ -703,7 +719,13 @@ void CGUIWindow::AllocResources(bool forceLoad /*= FALSE */)
int64_t end, freq;
end = CurrentHostCounter();
freq = CurrentHostFrequency();
CLog::Log(LOGDEBUG,"Alloc resources: %.2fms (%.2f ms skin load)", 1000.f * (end - start) / freq, 1000.f * (slend - start) / freq);
if (forceLoad)
CLog::Log(LOGDEBUG,"Alloc resources: %.2fms (%.2f ms skin load)", 1000.f * (end - start) / freq, 1000.f * (slend - start) / freq);
else
{
CLog::Log(LOGDEBUG,"Window %s was already loaded", GetProperty("xmlfile").c_str());
CLog::Log(LOGDEBUG,"Alloc resources: %.2fm", 1000.f * (end - start) / freq);
}
#endif
m_bAllocated = true;
}
Expand All @@ -714,7 +736,7 @@ void CGUIWindow::FreeResources(bool forceUnload /*= FALSE */)
CGUIControlGroup::FreeResources();
//g_TextureManager.Dump();
// unload the skin
if (m_loadType == LOAD_ON_DEMAND || forceUnload) ClearAll();
if (m_loadType == LOAD_EVERY_TIME || forceUnload) ClearAll();
}

void CGUIWindow::DynamicResourceAlloc(bool bOnOff)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/guilib/GUIWindow.h
Expand Up @@ -80,7 +80,7 @@ class CGUIWindow : public CGUIControlGroup, protected CCriticalSection
public:

enum WINDOW_TYPE { WINDOW = 0, MODAL_DIALOG, MODELESS_DIALOG, BUTTON_MENU, SUB_MENU };
enum LOAD_TYPE { LOAD_ON_DEMAND, LOAD_ON_GUI_INIT};
enum LOAD_TYPE { LOAD_EVERY_TIME, LOAD_ON_GUI_INIT, KEEP_IN_MEMORY };

CGUIWindow(int id, const CStdString &xmlFile);
virtual ~CGUIWindow(void);
Expand Down
3 changes: 2 additions & 1 deletion xbmc/guilib/GUIWindowManager.cpp
Expand Up @@ -870,7 +870,8 @@ void CGUIWindowManager::UnloadNotOnDemandWindows()
for (WindowMap::iterator it = m_mapWindows.begin(); it != m_mapWindows.end(); it++)
{
CGUIWindow *pWindow = (*it).second;
if (pWindow->GetLoadType() == CGUIWindow::LOAD_ON_GUI_INIT)
if (pWindow->GetLoadType() == CGUIWindow::LOAD_ON_GUI_INIT ||
pWindow->GetLoadType() == CGUIWindow::KEEP_IN_MEMORY)
{
pWindow->FreeResources(true);
}
Expand Down

0 comments on commit afffab0

Please sign in to comment.