Bug 731570 - Rename and make default shaders public. r=pcwalton
authorChris Lord <chrislord.net@gmail.com>
Fri, 02 Mar 2012 12:12:08 +0000
changeset 89287 181ef48393832c7579222b4214bf5b28980f8e8d
parent 89286 344ff7ba940f68f65eea10e1089ed953a2584564
child 89288 e595d6c1d837e9da412d40e8c2100857f6eb866f
push id22242
push userkgupta@mozilla.com
push dateWed, 14 Mar 2012 15:19:09 +0000
treeherdermozilla-central@936ef50fa498 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
bugs731570
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
mobile/android/base/gfx/GeckoLayerClient.java
mobile/android/base/gfx/LayerRenderer.java
--- a/mobile/android/base/gfx/GeckoLayerClient.java
+++ b/mobile/android/base/gfx/GeckoLayerClient.java
@@ -348,34 +348,34 @@ public class GeckoLayerClient implements
         }
     }
 
     /** This function is invoked by Gecko via JNI; be careful when modifying signature. */
     public LayerRenderer.Frame createFrame() {
         // Create the shaders and textures if necessary.
         if (!mLayerRendererInitialized) {
             mLayerRenderer.checkMonitoringEnabled();
-            mLayerRenderer.createProgram();
+            mLayerRenderer.createDefaultProgram();
             mLayerRendererInitialized = true;
         }
 
         // Build the contexts and create the frame.
         Layer.RenderContext pageContext = mLayerRenderer.createPageContext();
         Layer.RenderContext screenContext = mLayerRenderer.createScreenContext();
         return mLayerRenderer.createFrame(pageContext, screenContext);
     }
 
     /** 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 */
     public void renderRequested() {
         Log.e(LOGTAG, "### Render requested, scheduling composite");
         GeckoAppShell.scheduleComposite();
     }
 
--- a/mobile/android/base/gfx/LayerRenderer.java
+++ b/mobile/android/base/gfx/LayerRenderer.java
@@ -121,41 +121,41 @@ public class LayerRenderer implements GL
     private int mPositionHandle;
     private int mTextureHandle;
     private int mSampleHandle;
     private int mTMatrixHandle;
 
     // 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,
         -1.0f, -1.0f, 0.0f, 1.0f
     };
 
     private static final int COORD_BUFFER_SIZE = 20;
 
     // 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" +
         "varying vec2 vTexCoord;\n" +
         "void main() {\n" +
         "    gl_Position = uTMatrix * vPosition;\n" +
         "    vTexCoord = aTexCoord;\n" +
         "}\n";
 
     // 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" +
         "void main() {\n" +
         "    gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, 1.0 - vTexCoord.y));\n" +
         "}\n";
 
     public LayerRenderer(LayerView view) {
@@ -183,23 +183,23 @@ public class LayerRenderer implements GL
         // coordinates in draw() commands.
         ByteBuffer byteBuffer = GeckoAppShell.allocateDirectBuffer(COORD_BUFFER_SIZE * 4);
         byteBuffer.order(ByteOrder.nativeOrder());
         mCoordBuffer = byteBuffer.asFloatBuffer();
     }
 
     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
         GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
         GLES20.glLinkProgram(mProgram);                  // creates OpenGL program executables
 
         // Get handles to the vertex shader's vPosition, aTexCoord, sTexture, and uTMatrix members.
         mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
@@ -208,22 +208,22 @@ public class LayerRenderer implements GL
         mTMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uTMatrix");
 
         int maxTextureSizeResult[] = new int[1];
         GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSizeResult, 0);
         mMaxTextureSize = maxTextureSizeResult[0];
     }
 
     // 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());
 
         // Enable the arrays from which we get the vertex and texture coordinates
         GLES20.glEnableVertexAttribArray(mPositionHandle);
         GLES20.glEnableVertexAttribArray(mTextureHandle);
 
@@ -232,17 +232,17 @@ public class LayerRenderer implements GL
         TextureGenerator.get().fill();
 
         // TODO: Move these calls into a separate deactivate() call that is called after the
         // underlay and overlay are rendered.
     }
 
     // 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);
     }
 
     public int getMaxTextureSize() {
         return mMaxTextureSize;
     }
@@ -440,17 +440,17 @@ public class LayerRenderer implements GL
 
         mCheckerboardLayer.update(renderContext);   // called on compositor thread
     }
 
     /*
      * 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);
         return shader;
     }
 
     public Frame createFrame(RenderContext pageContext, RenderContext screenContext) {
         return new Frame(pageContext, screenContext);