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(); 39 40 // Sets and gets the current alpha, alpha must be in [0, 1]. setAlpha(float alpha)41 public void setAlpha(float alpha); getAlpha()42 public float getAlpha(); 43 44 // (current alpha) = (current alpha) * alpha multiplyAlpha(float alpha)45 public void multiplyAlpha(float alpha); 46 47 // Change the current transform matrix. translate(float x, float y, float z)48 public void translate(float x, float y, float z); translate(float x, float y)49 public void translate(float x, float y); scale(float sx, float sy, float sz)50 public void scale(float sx, float sy, float sz); rotate(float angle, float x, float y, float z)51 public void rotate(float angle, float x, float y, float z); multiplyMatrix(float[] mMatrix, int offset)52 public void multiplyMatrix(float[] mMatrix, int offset); 53 54 // Pushes the configuration state (matrix, and alpha) onto 55 // a private stack. save()56 public void save(); 57 58 // Same as save(), but only save those specified in saveFlags. save(int 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. restore()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). drawLine(float x1, float y1, float x2, float y2, GLPaint paint)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). drawRect(float x1, float y1, float x2, float y2, GLPaint paint)77 public void drawRect(float x1, float y1, float x2, float y2, GLPaint paint); 78 79 // Fills the specified rectangle with the specified color. fillRect(float x, float y, float width, float height, int color)80 public void fillRect(float x, float y, float width, float height, int color); 81 82 // Draws a texture to the specified rectangle. drawTexture( BasicTexture texture, int x, int y, int width, int height)83 public void drawTexture( 84 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)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. drawTexture(BasicTexture texture, RectF source, RectF target)89 public void drawTexture(BasicTexture texture, RectF source, RectF target); 90 91 // Draw a texture with a specified texture transform. drawTexture(BasicTexture texture, float[] mTextureTransform, int x, int y, int w, int h)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. drawMixed(BasicTexture from, int toColor, float ratio, int x, int y, int w, int h)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. getGLInstance()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 unloadTexture(BasicTexture texture)109 public boolean unloadTexture(BasicTexture texture); 110 111 // Delete the specified buffer object, similar to unloadTexture. deleteBuffer(int bufferId)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. deleteRecycledResources()116 public void deleteRecycledResources(); 117 118 // Dump statistics information and clear the counters. For debug only. dumpStatisticsAndClear()119 public void dumpStatisticsAndClear(); 120 beginRenderTarget(RawTexture texture)121 public void beginRenderTarget(RawTexture texture); 122 endRenderTarget()123 public void endRenderTarget(); 124 } 125