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