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
Родитель 8e95565784
Коммит 516db8b9ac
2 изменённых файлов: 15 добавлений и 15 удалений

Просмотреть файл

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

Просмотреть файл

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