void CanvasLayerWebKitThread::updateTextureContentsIfNeeded()
{
    if (!m_needsDisplay || !m_device)
        return;

    m_needsDisplay = false;
    m_device->makeRenderTargetCurrent();

    GLint previousTexture;
    glGetIntegerv(GL_TEXTURE_BINDING_2D, &previousTexture);

    if (!m_texID) {
        glGenTextures(1, &m_texID);
        glBindTexture(GL_TEXTURE_2D, m_texID);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_device->width(), m_device->height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);

        createFrontBufferLock();
    }

    pthread_mutex_lock(m_frontBufferLock);
    glBindTexture(GL_TEXTURE_2D, m_texID);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, m_device->width(), m_device->height(), 0);
    glBindTexture(GL_TEXTURE_2D, previousTexture);
    pthread_mutex_unlock(m_frontBufferLock);
}
void WebGLLayerWebKitThread::updateTextureContentsIfNeeded()
{
    // FIXME: Does WebGLLayer always need display? Or can we just return immediately if (!m_needsDisplay)?
    m_needsDisplay = false;

    if (!m_frontBufferLock)
        createFrontBufferLock();

    // Lock copied GL texture so that the UI thread won't access it while we are drawing into it.
    pthread_mutex_lock(m_frontBufferLock);
    m_webGLContext->prepareTexture();
    pthread_mutex_unlock(m_frontBufferLock);
}