void ShaderProgram::drawVideoLayerQuad(const TransformationMatrix& drawMatrix, float* textureMatrix, SkRect& geometry, int textureId) { // switch to our custom yuv video rendering program glUseProgram(m_videoProgram); TransformationMatrix modifiedDrawMatrix = drawMatrix; modifiedDrawMatrix.translate(geometry.fLeft, geometry.fTop); modifiedDrawMatrix.scale3d(geometry.width(), geometry.height(), 1); TransformationMatrix renderMatrix = m_projectionMatrix * modifiedDrawMatrix; GLfloat projectionMatrix[16]; GLUtils::toGLMatrix(projectionMatrix, renderMatrix); glUniformMatrix4fv(m_hVideoProjectionMatrix, 1, GL_FALSE, projectionMatrix); glUniformMatrix4fv(m_hVideoTextureMatrix, 1, GL_FALSE, textureMatrix); glActiveTexture(GL_TEXTURE0); glUniform1i(m_hVideoTexSampler, 0); glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureId); glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer[0]); glEnableVertexAttribArray(m_hVideoPosition); glVertexAttribPointer(m_hVideoPosition, 2, GL_FLOAT, GL_FALSE, 0, 0); setBlendingState(false); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }
void ShaderProgram::drawVideoLayerQuad(const TransformationMatrix& drawMatrix, float* textureMatrix, SkRect& geometry, int textureId) { // switch to our custom yuv video rendering program glUseProgram(m_handleArray[Video].programHandle); // TODO: Merge drawVideoLayerQuad into drawQuad. TransformationMatrix modifiedDrawMatrix; modifiedDrawMatrix.scale3d(m_currentScale, m_currentScale, 1); modifiedDrawMatrix.multiply(drawMatrix); modifiedDrawMatrix.translate(geometry.fLeft, geometry.fTop); modifiedDrawMatrix.scale3d(geometry.width(), geometry.height(), 1); TransformationMatrix renderMatrix = m_clipProjectionMatrix * m_webViewMatrix * modifiedDrawMatrix; GLfloat projectionMatrix[16]; GLUtils::toGLMatrix(projectionMatrix, renderMatrix); glUniformMatrix4fv(m_handleArray[Video].projMtxHandle, 1, GL_FALSE, projectionMatrix); glUniformMatrix4fv(m_handleArray[Video].videoMtxHandle, 1, GL_FALSE, textureMatrix); glActiveTexture(GL_TEXTURE0); glUniform1i(m_handleArray[Video].texSamplerHandle, 0); glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureId); GLint videoPosition = m_handleArray[Video].positionHandle; glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer[0]); glEnableVertexAttribArray(videoPosition); glVertexAttribPointer(videoPosition, 2, GL_FLOAT, GL_FALSE, 0, 0); setBlendingState(false); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }
void ShaderProgram::drawQuad(const DrawQuadData* data) { GLfloat* matrix = getTileProjectionMatrix(data); float opacity = data->opacity(); bool forceBlending = data->forceBlending(); bool enableBlending = forceBlending || opacity < 1.0; ShaderType shaderType = UndefinedShader; int textureId = 0; GLint textureFilter = 0; GLenum textureTarget = 0; Color quadColor = data->quadColor(); if (data->pureColor()) { shaderType = PureColor; quadColor = shaderColor(quadColor, opacity); enableBlending = enableBlending || quadColor.hasAlpha(); if (!quadColor.alpha() && enableBlending) return; } else { textureId = data->textureId(); textureFilter = GL_LINEAR; textureTarget = data->textureTarget(); shaderType = getTextureShaderType(textureTarget, data->hasRepeatScale()); } setBlendingState(enableBlending); drawQuadInternal(shaderType, matrix, textureId, opacity, textureTarget, textureFilter, quadColor, data->fillPortion(), data->repeatScale()); }
void ShaderProgram::drawLayerQuad(const TransformationMatrix& drawMatrix, const SkRect& geometry, int textureId, float opacity, bool forceBlending, GLenum textureTarget) { TransformationMatrix modifiedDrawMatrix = drawMatrix; // move the drawing depending on where the texture is on the layer modifiedDrawMatrix.translate(geometry.fLeft, geometry.fTop); modifiedDrawMatrix.scale3d(geometry.width(), geometry.height(), 1); TransformationMatrix renderMatrix; if (!m_alphaLayer) renderMatrix = m_projectionMatrix * m_repositionMatrix * m_webViewMatrix * modifiedDrawMatrix; else renderMatrix = m_projectionMatrix * modifiedDrawMatrix; GLfloat projectionMatrix[16]; GLUtils::toGLMatrix(projectionMatrix, renderMatrix); if (textureTarget == GL_TEXTURE_2D) { if (!TilesManager::instance()->invertedScreen()) { drawLayerQuadInternal(projectionMatrix, textureId, opacity, GL_TEXTURE_2D, m_program, m_hProjectionMatrix, m_hTexSampler, m_hPosition, m_hAlpha); } else { drawLayerQuadInternal(projectionMatrix, textureId, opacity, GL_TEXTURE_2D, m_programInverted, m_hProjectionMatrixInverted, m_hTexSamplerInverted, m_hPositionInverted, m_hAlphaInverted, m_hContrastInverted); } } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES && !TilesManager::instance()->invertedScreen()) { drawLayerQuadInternal(projectionMatrix, textureId, opacity, GL_TEXTURE_EXTERNAL_OES, m_surfTexOESProgram, m_hSTOESProjectionMatrix, m_hSTOESTexSampler, m_hSTOESPosition, m_hSTOESAlpha); } else if (textureTarget == GL_TEXTURE_EXTERNAL_OES && TilesManager::instance()->invertedScreen()) { drawLayerQuadInternal(projectionMatrix, textureId, opacity, GL_TEXTURE_EXTERNAL_OES, m_surfTexOESProgramInverted, m_hSTOESProjectionMatrixInverted, m_hSTOESTexSamplerInverted, m_hSTOESPositionInverted, m_hSTOESAlphaInverted, m_hSTOESContrastInverted); } setBlendingState(forceBlending || opacity < 1.0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); GLUtils::checkGlError("drawLayerQuad"); }
void ShaderProgram::drawQuadInternal(SkRect& geometry, GLint textureId, float opacity, GLint program, GLint projectionMatrixHandle, GLint texSampler, GLenum textureTarget, GLint position, GLint alpha, GLint texFilter, GLint contrast) { glUseProgram(program); if (!geometry.isEmpty()) setProjectionMatrix(geometry, projectionMatrixHandle); else { TransformationMatrix matrix; // Map x,y from (0,1) to (-1, 1) matrix.scale3d(2, 2, 1); matrix.translate3d(-0.5, -0.5, 0); GLfloat projectionMatrix[16]; GLUtils::toGLMatrix(projectionMatrix, matrix); glUniformMatrix4fv(projectionMatrixHandle, 1, GL_FALSE, projectionMatrix); } glActiveTexture(GL_TEXTURE0); glUniform1i(texSampler, 0); glBindTexture(textureTarget, textureId); glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, texFilter); glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, texFilter); glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer[0]); glEnableVertexAttribArray(position); glVertexAttribPointer(position, 2, GL_FLOAT, GL_FALSE, 0, 0); glUniform1f(alpha, opacity); if (contrast != -1) glUniform1f(contrast, m_contrast); setBlendingState(opacity < 1.0); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); }