6package org.mozilla.gecko.gfx;
8import android.graphics.Bitmap;
9import android.graphics.Canvas;
10import android.graphics.Color;
11import android.graphics.Paint;
12import android.graphics.PorterDuff;
13import android.graphics.Rect;
14import android.graphics.RectF;
15import android.opengl.GLES20;
20import java.nio.ByteBuffer;
21import java.nio.FloatBuffer;
50 "precision mediump float;\n" +
51 "varying vec2 vTexCoord;\n" +
52 "uniform sampler2D sTexture;\n" +
53 "uniform float uOpacity;\n" +
55 " gl_FragColor = texture2D(sTexture, vec2(vTexCoord.x, 1.0 - vTexCoord.y));\n" +
56 " gl_FragColor.a *= uOpacity;\n" +
120 foregroundPaint.setAntiAlias(
true);
121 foregroundPaint.setStyle(
Paint.Style.FILL);
122 foregroundPaint.setColor(
Color.argb(127, 0, 0, 0));
124 mCanvas.drawColor(
Color.argb(0, 0, 0, 0), PorterDuff.Mode.CLEAR);
127 mBitmap.copyPixelsToBuffer(buffer.asIntBuffer());
146 mProgram = GLES20.glCreateProgram();
147 GLES20.glAttachShader(
mProgram, vertexShader);
148 GLES20.glAttachShader(
mProgram, fragmentShader);
178 GLES20.glUseProgram(0);
226 GLES20.glEnable(GLES20.GL_BLEND);
227 GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);
232 GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
getTextureID());
234 float viewWidth = context.
viewport.width();
235 float viewHeight = context.
viewport.height();
237 float top = viewHeight - rect.top;
238 float bot = viewHeight - rect.bottom;
241 float[] bodyCoords = {
243 rect.left/viewWidth, bot/viewHeight, 0,
246 rect.left/viewWidth, (bot+rect.height())/viewHeight, 0,
249 (rect.left+rect.width())/viewWidth, bot/viewHeight, 0,
252 (rect.left+rect.width())/viewWidth, (bot+rect.height())/viewHeight, 0,
263 coordBuffer.position(0);
264 coordBuffer.put(bodyCoords);
267 GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
270 coordBuffer.position(0);
271 GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT,
false, 20,
275 coordBuffer.position(3);
276 GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT,
false, 20,
279 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
282 coordBuffer.position(0);
288 rect.left/viewWidth,
top/viewHeight, 0,
301 coordBuffer.put(topCap);
304 coordBuffer.position(0);
305 GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT,
false, 20,
310 coordBuffer.position(3);
311 GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT,
false, 20,
314 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
318 coordBuffer.position(0);
323 rect.left/viewWidth, (bot-
CAP_RADIUS)/viewHeight, 0,
326 rect.left/viewWidth, (bot)/viewHeight, 0,
332 (rect.left+
BAR_SIZE)/viewWidth, (bot)/viewHeight, 0,
336 coordBuffer.put(botCap);
339 coordBuffer.position(0);
340 GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT,
false, 20,
345 coordBuffer.position(3);
346 GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT,
false, 20,
349 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
353 coordBuffer.position(0);
358 (rect.left-
CAP_RADIUS)/viewWidth, bot/viewHeight, 0,
364 (rect.left)/viewWidth, (bot+
BAR_SIZE)/viewHeight, 0,
368 coordBuffer.put(leftCap);
371 coordBuffer.position(0);
372 GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT,
false, 20,
377 coordBuffer.position(3);
378 GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT,
false, 20,
381 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
385 coordBuffer.position(0);
390 rect.right/viewWidth, (bot)/viewHeight, 0,
393 rect.right/viewWidth, (bot+
BAR_SIZE)/viewHeight, 0,
396 (rect.right+
CAP_RADIUS)/viewWidth, (bot)/viewHeight, 0,
403 coordBuffer.put(rightCap);
406 coordBuffer.position(0);
407 GLES20.glVertexAttribPointer(positionHandle, 3, GLES20.GL_FLOAT,
false, 20,
412 coordBuffer.position(3);
413 GLES20.glVertexAttribPointer(textureHandle, 2, GLES20.GL_FLOAT,
false, 20,
416 GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
427 float barStart = ((viewport.top - pageRect.top) * (viewport.height() / pageRect.height())) +
CAP_RADIUS;
428 float barEnd = ((viewport.bottom - pageRect.top) * (viewport.height() / pageRect.height())) -
CAP_RADIUS;
429 if (barStart > barEnd) {
430 float middle = (barStart + barEnd) / 2.0f;
431 barStart = barEnd =
middle;
440 float barStart = ((viewport.left - pageRect.left) * (viewport.width() / pageRect.width())) +
CAP_RADIUS;
441 float barEnd = ((viewport.right - pageRect.left) * (viewport.width() / pageRect.width())) -
CAP_RADIUS;
442 if (barStart > barEnd) {
443 float middle = (barStart + barEnd) / 2.0f;
444 barStart = barEnd =
middle;
A Cairo image that simply saves a buffer of pixel data.
static final int FORMAT_ARGB32
abstract IntSize getSize()
static int nextPowerOfTwo(int value)
The layer renderer implements the rendering logic for a layer view.
static final float[] DEFAULT_TEXTURE_MATRIX
static int loadShader(int type, String shaderCode)
void deactivateDefaultProgram()
static final String DEFAULT_VERTEX_SHADER
void activateDefaultProgram()
A view rendered by the layer compositor.
final FloatBuffer coordBuffer
void endTransaction()
Call this when you're done modifying the layer.
void beginTransaction()
Call this before modifying the layer.
static Rect round(RectF rect)
Returns the nearest integer rect of the given rect.
Base class for tile layers, which encapsulate the logic needed to draw textured tiles in OpenGL ES.
static boolean fuzzyEquals(float a, float b)
Size imageSize(const sk_sp< SkImage > &image)