コード例 #1
0
void LayerCompositingThread::drawSurface(const TransformationMatrix& drawTransform, LayerCompositingThread* mask, const GLES2Program& program)
{
    using namespace BlackBerry::Platform::Graphics;

    if (m_layerRenderer->layerAlreadyOnSurface(this)) {
        Texture* surfaceTexture = layerRendererSurface()->texture();
        if (!surfaceTexture) {
            ASSERT_NOT_REACHED();
            return;
        }
        textureCacheCompositingThread()->textureAccessed(layerRendererSurface()->texture());
        GLuint surfaceTexID = reinterpret_cast<GLuint>(platformBufferHandle(surfaceTexture->textureId()));

        if (!surfaceTexID) {
            ASSERT_NOT_REACHED();
            return;
        }

        if (mask) {
            Texture* maskTexture = mask->contentsTexture();
            if (maskTexture) {
                GLuint maskTexID = reinterpret_cast<GLuint>(platformBufferHandle(maskTexture->textureId()));

                // Force creation if it's 0
                if (!maskTexID) {
                    // This call will cause display list to render to backing, which can mutate a lot of GL state.
                    GLES2ContextState::ProgramStateSaver programSaver;
                    GLES2ContextState::TextureAndFBOStateSaver textureSaver;
                    lockAndBindBufferGLTexture(maskTexture->textureId(), GL_TEXTURE_2D);
                    maskTexID = reinterpret_cast<GLuint>(platformBufferHandle(maskTexture->textureId()));
                }

                glActiveTexture(GL_TEXTURE1);
                glBindTexture(GL_TEXTURE_2D, maskTexID);
                glActiveTexture(GL_TEXTURE0);
            }
        }

        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        glBindTexture(GL_TEXTURE_2D, surfaceTexID);

        FloatQuad surfaceQuad = getTransformedRect(m_bounds, IntRect(IntPoint::zero(), m_bounds), drawTransform);
        glEnableVertexAttribArray(program.positionLocation());
        glEnableVertexAttribArray(program.texCoordLocation());
        glUniform1f(program.opacityLocation(), layerRendererSurface()->drawOpacity());
        glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &surfaceQuad);

        static float texcoords[4 * 2] = { 0, 0,  0, 1,  1, 1,  1, 0 };
        glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, texcoords);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    }
}
コード例 #2
0
void LayerCompositingThread::drawTextures(double scale, const GLES2Program& program, const FloatRect& visibleRect)
{
    static float texcoords[4 * 2] = { 0, 0,  0, 1,  1, 1,  1, 0 };

    if (m_pluginView) {
        if (m_isVisible) {
            // The layer contains Flash, video, or other plugin contents.
            m_pluginBuffer = m_pluginView->lockFrontBufferForRead();

            if (!m_pluginBuffer)
                return;

            if (!BlackBerry::Platform::Graphics::lockAndBindBufferGLTexture(m_pluginBuffer, GL_TEXTURE_2D)) {
                m_pluginView->unlockFrontBuffer();
                return;
            }

            m_layerRenderer->addLayerToReleaseTextureResourcesList(this);

            glEnable(GL_BLEND);
            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
            glEnableVertexAttribArray(program.positionLocation());
            glEnableVertexAttribArray(program.texCoordLocation());
            glUniform1f(program.opacityLocation(), drawOpacity());
            glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &m_transformedBounds);
            glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, texcoords);
            glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
        }
        return;
    }
#if ENABLE(VIDEO)
    if (m_mediaPlayer) {
        if (m_isVisible) {
            // We need to specify the media player location in contents coordinates. The 'visibleRect'
            // specifies the content region covered by our viewport. So we transform from our
            // normalized device coordinates [-1, 1] to the 'visibleRect'.
            float vrw2 = visibleRect.width() / 2.0;
            float vrh2 = visibleRect.height() / 2.0;
            float x = m_transformedBounds.p1().x() * vrw2 + vrw2 + visibleRect.x();
            float y = -m_transformedBounds.p1().y() * vrh2 + vrh2 + visibleRect.y();
            m_mediaPlayer->paint(0, IntRect((int)(x + 0.5), (int)(y + 0.5), m_bounds.width(), m_bounds.height()));
            MediaPlayerPrivate* mpp = static_cast<MediaPlayerPrivate*>(m_mediaPlayer->platformMedia().media.qnxMediaPlayer);
            mpp->drawBufferingAnimation(m_drawTransform, program);
        }
        return;
    }
#endif

    if (m_client)
        m_client->drawTextures(this, scale, program);
}
コード例 #3
0
void EGLImageLayerCompositingThreadClient::drawTextures(LayerCompositingThread* layer, const GLES2Program& program, double /*scale*/, const FloatRect& /*clipRect*/)
{
    if (!m_textureAccessor || !m_textureAccessor->textureID())
        return;

    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
    glUseProgram(program.m_program);
    glUniform1f(program.opacityLocation(), layer->drawOpacity());
    glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, layer->transformedBounds().data());
    glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, layer->textureCoordinates(LayerCompositingThread::UpsideDown).data());
    glBindTexture(GL_TEXTURE_2D, m_textureAccessor->textureID());
    glDrawArrays(GL_TRIANGLE_FAN, 0, layer->transformedBounds().size());
}
コード例 #4
0
void LayerCompositingThread::drawSurface(const TransformationMatrix& drawTransform, LayerCompositingThread* mask, const GLES2Program& program)
{
    using namespace BlackBerry::Platform::Graphics;

    if (m_layerRenderer->layerAlreadyOnSurface(this)) {
        LayerTexture* surfaceTexture = layerRendererSurface()->texture();
        if (!surfaceTexture) {
            ASSERT_NOT_REACHED();
            return;
        }
        textureCacheCompositingThread()->textureAccessed(layerRendererSurface()->texture());
        GLuint surfaceTexID = surfaceTexture->platformTexture();

        if (!surfaceTexID) {
            ASSERT_NOT_REACHED();
            return;
        }

        if (mask) {
            if (LayerTexture* maskTexture = mask->contentsTexture()) {
                GLuint maskTexID = maskTexture->platformTexture();

                glActiveTexture(GL_TEXTURE1);
                glBindTexture(GL_TEXTURE_2D, maskTexID);
                glActiveTexture(GL_TEXTURE0);
            }
        }

        glEnable(GL_BLEND);
        glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        glBindTexture(GL_TEXTURE_2D, surfaceTexID);

        FloatQuad surfaceQuad = drawTransform.mapQuad(FloatRect(-origin(), bounds()));
        glUniform1f(program.opacityLocation(), layerRendererSurface()->drawOpacity());
        glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, &surfaceQuad);

        static float texcoords[4 * 2] = { 0, 0,  1, 0,  1, 1,  0, 1 };
        glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, texcoords);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    }
}