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(); 39915c2c5b2c367df71599370613af0924bd7c4887Bobby Georgescu public void clearBuffer(float[] argb); 40f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 41f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Sets and gets the current alpha, alpha must be in [0, 1]. 42f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void setAlpha(float alpha); 43f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public float getAlpha(); 44f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 45f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // (current alpha) = (current alpha) * alpha 46f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void multiplyAlpha(float alpha); 47f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 48f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Change the current transform matrix. 49f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void translate(float x, float y, float z); 50174cac8f92029fc2829c94f274e70793ae948931Chih-Chung Chang public void translate(float x, float y); 51f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void scale(float sx, float sy, float sz); 52f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void rotate(float angle, float x, float y, float z); 53f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void multiplyMatrix(float[] mMatrix, int offset); 54f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 557b83fb8e3a8978b33a6b9bfc56d85fe2c1a9cf06Chih-Chung Chang // Pushes the configuration state (matrix, and alpha) onto 56f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // a private stack. 57cfa105d3934c4dfa14f02b693bfa97c8d17d56a9Chih-Chung Chang public void save(); 58f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 59f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Same as save(), but only save those specified in saveFlags. 60cfa105d3934c4dfa14f02b693bfa97c8d17d56a9Chih-Chung Chang public void save(int saveFlags); 61f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 62f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public static final int SAVE_FLAG_ALL = 0xFFFFFFFF; 637b83fb8e3a8978b33a6b9bfc56d85fe2c1a9cf06Chih-Chung Chang public static final int SAVE_FLAG_ALPHA = 0x01; 647b83fb8e3a8978b33a6b9bfc56d85fe2c1a9cf06Chih-Chung Chang public static final int SAVE_FLAG_MATRIX = 0x02; 65f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 66f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Pops from the top of the stack as current configuration state (matrix, 67f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // alpha, and clip). This call balances a previous call to save(), and is 68f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // used to remove all modifications to the configuration state since the 69f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // last save call. 70f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void restore(); 71f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 72f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a line using the specified paint from (x1, y1) to (x2, y2). 73f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // (Both end points are included). 74f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawLine(float x1, float y1, float x2, float y2, GLPaint paint); 75f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 76f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a rectangle using the specified paint from (x1, y1) to (x2, y2). 77f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // (Both end points are included). 78f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawRect(float x1, float y1, float x2, float y2, GLPaint paint); 79f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 80f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Fills the specified rectangle with the specified color. 81f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void fillRect(float x, float y, float width, float height, int color); 82f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 83f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draws a texture to the specified rectangle. 84f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawTexture( 85f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin BasicTexture texture, int x, int y, int width, int height); 86f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawMesh(BasicTexture tex, int x, int y, int xyBuffer, 87f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin int uvBuffer, int indexBuffer, int indexCount); 88f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 89b29a27f475a2c449abdda8d4e03d30914feed8c6Chih-Chung Chang // Draws the source rectangle part of the texture to the target rectangle. 90f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawTexture(BasicTexture texture, RectF source, RectF target); 91f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 92b29a27f475a2c449abdda8d4e03d30914feed8c6Chih-Chung Chang // Draw a texture with a specified texture transform. 93b29a27f475a2c449abdda8d4e03d30914feed8c6Chih-Chung Chang public void drawTexture(BasicTexture texture, float[] mTextureTransform, 94b29a27f475a2c449abdda8d4e03d30914feed8c6Chih-Chung Chang int x, int y, int w, int h); 95b29a27f475a2c449abdda8d4e03d30914feed8c6Chih-Chung Chang 96f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Draw two textures to the specified rectangle. The actual texture used is 97f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // from * (1 - ratio) + to * ratio 98f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // The two textures must have the same size. 99f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void drawMixed(BasicTexture from, int toColor, 100f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin float ratio, int x, int y, int w, int h); 101f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 102a8f3473271cb4bfc5b47f520402bad7cddb5d3e8Owen Lin // Draw a region of a texture and a specified color to the specified 103a8f3473271cb4bfc5b47f520402bad7cddb5d3e8Owen Lin // rectangle. The actual color used is from * (1 - ratio) + to * ratio. 104a8f3473271cb4bfc5b47f520402bad7cddb5d3e8Owen Lin // The region of the texture is defined by parameter "src". The target 105a8f3473271cb4bfc5b47f520402bad7cddb5d3e8Owen Lin // rectangle is specified by parameter "target". 106a8f3473271cb4bfc5b47f520402bad7cddb5d3e8Owen Lin public void drawMixed(BasicTexture from, int toColor, 107a8f3473271cb4bfc5b47f520402bad7cddb5d3e8Owen Lin float ratio, RectF src, RectF target); 108a8f3473271cb4bfc5b47f520402bad7cddb5d3e8Owen Lin 109f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Gets the underlying GL instance. This is used only when direct access to 110f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // GL is needed. 111f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public GL11 getGLInstance(); 112f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 113f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Unloads the specified texture from the canvas. The resource allocated 114f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // to draw the texture will be released. The specified texture will return 115f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // to the unloaded state. This function should be called only from 116f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // BasicTexture or its descendant 117f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public boolean unloadTexture(BasicTexture texture); 118f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 119f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Delete the specified buffer object, similar to unloadTexture. 120f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void deleteBuffer(int bufferId); 121f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 122f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // Delete the textures and buffers in GL side. This function should only be 123f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin // called in the GL thread. 124f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin public void deleteRecycledResources(); 125f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin 1267b83fb8e3a8978b33a6b9bfc56d85fe2c1a9cf06Chih-Chung Chang // Dump statistics information and clear the counters. For debug only. 1277b83fb8e3a8978b33a6b9bfc56d85fe2c1a9cf06Chih-Chung Chang public void dumpStatisticsAndClear(); 1288ac2e8630f33f4d5f65731dc56efa9bfb3570cd7Owen Lin 1298ac2e8630f33f4d5f65731dc56efa9bfb3570cd7Owen Lin public void beginRenderTarget(RawTexture texture); 1308ac2e8630f33f4d5f65731dc56efa9bfb3570cd7Owen Lin 1318ac2e8630f33f4d5f65731dc56efa9bfb3570cd7Owen Lin public void endRenderTarget(); 132f9a0a4306d589b4a4e20554fed512a603426bfa1Owen Lin} 133