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); } }
void LayerCompositingThread::drawTextures(double scale, const GLES2Program& program, const FloatRect& visibleRect) { 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); glUniform1f(program.opacityLocation(), drawOpacity()); glVertexAttribPointer(program.positionLocation(), 2, GL_FLOAT, GL_FALSE, 0, m_transformedBounds.data()); glVertexAttribPointer(program.texCoordLocation(), 2, GL_FLOAT, GL_FALSE, 0, textureCoordinates().data()); glDrawArrays(GL_TRIANGLE_FAN, 0, m_transformedBounds.size()); } return; } #if ENABLE(VIDEO) if (m_mediaPlayer) { if (m_isVisible) { IntRect paintRect; if (m_layerRenderer->client()->shouldChildWindowsUseDocumentCoordinates()) { // 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; FloatPoint p(m_transformedBounds[0].x() * vrw2 + vrw2 + visibleRect.x(), -m_transformedBounds[0].y() * vrh2 + vrh2 + visibleRect.y()); paintRect = IntRect(roundedIntPoint(p), m_bounds); } else paintRect = m_layerRenderer->toWindowCoordinates(m_boundingBox); m_mediaPlayer->paint(0, paintRect); 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); }
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()); }
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); } }