WebGLContextGroup.cpp [plain text]
#include "config.h"
#if ENABLE(WEBGL)
#include "WebGLContextGroup.h"
#include "GraphicsContext3D.h"
#include "WebGLRenderingContext.h"
#include "WebGLSharedObject.h"
#if PLATFORM(QT)
#undef emit
#endif
namespace WebCore {
PassRefPtr<WebGLContextGroup> WebGLContextGroup::create()
{
RefPtr<WebGLContextGroup> contextGroup = adoptRef(new WebGLContextGroup());
return contextGroup.release();
}
WebGLContextGroup::WebGLContextGroup()
{
}
WebGLContextGroup::~WebGLContextGroup()
{
detachAndRemoveAllObjects();
}
GraphicsContext3D* WebGLContextGroup::getAGraphicsContext3D()
{
ASSERT(!m_contexts.isEmpty());
HashSet<WebGLRenderingContext*>::iterator it = m_contexts.begin();
return (*it)->graphicsContext3D();
}
void WebGLContextGroup::addContext(WebGLRenderingContext* context)
{
m_contexts.add(context);
}
void WebGLContextGroup::removeContext(WebGLRenderingContext* context)
{
if (m_contexts.size() == 1 && m_contexts.contains(context))
detachAndRemoveAllObjects();
m_contexts.remove(context);
}
void WebGLContextGroup::removeObject(WebGLSharedObject* object)
{
m_groupObjects.remove(object);
}
void WebGLContextGroup::addObject(WebGLSharedObject* object)
{
m_groupObjects.add(object);
}
void WebGLContextGroup::detachAndRemoveAllObjects()
{
while (!m_groupObjects.isEmpty()) {
HashSet<WebGLSharedObject*>::iterator it = m_groupObjects.begin();
(*it)->detachContextGroup();
}
}
void WebGLContextGroup::loseContextGroup(WebGLRenderingContext::LostContextMode mode)
{
for (HashSet<WebGLRenderingContext*>::iterator it = m_contexts.begin(); it != m_contexts.end(); ++it)
(*it)->loseContextImpl(mode);
detachAndRemoveAllObjects();
}
}
#endif // ENABLE(WEBGL)