epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 10 | #ifndef GrContext_DEFINED |
| 11 | #define GrContext_DEFINED |
| 12 | |
| 13 | #include "GrClip.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 14 | #include "GrPaint.h" |
bsalomon@google.com | c287a89 | 2011-08-19 14:49:36 +0000 | [diff] [blame] | 15 | // not strictly needed but requires WK change in LayerTextureUpdaterCanvas to |
| 16 | // remove. |
| 17 | #include "GrRenderTarget.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 18 | |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 19 | class GrDrawTarget; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 20 | class GrFontCache; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 21 | class GrGpu; |
| 22 | struct GrGpuStats; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 23 | class GrIndexBuffer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 24 | class GrIndexBufferAllocPool; |
| 25 | class GrInOrderDrawBuffer; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 26 | class GrPathRenderer; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 27 | class GrPathRendererChain; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 28 | class GrResourceEntry; |
| 29 | class GrResourceCache; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 30 | class GrStencilBuffer; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 31 | class GrVertexBuffer; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 32 | class GrVertexBufferAllocPool; |
| 33 | |
bsalomon@google.com | 9182610 | 2011-03-21 19:51:57 +0000 | [diff] [blame] | 34 | class GR_API GrContext : public GrRefCnt { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 35 | public: |
| 36 | /** |
| 37 | * Creates a GrContext from within a 3D context. |
| 38 | */ |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 39 | static GrContext* Create(GrEngine engine, |
| 40 | GrPlatform3DContext context3D); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 41 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 42 | virtual ~GrContext(); |
| 43 | |
| 44 | /** |
| 45 | * The GrContext normally assumes that no outsider is setting state |
| 46 | * within the underlying 3D API's context/device/whatever. This call informs |
| 47 | * the context that the state was modified and it should resend. Shouldn't |
| 48 | * be called frequently for good performance. |
| 49 | */ |
| 50 | void resetContext(); |
| 51 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 52 | /** |
| 53 | * Abandons all gpu resources, assumes 3D API state is unknown. Call this |
| 54 | * if you have lost the associated GPU context, and thus internal texture, |
| 55 | * buffer, etc. references/IDs are now invalid. Should be called even when |
| 56 | * GrContext is no longer going to be used for two reasons: |
| 57 | * 1) ~GrContext will not try to free the objects in the 3D API. |
| 58 | * 2) If you've created GrResources that outlive the GrContext they will |
| 59 | * be marked as invalid (GrResource::isValid()) and won't attempt to |
| 60 | * free their underlying resource in the 3D API. |
| 61 | * Content drawn since the last GrContext::flush() may be lost. |
| 62 | */ |
| 63 | void contextLost(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 64 | |
| 65 | /** |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 66 | * Similar to contextLost, but makes no attempt to reset state. |
| 67 | * Use this method when GrContext destruction is pending, but |
| 68 | * the graphics context is destroyed first. |
| 69 | */ |
| 70 | void contextDestroyed(); |
| 71 | |
| 72 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 73 | * Frees gpu created by the context. Can be called to reduce GPU memory |
| 74 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 75 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 76 | void freeGpuResources(); |
| 77 | |
| 78 | /////////////////////////////////////////////////////////////////////////// |
| 79 | // Textures |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 80 | |
| 81 | /** |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 82 | * Token that refers to an entry in the texture cache. Returned by |
| 83 | * functions that lock textures. Passed to unlockTexture. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 84 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 85 | class TextureCacheEntry { |
| 86 | public: |
| 87 | TextureCacheEntry() : fEntry(NULL) {} |
| 88 | TextureCacheEntry(const TextureCacheEntry& e) : fEntry(e.fEntry) {} |
| 89 | TextureCacheEntry& operator= (const TextureCacheEntry& e) { |
| 90 | fEntry = e.fEntry; |
| 91 | return *this; |
| 92 | } |
| 93 | GrTexture* texture() const; |
| 94 | void reset() { fEntry = NULL; } |
| 95 | private: |
| 96 | explicit TextureCacheEntry(GrResourceEntry* entry) { fEntry = entry; } |
| 97 | void set(GrResourceEntry* entry) { fEntry = entry; } |
| 98 | GrResourceEntry* cacheEntry() { return fEntry; } |
| 99 | GrResourceEntry* fEntry; |
| 100 | friend class GrContext; |
| 101 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 102 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 103 | /** |
| 104 | * Key generated by client. Should be a unique key on the texture data. |
| 105 | * Does not need to consider that width and height of the texture. Two |
| 106 | * textures with the same TextureKey but different bounds will not collide. |
| 107 | */ |
| 108 | typedef uint64_t TextureKey; |
| 109 | |
| 110 | /** |
| 111 | * Search for an entry based on key and dimensions. If found, "lock" it and |
| 112 | * return it. The entry's texture() function will return NULL if not found. |
| 113 | * Must call be balanced with an unlockTexture() call. |
| 114 | */ |
| 115 | TextureCacheEntry findAndLockTexture(TextureKey key, |
| 116 | int width, |
| 117 | int height, |
| 118 | const GrSamplerState&); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Create a new entry, based on the specified key and texture, and return |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 122 | * its "locked" entry. Must call be balanced with an unlockTexture() call. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 123 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 124 | TextureCacheEntry createAndLockTexture(TextureKey key, |
| 125 | const GrSamplerState&, |
| 126 | const GrTextureDesc&, |
| 127 | void* srcData, size_t rowBytes); |
| 128 | |
| 129 | /** |
| 130 | * Enum that determines how closely a returned scratch texture must match |
| 131 | * a provided GrTextureDesc. |
| 132 | */ |
| 133 | enum ScratchTexMatch { |
| 134 | /** |
| 135 | * Finds a texture that exactly matches the descriptor. |
| 136 | */ |
| 137 | kExact_ScratchTexMatch, |
| 138 | /** |
| 139 | * Finds a texture that approximately matches the descriptor. Will be |
| 140 | * at least as large in width and height as desc specifies. If desc |
| 141 | * specifies that texture is a render target then result will be a |
| 142 | * render target. If desc specifies a render target and doesn't set the |
| 143 | * no stencil flag then result will have a stencil. Format and aa level |
| 144 | * will always match. |
| 145 | */ |
| 146 | kApprox_ScratchTexMatch |
| 147 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 148 | |
| 149 | /** |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 150 | * Returns a texture matching the desc. It's contents are unknown. Subsequent |
| 151 | * requests with the same descriptor are not guaranteed to return the same |
| 152 | * texture. The same texture is guaranteed not be returned again until it is |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 153 | * unlocked. Must call be balanced with an unlockTexture() call. |
bsalomon@google.com | a39f404 | 2011-04-26 13:18:16 +0000 | [diff] [blame] | 154 | * |
| 155 | * Textures created by createAndLockTexture() hide the complications of |
| 156 | * tiling non-power-of-two textures on APIs that don't support this (e.g. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 157 | * unextended GLES2). Tiling a npot texture created by lockScratchTexture on |
bsalomon@google.com | a39f404 | 2011-04-26 13:18:16 +0000 | [diff] [blame] | 158 | * such an API will create gaps in the tiling pattern. This includes clamp |
| 159 | * mode. (This may be addressed in a future update.) |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 160 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 161 | TextureCacheEntry lockScratchTexture(const GrTextureDesc& desc, ScratchTexMatch match); |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 162 | |
| 163 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 164 | * When done with an entry, call unlockTexture(entry) on it, which returns |
| 165 | * it to the cache, where it may be purged. |
| 166 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 167 | void unlockTexture(TextureCacheEntry entry); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 168 | |
| 169 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 170 | * Creates a texture that is outside the cache. Does not count against |
| 171 | * cache's budget. |
| 172 | */ |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 173 | GrTexture* createUncachedTexture(const GrTextureDesc&, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 174 | void* srcData, |
| 175 | size_t rowBytes); |
| 176 | |
| 177 | /** |
| 178 | * Returns true if the specified use of an indexed texture is supported. |
| 179 | */ |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 180 | bool supportsIndex8PixelConfig(const GrSamplerState&, |
| 181 | int width, |
| 182 | int height) const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * Return the current texture cache limits. |
| 186 | * |
| 187 | * @param maxTextures If non-null, returns maximum number of textures that |
| 188 | * can be held in the cache. |
| 189 | * @param maxTextureBytes If non-null, returns maximum number of bytes of |
| 190 | * texture memory that can be held in the cache. |
| 191 | */ |
| 192 | void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const; |
| 193 | |
| 194 | /** |
| 195 | * Specify the texture cache limits. If the current cache exceeds either |
| 196 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 197 | * |
| 198 | * @param maxTextures The maximum number of textures that can be held in |
| 199 | * the cache. |
| 200 | * @param maxTextureBytes The maximum number of bytes of texture memory |
| 201 | * that can be held in the cache. |
| 202 | */ |
| 203 | void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes); |
| 204 | |
| 205 | /** |
| 206 | * Return the max width or height of a texture supported by the current gpu |
| 207 | */ |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 208 | int getMaxTextureSize() const; |
| 209 | |
| 210 | /** |
| 211 | * Return the max width or height of a render target supported by the |
| 212 | * current gpu |
| 213 | */ |
| 214 | int getMaxRenderTargetSize() const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 215 | |
| 216 | /////////////////////////////////////////////////////////////////////////// |
| 217 | // Render targets |
| 218 | |
| 219 | /** |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 220 | * Sets the render target. |
| 221 | * @param target the render target to set. (should not be NULL.) |
| 222 | */ |
| 223 | void setRenderTarget(GrRenderTarget* target); |
| 224 | |
| 225 | /** |
| 226 | * Gets the current render target. |
| 227 | * @return the currently bound render target. Should never be NULL. |
| 228 | */ |
| 229 | const GrRenderTarget* getRenderTarget() const; |
| 230 | GrRenderTarget* getRenderTarget(); |
| 231 | |
| 232 | /////////////////////////////////////////////////////////////////////////// |
| 233 | // Platform Surfaces |
| 234 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 235 | /** |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 236 | * Wraps an existing texture with a GrTexture object. |
| 237 | * |
| 238 | * OpenGL: if the object is a texture Gr may change its GL texture params |
| 239 | * when it is drawn. |
| 240 | * |
| 241 | * @param desc description of the object to create. |
| 242 | * |
| 243 | * @return GrTexture object or NULL on failure. |
| 244 | */ |
| 245 | GrTexture* createPlatformTexture(const GrPlatformTextureDesc& desc); |
| 246 | |
| 247 | /** |
| 248 | * Wraps an existing render target with a GrRenderTarget object. It is |
| 249 | * similar to createPlatformTexture but can be used to draw into surfaces |
| 250 | * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
| 251 | * the client will resolve to a texture). |
| 252 | * |
| 253 | * @param desc description of the object to create. |
| 254 | * |
| 255 | * @return GrTexture object or NULL on failure. |
| 256 | */ |
| 257 | GrRenderTarget* createPlatformRenderTarget( |
| 258 | const GrPlatformRenderTargetDesc& desc); |
| 259 | |
| 260 | /** |
| 261 | * This interface is depracted and will be removed in a future revision. |
| 262 | * Callers should use createPlatformTexture or createPlatformRenderTarget |
| 263 | * instead. |
| 264 | * |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 265 | * Wraps an existing 3D API surface in a GrObject. desc.fFlags determines |
| 266 | * the type of object returned. If kIsTexture is set the returned object |
| 267 | * will be a GrTexture*. Otherwise, it will be a GrRenderTarget*. If both |
| 268 | * are set the render target object is accessible by |
| 269 | * GrTexture::asRenderTarget(). |
| 270 | * |
| 271 | * GL: if the object is a texture Gr may change its GL texture parameters |
| 272 | * when it is drawn. |
| 273 | * |
| 274 | * @param desc description of the object to create. |
| 275 | * @return either a GrTexture* or GrRenderTarget* depending on desc. NULL |
| 276 | * on failure. |
| 277 | */ |
| 278 | GrResource* createPlatformSurface(const GrPlatformSurfaceDesc& desc); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 279 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 280 | /////////////////////////////////////////////////////////////////////////// |
| 281 | // Matrix state |
| 282 | |
| 283 | /** |
| 284 | * Gets the current transformation matrix. |
| 285 | * @return the current matrix. |
| 286 | */ |
| 287 | const GrMatrix& getMatrix() const; |
| 288 | |
| 289 | /** |
| 290 | * Sets the transformation matrix. |
| 291 | * @param m the matrix to set. |
| 292 | */ |
| 293 | void setMatrix(const GrMatrix& m); |
| 294 | |
| 295 | /** |
| 296 | * Concats the current matrix. The passed matrix is applied before the |
| 297 | * current matrix. |
| 298 | * @param m the matrix to concat. |
| 299 | */ |
| 300 | void concatMatrix(const GrMatrix& m) const; |
| 301 | |
| 302 | |
| 303 | /////////////////////////////////////////////////////////////////////////// |
| 304 | // Clip state |
| 305 | /** |
| 306 | * Gets the current clip. |
| 307 | * @return the current clip. |
| 308 | */ |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 309 | const GrClip& getClip() const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 310 | |
| 311 | /** |
| 312 | * Sets the clip. |
| 313 | * @param clip the clip to set. |
| 314 | */ |
| 315 | void setClip(const GrClip& clip); |
| 316 | |
| 317 | /** |
| 318 | * Convenience method for setting the clip to a rect. |
| 319 | * @param rect the rect to set as the new clip. |
| 320 | */ |
| 321 | void setClip(const GrIRect& rect); |
| 322 | |
| 323 | /////////////////////////////////////////////////////////////////////////// |
| 324 | // Draws |
| 325 | |
| 326 | /** |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 327 | * Clear the entire or rect of the render target, ignoring any clips. |
| 328 | * @param rect the rect to clear or the whole thing if rect is NULL. |
| 329 | * @param color the color to clear to. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 330 | */ |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 331 | void clear(const GrIRect* rect, GrColor color); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * Draw everywhere (respecting the clip) with the paint. |
| 335 | */ |
| 336 | void drawPaint(const GrPaint& paint); |
| 337 | |
| 338 | /** |
| 339 | * Draw the rect using a paint. |
| 340 | * @param paint describes how to color pixels. |
| 341 | * @param strokeWidth If strokeWidth < 0, then the rect is filled, else |
| 342 | * the rect is mitered stroked based on strokeWidth. If |
| 343 | * strokeWidth == 0, then the stroke is always a single |
| 344 | * pixel thick. |
| 345 | * @param matrix Optional matrix applied to the rect. Applied before |
| 346 | * context's matrix or the paint's matrix. |
| 347 | * The rects coords are used to access the paint (through texture matrix) |
| 348 | */ |
| 349 | void drawRect(const GrPaint& paint, |
| 350 | const GrRect&, |
| 351 | GrScalar strokeWidth = -1, |
| 352 | const GrMatrix* matrix = NULL); |
| 353 | |
| 354 | /** |
| 355 | * Maps a rect of paint coordinates onto the a rect of destination |
| 356 | * coordinates. Each rect can optionally be transformed. The srcRect |
| 357 | * is stretched over the dstRect. The dstRect is transformed by the |
| 358 | * context's matrix and the srcRect is transformed by the paint's matrix. |
| 359 | * Additional optional matrices can be provided by parameters. |
| 360 | * |
| 361 | * @param paint describes how to color pixels. |
| 362 | * @param dstRect the destination rect to draw. |
| 363 | * @param srcRect rect of paint coordinates to be mapped onto dstRect |
| 364 | * @param dstMatrix Optional matrix to transform dstRect. Applied before |
| 365 | * context's matrix. |
| 366 | * @param srcMatrix Optional matrix to transform srcRect Applied before |
| 367 | * paint's matrix. |
| 368 | */ |
| 369 | void drawRectToRect(const GrPaint& paint, |
| 370 | const GrRect& dstRect, |
| 371 | const GrRect& srcRect, |
| 372 | const GrMatrix* dstMatrix = NULL, |
| 373 | const GrMatrix* srcMatrix = NULL); |
| 374 | |
| 375 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 376 | * Draws a path. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 377 | * |
| 378 | * @param paint describes how to color pixels. |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 379 | * @param path the path to draw |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 380 | * @param fill the path filling rule to use. |
| 381 | * @param translate optional additional translation applied to the |
| 382 | * path. |
| 383 | */ |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 384 | void drawPath(const GrPaint& paint, const GrPath& path, GrPathFill fill, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 385 | const GrPoint* translate = NULL); |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 386 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 387 | /** |
| 388 | * Draws vertices with a paint. |
| 389 | * |
| 390 | * @param paint describes how to color pixels. |
| 391 | * @param primitiveType primitives type to draw. |
| 392 | * @param vertexCount number of vertices. |
| 393 | * @param positions array of vertex positions, required. |
| 394 | * @param texCoords optional array of texture coordinates used |
| 395 | * to access the paint. |
| 396 | * @param colors optional array of per-vertex colors, supercedes |
| 397 | * the paint's color field. |
| 398 | * @param indices optional array of indices. If NULL vertices |
| 399 | * are drawn non-indexed. |
| 400 | * @param indexCount if indices is non-null then this is the |
| 401 | * number of indices. |
| 402 | */ |
| 403 | void drawVertices(const GrPaint& paint, |
| 404 | GrPrimitiveType primitiveType, |
| 405 | int vertexCount, |
| 406 | const GrPoint positions[], |
| 407 | const GrPoint texs[], |
| 408 | const GrColor colors[], |
| 409 | const uint16_t indices[], |
| 410 | int indexCount); |
| 411 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 412 | /////////////////////////////////////////////////////////////////////////// |
| 413 | // Misc. |
| 414 | |
| 415 | /** |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 416 | * Currently needed by SkGpuDevice. Ideally this shouldn't be exposed. |
| 417 | */ |
| 418 | bool supportsShaders() const; |
| 419 | |
| 420 | /** |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 421 | * Flags that affect flush() behavior. |
| 422 | */ |
| 423 | enum FlushBits { |
| 424 | /** |
| 425 | * A client may want Gr to bind a GrRenderTarget in the 3D API so that |
| 426 | * it can be rendered to directly. However, Gr lazily sets state. Simply |
| 427 | * calling setRenderTarget() followed by flush() without flags may not |
| 428 | * bind the render target. This flag forces the context to bind the last |
| 429 | * set render target in the 3D API. |
| 430 | */ |
| 431 | kForceCurrentRenderTarget_FlushBit = 0x1, |
| 432 | /** |
| 433 | * A client may reach a point where it has partially rendered a frame |
| 434 | * through a GrContext that it knows the user will never see. This flag |
| 435 | * causes the flush to skip submission of deferred content to the 3D API |
| 436 | * during the flush. |
| 437 | */ |
| 438 | kDiscard_FlushBit = 0x2, |
| 439 | }; |
| 440 | |
| 441 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 442 | * Call to ensure all drawing to the context has been issued to the |
| 443 | * underlying 3D API. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 444 | * @param flagsBitfield flags that control the flushing behavior. See |
| 445 | * FlushBits. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 446 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 447 | void flush(int flagsBitfield = 0); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 448 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 449 | /** |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 450 | * Reads a rectangle of pixels from a render target. |
| 451 | * @param renderTarget the render target to read from. NULL means the |
| 452 | * current render target. |
| 453 | * @param left left edge of the rectangle to read (inclusive) |
| 454 | * @param top top edge of the rectangle to read (inclusive) |
| 455 | * @param width width of rectangle to read in pixels. |
| 456 | * @param height height of rectangle to read in pixels. |
| 457 | * @param config the pixel config of the destination buffer |
| 458 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 459 | * @param rowBytes number of bytes bewtween consecueive rows. Zero |
| 460 | * means rows are tightly packed. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 461 | * |
| 462 | * @return true if the read succeeded, false if not. The read can fail |
| 463 | * because of a unsupported pixel config or because no render |
| 464 | * target is currently set. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 465 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 466 | bool readRenderTargetPixels(GrRenderTarget* target, |
| 467 | int left, int top, int width, int height, |
bsalomon@google.com | c698097 | 2011-11-02 19:57:21 +0000 | [diff] [blame] | 468 | GrPixelConfig config, void* buffer, |
| 469 | size_t rowBytes = 0); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * Reads a rectangle of pixels from a texture. |
| 473 | * @param texture the render target to read from. |
| 474 | * @param left left edge of the rectangle to read (inclusive) |
| 475 | * @param top top edge of the rectangle to read (inclusive) |
| 476 | * @param width width of rectangle to read in pixels. |
| 477 | * @param height height of rectangle to read in pixels. |
| 478 | * @param config the pixel config of the destination buffer |
| 479 | * @param buffer memory to read the rectangle into. |
| 480 | * |
| 481 | * @return true if the read succeeded, false if not. The read can fail |
| 482 | * because of a unsupported pixel config. |
| 483 | */ |
| 484 | bool readTexturePixels(GrTexture* target, |
| 485 | int left, int top, int width, int height, |
| 486 | GrPixelConfig config, void* buffer); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 487 | |
| 488 | /** |
| 489 | * Copy the src pixels [buffer, stride, pixelconfig] into the current |
| 490 | * render-target at the specified rectangle. |
| 491 | */ |
| 492 | void writePixels(int left, int top, int width, int height, |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 493 | GrPixelConfig, const void* buffer, size_t stride); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 494 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 495 | /** |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 496 | * Applies a 1D convolution kernel in the X direction to a rectangle of |
| 497 | * pixels from a given texture. |
| 498 | * @param texture the texture to read from |
| 499 | * @param rect the destination rectangle |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 500 | * @param kernel the convolution kernel (kernelWidth elements) |
| 501 | * @param kernelWidth the width of the convolution kernel |
| 502 | */ |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 503 | void convolveInX(GrTexture* texture, |
| 504 | const SkRect& rect, |
| 505 | const float* kernel, |
| 506 | int kernelWidth); |
| 507 | /** |
| 508 | * Applies a 1D convolution kernel in the Y direction to a rectangle of |
| 509 | * pixels from a given texture. |
| 510 | * direction. |
| 511 | * @param texture the texture to read from |
| 512 | * @param rect the destination rectangle |
| 513 | * @param kernel the convolution kernel (kernelWidth elements) |
| 514 | * @param kernelWidth the width of the convolution kernel |
| 515 | */ |
| 516 | void convolveInY(GrTexture* texture, |
| 517 | const SkRect& rect, |
| 518 | const float* kernel, |
| 519 | int kernelWidth); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 520 | /////////////////////////////////////////////////////////////////////////// |
| 521 | // Helpers |
| 522 | |
| 523 | class AutoRenderTarget : ::GrNoncopyable { |
| 524 | public: |
| 525 | AutoRenderTarget(GrContext* context, GrRenderTarget* target) { |
| 526 | fContext = NULL; |
| 527 | fPrevTarget = context->getRenderTarget(); |
| 528 | if (fPrevTarget != target) { |
| 529 | context->setRenderTarget(target); |
| 530 | fContext = context; |
| 531 | } |
| 532 | } |
| 533 | ~AutoRenderTarget() { |
| 534 | if (fContext) { |
| 535 | fContext->setRenderTarget(fPrevTarget); |
| 536 | } |
| 537 | } |
| 538 | private: |
| 539 | GrContext* fContext; |
| 540 | GrRenderTarget* fPrevTarget; |
| 541 | }; |
| 542 | |
| 543 | |
| 544 | /////////////////////////////////////////////////////////////////////////// |
| 545 | // Functions intended for internal use only. |
| 546 | GrGpu* getGpu() { return fGpu; } |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 547 | const GrGpu* getGpu() const { return fGpu; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 548 | GrFontCache* getFontCache() { return fFontCache; } |
| 549 | GrDrawTarget* getTextTarget(const GrPaint& paint); |
| 550 | void flushText(); |
| 551 | const GrIndexBuffer* getQuadIndexBuffer() const; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 552 | void resetStats(); |
| 553 | const GrGpuStats& getStats() const; |
| 554 | void printStats() const; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 555 | /** |
| 556 | * Stencil buffers add themselves to the cache using |
| 557 | * addAndLockStencilBuffer. When a SB's RT-attachment count |
| 558 | * reaches zero the SB unlocks itself using unlockStencilBuffer and is |
| 559 | * eligible for purging. findStencilBuffer is called to check the cache for |
| 560 | * a SB that matching an RT's criteria. If a match is found that has been |
| 561 | * unlocked (its attachment count has reached 0) then it will be relocked. |
| 562 | */ |
| 563 | GrResourceEntry* addAndLockStencilBuffer(GrStencilBuffer* sb); |
| 564 | void unlockStencilBuffer(GrResourceEntry* sbEntry); |
| 565 | GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 566 | |
| 567 | private: |
| 568 | // used to keep track of when we need to flush the draw buffer |
| 569 | enum DrawCategory { |
| 570 | kBuffered_DrawCategory, // last draw was inserted in draw buffer |
| 571 | kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer |
| 572 | kText_DrawCategory // text context was last to draw |
| 573 | }; |
| 574 | DrawCategory fLastDrawCategory; |
| 575 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 576 | GrGpu* fGpu; |
| 577 | GrResourceCache* fTextureCache; |
| 578 | GrFontCache* fFontCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 579 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 580 | GrPathRendererChain* fPathRendererChain; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 581 | |
| 582 | GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
| 583 | GrIndexBufferAllocPool* fDrawBufferIBAllocPool; |
| 584 | GrInOrderDrawBuffer* fDrawBuffer; |
| 585 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 586 | GrIndexBuffer* fAAFillRectIndexBuffer; |
| 587 | GrIndexBuffer* fAAStrokeRectIndexBuffer; |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 588 | int fMaxOffscreenAASize; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 589 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 590 | GrContext(GrGpu* gpu); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 591 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 592 | void fillAARect(GrDrawTarget* target, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 593 | const GrRect& devRect, |
| 594 | bool useVertexCoverage); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 595 | |
| 596 | void strokeAARect(GrDrawTarget* target, |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 597 | const GrRect& devRect, |
bsalomon@google.com | a310826 | 2011-10-10 14:08:47 +0000 | [diff] [blame] | 598 | const GrVec& devStrokeSize, |
| 599 | bool useVertexCoverage); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 600 | |
| 601 | inline int aaFillRectIndexCount() const; |
| 602 | GrIndexBuffer* aaFillRectIndexBuffer(); |
| 603 | |
| 604 | inline int aaStrokeRectIndexCount() const; |
| 605 | GrIndexBuffer* aaStrokeRectIndexBuffer(); |
| 606 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 607 | void setupDrawBuffer(); |
| 608 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 609 | void flushDrawBuffer(); |
| 610 | |
| 611 | static void SetPaint(const GrPaint& paint, GrDrawTarget* target); |
| 612 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 613 | GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType); |
| 614 | |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 615 | GrPathRenderer* getPathRenderer(const GrPath& path, |
| 616 | GrPathFill fill, |
| 617 | bool antiAlias); |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 618 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 619 | struct OffscreenRecord; |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 620 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 621 | // determines whether offscreen AA should be applied |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 622 | bool doOffscreenAA(GrDrawTarget* target, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 623 | bool isHairLines) const; |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 624 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 625 | // attempts to setup offscreen AA. All paint state must be transferred to |
| 626 | // target by the time this is called. |
| 627 | bool prepareForOffscreenAA(GrDrawTarget* target, |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 628 | bool requireStencil, |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 629 | const GrIRect& boundRect, |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 630 | GrPathRenderer* pr, |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 631 | OffscreenRecord* record); |
| 632 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 633 | // sets up target to draw coverage to the supersampled render target |
| 634 | void setupOffscreenAAPass1(GrDrawTarget* target, |
| 635 | const GrIRect& boundRect, |
| 636 | int tileX, int tileY, |
| 637 | OffscreenRecord* record); |
| 638 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 639 | // sets up target to sample coverage of supersampled render target back |
| 640 | // to the main render target using stage kOffscreenStage. |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 641 | void doOffscreenAAPass2(GrDrawTarget* target, |
| 642 | const GrPaint& paint, |
| 643 | const GrIRect& boundRect, |
| 644 | int tileX, int tileY, |
| 645 | OffscreenRecord* record); |
| 646 | |
| 647 | // restored the draw target state and releases offscreen target to cache |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 648 | void cleanupOffscreenAA(GrDrawTarget* target, |
| 649 | GrPathRenderer* pr, |
| 650 | OffscreenRecord* record); |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 651 | |
| 652 | void convolve(GrTexture* texture, |
| 653 | const SkRect& rect, |
| 654 | float imageIncrement[2], |
| 655 | const float* kernel, |
| 656 | int kernelWidth); |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 657 | |
bsalomon@google.com | 26c2d0a | 2011-05-17 20:15:30 +0000 | [diff] [blame] | 658 | // computes vertex layout bits based on the paint. If paint expresses |
| 659 | // a texture for a stage, the stage coords will be bound to postitions |
| 660 | // unless hasTexCoords[s]==true in which case stage s's input coords |
| 661 | // are bound to tex coord index s. hasTexCoords == NULL is a shortcut |
| 662 | // for an array where all the values are false. |
| 663 | static int PaintStageVertexLayoutBits( |
| 664 | const GrPaint& paint, |
| 665 | const bool hasTexCoords[GrPaint::kTotalStages]); |
| 666 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 667 | }; |
| 668 | |
| 669 | /** |
| 670 | * Save/restore the view-matrix in the context. |
| 671 | */ |
| 672 | class GrAutoMatrix : GrNoncopyable { |
| 673 | public: |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 674 | GrAutoMatrix() : fContext(NULL) {} |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 675 | GrAutoMatrix(GrContext* ctx) : fContext(ctx) { |
| 676 | fMatrix = ctx->getMatrix(); |
| 677 | } |
| 678 | GrAutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) { |
| 679 | fMatrix = ctx->getMatrix(); |
| 680 | ctx->setMatrix(matrix); |
| 681 | } |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 682 | void set(GrContext* ctx) { |
| 683 | if (NULL != fContext) { |
| 684 | fContext->setMatrix(fMatrix); |
| 685 | } |
| 686 | fMatrix = ctx->getMatrix(); |
| 687 | fContext = ctx; |
| 688 | } |
| 689 | void set(GrContext* ctx, const GrMatrix& matrix) { |
| 690 | if (NULL != fContext) { |
| 691 | fContext->setMatrix(fMatrix); |
| 692 | } |
| 693 | fMatrix = ctx->getMatrix(); |
| 694 | ctx->setMatrix(matrix); |
| 695 | fContext = ctx; |
| 696 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 697 | ~GrAutoMatrix() { |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 698 | if (NULL != fContext) { |
| 699 | fContext->setMatrix(fMatrix); |
| 700 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | private: |
| 704 | GrContext* fContext; |
| 705 | GrMatrix fMatrix; |
| 706 | }; |
| 707 | |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 708 | /** |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 709 | * Gets and locks a scratch texture from a descriptor using |
| 710 | * either exact or approximate criteria. Unlocks texture in |
| 711 | * the destructor. |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 712 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 713 | class GrAutoScratchTexture : ::GrNoncopyable { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 714 | public: |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 715 | GrAutoScratchTexture() |
| 716 | : fContext(NULL) { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 717 | } |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 718 | |
| 719 | GrAutoScratchTexture(GrContext* context, |
| 720 | const GrTextureDesc& desc, |
| 721 | GrContext::ScratchTexMatch match = |
| 722 | GrContext::kApprox_ScratchTexMatch) |
| 723 | : fContext(NULL) { |
| 724 | this->set(context, desc, match); |
| 725 | } |
| 726 | |
| 727 | ~GrAutoScratchTexture() { |
| 728 | if (NULL != fContext) { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 729 | fContext->unlockTexture(fEntry); |
| 730 | } |
| 731 | } |
bsalomon@google.com | 8422311 | 2011-07-14 14:45:44 +0000 | [diff] [blame] | 732 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 733 | GrTexture* set(GrContext* context, |
| 734 | const GrTextureDesc& desc, |
| 735 | GrContext::ScratchTexMatch match = |
| 736 | GrContext::kApprox_ScratchTexMatch) { |
| 737 | if (NULL != fContext) { |
| 738 | fContext->unlockTexture(fEntry); |
| 739 | } |
| 740 | fContext = context; |
| 741 | if (NULL != fContext) { |
| 742 | fEntry = fContext->lockScratchTexture(desc, match); |
| 743 | GrTexture* ret = fEntry.texture(); |
| 744 | if (NULL == ret) { |
| 745 | fContext = NULL; |
| 746 | } |
| 747 | return ret; |
| 748 | } else { |
| 749 | return NULL; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | GrTexture* texture() { return fEntry.texture(); } |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 754 | private: |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 755 | GrContext* fContext; |
| 756 | GrContext::TextureCacheEntry fEntry; |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 757 | }; |
| 758 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 759 | #endif |
| 760 | |