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 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 13 | #include "GrConfig.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 14 | #include "GrPaint.h" |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 15 | #include "GrAARectRenderer.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 16 | #include "GrClipData.h" |
bsalomon@google.com | c287a89 | 2011-08-19 14:49:36 +0000 | [diff] [blame] | 17 | // not strictly needed but requires WK change in LayerTextureUpdaterCanvas to |
| 18 | // remove. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 19 | #include "GrRenderTarget.h" |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 20 | #include "SkClipStack.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 21 | |
senorblanco@chromium.org | 3b4dd90 | 2012-03-05 20:41:22 +0000 | [diff] [blame] | 22 | class GrAutoScratchTexture; |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 23 | class GrCacheKey; |
bsalomon@google.com | 10e04bf | 2012-03-30 14:35:04 +0000 | [diff] [blame] | 24 | class GrDrawState; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 25 | class GrDrawTarget; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 26 | class GrFontCache; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 27 | class GrGpu; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 28 | class GrIndexBuffer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 29 | class GrIndexBufferAllocPool; |
| 30 | class GrInOrderDrawBuffer; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 31 | class GrPathRenderer; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 32 | class GrPathRendererChain; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 33 | class GrResourceEntry; |
| 34 | class GrResourceCache; |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 35 | class GrStencilBuffer; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 36 | class GrVertexBuffer; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 37 | class GrVertexBufferAllocPool; |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 38 | class GrSoftwarePathRenderer; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 39 | |
bsalomon@google.com | 9182610 | 2011-03-21 19:51:57 +0000 | [diff] [blame] | 40 | class GR_API GrContext : public GrRefCnt { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 41 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 42 | SK_DECLARE_INST_COUNT(GrContext) |
| 43 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 44 | /** |
| 45 | * Creates a GrContext from within a 3D context. |
| 46 | */ |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 47 | static GrContext* Create(GrEngine engine, |
| 48 | GrPlatform3DContext context3D); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 49 | |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 50 | /** |
| 51 | * Returns the number of GrContext instances for the current thread. |
| 52 | */ |
| 53 | static int GetThreadInstanceCount(); |
| 54 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 55 | virtual ~GrContext(); |
| 56 | |
| 57 | /** |
| 58 | * The GrContext normally assumes that no outsider is setting state |
| 59 | * within the underlying 3D API's context/device/whatever. This call informs |
| 60 | * the context that the state was modified and it should resend. Shouldn't |
| 61 | * be called frequently for good performance. |
| 62 | */ |
| 63 | void resetContext(); |
| 64 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 65 | /** |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 66 | * Callback function to allow classes to cleanup on GrContext destruction. |
| 67 | * The 'info' field is filled in with the 'info' passed to addCleanUp. |
| 68 | */ |
| 69 | typedef void (*PFCleanUpFunc)(const GrContext* context, void* info); |
| 70 | |
| 71 | /** |
| 72 | * Add a function to be called from within GrContext's destructor. |
| 73 | * This gives classes a chance to free resources held on a per context basis. |
| 74 | * The 'info' parameter will be stored and passed to the callback function. |
| 75 | */ |
| 76 | void addCleanUp(PFCleanUpFunc cleanUp, void* info) { |
| 77 | CleanUpData* entry = fCleanUpData.push(); |
| 78 | |
| 79 | entry->fFunc = cleanUp; |
| 80 | entry->fInfo = info; |
| 81 | } |
| 82 | |
| 83 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 84 | * Abandons all gpu resources, assumes 3D API state is unknown. Call this |
| 85 | * if you have lost the associated GPU context, and thus internal texture, |
| 86 | * buffer, etc. references/IDs are now invalid. Should be called even when |
| 87 | * GrContext is no longer going to be used for two reasons: |
| 88 | * 1) ~GrContext will not try to free the objects in the 3D API. |
| 89 | * 2) If you've created GrResources that outlive the GrContext they will |
| 90 | * be marked as invalid (GrResource::isValid()) and won't attempt to |
| 91 | * free their underlying resource in the 3D API. |
| 92 | * Content drawn since the last GrContext::flush() may be lost. |
| 93 | */ |
| 94 | void contextLost(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 95 | |
| 96 | /** |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 97 | * Similar to contextLost, but makes no attempt to reset state. |
| 98 | * Use this method when GrContext destruction is pending, but |
| 99 | * the graphics context is destroyed first. |
| 100 | */ |
| 101 | void contextDestroyed(); |
| 102 | |
| 103 | /** |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 104 | * Frees gpu created by the context. Can be called to reduce GPU memory |
| 105 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 106 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 107 | void freeGpuResources(); |
| 108 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 109 | /** |
| 110 | * Returns the number of bytes of GPU memory hosted by the texture cache. |
| 111 | */ |
| 112 | size_t getGpuTextureCacheBytes() const; |
| 113 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 114 | /////////////////////////////////////////////////////////////////////////// |
| 115 | // Textures |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 116 | |
| 117 | /** |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 118 | * Create a new entry, based on the specified key and texture, and return |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 119 | * a "locked" texture. Must call be balanced with an unlockTexture() call. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 120 | * |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 121 | * @param params The tex params used to draw a texture may help determine |
| 122 | * the cache entry used. (e.g. different versions may exist |
| 123 | * for different wrap modes on GPUs with limited NPOT |
| 124 | * texture support). NULL implies clamp wrap modes. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 125 | * @param desc Description of the texture properties. |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 126 | * @param cacheData Cache-specific properties (e.g., texture gen ID) |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 127 | * @param srcData Pointer to the pixel values. |
| 128 | * @param rowBytes The number of bytes between rows of the texture. Zero |
| 129 | * implies tightly packed rows. |
| 130 | */ |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 131 | GrTexture* createTexture(const GrTextureParams* params, |
| 132 | const GrTextureDesc& desc, |
| 133 | const GrCacheData& cacheData, |
| 134 | void* srcData, size_t rowBytes); |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 135 | |
| 136 | /** |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 137 | * Look for a texture that matches 'key' in the cache. If not found, |
| 138 | * return NULL. |
| 139 | */ |
| 140 | GrTexture* findTexture(const GrCacheKey& key); |
| 141 | |
| 142 | /** |
skia.committer@gmail.com | d6ce0db | 2012-09-10 02:01:22 +0000 | [diff] [blame] | 143 | * Search for an entry based on key and dimensions. If found, |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 144 | * return it. The return value will be NULL if not found. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 145 | * |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 146 | * @param desc Description of the texture properties. |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 147 | * @param cacheData Cache-specific properties (e.g., texture gen ID) |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 148 | * @param params The tex params used to draw a texture may help determine |
| 149 | * the cache entry used. (e.g. different versions may exist |
| 150 | * for different wrap modes on GPUs with limited NPOT |
| 151 | * texture support). NULL implies clamp wrap modes. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 152 | */ |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 153 | GrTexture* findTexture(const GrTextureDesc& desc, |
| 154 | const GrCacheData& cacheData, |
| 155 | const GrTextureParams* params); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 156 | /** |
| 157 | * Determines whether a texture is in the cache. If the texture is found it |
| 158 | * will not be locked or returned. This call does not affect the priority of |
| 159 | * the texture for deletion. |
| 160 | */ |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 161 | bool isTextureInCache(const GrTextureDesc& desc, |
robertphillips@google.com | 9c2ea84 | 2012-08-13 17:47:59 +0000 | [diff] [blame] | 162 | const GrCacheData& cacheData, |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 163 | const GrTextureParams* params) const; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 164 | |
| 165 | /** |
| 166 | * Enum that determines how closely a returned scratch texture must match |
| 167 | * a provided GrTextureDesc. |
| 168 | */ |
| 169 | enum ScratchTexMatch { |
| 170 | /** |
| 171 | * Finds a texture that exactly matches the descriptor. |
| 172 | */ |
| 173 | kExact_ScratchTexMatch, |
| 174 | /** |
| 175 | * Finds a texture that approximately matches the descriptor. Will be |
| 176 | * at least as large in width and height as desc specifies. If desc |
| 177 | * specifies that texture is a render target then result will be a |
| 178 | * render target. If desc specifies a render target and doesn't set the |
| 179 | * no stencil flag then result will have a stencil. Format and aa level |
| 180 | * will always match. |
| 181 | */ |
| 182 | kApprox_ScratchTexMatch |
| 183 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 184 | |
| 185 | /** |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 186 | * Returns a texture matching the desc. It's contents are unknown. Subsequent |
| 187 | * requests with the same descriptor are not guaranteed to return the same |
| 188 | * texture. The same texture is guaranteed not be returned again until it is |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 189 | * unlocked. Call must be balanced with an unlockTexture() call. |
bsalomon@google.com | a39f404 | 2011-04-26 13:18:16 +0000 | [diff] [blame] | 190 | * |
| 191 | * Textures created by createAndLockTexture() hide the complications of |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 192 | * 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] | 193 | * unextended GLES2). Tiling a npot texture created by lockScratchTexture on |
bsalomon@google.com | a39f404 | 2011-04-26 13:18:16 +0000 | [diff] [blame] | 194 | * such an API will create gaps in the tiling pattern. This includes clamp |
| 195 | * mode. (This may be addressed in a future update.) |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 196 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 197 | GrTexture* lockScratchTexture(const GrTextureDesc& desc, |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 198 | ScratchTexMatch match); |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 199 | |
| 200 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 201 | * When done with an entry, call unlockTexture(entry) on it, which returns |
| 202 | * it to the cache, where it may be purged. |
| 203 | */ |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 204 | void unlockScratchTexture(GrTexture* texture); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 205 | |
| 206 | /** |
robertphillips@google.com | 50a035d | 2012-09-07 19:44:33 +0000 | [diff] [blame] | 207 | * This method should be called whenever a GrTexture is unreffed or |
| 208 | * switched from exclusive to non-exclusive. This |
| 209 | * gives the resource cache a chance to discard unneeded textures. |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 210 | * Note: this entry point will be removed once totally ref-driven |
| 211 | * cache maintenance is implemented |
robertphillips@google.com | 50a035d | 2012-09-07 19:44:33 +0000 | [diff] [blame] | 212 | */ |
| 213 | void purgeCache(); |
| 214 | |
| 215 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 216 | * Creates a texture that is outside the cache. Does not count against |
| 217 | * cache's budget. |
| 218 | */ |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 219 | GrTexture* createUncachedTexture(const GrTextureDesc& desc, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 220 | void* srcData, |
| 221 | size_t rowBytes); |
| 222 | |
| 223 | /** |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 224 | * Returns true if the specified use of an indexed texture is supported. |
| 225 | * Support may depend upon whether the texture params indicate that the |
| 226 | * texture will be tiled. Passing NULL for the texture params indicates |
| 227 | * clamp mode. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 228 | */ |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 229 | bool supportsIndex8PixelConfig(const GrTextureParams*, |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 230 | int width, |
| 231 | int height) const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 232 | |
| 233 | /** |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 234 | * Return the current texture cache limits. |
| 235 | * |
| 236 | * @param maxTextures If non-null, returns maximum number of textures that |
| 237 | * can be held in the cache. |
| 238 | * @param maxTextureBytes If non-null, returns maximum number of bytes of |
| 239 | * texture memory that can be held in the cache. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 240 | */ |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 241 | void getTextureCacheLimits(int* maxTextures, size_t* maxTextureBytes) const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 242 | |
| 243 | /** |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 244 | * Specify the texture cache limits. If the current cache exceeds either |
| 245 | * of these, it will be purged (LRU) to keep the cache within these limits. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 246 | * |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 247 | * @param maxTextures The maximum number of textures that can be held in |
| 248 | * the cache. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 249 | * @param maxTextureBytes The maximum number of bytes of texture memory |
| 250 | * that can be held in the cache. |
| 251 | */ |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 252 | void setTextureCacheLimits(int maxTextures, size_t maxTextureBytes); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 253 | |
| 254 | /** |
| 255 | * Return the max width or height of a texture supported by the current gpu |
| 256 | */ |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 257 | int getMaxTextureSize() const; |
| 258 | |
| 259 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 260 | * Return the max width or height of a render target supported by the |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 261 | * current gpu |
| 262 | */ |
| 263 | int getMaxRenderTargetSize() const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 264 | |
| 265 | /////////////////////////////////////////////////////////////////////////// |
| 266 | // Render targets |
| 267 | |
| 268 | /** |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 269 | * Sets the render target. |
| 270 | * @param target the render target to set. (should not be NULL.) |
| 271 | */ |
| 272 | void setRenderTarget(GrRenderTarget* target); |
| 273 | |
| 274 | /** |
| 275 | * Gets the current render target. |
| 276 | * @return the currently bound render target. Should never be NULL. |
| 277 | */ |
| 278 | const GrRenderTarget* getRenderTarget() const; |
| 279 | GrRenderTarget* getRenderTarget(); |
| 280 | |
robertphillips@google.com | f69a11b | 2012-06-15 13:58:07 +0000 | [diff] [blame] | 281 | GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } |
| 282 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 283 | /** |
| 284 | * Can the provided configuration act as a color render target? |
| 285 | */ |
| 286 | bool isConfigRenderable(GrPixelConfig config) const; |
| 287 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 288 | /////////////////////////////////////////////////////////////////////////// |
| 289 | // Platform Surfaces |
| 290 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 291 | /** |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 292 | * Wraps an existing texture with a GrTexture object. |
| 293 | * |
| 294 | * OpenGL: if the object is a texture Gr may change its GL texture params |
| 295 | * when it is drawn. |
| 296 | * |
| 297 | * @param desc description of the object to create. |
| 298 | * |
| 299 | * @return GrTexture object or NULL on failure. |
| 300 | */ |
| 301 | GrTexture* createPlatformTexture(const GrPlatformTextureDesc& desc); |
| 302 | |
| 303 | /** |
| 304 | * Wraps an existing render target with a GrRenderTarget object. It is |
| 305 | * similar to createPlatformTexture but can be used to draw into surfaces |
| 306 | * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
| 307 | * the client will resolve to a texture). |
| 308 | * |
| 309 | * @param desc description of the object to create. |
| 310 | * |
| 311 | * @return GrTexture object or NULL on failure. |
| 312 | */ |
| 313 | GrRenderTarget* createPlatformRenderTarget( |
| 314 | const GrPlatformRenderTargetDesc& desc); |
| 315 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 316 | /////////////////////////////////////////////////////////////////////////// |
| 317 | // Matrix state |
| 318 | |
| 319 | /** |
| 320 | * Gets the current transformation matrix. |
| 321 | * @return the current matrix. |
| 322 | */ |
| 323 | const GrMatrix& getMatrix() const; |
| 324 | |
| 325 | /** |
| 326 | * Sets the transformation matrix. |
| 327 | * @param m the matrix to set. |
| 328 | */ |
| 329 | void setMatrix(const GrMatrix& m); |
| 330 | |
| 331 | /** |
| 332 | * Concats the current matrix. The passed matrix is applied before the |
| 333 | * current matrix. |
| 334 | * @param m the matrix to concat. |
| 335 | */ |
| 336 | void concatMatrix(const GrMatrix& m) const; |
| 337 | |
| 338 | |
| 339 | /////////////////////////////////////////////////////////////////////////// |
| 340 | // Clip state |
| 341 | /** |
| 342 | * Gets the current clip. |
| 343 | * @return the current clip. |
| 344 | */ |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 345 | const GrClipData* getClip() const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 346 | |
| 347 | /** |
| 348 | * Sets the clip. |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 349 | * @param clipData the clip to set. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 350 | */ |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 351 | void setClip(const GrClipData* clipData); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 352 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 353 | /////////////////////////////////////////////////////////////////////////// |
| 354 | // Draws |
| 355 | |
| 356 | /** |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 357 | * Clear the entire or rect of the render target, ignoring any clips. |
| 358 | * @param rect the rect to clear or the whole thing if rect is NULL. |
| 359 | * @param color the color to clear to. |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 360 | * @param target if non-NULL, the render target to clear otherwise clear |
| 361 | * the current render target |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 362 | */ |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 363 | void clear(const GrIRect* rect, GrColor color, |
robertphillips@google.com | c82a8b7 | 2012-06-21 20:15:48 +0000 | [diff] [blame] | 364 | GrRenderTarget* target = NULL); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 365 | |
| 366 | /** |
| 367 | * Draw everywhere (respecting the clip) with the paint. |
| 368 | */ |
| 369 | void drawPaint(const GrPaint& paint); |
| 370 | |
| 371 | /** |
| 372 | * Draw the rect using a paint. |
| 373 | * @param paint describes how to color pixels. |
| 374 | * @param strokeWidth If strokeWidth < 0, then the rect is filled, else |
| 375 | * the rect is mitered stroked based on strokeWidth. If |
| 376 | * strokeWidth == 0, then the stroke is always a single |
| 377 | * pixel thick. |
| 378 | * @param matrix Optional matrix applied to the rect. Applied before |
| 379 | * context's matrix or the paint's matrix. |
| 380 | * The rects coords are used to access the paint (through texture matrix) |
| 381 | */ |
| 382 | void drawRect(const GrPaint& paint, |
| 383 | const GrRect&, |
| 384 | GrScalar strokeWidth = -1, |
| 385 | const GrMatrix* matrix = NULL); |
| 386 | |
| 387 | /** |
| 388 | * Maps a rect of paint coordinates onto the a rect of destination |
| 389 | * coordinates. Each rect can optionally be transformed. The srcRect |
| 390 | * is stretched over the dstRect. The dstRect is transformed by the |
| 391 | * context's matrix and the srcRect is transformed by the paint's matrix. |
| 392 | * Additional optional matrices can be provided by parameters. |
| 393 | * |
| 394 | * @param paint describes how to color pixels. |
| 395 | * @param dstRect the destination rect to draw. |
| 396 | * @param srcRect rect of paint coordinates to be mapped onto dstRect |
| 397 | * @param dstMatrix Optional matrix to transform dstRect. Applied before |
| 398 | * context's matrix. |
| 399 | * @param srcMatrix Optional matrix to transform srcRect Applied before |
| 400 | * paint's matrix. |
| 401 | */ |
| 402 | void drawRectToRect(const GrPaint& paint, |
| 403 | const GrRect& dstRect, |
| 404 | const GrRect& srcRect, |
| 405 | const GrMatrix* dstMatrix = NULL, |
| 406 | const GrMatrix* srcMatrix = NULL); |
| 407 | |
| 408 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 409 | * Draws a path. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 410 | * |
| 411 | * @param paint describes how to color pixels. |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 412 | * @param path the path to draw |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 413 | * @param fill the path filling rule to use. |
| 414 | * @param translate optional additional translation applied to the |
| 415 | * path. |
| 416 | */ |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 417 | void drawPath(const GrPaint& paint, const SkPath& path, GrPathFill fill, |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 418 | const GrPoint* translate = NULL); |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 419 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 420 | /** |
| 421 | * Draws vertices with a paint. |
| 422 | * |
| 423 | * @param paint describes how to color pixels. |
| 424 | * @param primitiveType primitives type to draw. |
| 425 | * @param vertexCount number of vertices. |
| 426 | * @param positions array of vertex positions, required. |
| 427 | * @param texCoords optional array of texture coordinates used |
| 428 | * to access the paint. |
| 429 | * @param colors optional array of per-vertex colors, supercedes |
| 430 | * the paint's color field. |
| 431 | * @param indices optional array of indices. If NULL vertices |
| 432 | * are drawn non-indexed. |
| 433 | * @param indexCount if indices is non-null then this is the |
| 434 | * number of indices. |
| 435 | */ |
| 436 | void drawVertices(const GrPaint& paint, |
| 437 | GrPrimitiveType primitiveType, |
| 438 | int vertexCount, |
| 439 | const GrPoint positions[], |
| 440 | const GrPoint texs[], |
| 441 | const GrColor colors[], |
| 442 | const uint16_t indices[], |
| 443 | int indexCount); |
| 444 | |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 445 | /** |
| 446 | * Draws an oval. |
| 447 | * |
| 448 | * @param paint describes how to color pixels. |
| 449 | * @param rect the bounding rect of the oval. |
| 450 | * @param strokeWidth if strokeWidth < 0, then the oval is filled, else |
| 451 | * the rect is stroked based on strokeWidth. If |
| 452 | * strokeWidth == 0, then the stroke is always a single |
| 453 | * pixel thick. |
| 454 | */ |
| 455 | void drawOval(const GrPaint& paint, |
| 456 | const GrRect& rect, |
| 457 | SkScalar strokeWidth); |
| 458 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 459 | /////////////////////////////////////////////////////////////////////////// |
| 460 | // Misc. |
| 461 | |
| 462 | /** |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 463 | * Flags that affect flush() behavior. |
| 464 | */ |
| 465 | enum FlushBits { |
| 466 | /** |
| 467 | * A client may want Gr to bind a GrRenderTarget in the 3D API so that |
| 468 | * it can be rendered to directly. However, Gr lazily sets state. Simply |
| 469 | * calling setRenderTarget() followed by flush() without flags may not |
| 470 | * bind the render target. This flag forces the context to bind the last |
| 471 | * set render target in the 3D API. |
| 472 | */ |
| 473 | kForceCurrentRenderTarget_FlushBit = 0x1, |
| 474 | /** |
| 475 | * A client may reach a point where it has partially rendered a frame |
| 476 | * through a GrContext that it knows the user will never see. This flag |
| 477 | * causes the flush to skip submission of deferred content to the 3D API |
| 478 | * during the flush. |
| 479 | */ |
| 480 | kDiscard_FlushBit = 0x2, |
| 481 | }; |
| 482 | |
| 483 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 484 | * Call to ensure all drawing to the context has been issued to the |
| 485 | * underlying 3D API. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 486 | * @param flagsBitfield flags that control the flushing behavior. See |
| 487 | * FlushBits. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 488 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 489 | void flush(int flagsBitfield = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 490 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 491 | /** |
| 492 | * These flags can be used with the read/write pixels functions below. |
| 493 | */ |
| 494 | enum PixelOpsFlags { |
| 495 | /** The GrContext will not be flushed. This means that the read or write may occur before |
| 496 | previous draws have executed. */ |
| 497 | kDontFlush_PixelOpsFlag = 0x1, |
| 498 | /** The src for write or dst read is unpremultiplied. This is only respected if both the |
| 499 | config src and dst configs are an RGBA/BGRA 8888 format. */ |
| 500 | kUnpremul_PixelOpsFlag = 0x2, |
| 501 | }; |
| 502 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 503 | /** |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 504 | * Reads a rectangle of pixels from a render target. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 505 | * @param target the render target to read from. NULL means the current render target. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 506 | * @param left left edge of the rectangle to read (inclusive) |
| 507 | * @param top top edge of the rectangle to read (inclusive) |
| 508 | * @param width width of rectangle to read in pixels. |
| 509 | * @param height height of rectangle to read in pixels. |
| 510 | * @param config the pixel config of the destination buffer |
| 511 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 512 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 513 | * packed. |
| 514 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 515 | * |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 516 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
| 517 | * pixel config or because no render target is currently set and NULL was passed for |
| 518 | * target. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 519 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 520 | bool readRenderTargetPixels(GrRenderTarget* target, |
| 521 | int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 522 | GrPixelConfig config, void* buffer, |
| 523 | size_t rowBytes = 0, |
| 524 | uint32_t pixelOpsFlags = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 525 | |
| 526 | /** |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 527 | * Copy the src pixels [buffer, rowbytes, pixelconfig] into a render target at the specified |
| 528 | * rectangle. |
| 529 | * @param target the render target to write into. NULL means the current render target. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 530 | * @param left left edge of the rectangle to write (inclusive) |
| 531 | * @param top top edge of the rectangle to write (inclusive) |
| 532 | * @param width width of rectangle to write in pixels. |
| 533 | * @param height height of rectangle to write in pixels. |
| 534 | * @param config the pixel config of the source buffer |
| 535 | * @param buffer memory to read the rectangle from. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 536 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 537 | * packed. |
| 538 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 539 | */ |
| 540 | void writeRenderTargetPixels(GrRenderTarget* target, |
| 541 | int left, int top, int width, int height, |
| 542 | GrPixelConfig config, const void* buffer, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 543 | size_t rowBytes = 0, |
| 544 | uint32_t pixelOpsFlags = 0); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 545 | |
| 546 | /** |
| 547 | * Reads a rectangle of pixels from a texture. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 548 | * @param texture the texture to read from. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 549 | * @param left left edge of the rectangle to read (inclusive) |
| 550 | * @param top top edge of the rectangle to read (inclusive) |
| 551 | * @param width width of rectangle to read in pixels. |
| 552 | * @param height height of rectangle to read in pixels. |
| 553 | * @param config the pixel config of the destination buffer |
| 554 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 555 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 556 | * packed. |
| 557 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 558 | * |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 559 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
| 560 | * pixel config. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 561 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 562 | bool readTexturePixels(GrTexture* texture, |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 563 | int left, int top, int width, int height, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 564 | GrPixelConfig config, void* buffer, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 565 | size_t rowBytes = 0, |
| 566 | uint32_t pixelOpsFlags = 0); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 567 | |
| 568 | /** |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 569 | * Writes a rectangle of pixels to a texture. |
| 570 | * @param texture the render target to read from. |
| 571 | * @param left left edge of the rectangle to write (inclusive) |
| 572 | * @param top top edge of the rectangle to write (inclusive) |
| 573 | * @param width width of rectangle to write in pixels. |
| 574 | * @param height height of rectangle to write in pixels. |
| 575 | * @param config the pixel config of the source buffer |
| 576 | * @param buffer memory to read pixels from |
| 577 | * @param rowBytes number of bytes bewtween consecutive rows. Zero |
| 578 | * means rows are tightly packed. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 579 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 580 | */ |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 581 | void writeTexturePixels(GrTexture* texture, |
| 582 | int left, int top, int width, int height, |
| 583 | GrPixelConfig config, const void* buffer, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 584 | size_t rowBytes, |
| 585 | uint32_t pixelOpsFlags = 0); |
| 586 | |
| 587 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 588 | /** |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 589 | * Copies all texels from one texture to another. |
| 590 | * @param src the texture to copy from. |
| 591 | * @param dst the render target to copy to. |
| 592 | */ |
| 593 | void copyTexture(GrTexture* src, GrRenderTarget* dst); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 594 | |
| 595 | /** |
| 596 | * Resolves a render target that has MSAA. The intermediate MSAA buffer is |
| 597 | * downsampled to the associated GrTexture (accessible via |
| 598 | * GrRenderTarget::asTexture()). Any pending draws to the render target will |
| 599 | * be executed before the resolve. |
| 600 | * |
| 601 | * This is only necessary when a client wants to access the object directly |
| 602 | * using the underlying graphics API. GrContext will detect when it must |
| 603 | * perform a resolve to a GrTexture used as the source of a draw or before |
| 604 | * reading pixels back from a GrTexture or GrRenderTarget. |
| 605 | */ |
| 606 | void resolveRenderTarget(GrRenderTarget* target); |
| 607 | |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 608 | /** |
senorblanco@chromium.org | 3b4dd90 | 2012-03-05 20:41:22 +0000 | [diff] [blame] | 609 | * Applies a 2D Gaussian blur to a given texture. |
| 610 | * @param srcTexture The source texture to be blurred. |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 611 | * @param canClobberSrc If true, srcTexture may be overwritten, and |
| 612 | * may be returned as the result. |
senorblanco@chromium.org | 3b4dd90 | 2012-03-05 20:41:22 +0000 | [diff] [blame] | 613 | * @param rect The destination rectangle. |
| 614 | * @param sigmaX The blur's standard deviation in X. |
| 615 | * @param sigmaY The blur's standard deviation in Y. |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 616 | * @return the blurred texture, which may be srcTexture ref'ed, or a |
| 617 | * new texture. It is the caller's responsibility to unref this texture. |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 618 | */ |
senorblanco@chromium.org | 3b4dd90 | 2012-03-05 20:41:22 +0000 | [diff] [blame] | 619 | GrTexture* gaussianBlur(GrTexture* srcTexture, |
senorblanco@chromium.org | 1e95d71 | 2012-07-18 19:52:53 +0000 | [diff] [blame] | 620 | bool canClobberSrc, |
senorblanco@chromium.org | 3b4dd90 | 2012-03-05 20:41:22 +0000 | [diff] [blame] | 621 | const SkRect& rect, |
| 622 | float sigmaX, float sigmaY); |
| 623 | |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 624 | /** |
bsalomon@google.com | 82aa748 | 2012-08-13 14:22:17 +0000 | [diff] [blame] | 625 | * Zooms a subset of the texture to a larger size with a nice edge. |
| 626 | * The inner rectangle is a simple scaling of the texture by a factor of |
| 627 | * |zoom|. The outer |inset| pixels transition from the background texture |
| 628 | * to the zoomed coordinate system at a rate of |
| 629 | * (distance_to_edge / inset) ^2, producing a rounded lens effect. |
| 630 | * @param srcTexture The source texture to be zoomed. |
| 631 | * @param dstRect The destination rectangle. |
| 632 | * @param srcRect The source rectangle. Must be smaller than |
| 633 | * dstRect |
| 634 | * @param inset Number of pixels to blend along the edges. |
| 635 | * @return the zoomed texture, which is dstTexture. |
| 636 | */ |
| 637 | GrTexture* zoom(GrTexture* srcTexture, |
| 638 | const SkRect& dstRect, const SkRect& srcRect, float inset); |
| 639 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 640 | /////////////////////////////////////////////////////////////////////////// |
| 641 | // Helpers |
| 642 | |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 643 | class AutoRenderTarget : public ::GrNoncopyable { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 644 | public: |
| 645 | AutoRenderTarget(GrContext* context, GrRenderTarget* target) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 646 | fPrevTarget = context->getRenderTarget(); |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 647 | GrSafeRef(fPrevTarget); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 648 | context->setRenderTarget(target); |
| 649 | fContext = context; |
| 650 | } |
| 651 | AutoRenderTarget(GrContext* context) { |
| 652 | fPrevTarget = context->getRenderTarget(); |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 653 | GrSafeRef(fPrevTarget); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 654 | fContext = context; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 655 | } |
| 656 | ~AutoRenderTarget() { |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 657 | if (NULL != fContext) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 658 | fContext->setRenderTarget(fPrevTarget); |
| 659 | } |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 660 | GrSafeUnref(fPrevTarget); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 661 | } |
| 662 | private: |
| 663 | GrContext* fContext; |
| 664 | GrRenderTarget* fPrevTarget; |
| 665 | }; |
| 666 | |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 667 | /** |
| 668 | * Save/restore the view-matrix in the context. |
| 669 | */ |
| 670 | class AutoMatrix : GrNoncopyable { |
| 671 | public: |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 672 | enum InitialMatrix { |
| 673 | kPreserve_InitialMatrix, |
| 674 | kIdentity_InitialMatrix, |
| 675 | }; |
| 676 | |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 677 | AutoMatrix() : fContext(NULL) {} |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 678 | |
| 679 | AutoMatrix(GrContext* ctx, InitialMatrix initialState) : fContext(ctx) { |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 680 | fMatrix = ctx->getMatrix(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 681 | switch (initialState) { |
| 682 | case kPreserve_InitialMatrix: |
| 683 | break; |
| 684 | case kIdentity_InitialMatrix: |
| 685 | ctx->setMatrix(GrMatrix::I()); |
| 686 | break; |
| 687 | default: |
| 688 | GrCrash("Unexpected initial matrix state"); |
| 689 | } |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 690 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 691 | |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 692 | AutoMatrix(GrContext* ctx, const GrMatrix& matrix) : fContext(ctx) { |
| 693 | fMatrix = ctx->getMatrix(); |
| 694 | ctx->setMatrix(matrix); |
| 695 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 696 | |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 697 | void set(GrContext* ctx) { |
| 698 | if (NULL != fContext) { |
| 699 | fContext->setMatrix(fMatrix); |
| 700 | } |
| 701 | fMatrix = ctx->getMatrix(); |
| 702 | fContext = ctx; |
| 703 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 704 | |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 705 | void set(GrContext* ctx, const GrMatrix& matrix) { |
| 706 | if (NULL != fContext) { |
| 707 | fContext->setMatrix(fMatrix); |
| 708 | } |
| 709 | fMatrix = ctx->getMatrix(); |
| 710 | ctx->setMatrix(matrix); |
| 711 | fContext = ctx; |
| 712 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 713 | |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 714 | ~AutoMatrix() { |
| 715 | if (NULL != fContext) { |
| 716 | fContext->setMatrix(fMatrix); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | private: |
| 721 | GrContext* fContext; |
| 722 | GrMatrix fMatrix; |
| 723 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 724 | |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 725 | class AutoClip : GrNoncopyable { |
| 726 | public: |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 727 | // This enum exists to require a caller of the constructor to acknowledge that the clip will |
| 728 | // initially be wide open. It also could be extended if there are other desirable initial |
| 729 | // clip states. |
| 730 | enum InitialClip { |
| 731 | kWideOpen_InitialClip, |
| 732 | }; |
| 733 | |
skia.committer@gmail.com | dc3a4e5 | 2012-10-02 02:01:24 +0000 | [diff] [blame] | 734 | AutoClip(GrContext* context, InitialClip initialState) |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 735 | : fContext(context) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 736 | GrAssert(kWideOpen_InitialClip == initialState); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 737 | fNewClipData.fClipStack = &fNewClipStack; |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 738 | |
| 739 | fOldClip = context->getClip(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 740 | context->setClip(&fNewClipData); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 741 | } |
| 742 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 743 | AutoClip(GrContext* context, const GrRect& newClipRect) |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 744 | : fContext(context) |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 745 | , fNewClipStack(newClipRect) { |
| 746 | fNewClipData.fClipStack = &fNewClipStack; |
| 747 | |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 748 | fOldClip = fContext->getClip(); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 749 | fContext->setClip(&fNewClipData); |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | ~AutoClip() { |
| 753 | if (NULL != fContext) { |
| 754 | fContext->setClip(fOldClip); |
| 755 | } |
| 756 | } |
| 757 | private: |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 758 | GrContext* fContext; |
| 759 | const GrClipData* fOldClip; |
| 760 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 761 | SkClipStack fNewClipStack; |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 762 | GrClipData fNewClipData; |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 763 | }; |
| 764 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 765 | class AutoWideOpenIdentityDraw { |
| 766 | public: |
| 767 | AutoWideOpenIdentityDraw(GrContext* ctx, GrRenderTarget* rt) |
| 768 | : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) |
| 769 | , fAutoRT(ctx, rt) |
| 770 | , fAutoMatrix(ctx, AutoMatrix::kIdentity_InitialMatrix) { |
| 771 | } |
| 772 | private: |
| 773 | AutoClip fAutoClip; |
| 774 | AutoRenderTarget fAutoRT; |
| 775 | AutoMatrix fAutoMatrix; |
| 776 | }; |
| 777 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 778 | /////////////////////////////////////////////////////////////////////////// |
| 779 | // Functions intended for internal use only. |
| 780 | GrGpu* getGpu() { return fGpu; } |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 781 | const GrGpu* getGpu() const { return fGpu; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 782 | GrFontCache* getFontCache() { return fFontCache; } |
| 783 | GrDrawTarget* getTextTarget(const GrPaint& paint); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 784 | const GrIndexBuffer* getQuadIndexBuffer() const; |
bsalomon@google.com | 9923c2b | 2012-06-06 18:21:18 +0000 | [diff] [blame] | 785 | |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 786 | /** |
| 787 | * Stencil buffers add themselves to the cache using |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 788 | * addStencilBuffer. findStencilBuffer is called to check the |
skia.committer@gmail.com | 6c77816 | 2012-09-06 02:01:13 +0000 | [diff] [blame] | 789 | * cache for a SB that matches an RT's criteria. |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 790 | */ |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 791 | void addStencilBuffer(GrStencilBuffer* sb); |
| 792 | GrStencilBuffer* findStencilBuffer(int width, int height, int sampleCnt); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 793 | |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 794 | GrPathRenderer* getPathRenderer(const SkPath& path, |
| 795 | GrPathFill fill, |
| 796 | const GrDrawTarget* target, |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 797 | bool antiAlias, |
| 798 | bool allowSW); |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 799 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 800 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 801 | void printCacheStats() const; |
| 802 | #endif |
| 803 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 804 | private: |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 805 | // Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer. |
| 806 | enum BufferedDraw { |
| 807 | kYes_BufferedDraw, |
| 808 | kNo_BufferedDraw, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 809 | }; |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 810 | BufferedDraw fLastDrawWasBuffered; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 811 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 812 | GrGpu* fGpu; |
bsalomon@google.com | 10e04bf | 2012-03-30 14:35:04 +0000 | [diff] [blame] | 813 | GrDrawState* fDrawState; |
| 814 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 815 | GrResourceCache* fTextureCache; |
| 816 | GrFontCache* fFontCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 817 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 818 | GrPathRendererChain* fPathRendererChain; |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 819 | GrSoftwarePathRenderer* fSoftwarePathRenderer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 820 | |
| 821 | GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
| 822 | GrIndexBufferAllocPool* fDrawBufferIBAllocPool; |
| 823 | GrInOrderDrawBuffer* fDrawBuffer; |
| 824 | |
robertphillips@google.com | f69a11b | 2012-06-15 13:58:07 +0000 | [diff] [blame] | 825 | GrAARectRenderer* fAARectRenderer; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 826 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 827 | bool fDidTestPMConversions; |
| 828 | int fPMToUPMConversion; |
| 829 | int fUPMToPMConversion; |
| 830 | |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 831 | struct CleanUpData { |
| 832 | PFCleanUpFunc fFunc; |
| 833 | void* fInfo; |
| 834 | }; |
| 835 | |
| 836 | SkTDArray<CleanUpData> fCleanUpData; |
| 837 | |
robertphillips@google.com | f69a11b | 2012-06-15 13:58:07 +0000 | [diff] [blame] | 838 | GrContext(GrGpu* gpu); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 839 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 840 | void setupDrawBuffer(); |
| 841 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 842 | void flushDrawBuffer(); |
| 843 | |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 844 | /// Sets the paint and returns the target to draw into. The paint can be NULL in which case the |
| 845 | /// draw state is left unmodified. |
| 846 | GrDrawTarget* prepareToDraw(const GrPaint*, BufferedDraw); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 847 | |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 848 | void internalDrawPath(const GrPaint& paint, const SkPath& path, |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 849 | GrPathFill fill, const GrPoint* translate); |
| 850 | |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 851 | GrTexture* createResizedTexture(const GrTextureDesc& desc, |
| 852 | const GrCacheData& cacheData, |
| 853 | void* srcData, |
| 854 | size_t rowBytes, |
| 855 | bool needsFiltering); |
| 856 | |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 857 | // Needed so GrTexture's returnToCache helper function can call |
| 858 | // addExistingTextureToCache |
| 859 | friend class GrTexture; |
| 860 | |
| 861 | // Add an existing texture to the texture cache. This is intended solely |
| 862 | // for use with textures released from an GrAutoScratchTexture. |
| 863 | void addExistingTextureToCache(GrTexture* texture); |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 864 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 865 | GrCustomStage* createPMToUPMEffect(GrTexture* texture, bool swapRAndB); |
| 866 | GrCustomStage* createUPMToPMEffect(GrTexture* texture, bool swapRAndB); |
| 867 | |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 868 | typedef GrRefCnt INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 869 | }; |
| 870 | |
| 871 | /** |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 872 | * Gets and locks a scratch texture from a descriptor using |
| 873 | * either exact or approximate criteria. Unlocks texture in |
| 874 | * the destructor. |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 875 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 876 | class GrAutoScratchTexture : ::GrNoncopyable { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 877 | public: |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 878 | GrAutoScratchTexture() |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 879 | : fContext(NULL) |
| 880 | , fTexture(NULL) { |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 881 | } |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 882 | |
| 883 | GrAutoScratchTexture(GrContext* context, |
| 884 | const GrTextureDesc& desc, |
| 885 | GrContext::ScratchTexMatch match = |
| 886 | GrContext::kApprox_ScratchTexMatch) |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 887 | : fContext(NULL) |
| 888 | , fTexture(NULL) { |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 889 | this->set(context, desc, match); |
| 890 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 891 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 892 | ~GrAutoScratchTexture() { |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 893 | this->reset(); |
| 894 | } |
| 895 | |
| 896 | void reset() { |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 897 | if (NULL != fContext && NULL != fTexture) { |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 898 | fContext->unlockScratchTexture(fTexture); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 899 | fTexture = NULL; |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 900 | } |
| 901 | } |
bsalomon@google.com | 8422311 | 2011-07-14 14:45:44 +0000 | [diff] [blame] | 902 | |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 903 | /* |
| 904 | * When detaching a texture we do not unlock it in the texture cache but |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 905 | * we do set the returnToCache flag. In this way the texture remains |
| 906 | * "locked" in the texture cache until it is freed and recycled in |
| 907 | * GrTexture::internal_dispose. In reality, the texture has been removed |
| 908 | * from the cache (because this is in AutoScratchTexture) and by not |
| 909 | * calling unlockTexture we simply don't re-add it. It will be reattached |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 910 | * in GrTexture::internal_dispose. |
| 911 | * |
| 912 | * Note that the caller is assumed to accept and manage the ref to the |
| 913 | * returned texture. |
| 914 | */ |
| 915 | GrTexture* detach() { |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 916 | GrTexture* temp = fTexture; |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 917 | |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 918 | // Conceptually the texture's cache entry loses its ref to the |
| 919 | // texture while the caller of this method gets a ref. |
| 920 | GrAssert(NULL != temp->getCacheEntry()); |
| 921 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 922 | fTexture = NULL; |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 923 | |
| 924 | temp->setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 925 | return temp; |
| 926 | } |
| 927 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 928 | GrTexture* set(GrContext* context, |
| 929 | const GrTextureDesc& desc, |
| 930 | GrContext::ScratchTexMatch match = |
| 931 | GrContext::kApprox_ScratchTexMatch) { |
robertphillips@google.com | 9ec0753 | 2012-06-22 12:01:30 +0000 | [diff] [blame] | 932 | this->reset(); |
| 933 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 934 | fContext = context; |
| 935 | if (NULL != fContext) { |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 936 | fTexture = fContext->lockScratchTexture(desc, match); |
| 937 | if (NULL == fTexture) { |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 938 | fContext = NULL; |
| 939 | } |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 940 | return fTexture; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 941 | } else { |
| 942 | return NULL; |
| 943 | } |
| 944 | } |
| 945 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 946 | GrTexture* texture() { return fTexture; } |
| 947 | |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 948 | private: |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 949 | GrContext* fContext; |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 950 | GrTexture* fTexture; |
senorblanco@chromium.org | aadd9f8 | 2011-07-12 19:44:51 +0000 | [diff] [blame] | 951 | }; |
| 952 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 953 | #endif |