Bug 771746 - Some cleanup in ScrollbarLayer.java. r=Cwiiis
authorKartikaya Gupta <kgupta@mozilla.com>
Sat, 29 Dec 2012 15:22:59 -0500
changeset 126329 97542ba6b0aa408d7918bea31c401c6db457ab47
parent 126328 33d3e7354bf964576ff49a96e70eb39b1a619278
child 126330 d462bf431ae4725d865b9504249fbff87918716a
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersCwiiis
bugs771746
milestone20.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 771746 - Some cleanup in ScrollbarLayer.java. r=Cwiiis
mobile/android/base/gfx/ScrollbarLayer.java
--- a/mobile/android/base/gfx/ScrollbarLayer.java
+++ b/mobile/android/base/gfx/ScrollbarLayer.java
@@ -27,18 +27,16 @@ public class ScrollbarLayer extends Tile
     public static final long FADE_DELAY = 500; // milliseconds before fade-out starts
     private static final float FADE_AMOUNT = 0.03f; // how much (as a percent) the scrollbar should fade per frame
 
     private static final int PADDING = 1;   // gap between scrollbar and edge of viewport
     private static final int BAR_SIZE = 6;
     private static final int CAP_RADIUS = (BAR_SIZE / 2);
 
     private final boolean mVertical;
-    private final Bitmap mBitmap;
-    private final Canvas mCanvas;
     private float mOpacity;
 
     // To avoid excessive GC, declare some objects here that would otherwise
     // be created and destroyed frequently during draw().
     private final RectF mBarRectF;
     private final Rect mBarRect;
     private final float[] mCoords;
     private final RectF mCapRectF;
@@ -73,29 +71,29 @@ public class ScrollbarLayer extends Tile
     private static final Rect BOT_CAP_TEX_COORDS = new Rect(0, TEX_HEIGHT - BAR_SIZE, BAR_SIZE, TEX_HEIGHT - CAP_RADIUS);
 
     private ScrollbarLayer(LayerRenderer renderer, CairoImage image, boolean vertical, ByteBuffer buffer) {
         super(image, TileLayer.PaintMode.NORMAL);
         mVertical = vertical;
         mRenderer = renderer;
 
         IntSize size = image.getSize();
-        mBitmap = Bitmap.createBitmap(size.width, size.height, Bitmap.Config.ARGB_8888);
-        mCanvas = new Canvas(mBitmap);
+        Bitmap bitmap = Bitmap.createBitmap(size.width, size.height, Bitmap.Config.ARGB_8888);
+        Canvas canvas = new Canvas(bitmap);
 
         // Paint a spot to use as the scroll indicator
         Paint foregroundPaint = new Paint();
         foregroundPaint.setAntiAlias(true);
         foregroundPaint.setStyle(Paint.Style.FILL);
         foregroundPaint.setColor(Color.argb(127, 0, 0, 0));
 
-        mCanvas.drawColor(Color.argb(0, 0, 0, 0), PorterDuff.Mode.CLEAR);
-        mCanvas.drawCircle(CAP_RADIUS, CAP_RADIUS, CAP_RADIUS, foregroundPaint);
+        canvas.drawColor(Color.argb(0, 0, 0, 0), PorterDuff.Mode.CLEAR);
+        canvas.drawCircle(CAP_RADIUS, CAP_RADIUS, CAP_RADIUS, foregroundPaint);
 
-        mBitmap.copyPixelsToBuffer(buffer.asIntBuffer());
+        bitmap.copyPixelsToBuffer(buffer.asIntBuffer());
 
         mBarRectF = new RectF();
         mBarRect = new Rect();
         mCoords = new float[20];
         mCapRectF = new RectF();
     }
 
     public static ScrollbarLayer create(LayerRenderer renderer, boolean vertical) {
@@ -224,116 +222,71 @@ public class ScrollbarLayer extends Tile
         coordBuffer.position(0);
         coordBuffer.put(mCoords);
 
         // Unbind any the current array buffer so we can use client side buffers
         GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
 
         // Vertex coordinates are x,y,z starting at position 0 into the buffer.
         coordBuffer.position(0);
-        GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20,
-                coordBuffer);
+        GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20, coordBuffer);
 
         // Texture coordinates are texture_x, texture_y starting at position 3 into the buffer.
         coordBuffer.position(3);
-        GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20,
-                coordBuffer);
+        GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20, coordBuffer);
 
         GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
 
         // Reset the position in the buffer for the next set of vertex and texture coordinates.
         coordBuffer.position(0);
