WebGLLayerChromium.cpp [plain text]
#include "config.h"
#if USE(ACCELERATED_COMPOSITING)
#include "WebGLLayerChromium.h"
#include "Extensions3DChromium.h"
#include "GraphicsContext3D.h"
#include "LayerRendererChromium.h"
#include "TraceEvent.h"
namespace WebCore {
PassRefPtr<WebGLLayerChromium> WebGLLayerChromium::create(GraphicsLayerChromium* owner)
{
return adoptRef(new WebGLLayerChromium(owner));
}
WebGLLayerChromium::WebGLLayerChromium(GraphicsLayerChromium* owner)
: CanvasLayerChromium(owner)
, m_context(0)
, m_contextSupportsRateLimitingExtension(false)
, m_rateLimitingTimer(this, &WebGLLayerChromium::rateLimitContext)
, m_textureUpdated(false)
{
}
WebGLLayerChromium::~WebGLLayerChromium()
{
if (m_context && layerRenderer())
layerRenderer()->removeChildContext(m_context);
}
void WebGLLayerChromium::updateCompositorResources()
{
if (!m_context)
return;
if (!m_contentsDirty)
return;
GraphicsContext3D* rendererContext = layerRendererContext();
if (m_textureChanged) {
rendererContext->bindTexture(GraphicsContext3D::TEXTURE_2D, m_textureId);
rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR);
rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR);
rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE);
rendererContext->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE);
m_textureChanged = false;
}
if (m_contentsDirty && m_textureUpdated) {
m_context->prepareTexture();
m_context->markLayerComposited();
m_contentsDirty = false;
m_textureUpdated = false;
}
}
void WebGLLayerChromium::setTextureUpdated()
{
m_textureUpdated = true;
if (layerRenderer() && !layerRenderer()->isAnimating() && m_contextSupportsRateLimitingExtension && !m_rateLimitingTimer.isActive())
m_rateLimitingTimer.startOneShot(0);
}
void WebGLLayerChromium::setContext(const GraphicsContext3D* context)
{
if (m_context != context && layerRenderer()) {
if (m_context)
layerRenderer()->removeChildContext(m_context);
if (context)
layerRenderer()->addChildContext(const_cast<GraphicsContext3D*>(context));
}
m_context = const_cast<GraphicsContext3D*>(context);
if (!m_context)
return;
unsigned int textureId = m_context->platformTexture();
if (textureId != m_textureId) {
m_textureChanged = true;
m_textureUpdated = true;
}
m_textureId = textureId;
m_premultipliedAlpha = m_context->getContextAttributes().premultipliedAlpha;
m_contextSupportsRateLimitingExtension = m_context->getExtensions()->supports("GL_CHROMIUM_rate_limit_offscreen_context");
}
void WebGLLayerChromium::setLayerRenderer(LayerRendererChromium* newLayerRenderer)
{
if (layerRenderer() != newLayerRenderer) {
if (m_context) {
if (layerRenderer())
layerRenderer()->removeChildContext(m_context);
if (newLayerRenderer)
newLayerRenderer->addChildContext(m_context);
}
LayerChromium::setLayerRenderer(newLayerRenderer);
}
}
void WebGLLayerChromium::rateLimitContext(Timer<WebGLLayerChromium>*)
{
TRACE_EVENT("WebGLLayerChromium::rateLimitContext", this, 0);
if (!m_context)
return;
Extensions3DChromium* extensions = static_cast<Extensions3DChromium*>(m_context->getExtensions());
extensions->rateLimitOffscreenContextCHROMIUM();
}
}
#endif // USE(ACCELERATED_COMPOSITING)