Bug 731570 - Rename and make default shaders public. r=pcwalton

Rename and make public the default shaders used in LayerRenderer, and make
loadShader a public, static method. This should make it easier for layers to
implement their own shader programs.
This commit is contained in:
Chris Lord 2012-03-02 12:12:08 +00:00
parent e2adb8c58b
commit f8ecc16e00
2 changed files with 15 additions and 15 deletions

View File

@ -353,7 +353,7 @@ public class GeckoLayerClient implements GeckoEventResponder,
// Create the shaders and textures if necessary.
if (!mLayerRendererInitialized) {
mLayerRenderer.checkMonitoringEnabled();
mLayerRenderer.createProgram();
mLayerRenderer.createDefaultProgram();
mLayerRendererInitialized = true;
}
@ -365,12 +365,12 @@ public class GeckoLayerClient implements GeckoEventResponder,
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
public void activateProgram() {
mLayerRenderer.activateProgram();
mLayerRenderer.activateDefaultProgram();
}
/** This function is invoked by Gecko via JNI; be careful when modifying signature. */
public void deactivateProgram() {
mLayerRenderer.deactivateProgram();
mLayerRenderer.deactivateDefaultProgram();
}
/** Implementation of FlexibleGLSurfaceView.Listener */

View File

@ -126,7 +126,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
// column-major matrix applied to each vertex to shift the viewport from
// one ranging from (-1, -1),(1,1) to (0,0),(1,1) and to scale all sizes by
// a factor of 2 to fill up the screen
private static final float[] TEXTURE_MATRIX = {
public static final float[] DEFAULT_TEXTURE_MATRIX = {
2.0f, 0.0f, 0.0f, 0.0f,
0.0f, 2.0f, 0.0f, 0.0f,
0.0f, 0.0f, 2.0f, 0.0f,
@ -137,7 +137,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
// The shaders run on the GPU directly, the vertex shader is only applying the
// matrix transform detailed above
private static final String VERTEX_SHADER =
public static final String DEFAULT_VERTEX_SHADER =
"uniform mat4 uTMatrix;\n" +
"attribute vec4 vPosition;\n" +
"attribute vec2 aTexCoord;\n" +
@ -150,7 +150,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
// Note we flip the y-coordinate in the fragment shader from a
// coordinate system with (0,0) in the top left to one with (0,0) in
// the bottom left.
private static final String FRAGMENT_SHADER =
public static final String DEFAULT_FRAGMENT_SHADER =
"precision mediump float;\n" +
"varying vec2 vTexCoord;\n" +
"uniform sampler2D sTexture;\n" +
@ -188,13 +188,13 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
checkMonitoringEnabled();
createProgram();
activateProgram();
createDefaultProgram();
activateDefaultProgram();
}
public void createProgram() {
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, VERTEX_SHADER);
int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
public void createDefaultProgram() {
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, DEFAULT_VERTEX_SHADER);
int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, DEFAULT_FRAGMENT_SHADER);
mProgram = GLES20.glCreateProgram();
GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
@ -213,12 +213,12 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
}
// Activates the shader program.
public void activateProgram() {
public void activateDefaultProgram() {
// Add the program to the OpenGL environment
GLES20.glUseProgram(mProgram);
// Set the transformation matrix
GLES20.glUniformMatrix4fv(mTMatrixHandle, 1, false, TEXTURE_MATRIX, 0);
GLES20.glUniformMatrix4fv(mTMatrixHandle, 1, false, DEFAULT_TEXTURE_MATRIX, 0);
Log.e(LOGTAG, "### Position handle is " + mPositionHandle + ", texture handle is " +
mTextureHandle + ", last error is " + GLES20.glGetError());
@ -237,7 +237,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
// Deactivates the shader program. This must be done to avoid crashes after returning to the
// Gecko C++ compositor from Java.
public void deactivateProgram() {
public void deactivateDefaultProgram() {
GLES20.glDisableVertexAttribArray(mTextureHandle);
GLES20.glDisableVertexAttribArray(mPositionHandle);
GLES20.glUseProgram(0);
@ -445,7 +445,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer {
* create a vertex shader type (GLES20.GL_VERTEX_SHADER)
* or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
*/
private int loadShader(int type, String shaderCode) {
public static int loadShader(int type, String shaderCode) {
int shader = GLES20.glCreateShader(type);
GLES20.glShaderSource(shader, shaderCode);
GLES20.glCompileShader(shader);