WebGLContextGroup.cpp [plain text]
#include "config.h"
#include "WebGLContextGroup.h"
#if ENABLE(WEBGL)
#include "GraphicsContext3D.h"
#include "WebGLRenderingContextBase.h"
#include "WebGLSharedObject.h"
namespace WebCore {
Ref<WebGLContextGroup> WebGLContextGroup::create()
{
return adoptRef(*new WebGLContextGroup);
}
WebGLContextGroup::~WebGLContextGroup()
{
detachAndRemoveAllObjects();
}
GraphicsContext3D& WebGLContextGroup::getAGraphicsContext3D()
{
ASSERT(!m_contexts.isEmpty());
return *(*m_contexts.begin())->graphicsContext3D();
}
void WebGLContextGroup::addContext(WebGLRenderingContextBase& context)
{
m_contexts.add(&context);
}
void WebGLContextGroup::removeContext(WebGLRenderingContextBase& 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())
(*m_groupObjects.begin())->detachContextGroup();
}
void WebGLContextGroup::loseContextGroup(WebGLRenderingContextBase::LostContextMode mode)
{
for (auto& context : m_contexts)
context->loseContextImpl(mode);
detachAndRemoveAllObjects();
}
}
#endif // ENABLE(WEBGL)