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