summaryrefslogtreecommitdiffstats
path: root/WebCore/platform
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2011-01-29 11:54:52 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-01-29 11:54:52 -0800
commite991ae38e756dc1efe730946f95747e42e5a920a (patch)
tree1468c51d2a8d60eaf33c0bc77d2502dad3535ad4 /WebCore/platform
parent5e3e997a109b7e20ddd7e04c6ec14b01dac2f32a (diff)
parent9586d1ddb0e8c47a4983aff77bdc71333617bb7e (diff)
downloadexternal_webkit-e991ae38e756dc1efe730946f95747e42e5a920a.zip
external_webkit-e991ae38e756dc1efe730946f95747e42e5a920a.tar.gz
external_webkit-e991ae38e756dc1efe730946f95747e42e5a920a.tar.bz2
Merge "Add YUV shader for plugin video playback." into honeycomb
Diffstat (limited to 'WebCore/platform')
-rw-r--r--WebCore/platform/graphics/android/MediaTexture.cpp3
-rw-r--r--WebCore/platform/graphics/android/ShaderProgram.cpp41
-rw-r--r--WebCore/platform/graphics/android/ShaderProgram.h5
3 files changed, 48 insertions, 1 deletions
diff --git a/WebCore/platform/graphics/android/MediaTexture.cpp b/WebCore/platform/graphics/android/MediaTexture.cpp
index 71a4a0e..22fabc3 100644
--- a/WebCore/platform/graphics/android/MediaTexture.cpp
+++ b/WebCore/platform/graphics/android/MediaTexture.cpp
@@ -16,6 +16,7 @@
#include "config.h"
#include "MediaTexture.h"
#include "TilesManager.h"
+#include "GLUtils.h"
#if USE(ACCELERATED_COMPOSITING)
@@ -85,7 +86,7 @@ void VideoTexture::drawVideo(TransformationMatrix matrix)
return;
m_surfaceTexture->updateTexImage();
- TilesManager::instance()->shader()->drawLayerQuad(matrix, m_dimensions, m_textureId, 1.0f);
+ TilesManager::instance()->shader()->drawVideoLayerQuad(matrix, m_dimensions, m_textureId);
}
ANativeWindow* VideoTexture::requestNewWindow()
diff --git a/WebCore/platform/graphics/android/ShaderProgram.cpp b/WebCore/platform/graphics/android/ShaderProgram.cpp
index ed5fe42..103bb02 100644
--- a/WebCore/platform/graphics/android/ShaderProgram.cpp
+++ b/WebCore/platform/graphics/android/ShaderProgram.cpp
@@ -59,6 +59,15 @@ static const char gFragmentShader[] =
" gl_FragColor *= alpha; "
"}\n";
+static const char gVideoFragmentShader[] =
+ "#extension GL_OES_EGL_image_external : require\n"
+ "precision mediump float;\n"
+ "uniform samplerExternalOES s_yuvTexture;\n"
+ "varying vec2 v_texCoord;\n"
+ "void main() {\n"
+ " gl_FragColor = texture2D(s_yuvTexture, v_texCoord);\n"
+ "}\n";
+
GLuint ShaderProgram::loadShader(GLenum shaderType, const char* pSource)
{
GLuint shader = glCreateShader(shaderType);
@@ -125,11 +134,15 @@ GLuint ShaderProgram::createProgram(const char* pVertexSource, const char* pFrag
ShaderProgram::ShaderProgram()
{
m_program = createProgram(gVertexShader, gFragmentShader);
+ m_videoProgram = createProgram(gVertexShader, gVideoFragmentShader);
m_hProjectionMatrix = glGetUniformLocation(m_program, "projectionMatrix");
m_hAlpha = glGetUniformLocation(m_program, "alpha");
m_hTexSampler = glGetUniformLocation(m_program, "s_texture");
+ m_hVideoProjectionMatrix = glGetUniformLocation(m_videoProgram, "projectionMatrix");
+ m_hVideoTexSampler = glGetUniformLocation(m_videoProgram, "s_yuvTexture");
+
const GLfloat coord[] = {
0.0f, 0.0f, // C
1.0f, 0.0f, // D
@@ -263,6 +276,34 @@ void ShaderProgram::drawLayerQuad(const TransformationMatrix& drawMatrix,
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
+void ShaderProgram::drawVideoLayerQuad(const TransformationMatrix& drawMatrix,
+ SkRect& geometry, int textureId)
+{
+ // switch to our custom yuv video rendering program
+ glUseProgram(m_videoProgram);
+
+ TransformationMatrix renderMatrix = drawMatrix;
+ renderMatrix.translate(geometry.fLeft, geometry.fTop);
+ renderMatrix.scale3d(geometry.width(), geometry.height(), 1);
+ renderMatrix.multiply(m_projectionMatrix);
+
+ GLfloat projectionMatrix[16];
+ GLUtils::toGLMatrix(projectionMatrix, renderMatrix);
+ glUniformMatrix4fv(m_hVideoProjectionMatrix, 1, GL_FALSE, projectionMatrix);
+
+ glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureId);
+
+ glBindBuffer(GL_ARRAY_BUFFER, m_textureBuffer[0]);
+ glEnableVertexAttribArray(1);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ glBindAttribLocation(m_videoProgram, 1, "vPosition");
+
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
+
+ // switch back to our normal rendering program
+ glUseProgram(m_program);
+}
+
} // namespace WebCore
#endif // USE(ACCELERATED_COMPOSITING)
diff --git a/WebCore/platform/graphics/android/ShaderProgram.h b/WebCore/platform/graphics/android/ShaderProgram.h
index 0298594..afc36f5 100644
--- a/WebCore/platform/graphics/android/ShaderProgram.h
+++ b/WebCore/platform/graphics/android/ShaderProgram.h
@@ -40,6 +40,8 @@ class ShaderProgram {
void drawQuad(SkRect& geometry, int textureId, float opacity);
void drawLayerQuad(const TransformationMatrix& drawMatrix,
SkRect& geometry, int textureId, float opacity);
+ void drawVideoLayerQuad(const TransformationMatrix& drawMatrix,
+ SkRect& geometry, int textureId);
void setViewRect(const IntRect& viewRect);
FloatRect clipRectInScreenCoord(const TransformationMatrix& drawMatrix,
const IntSize& size);
@@ -52,6 +54,7 @@ class ShaderProgram {
void setProjectionMatrix(SkRect& geometry);
int m_program;
+ int m_videoProgram;
TransformationMatrix m_projectionMatrix;
GLuint m_textureBuffer[1];
@@ -65,6 +68,8 @@ class ShaderProgram {
int m_hProjectionMatrix;
int m_hAlpha;
int m_hTexSampler;
+ int m_hVideoProjectionMatrix;
+ int m_hVideoTexSampler;
};
} // namespace WebCore