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