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