blob: 1359115f89cf68a55a8ca2fcdb2ab82b272956eb [file] [log] [blame]
Owen Lina2fba682011-08-17 22:07:43 +08001/*
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
Owen Lina2fba682011-08-17 22:07:43 +080040 // 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 Chang3f43ecb2012-02-16 07:27:03 +080049 public void translate(float x, float y);
Owen Lina2fba682011-08-17 22:07:43 +080050 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 Chang980724b2012-02-22 08:00:31 +080054 // Pushes the configuration state (matrix, and alpha) onto
Owen Lina2fba682011-08-17 22:07:43 +080055 // a private stack.
Chih-Chung Changbe55f1e2012-02-18 06:17:18 +080056 public void save();
Owen Lina2fba682011-08-17 22:07:43 +080057
58 // Same as save(), but only save those specified in saveFlags.
Chih-Chung Changbe55f1e2012-02-18 06:17:18 +080059 public void save(int saveFlags);
Owen Lina2fba682011-08-17 22:07:43 +080060
61 public static final int SAVE_FLAG_ALL = 0xFFFFFFFF;
Chih-Chung Chang980724b2012-02-22 08:00:31 +080062 public static final int SAVE_FLAG_ALPHA = 0x01;
63 public static final int SAVE_FLAG_MATRIX = 0x02;
Owen Lina2fba682011-08-17 22:07:43 +080064
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 Lina2fba682011-08-17 22:07:43 +080088 // 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 Lina2fba682011-08-17 22:07:43 +080094 public void drawMixed(BasicTexture from, int toColor,
95 float ratio, int x, int y, int w, int h);
96
Owen Lina2fba682011-08-17 22:07:43 +080097 // 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 Chang980724b2012-02-22 08:00:31 +0800114 // Dump statistics information and clear the counters. For debug only.
115 public void dumpStatisticsAndClear();
Owen Lina2fba682011-08-17 22:07:43 +0800116}