1f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin/* 2f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * Copyright (C) 2010 The Android Open Source Project 3f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * 4f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * Licensed under the Apache License, Version 2.0 (the "License"); 5f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * you may not use this file except in compliance with the License. 6f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * You may obtain a copy of the License at 7f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * 8f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * http://www.apache.org/licenses/LICENSE-2.0 9f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * 10f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * Unless required by applicable law or agreed to in writing, software 11f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * distributed under the License is distributed on an "AS IS" BASIS, 12f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * See the License for the specific language governing permissions and 14f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin * limitations under the License. 15f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin */ 16f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 17f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Linpackage com.android.gallery3d.ui; 18f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 19f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Linimport android.graphics.RectF; 20f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 21f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Linimport javax.microedition.khronos.opengles.GL11; 22f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 23f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin// 24f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin// GLCanvas gives a convenient interface to draw using OpenGL. 25f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin// 26f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin// When a rectangle is specified in this interface, it means the region 27f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin// [x, x+width) * [y, y+height) 28f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin// 29f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Linpublic interface GLCanvas { 30f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Tells GLCanvas the size of the underlying GL surface. This should be 31f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // called before first drawing and when the size of GL surface is changed. 32f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // This is called by GLRoot and should not be called by the clients 33f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // who only want to draw on the GLCanvas. Both width and height must be 34f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // nonnegative. 35f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void setSize(int width, int height); 36f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 37f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Clear the drawing buffers. This should only be used by GLRoot. 38f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void clearBuffer(); 39f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 40f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // This is the time value used to calculate the animation in the current 41f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // frame. The "set" function should only called by GLRoot, and the 42f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // "time" parameter must be nonnegative. 43f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void setCurrentAnimationTimeMillis(long time); 44f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public long currentAnimationTimeMillis(); 45f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 46f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void setBlendEnabled(boolean enabled); 47f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 48f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Sets and gets the current alpha, alpha must be in [0, 1]. 49f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void setAlpha(float alpha); 50f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public float getAlpha(); 51f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 52f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // (current alpha) = (current alpha) * alpha 53f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void multiplyAlpha(float alpha); 54f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 55f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Change the current transform matrix. 56f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void translate(float x, float y, float z); 57f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void scale(float sx, float sy, float sz); 58f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void rotate(float angle, float x, float y, float z); 59f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void multiplyMatrix(float[] mMatrix, int offset); 60f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 61f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Modifies the current clip with the specified rectangle. 62f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // (current clip) = (current clip) intersect (specified rectangle). 63f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Returns true if the result clip is non-empty. 64f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public boolean clipRect(int left, int top, int right, int bottom); 65f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 66f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Pushes the configuration state (matrix, alpha, and clip) onto 67f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // a private stack. 68f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public int save(); 69f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 70f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Same as save(), but only save those specified in saveFlags. 71f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public int save(int saveFlags); 72f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 73f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public static final int SAVE_FLAG_ALL = 0xFFFFFFFF; 74f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public static final int SAVE_FLAG_CLIP = 0x01; 75f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public static final int SAVE_FLAG_ALPHA = 0x02; 76f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public static final int SAVE_FLAG_MATRIX = 0x04; 77f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 78f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Pops from the top of the stack as current configuration state (matrix, 79f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // alpha, and clip). This call balances a previous call to save(), and is 80f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // used to remove all modifications to the configuration state since the 81f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // last save call. 82f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void restore(); 83f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 84f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a line using the specified paint from (x1, y1) to (x2, y2). 85f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // (Both end points are included). 86f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawLine(float x1, float y1, float x2, float y2, GLPaint paint); 87f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 88f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a rectangle using the specified paint from (x1, y1) to (x2, y2). 89f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // (Both end points are included). 90f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawRect(float x1, float y1, float x2, float y2, GLPaint paint); 91f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 92f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Fills the specified rectangle with the specified color. 93f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void fillRect(float x, float y, float width, float height, int color); 94f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 95f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a texture to the specified rectangle. 96f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawTexture( 97f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin BasicTexture texture, int x, int y, int width, int height); 98f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawMesh(BasicTexture tex, int x, int y, int xyBuffer, 99f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin int uvBuffer, int indexBuffer, int indexCount); 100f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 101f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a texture to the specified rectangle. The "alpha" parameter 102f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // overrides the current drawing alpha value. 103f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawTexture(BasicTexture texture, 104f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin int x, int y, int width, int height, float alpha); 105f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 106f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a the source rectangle part of the texture to the target rectangle. 107f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawTexture(BasicTexture texture, RectF source, RectF target); 108f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 109f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draw two textures to the specified rectangle. The actual texture used is 110f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // from * (1 - ratio) + to * ratio 111f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // The two textures must have the same size. 112f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawMixed(BasicTexture from, BasicTexture to, 113f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin float ratio, int x, int y, int w, int h); 114f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 115f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawMixed(BasicTexture from, int toColor, 116f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin float ratio, int x, int y, int w, int h); 117f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 118f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Return a texture copied from the specified rectangle. 119f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public BasicTexture copyTexture(int x, int y, int width, int height); 120f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 121f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Gets the underlying GL instance. This is used only when direct access to 122f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // GL is needed. 123f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public GL11 getGLInstance(); 124f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 125f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Unloads the specified texture from the canvas. The resource allocated 126f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // to draw the texture will be released. The specified texture will return 127f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // to the unloaded state. This function should be called only from 128f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // BasicTexture or its descendant 129f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public boolean unloadTexture(BasicTexture texture); 130f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 131f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Delete the specified buffer object, similar to unloadTexture. 132f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void deleteBuffer(int bufferId); 133f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 134f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Delete the textures and buffers in GL side. This function should only be 135f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // called in the GL thread. 136f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void deleteRecycledResources(); 137f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 138f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin} 139