Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 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 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_UI_OPENGL_RENDERER_H |
| 18 | #define ANDROID_UI_OPENGL_RENDERER_H |
| 19 | |
| 20 | #include <GLES2/gl2.h> |
| 21 | #include <GLES2/gl2ext.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 22 | |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 23 | #include <SkBitmap.h> |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 24 | #include <SkMatrix.h> |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 25 | #include <SkPaint.h> |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 26 | #include <SkRegion.h> |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 27 | #include <SkShader.h> |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 28 | #include <SkXfermode.h> |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 29 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 30 | #include <utils/RefBase.h> |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 31 | #include <utils/ResourceTypes.h> |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 32 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 33 | #include "Matrix.h" |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 34 | #include "Program.h" |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 35 | #include "Rect.h" |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 36 | #include "Snapshot.h" |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 37 | #include "TextureCache.h" |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 38 | #include "LayerCache.h" |
Romain Guy | c0ac193 | 2010-07-19 18:43:02 -0700 | [diff] [blame] | 39 | #include "GradientCache.h" |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 40 | #include "PatchCache.h" |
| 41 | #include "Vertex.h" |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame^] | 42 | #include "FontRenderer.h" |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 43 | |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 44 | namespace android { |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 45 | namespace uirenderer { |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 46 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 47 | /////////////////////////////////////////////////////////////////////////////// |
| 48 | // Support |
| 49 | /////////////////////////////////////////////////////////////////////////////// |
| 50 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 51 | /** |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 52 | * Structure mapping Skia xfermodes to OpenGL blending factors. |
| 53 | */ |
| 54 | struct Blender { |
| 55 | SkXfermode::Mode mode; |
| 56 | GLenum src; |
| 57 | GLenum dst; |
| 58 | }; // struct Blender |
| 59 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 60 | /////////////////////////////////////////////////////////////////////////////// |
| 61 | // Renderer |
| 62 | /////////////////////////////////////////////////////////////////////////////// |
| 63 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 64 | /** |
| 65 | * OpenGL renderer used to draw accelerated 2D graphics. The API is a |
| 66 | * simplified version of Skia's Canvas API. |
| 67 | */ |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 68 | class OpenGLRenderer { |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 69 | public: |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 70 | OpenGLRenderer(); |
| 71 | ~OpenGLRenderer(); |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 72 | |
| 73 | void setViewport(int width, int height); |
| 74 | void prepare(); |
Romain Guy | 08ae317 | 2010-06-21 19:35:50 -0700 | [diff] [blame] | 75 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 76 | int getSaveCount() const; |
| 77 | int save(int flags); |
| 78 | void restore(); |
| 79 | void restoreToCount(int saveCount); |
| 80 | |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 81 | int saveLayer(float left, float top, float right, float bottom, const SkPaint* p, int flags); |
| 82 | int saveLayerAlpha(float left, float top, float right, float bottom, int alpha, int flags); |
| 83 | |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 84 | void translate(float dx, float dy); |
| 85 | void rotate(float degrees); |
| 86 | void scale(float sx, float sy); |
| 87 | |
| 88 | void setMatrix(SkMatrix* matrix); |
| 89 | void getMatrix(SkMatrix* matrix); |
| 90 | void concatMatrix(SkMatrix* matrix); |
| 91 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 92 | const Rect& getClipBounds(); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 93 | bool quickReject(float left, float top, float right, float bottom); |
Romain Guy | 079ba2c | 2010-07-16 14:12:24 -0700 | [diff] [blame] | 94 | bool clipRect(float left, float top, float right, float bottom, SkRegion::Op op); |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 95 | |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 96 | void drawBitmap(SkBitmap* bitmap, float left, float top, const SkPaint* paint); |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 97 | void drawBitmap(SkBitmap* bitmap, const SkMatrix* matrix, const SkPaint* paint); |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 98 | void drawBitmap(SkBitmap* bitmap, float srcLeft, float srcTop, float srcRight, float srcBottom, |
Romain Guy | f86ef57 | 2010-07-01 11:05:42 -0700 | [diff] [blame] | 99 | float dstLeft, float dstTop, float dstRight, float dstBottom, const SkPaint* paint); |
Romain Guy | deba785 | 2010-07-07 17:54:48 -0700 | [diff] [blame] | 100 | void drawPatch(SkBitmap* bitmap, Res_png_9patch* patch, float left, float top, |
| 101 | float right, float bottom, const SkPaint* paint); |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 102 | void drawColor(int color, SkXfermode::Mode mode); |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 103 | void drawRect(float left, float top, float right, float bottom, const SkPaint* paint); |
Romain Guy | 08ae317 | 2010-06-21 19:35:50 -0700 | [diff] [blame] | 104 | |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 105 | void resetShader(); |
| 106 | void setupBitmapShader(SkBitmap* bitmap, SkShader::TileMode tileX, SkShader::TileMode tileY, |
| 107 | SkMatrix* matrix, bool hasAlpha); |
Romain Guy | f9764a4 | 2010-07-16 23:13:33 -0700 | [diff] [blame] | 108 | void setupLinearGradientShader(SkShader* shader, float* bounds, uint32_t* colors, |
Romain Guy | c0ac193 | 2010-07-19 18:43:02 -0700 | [diff] [blame] | 109 | float* positions, int count, SkShader::TileMode tileMode, |
| 110 | SkMatrix* matrix, bool hasAlpha); |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 111 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame^] | 112 | void drawText(const char* text, int count, float x, float y, SkPaint* paint); |
| 113 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 114 | private: |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 115 | /** |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 116 | * Type of Skia shader in use. |
| 117 | */ |
| 118 | enum ShaderType { |
| 119 | kShaderNone, |
| 120 | kShaderBitmap, |
| 121 | kShaderLinearGradient, |
| 122 | kShaderCircularGradient, |
| 123 | kShaderSweepGradient |
| 124 | }; |
| 125 | |
| 126 | /** |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 127 | * Saves the current state of the renderer as a new snapshot. |
| 128 | * The new snapshot is saved in mSnapshot and the previous snapshot |
| 129 | * is linked from mSnapshot->previous. |
| 130 | * |
| 131 | * @return The new save count. This value can be passed to #restoreToCount() |
| 132 | */ |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 133 | int saveSnapshot(); |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Restores the current snapshot; mSnapshot becomes mSnapshot->previous. |
| 137 | * |
| 138 | * @return True if the clip should be also reapplied by calling |
| 139 | * #setScissorFromClip(). |
| 140 | */ |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 141 | bool restoreSnapshot(); |
| 142 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 143 | /** |
| 144 | * Sets the clipping rectangle using glScissor. The clip is defined by |
| 145 | * the current snapshot's clipRect member. |
| 146 | */ |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 147 | void setScissorFromClip(); |
| 148 | |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 149 | /** |
Romain Guy | d55a861 | 2010-06-28 17:42:46 -0700 | [diff] [blame] | 150 | * Compose the layer defined in the current snapshot with the layer |
| 151 | * defined by the previous snapshot. |
| 152 | * |
| 153 | * The current snapshot *must* be a layer (flag kFlagIsLayer set.) |
| 154 | * |
| 155 | * @param curent The current snapshot containing the layer to compose |
| 156 | * @param previous The previous snapshot to compose the current layer with |
| 157 | */ |
| 158 | void composeLayer(sp<Snapshot> current, sp<Snapshot> previous); |
| 159 | |
| 160 | /** |
| 161 | * Creates a new layer stored in the specified snapshot. |
| 162 | * |
| 163 | * @param snapshot The snapshot associated with the new layer |
| 164 | * @param left The left coordinate of the layer |
| 165 | * @param top The top coordinate of the layer |
| 166 | * @param right The right coordinate of the layer |
| 167 | * @param bottom The bottom coordinate of the layer |
| 168 | * @param alpha The translucency of the layer |
| 169 | * @param mode The blending mode of the layer |
| 170 | * @param flags The layer save flags |
| 171 | * |
| 172 | * @return True if the layer was successfully created, false otherwise |
| 173 | */ |
| 174 | bool createLayer(sp<Snapshot> snapshot, float left, float top, float right, float bottom, |
| 175 | int alpha, SkXfermode::Mode mode, int flags); |
| 176 | |
| 177 | /** |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 178 | * Draws a colored rectangle with the specified color. The specified coordinates |
| 179 | * are transformed by the current snapshot's transform matrix. |
| 180 | * |
| 181 | * @param left The left coordinate of the rectangle |
| 182 | * @param top The top coordinate of the rectangle |
| 183 | * @param right The right coordinate of the rectangle |
| 184 | * @param bottom The bottom coordinate of the rectangle |
| 185 | * @param color The rectangle's ARGB color, defined as a packed 32 bits word |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 186 | * @param mode The Skia xfermode to use |
Romain Guy | 3d58c03 | 2010-07-14 16:34:53 -0700 | [diff] [blame] | 187 | * @param ignoreTransform True if the current transform should be ignored |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 188 | */ |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 189 | void drawColorRect(float left, float top, float right, float bottom, |
Romain Guy | 3d58c03 | 2010-07-14 16:34:53 -0700 | [diff] [blame] | 190 | int color, SkXfermode::Mode mode, bool ignoreTransform = false); |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 191 | |
| 192 | /** |
| 193 | * Draws a textured rectangle with the specified texture. The specified coordinates |
| 194 | * are transformed by the current snapshot's transform matrix. |
| 195 | * |
| 196 | * @param left The left coordinate of the rectangle |
| 197 | * @param top The top coordinate of the rectangle |
| 198 | * @param right The right coordinate of the rectangle |
| 199 | * @param bottom The bottom coordinate of the rectangle |
| 200 | * @param texture The texture name to map onto the rectangle |
| 201 | * @param alpha An additional translucency parameter, between 0.0f and 1.0f |
Romain Guy | d55a861 | 2010-06-28 17:42:46 -0700 | [diff] [blame] | 202 | * @param mode The blending mode |
Romain Guy | c1396e9 | 2010-06-30 17:56:19 -0700 | [diff] [blame] | 203 | * @param blend True if the texture contains an alpha channel |
Romain Guy | 5cbbce5 | 2010-06-27 22:59:20 -0700 | [diff] [blame] | 204 | */ |
Romain Guy | bd6b79b | 2010-06-26 00:13:53 -0700 | [diff] [blame] | 205 | void drawTextureRect(float left, float top, float right, float bottom, GLuint texture, |
Romain Guy | a979474 | 2010-07-13 11:37:54 -0700 | [diff] [blame] | 206 | float alpha, SkXfermode::Mode mode, bool blend); |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 207 | |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 208 | /** |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 209 | * Draws a textured rectangle with the specified texture. The specified coordinates |
| 210 | * are transformed by the current snapshot's transform matrix. |
| 211 | * |
| 212 | * @param left The left coordinate of the rectangle |
| 213 | * @param top The top coordinate of the rectangle |
| 214 | * @param right The right coordinate of the rectangle |
| 215 | * @param bottom The bottom coordinate of the rectangle |
| 216 | * @param texture The texture to use |
| 217 | * @param paint The paint containing the alpha, blending mode, etc. |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 218 | */ |
Romain Guy | a979474 | 2010-07-13 11:37:54 -0700 | [diff] [blame] | 219 | void drawTextureRect(float left, float top, float right, float bottom, |
| 220 | const Texture* texture, const SkPaint* paint); |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * Draws a textured mesh with the specified texture. If the indices are omitted, the |
| 224 | * mesh is drawn as a simple quad. |
| 225 | * |
| 226 | * @param left The left coordinate of the rectangle |
| 227 | * @param top The top coordinate of the rectangle |
| 228 | * @param right The right coordinate of the rectangle |
| 229 | * @param bottom The bottom coordinate of the rectangle |
| 230 | * @param texture The texture name to map onto the rectangle |
| 231 | * @param alpha An additional translucency parameter, between 0.0f and 1.0f |
| 232 | * @param mode The blending mode |
| 233 | * @param blend True if the texture contains an alpha channel |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 234 | * @param vertices The vertices that define the mesh |
| 235 | * @param texCoords The texture coordinates of each vertex |
| 236 | * @param indices The indices of the vertices, can be NULL |
| 237 | * @param elementsCount The number of elements in the mesh, required by indices |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 238 | */ |
| 239 | void drawTextureMesh(float left, float top, float right, float bottom, GLuint texture, |
Romain Guy | a979474 | 2010-07-13 11:37:54 -0700 | [diff] [blame] | 240 | float alpha, SkXfermode::Mode mode, bool blend, |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 241 | GLvoid* vertices, GLvoid* texCoords, GLvoid* indices, GLsizei elementsCount = 0); |
| 242 | |
| 243 | /** |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 244 | * Fills the specified rectangle with the currently set bitmap shader. |
| 245 | * |
| 246 | * @param left The left coordinate of the rectangle |
| 247 | * @param top The top coordinate of the rectangle |
| 248 | * @param right The right coordinate of the rectangle |
| 249 | * @param bottom The bottom coordinate of the rectangle |
| 250 | * @param alpha An additional translucency parameter, between 0.0f and 1.0f |
| 251 | * @param mode The blending mode |
| 252 | */ |
| 253 | void drawBitmapShader(float left, float top, float right, float bottom, float alpha, |
| 254 | SkXfermode::Mode mode); |
| 255 | |
| 256 | /** |
Romain Guy | c0ac193 | 2010-07-19 18:43:02 -0700 | [diff] [blame] | 257 | * Fills the specified rectangle with the currently set linear gradient shader. |
| 258 | * |
| 259 | * @param left The left coordinate of the rectangle |
| 260 | * @param top The top coordinate of the rectangle |
| 261 | * @param right The right coordinate of the rectangle |
| 262 | * @param bottom The bottom coordinate of the rectangle |
| 263 | * @param alpha An additional translucency parameter, between 0.0f and 1.0f |
| 264 | * @param mode The blending mode |
| 265 | */ |
| 266 | void drawLinearGradientShader(float left, float top, float right, float bottom, float alpha, |
| 267 | SkXfermode::Mode mode); |
| 268 | |
| 269 | /** |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 270 | * Resets the texture coordinates stored in mDrawTextureVertices. Setting the values |
| 271 | * back to default is achieved by calling: |
| 272 | * |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 273 | * resetDrawTextureTexCoords(0.0f, 0.0f, 1.0f, 1.0f); |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 274 | * |
| 275 | * @param u1 The left coordinate of the texture |
| 276 | * @param v1 The bottom coordinate of the texture |
| 277 | * @param u2 The right coordinate of the texture |
| 278 | * @param v2 The top coordinate of the texture |
| 279 | */ |
| 280 | void resetDrawTextureTexCoords(float u1, float v1, float u2, float v2); |
| 281 | |
Romain Guy | 8ba548f | 2010-06-30 19:21:21 -0700 | [diff] [blame] | 282 | /** |
| 283 | * Gets the alpha and xfermode out of a paint object. If the paint is null |
| 284 | * alpha will be 255 and the xfermode will be SRC_OVER. |
| 285 | * |
| 286 | * @param paint The paint to extract values from |
| 287 | * @param alpha Where to store the resulting alpha |
| 288 | * @param mode Where to store the resulting xfermode |
| 289 | */ |
| 290 | inline void getAlphaAndMode(const SkPaint* paint, int* alpha, SkXfermode::Mode* mode); |
| 291 | |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 292 | /** |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 293 | * Binds the specified texture with the specified wrap modes. |
| 294 | */ |
| 295 | inline void bindTexture(GLuint texture, GLenum wrapS, GLenum wrapT); |
| 296 | |
| 297 | /** |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 298 | * Enable or disable blending as necessary. This function sets the appropriate |
| 299 | * blend function based on the specified xfermode. |
| 300 | */ |
Romain Guy | a979474 | 2010-07-13 11:37:54 -0700 | [diff] [blame] | 301 | inline void chooseBlending(bool blend, SkXfermode::Mode mode, bool isPremultiplied = true); |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 302 | |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 303 | /** |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 304 | * Use the specified program with the current GL context. If the program is already |
| 305 | * in use, it will not be bound again. If it is not in use, the current program is |
| 306 | * marked unused and the specified program becomes used and becomes the new |
| 307 | * current program. |
Romain Guy | 6926c72 | 2010-07-12 20:20:03 -0700 | [diff] [blame] | 308 | * |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 309 | * @param program The program to use |
| 310 | * |
| 311 | * @return true If the specified program was already in use, false otherwise. |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 312 | */ |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 313 | inline bool useProgram(const sp<Program>& program); |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 314 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 315 | // Dimensions of the drawing surface |
| 316 | int mWidth, mHeight; |
| 317 | |
Romain Guy | 85bf02f | 2010-06-22 13:11:24 -0700 | [diff] [blame] | 318 | // Matrix used for ortho projection in shaders |
Romain Guy | 260e102 | 2010-07-12 14:41:06 -0700 | [diff] [blame] | 319 | mat4 mOrthoMatrix; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 320 | |
Romain Guy | c7d5349 | 2010-06-25 13:41:57 -0700 | [diff] [blame] | 321 | // Model-view matrix used to position/size objects |
| 322 | mat4 mModelView; |
| 323 | |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 324 | // Number of saved states |
| 325 | int mSaveCount; |
Romain Guy | f6a11b8 | 2010-06-23 17:47:49 -0700 | [diff] [blame] | 326 | // Base state |
| 327 | Snapshot mFirstSnapshot; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 328 | // Current state |
| 329 | sp<Snapshot> mSnapshot; |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 330 | |
| 331 | // Shaders |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 332 | sp<Program> mCurrentProgram; |
| 333 | sp<DrawColorProgram> mDrawColorProgram; |
| 334 | sp<DrawTextureProgram> mDrawTextureProgram; |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame^] | 335 | sp<DrawTextProgram> mDrawTextProgram; |
Romain Guy | f9764a4 | 2010-07-16 23:13:33 -0700 | [diff] [blame] | 336 | sp<DrawLinearGradientProgram> mDrawLinearGradientProgram; |
Romain Guy | 026c5e16 | 2010-06-28 17:12:22 -0700 | [diff] [blame] | 337 | |
| 338 | // Used to draw textured quads |
| 339 | TextureVertex mDrawTextureVertices[4]; |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 340 | |
Romain Guy | 1e79386 | 2010-07-16 15:07:42 -0700 | [diff] [blame] | 341 | // Current texture state |
| 342 | GLuint mLastTexture; |
| 343 | |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 344 | // Last known blend state |
| 345 | bool mBlend; |
| 346 | GLenum mLastSrcMode; |
| 347 | GLenum mLastDstMode; |
| 348 | |
Romain Guy | 7fac2e1 | 2010-07-16 17:10:13 -0700 | [diff] [blame] | 349 | // Skia shaders |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 350 | ShaderType mShader; |
Romain Guy | f9764a4 | 2010-07-16 23:13:33 -0700 | [diff] [blame] | 351 | SkShader* mShaderKey; |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 352 | bool mShaderBlend; |
Romain Guy | a1db574 | 2010-07-20 13:09:13 -0700 | [diff] [blame] | 353 | GLenum mShaderTileX; |
| 354 | GLenum mShaderTileY; |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 355 | SkMatrix* mShaderMatrix; |
Romain Guy | 7fac2e1 | 2010-07-16 17:10:13 -0700 | [diff] [blame] | 356 | // Bitmaps |
| 357 | SkBitmap* mShaderBitmap; |
| 358 | // Gradients |
| 359 | float* mShaderBounds; |
| 360 | uint32_t* mShaderColors; |
| 361 | float* mShaderPositions; |
Romain Guy | c0ac193 | 2010-07-19 18:43:02 -0700 | [diff] [blame] | 362 | int mShaderCount; |
Romain Guy | d27977d | 2010-07-14 19:18:51 -0700 | [diff] [blame] | 363 | |
Romain Guy | 694b519 | 2010-07-21 21:33:20 -0700 | [diff] [blame^] | 364 | // Font renderer |
| 365 | FontRenderer mFontRenderer; |
| 366 | |
Romain Guy | 82ba814 | 2010-07-09 13:25:56 -0700 | [diff] [blame] | 367 | // Various caches |
Romain Guy | ce0537b | 2010-06-29 21:05:21 -0700 | [diff] [blame] | 368 | TextureCache mTextureCache; |
Romain Guy | dda57020 | 2010-07-06 11:39:32 -0700 | [diff] [blame] | 369 | LayerCache mLayerCache; |
Romain Guy | c0ac193 | 2010-07-19 18:43:02 -0700 | [diff] [blame] | 370 | GradientCache mGradientCache; |
Romain Guy | f7f9355 | 2010-07-08 19:17:03 -0700 | [diff] [blame] | 371 | PatchCache mPatchCache; |
Romain Guy | bb9524b | 2010-06-22 18:56:38 -0700 | [diff] [blame] | 372 | }; // class OpenGLRenderer |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 373 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 374 | }; // namespace uirenderer |
Romain Guy | e4d0112 | 2010-06-16 18:44:05 -0700 | [diff] [blame] | 375 | }; // namespace android |
| 376 | |
Romain Guy | 9d5316e | 2010-06-24 19:30:36 -0700 | [diff] [blame] | 377 | #endif // ANDROID_UI_OPENGL_RENDERER_H |