summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/glrenderer/GLCanvas.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/gallery3d/glrenderer/GLCanvas.java')
-rw-r--r--src/com/android/gallery3d/glrenderer/GLCanvas.java119
1 files changed, 45 insertions, 74 deletions
diff --git a/src/com/android/gallery3d/glrenderer/GLCanvas.java b/src/com/android/gallery3d/glrenderer/GLCanvas.java
index 5e319f894..4cf16892e 100644
--- a/src/com/android/gallery3d/glrenderer/GLCanvas.java
+++ b/src/com/android/gallery3d/glrenderer/GLCanvas.java
@@ -20,83 +20,56 @@ import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.RectF;
-import com.android.gallery3d.common.ApiHelper;
-
-import javax.microedition.khronos.opengles.GL11;
-
//
// GLCanvas gives a convenient interface to draw using OpenGL.
//
// When a rectangle is specified in this interface, it means the region
// [x, x+width) * [y, y+height)
//
-public abstract class GLCanvas {
+public interface GLCanvas {
public enum Blending {
Additive, Mix,
}
- private static GLCanvas sInstance = instantiateCanvas();
- private static GLId sGLId = instantiateGLId();
-
- public static GLId getGLId() {
- return sGLId;
- }
-
- public static GLCanvas getInstance() {
- return sInstance;
- }
-
- private static GLId instantiateGLId() {
- return ApiHelper.HAS_GLES20_REQUIRED ? (GLES20Canvas) sInstance : new GLIdImpl();
- }
-
- private static GLCanvas instantiateCanvas() {
- return ApiHelper.HAS_GLES20_REQUIRED ? new GLES20Canvas() : new GLES11Canvas();
- }
-
- public static int getEGLContextClientVersion() {
- return ApiHelper.HAS_GLES20_REQUIRED ? 2 : 1;
- }
-
- public abstract void initialize(GL11 gl);
+ public GLId getGLId();
// Tells GLCanvas the size of the underlying GL surface. This should be
// called before first drawing and when the size of GL surface is changed.
// This is called by GLRoot and should not be called by the clients
// who only want to draw on the GLCanvas. Both width and height must be
// nonnegative.
- public abstract void setSize(int width, int height);
+ public void setSize(int width, int height);
// Clear the drawing buffers. This should only be used by GLRoot.
- public abstract void clearBuffer();
+ public void clearBuffer();
- public abstract void clearBuffer(float[] argb);
+ public void clearBuffer(float[] argb);
// Sets and gets the current alpha, alpha must be in [0, 1].
- public abstract void setAlpha(float alpha);
+ public void setAlpha(float alpha);
- public abstract float getAlpha();
+ public float getAlpha();
// (current alpha) = (current alpha) * alpha
- public abstract void multiplyAlpha(float alpha);
+ public void multiplyAlpha(float alpha);
// Change the current transform matrix.
- public abstract void translate(float x, float y, float z);
+ public void translate(float x, float y, float z);
- public abstract void translate(float x, float y);
+ public void translate(float x, float y);
- public abstract void scale(float sx, float sy, float sz);
+ public void scale(float sx, float sy, float sz);
- public abstract void rotate(float angle, float x, float y, float z);
+ public void rotate(float angle, float x, float y, float z);
- public abstract void multiplyMatrix(float[] mMatrix, int offset);
+ public void multiplyMatrix(float[] mMatrix, int offset);
// Pushes the configuration state (matrix, and alpha) onto
// a private stack.
- public abstract void save();
+ public void save();
// Same as save(), but only save those specified in saveFlags.
- public abstract void save(int saveFlags);
+ public void save(int saveFlags);
public static final int SAVE_FLAG_ALL = 0xFFFFFFFF;
public static final int SAVE_FLAG_ALPHA = 0x01;
@@ -107,65 +80,64 @@ public abstract class GLCanvas {
// alpha, and clip). This call balances a previous call to save(), and is
// used to remove all modifications to the configuration state since the
// last save call.
- public abstract void restore();
+ public void restore();
// Draws a line using the specified paint from (x1, y1) to (x2, y2).
// (Both end points are included).
- public abstract void drawLine(float x1, float y1, float x2, float y2, GLPaint paint);
+ public void drawLine(float x1, float y1, float x2, float y2, GLPaint paint);
// Draws a rectangle using the specified paint from (x1, y1) to (x2, y2).
// (Both end points are included).
- public abstract void drawRect(float x1, float y1, float x2, float y2, GLPaint paint);
+ public void drawRect(float x1, float y1, float x2, float y2, GLPaint paint);
// Fills the specified rectangle with the specified color.
- public abstract void fillRect(float x, float y, float width, float height, int color);
+ public void fillRect(float x, float y, float width, float height, int color);
// Draws a texture to the specified rectangle.
- public abstract void drawTexture(
- BasicTexture texture, int x, int y, int width, int height);
+ public void drawTexture(BasicTexture texture, int x, int y, int width, int height);
- public abstract void drawMesh(BasicTexture tex, int x, int y, int xyBuffer,
+ public void drawMesh(BasicTexture tex, int x, int y, int xyBuffer,
int uvBuffer, int indexBuffer, int indexCount);
// Draws the source rectangle part of the texture to the target rectangle.
- public abstract void drawTexture(BasicTexture texture, RectF source, RectF target);
+ public void drawTexture(BasicTexture texture, RectF source, RectF target);
// Draw a texture with a specified texture transform.
- public abstract void drawTexture(BasicTexture texture, float[] mTextureTransform,
+ public void drawTexture(BasicTexture texture, float[] mTextureTransform,
int x, int y, int w, int h);
// Draw two textures to the specified rectangle. The actual texture used is
// from * (1 - ratio) + to * ratio
// The two textures must have the same size.
- public abstract void drawMixed(BasicTexture from, int toColor,
+ public void drawMixed(BasicTexture from, int toColor,
float ratio, int x, int y, int w, int h);
// Draw a region of a texture and a specified color to the specified
// rectangle. The actual color used is from * (1 - ratio) + to * ratio.
// The region of the texture is defined by parameter "src". The target
// rectangle is specified by parameter "target".
- public abstract void drawMixed(BasicTexture from, int toColor,
+ public void drawMixed(BasicTexture from, int toColor,
float ratio, RectF src, RectF target);
// Unloads the specified texture from the canvas. The resource allocated
// to draw the texture will be released. The specified texture will return
// to the unloaded state. This function should be called only from
// BasicTexture or its descendant
- public abstract boolean unloadTexture(BasicTexture texture);
+ public boolean unloadTexture(BasicTexture texture);
// Delete the specified buffer object, similar to unloadTexture.
- public abstract void deleteBuffer(int bufferId);
+ public void deleteBuffer(int bufferId);
// Delete the textures and buffers in GL side. This function should only be
// called in the GL thread.
- public abstract void deleteRecycledResources();
+ public void deleteRecycledResources();
// Dump statistics information and clear the counters. For debug only.
- public abstract void dumpStatisticsAndClear();
+ public void dumpStatisticsAndClear();
- public abstract void beginRenderTarget(RawTexture texture);
+ public void beginRenderTarget(RawTexture texture);
- public abstract void endRenderTarget();
+ public void endRenderTarget();
/**
* Sets texture parameters to use GL_CLAMP_TO_EDGE for both
@@ -175,7 +147,7 @@ public abstract class GLCanvas {
*
* @param texture The texture to set parameters on.
*/
- public abstract void setTextureParameters(BasicTexture texture);
+ public void setTextureParameters(BasicTexture texture);
/**
* Initializes the texture to a size by calling texImage2D on it.
@@ -184,7 +156,7 @@ public abstract class GLCanvas {
* @param format The texture format (e.g. GL_RGBA)
* @param type The texture type (e.g. GL_UNSIGNED_BYTE)
*/
- public abstract void initializeTextureSize(BasicTexture texture, int format, int type);
+ public void initializeTextureSize(BasicTexture texture, int format, int type);
/**
* Initializes the texture to a size by calling texImage2D on it.
@@ -192,7 +164,7 @@ public abstract class GLCanvas {
* @param texture The texture to initialize the size.
* @param bitmap The bitmap to initialize the bitmap with.
*/
- public abstract void initializeTexture(BasicTexture texture, Bitmap bitmap);
+ public void initializeTexture(BasicTexture texture, Bitmap bitmap);
/**
* Calls glTexSubImage2D to upload a bitmap to the texture.
@@ -205,8 +177,7 @@ public abstract class GLCanvas {
* @param format The texture format (e.g. GL_RGBA)
* @param type The texture type (e.g. GL_UNSIGNED_BYTE)
*/
- public abstract void texSubImage2D(BasicTexture texture, int xOffset, int yOffset,
- Bitmap bitmap,
+ public void texSubImage2D(BasicTexture texture, int xOffset, int yOffset, Bitmap bitmap,
int format, int type);
/**
@@ -215,7 +186,7 @@ public abstract class GLCanvas {
* @param buffer The buffer to upload
* @return The buffer ID that was generated.
*/
- public abstract int uploadBuffer(java.nio.FloatBuffer buffer);
+ public int uploadBuffer(java.nio.FloatBuffer buffer);
/**
* Generates buffers and uploads the element array buffer data.
@@ -223,36 +194,36 @@ public abstract class GLCanvas {
* @param buffer The buffer to upload
* @return The buffer ID that was generated.
*/
- public abstract int uploadBuffer(java.nio.ByteBuffer buffer);
+ public int uploadBuffer(java.nio.ByteBuffer buffer);
/**
* Sets the blending algorithm if a texture is not opaque.
*
* @param blending Either mixing (overlay) or adding a texture.
*/
- public abstract void setBlending(Blending blending);
+ public void setBlending(Blending blending);
/**
* Enable stencil test
*/
- public abstract void enableStencil();
+ public void enableStencil();
/**
* Disable stencil.
*/
- public abstract void disableStencil();
+ public void disableStencil();
/**
* Clears the stencil so that a new stencil can be generated.
*/
- public abstract void clearStencilBuffer();
+ public void clearStencilBuffer();
/**
* Start/stop updating the stencil buffer.
*
* @param update True if the stencil should be updated, false otherwise.
*/
- public abstract void updateStencil(boolean update);
+ public void updateStencil(boolean update);
/**
* Changes how the stencil buffer is used.
@@ -261,13 +232,13 @@ public abstract class GLCanvas {
* changed. If false, the area inside the stencil can be drawn to
* as well.
*/
- public abstract void drawOnlyOutsideStencil(boolean onlyOutside);
+ public void drawOnlyOutsideStencil(boolean onlyOutside);
/**
* After LightCycle makes GL calls, this method is called to restore the GL
* configuration to the one expected by GLCanvas.
*/
- public abstract void recoverFromLightCycle();
+ public void recoverFromLightCycle();
/**
* Gets the bounds given by x, y, width, and height as well as the internal
@@ -280,5 +251,5 @@ public abstract class GLCanvas {
* @param width The width of the input rectangle.
* @param height The height of the input rectangle.
*/
- public abstract void getBounds(Rect bounds, int x, int y, int width, int height);
+ public void getBounds(Rect bounds, int x, int y, int width, int height);
}