Skip to content

Commit

Permalink
refactor GUiRenderingControl, clear dependency to viz
Browse files Browse the repository at this point in the history
  • Loading branch information
FernetMenta committed Mar 1, 2013
1 parent aae7f2d commit f870519
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 26 deletions.
2 changes: 1 addition & 1 deletion xbmc/addons/Visualisation.cpp
Expand Up @@ -63,7 +63,7 @@ void CAudioBuffer::Set(const float* psBuffer, int iSize)
for (int i = iSize; i < m_iLen; ++i) m_pBuffer[i] = 0;
}

bool CVisualisation::Create(int x, int y, int w, int h)
bool CVisualisation::Create(int x, int y, int w, int h, void *device)
{
m_pInfo = new VIS_PROPS;
#ifdef HAS_DX
Expand Down
4 changes: 3 additions & 1 deletion xbmc/addons/Visualisation.h
Expand Up @@ -23,6 +23,7 @@
#include "AddonDll.h"
#include "cores/IAudioCallback.h"
#include "include/xbmc_vis_types.h"
#include "guilib/IRenderingCallback.h"

#include <map>
#include <list>
Expand Down Expand Up @@ -52,13 +53,14 @@ namespace ADDON
{
class CVisualisation : public CAddonDll<DllVisualisation, Visualisation, VIS_PROPS>
, public IAudioCallback
, public IRenderingCallback
{
public:
CVisualisation(const ADDON::AddonProps &props) : CAddonDll<DllVisualisation, Visualisation, VIS_PROPS>(props) {}
CVisualisation(const cp_extension_t *ext) : CAddonDll<DllVisualisation, Visualisation, VIS_PROPS>(ext) {}
virtual void OnInitialize(int iChannels, int iSamplesPerSec, int iBitsPerSample);
virtual void OnAudioData(const float* pAudioData, int iAudioDataLength);
bool Create(int x, int y, int w, int h);
bool Create(int x, int y, int w, int h, void *device);
void Start(int iChannels, int iSamplesPerSec, int iBitsPerSample, const CStdString strSongName);
void AudioData(const float *pAudioData, int iAudioDataLength, float *pFreqData, int iFreqDataLength);
void Render();
Expand Down
43 changes: 25 additions & 18 deletions xbmc/guilib/GUIRenderingControl.cpp
Expand Up @@ -20,11 +20,11 @@

#include "GUIRenderingControl.h"
#include "GUIUserMessages.h"
#include "addons/Visualisation.h"
#include "threads/SingleLock.h"
#include "guilib/IRenderingCallback.h"
#include "windowing/WindowingFactory.h"

using namespace std;
using namespace ADDON;

#define LABEL_ROW1 10
#define LABEL_ROW2 11
Expand All @@ -34,18 +34,20 @@ CGUIRenderingControl::CGUIRenderingControl(int parentID, int controlID, float po
: CGUIControl(parentID, controlID, posX, posY, width, height)
{
ControlType = GUICONTROL_RENDERADDON;
m_callback = NULL;
}

CGUIRenderingControl::CGUIRenderingControl(const CGUIRenderingControl &from)
: CGUIControl(from)
{
ControlType = GUICONTROL_RENDERADDON;
m_callback = NULL;
}

void CGUIRenderingControl::LoadAddon(const AddonPtr &addon)
bool CGUIRenderingControl::InitCallback(IRenderingCallback *callback)
{
if (!addon)
return;
if (!callback)
return false;

CSingleLock lock(m_rendering);
g_graphicsContext.CaptureStateBlock();
Expand All @@ -58,29 +60,33 @@ void CGUIRenderingControl::LoadAddon(const AddonPtr &addon)
if (x + w > g_graphicsContext.GetWidth()) w = g_graphicsContext.GetWidth() - x;
if (y + h > g_graphicsContext.GetHeight()) h = g_graphicsContext.GetHeight() - y;

VizPtr viz = boost::dynamic_pointer_cast<CVisualisation>(addon);
if (viz && viz->Create((int)(x+0.5f), (int)(y+0.5f), (int)(w+0.5f), (int)(h+0.5f)))
{
m_addon = viz;
}
void *device = NULL;
#if HAS_DX
device = g_Windowing.Get3DDevice();
#endif
if (callback->Create((int)(x+0.5f), (int)(y+0.5f), (int)(w+0.5f), (int)(h+0.5f), device))
m_callback = callback;
else
return false;

g_graphicsContext.ApplyStateBlock();
return true;
}

void CGUIRenderingControl::UpdateVisibility(const CGUIListItem *item)
{
// if made invisible, start timer, only free addonptr after
// some period, configurable by window class
CGUIControl::UpdateVisibility(item);
if (!IsVisible() && m_addon)
if (!IsVisible() && m_callback)
FreeResources();
}

void CGUIRenderingControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
{
// TODO Add processing to the addon so it could mark when actually changing
CSingleLock lock(m_rendering);
if (m_addon)
if (m_callback && m_callback->IsDirty())
MarkDirtyRegion();

CGUIControl::Process(currentTime, dirtyregions);
Expand All @@ -89,14 +95,14 @@ void CGUIRenderingControl::Process(unsigned int currentTime, CDirtyRegionList &d
void CGUIRenderingControl::Render()
{
CSingleLock lock(m_rendering);
if (m_addon)
if (m_callback)
{
// set the viewport - note: We currently don't have any control over how
// the addon renders, so the best we can do is attempt to define
// a viewport??
g_graphicsContext.SetViewPort(m_posX, m_posY, m_width, m_height);
g_graphicsContext.CaptureStateBlock();
m_addon->Render();
m_callback->Render();
g_graphicsContext.ApplyStateBlock();
g_graphicsContext.RestoreViewPort();
}
Expand All @@ -106,13 +112,14 @@ void CGUIRenderingControl::Render()

void CGUIRenderingControl::FreeResources(bool immediately)
{
if (!m_addon) return;

CSingleLock lock(m_rendering);

if (!m_callback) return;

g_graphicsContext.CaptureStateBlock(); //TODO locking
m_addon->Stop();
m_callback->Stop();
g_graphicsContext.ApplyStateBlock();
m_addon.reset();
m_callback = NULL;
}

bool CGUIRenderingControl::CanFocusFromPoint(const CPoint &point) const
Expand Down
7 changes: 4 additions & 3 deletions xbmc/guilib/GUIRenderingControl.h
Expand Up @@ -20,7 +20,8 @@
*/

#include "GUIControl.h"
#include "addons/IAddon.h"

class IRenderingCallback;

class CGUIRenderingControl : public CGUIControl
{
Expand All @@ -35,9 +36,9 @@ class CGUIRenderingControl : public CGUIControl
virtual void FreeResources(bool immediately = false);
virtual bool CanFocus() const { return false; }
virtual bool CanFocusFromPoint(const CPoint &point) const;
void LoadAddon(const ADDON::AddonPtr &addon);
bool InitCallback(IRenderingCallback *callback);

protected:
CCriticalSection m_rendering;
ADDON::VizPtr m_addon;
IRenderingCallback *m_callback;
};
13 changes: 10 additions & 3 deletions xbmc/guilib/GUIVisualisationControl.cpp
Expand Up @@ -25,6 +25,7 @@
#include "addons/AddonManager.h"
#include "addons/Visualisation.h"
#include "utils/log.h"
#include "guilib/IRenderingCallback.h"

using namespace std;
using namespace ADDON;
Expand Down Expand Up @@ -99,9 +100,14 @@ void CGUIVisualisationControl::Process(unsigned int currentTime, CDirtyRegionLis

if (!m_addon && !m_bAttemptedLoad)
{
AddonPtr viz;
if (ADDON::CAddonMgr::Get().GetDefault(ADDON_VIZ, viz))
LoadAddon(viz);
AddonPtr addon;
if (ADDON::CAddonMgr::Get().GetDefault(ADDON_VIZ, addon))
{
m_addon = boost::dynamic_pointer_cast<CVisualisation>(addon);
if (m_addon)
if (!InitCallback(m_addon.get()))
m_addon.reset();
}

m_bAttemptedLoad = true;
}
Expand All @@ -120,6 +126,7 @@ void CGUIVisualisationControl::FreeResources(bool immediately)
g_windowManager.SendMessage(msg);
CLog::Log(LOGDEBUG, "FreeVisualisation() started");
CGUIRenderingControl::FreeResources(immediately);
m_addon.reset();
CLog::Log(LOGDEBUG, "FreeVisualisation() done");
}

2 changes: 2 additions & 0 deletions xbmc/guilib/GUIVisualisationControl.h
Expand Up @@ -20,6 +20,7 @@
*/

#include "GUIRenderingControl.h"
#include "addons/IAddon.h"

class CGUIVisualisationControl : public CGUIRenderingControl
{
Expand All @@ -33,4 +34,5 @@ class CGUIVisualisationControl : public CGUIRenderingControl
virtual bool OnMessage(CGUIMessage &message);
private:
bool m_bAttemptedLoad;
ADDON::VizPtr m_addon;
};
30 changes: 30 additions & 0 deletions xbmc/guilib/IRenderingCallback.h
@@ -0,0 +1,30 @@
#pragma once

/*
* Copyright (C) 2005-2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

class IRenderingCallback
{
public:
virtual bool Create(int x, int y, int w, int h, void *device) = 0;
virtual void Render() = 0;
virtual void Stop() = 0;
virtual bool IsDirty() { return true; }
};

0 comments on commit f870519

Please sign in to comment.