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 17package com.android.gallery3d.ui; 18 19import android.graphics.RectF; 20 21import 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// 29public 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 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); 49 public void translate(float x, float y); 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 54 // Pushes the configuration state (matrix, and alpha) onto 55 // a private stack. 56 public void save(); 57 58 // Same as save(), but only save those specified in saveFlags. 59 public void save(int saveFlags); 60 61 public static final int SAVE_FLAG_ALL = 0xFFFFFFFF; 62 public static final int SAVE_FLAG_ALPHA = 0x01; 63 public static final int SAVE_FLAG_MATRIX = 0x02; 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 88 // Draws the source rectangle part of the texture to the target rectangle. 89 public void drawTexture(BasicTexture texture, RectF source, RectF target); 90 91 // Draw a texture with a specified texture transform. 92 public void drawTexture(BasicTexture texture, float[] mTextureTransform, 93 int x, int y, int w, int h); 94 95 // Draw two textures to the specified rectangle. The actual texture used is 96 // from * (1 - ratio) + to * ratio 97 // The two textures must have the same size. 98 public void drawMixed(BasicTexture from, int toColor, 99 float ratio, int x, int y, int w, int h); 100 101 // Gets the underlying GL instance. This is used only when direct access to 102 // GL is needed. 103 public GL11 getGLInstance(); 104 105 // Unloads the specified texture from the canvas. The resource allocated 106 // to draw the texture will be released. The specified texture will return 107 // to the unloaded state. This function should be called only from 108 // BasicTexture or its descendant 109 public boolean unloadTexture(BasicTexture texture); 110 111 // Delete the specified buffer object, similar to unloadTexture. 112 public void deleteBuffer(int bufferId); 113 114 // Delete the textures and buffers in GL side. This function should only be 115 // called in the GL thread. 116 public void deleteRecycledResources(); 117 118 // Dump statistics information and clear the counters. For debug only. 119 public void dumpStatisticsAndClear(); 120 121 public void beginRenderTarget(RawTexture texture); 122 123 public void endRenderTarget(); 124} 125