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