-
         if (mVertical) {
             // top endcap
             mCapRectF.set(mBarRectF.left, mBarRectF.top + CAP_RADIUS, mBarRectF.left + BAR_SIZE, mBarRectF.top);
             fillRectCoordBuffer(mCoords, mCapRectF, viewWidth, viewHeight, TOP_CAP_TEX_COORDS, TEX_WIDTH, TEX_HEIGHT);
-
-            coordBuffer.put(mCoords);
+        } else {
+            mCapRectF.set(mBarRectF.left - CAP_RADIUS, mBarRectF.bottom + BAR_SIZE, mBarRectF.left, mBarRectF.bottom);
+            fillRectCoordBuffer(mCoords, mCapRectF, viewWidth, viewHeight, LEFT_CAP_TEX_COORDS, TEX_WIDTH, TEX_HEIGHT);
+        }
+        coordBuffer.put(mCoords);
 
-            // Vertex coordinates are x,y,z starting at position 0 into the buffer.
-            coordBuffer.position(0);
-            GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
+        // Vertex coordinates are x,y,z starting at position 0 into the buffer.
+        coordBuffer.position(0);
+        GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20, coordBuffer);
 
-            // Texture coordinates are texture_x, texture_y starting at position 3 into the
-            // buffer.
-            coordBuffer.position(3);
-            GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
+        // Texture coordinates are texture_x, texture_y starting at position 3 into the buffer.
+        coordBuffer.position(3);
+        GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20, coordBuffer);
 
-            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
+        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
 
-            // Reset the position in the buffer for the next set of vertex and texture
-            // coordinates.
-            coordBuffer.position(0);
-
+        // Reset the position in the buffer for the next set of vertex and texture coordinates.
+        coordBuffer.position(0);
+        if (mVertical) {
             // bottom endcap
             mCapRectF.set(mBarRectF.left, mBarRectF.bottom, mBarRectF.left + BAR_SIZE, mBarRectF.bottom - CAP_RADIUS);
             fillRectCoordBuffer(mCoords, mCapRectF, viewWidth, viewHeight, BOT_CAP_TEX_COORDS, TEX_WIDTH, TEX_HEIGHT);
-
-            coordBuffer.put(mCoords);
-
-            // Vertex coordinates are x,y,z starting at position 0 into the buffer.
-            coordBuffer.position(0);
-            GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
-
-            // Texture coordinates are texture_x, texture_y starting at position 3 into the
-            // buffer.
-            coordBuffer.position(3);
-            GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
-
-            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
-
-            // Reset the position in the buffer for the next set of vertex and texture
-            // coordinates.
-            coordBuffer.position(0);
         } else {
-            // left endcap
-            mCapRectF.set(mBarRectF.left - CAP_RADIUS, mBarRectF.bottom + BAR_SIZE, mBarRectF.left, mBarRectF.bottom);
-            fillRectCoordBuffer(mCoords, mCapRectF, viewWidth, viewHeight, LEFT_CAP_TEX_COORDS, TEX_WIDTH, TEX_HEIGHT);
-            coordBuffer.put(mCoords);
-
-            // Vertex coordinates are x,y,z starting at position 0 into the buffer.
-            coordBuffer.position(0);
-            GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
-
-            // Texture coordinates are texture_x, texture_y starting at position 3 into the
-            // buffer.
-            coordBuffer.position(3);
-            GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
-
-            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
-
-            // Reset the position in the buffer for the next set of vertex and texture
-            // coordinates.
-            coordBuffer.position(0);
-
             // right endcap
             mCapRectF.set(mBarRectF.right, mBarRectF.bottom + BAR_SIZE, mBarRectF.right + CAP_RADIUS, mBarRectF.bottom);
             fillRectCoordBuffer(mCoords, mCapRectF, viewWidth, viewHeight, RIGHT_CAP_TEX_COORDS, TEX_WIDTH, TEX_HEIGHT);
-            coordBuffer.put(mCoords);
+        }
+        coordBuffer.put(mCoords);
 
-            // Vertex coordinates are x,y,z starting at position 0 into the buffer.
-            coordBuffer.position(0);
-            GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
+        // Vertex coordinates are x,y,z starting at position 0 into the buffer.
+        coordBuffer.position(0);
+        GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT, false, 20, coordBuffer);
 
-            // Texture coordinates are texture_x, texture_y starting at position 3 into the
-            // buffer.
-            coordBuffer.position(3);
-            GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20,
-                    coordBuffer);
+        // Texture coordinates are texture_x, texture_y starting at position 3 into the buffer.
+        coordBuffer.position(3);
+        GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT, false, 20, coordBuffer);
 
-            GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
-        }
+        GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
+
+        // Reset the position in the buffer for the next set of vertex and texture coordinates.
+        coordBuffer.position(0);
 
         // Enable the default shader program again
         deactivateProgram();
         mRenderer.activateDefaultProgram();
     }
 
     private void getVerticalRect(RenderContext context, RectF dest) {
         RectF viewport = context.viewport;