bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef GrContext_DEFINED |
| 9 | #define GrContext_DEFINED |
| 10 | |
robertphillips@google.com | a2d7148 | 2012-08-01 20:08:47 +0000 | [diff] [blame] | 11 | #include "GrClipData.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 12 | #include "GrColor.h" |
bsalomon@google.com | 288d954 | 2012-10-17 12:53:54 +0000 | [diff] [blame] | 13 | #include "GrPaint.h" |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 14 | #include "GrPathRendererChain.h" |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 15 | #include "GrRenderTarget.h" |
bsalomon@google.com | 288d954 | 2012-10-17 12:53:54 +0000 | [diff] [blame] | 16 | #include "GrTexture.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 17 | #include "SkMatrix.h" |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 18 | #include "SkPathEffect.h" |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 19 | #include "SkTypes.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 20 | |
jvanverth@google.com | bfe2b9d | 2013-09-06 16:57:29 +0000 | [diff] [blame] | 21 | class GrAARectRenderer; |
bsalomon@google.com | 10e04bf | 2012-03-30 14:35:04 +0000 | [diff] [blame] | 22 | class GrDrawState; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 23 | class GrDrawTarget; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 24 | class GrFontCache; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 25 | class GrFragmentProcessor; |
bsalomon@google.com | 05ef510 | 2011-05-02 21:14:59 +0000 | [diff] [blame] | 26 | class GrGpu; |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 27 | class GrGpuTraceMarker; |
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; |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 31 | class GrLayerCache; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 32 | class GrOvalRenderer; |
commit-bot@chromium.org | 5c8ee25 | 2013-11-01 15:23:44 +0000 | [diff] [blame] | 33 | class GrPath; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 34 | class GrPathRenderer; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 35 | class GrResourceEntry; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 36 | class GrResourceCache2; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 37 | class GrTestTarget; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 38 | class GrTextContext; |
bsalomon@google.com | 288d954 | 2012-10-17 12:53:54 +0000 | [diff] [blame] | 39 | class GrTextureParams; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 40 | class GrVertexBuffer; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 41 | class GrVertexBufferAllocPool; |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 42 | class GrStrokeInfo; |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 43 | class GrSoftwarePathRenderer; |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 44 | class SkStrokeRec; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 45 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 46 | class SK_API GrContext : public SkRefCnt { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 47 | public: |
reed@google.com | fa35e3d | 2012-06-26 20:16:17 +0000 | [diff] [blame] | 48 | SK_DECLARE_INST_COUNT(GrContext) |
| 49 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 50 | struct Options { |
| 51 | Options() : fDrawPathToCompressedTexture(false) { } |
| 52 | |
| 53 | // EXPERIMENTAL |
| 54 | // May be removed in the future, or may become standard depending |
| 55 | // on the outcomes of a variety of internal tests. |
| 56 | bool fDrawPathToCompressedTexture; |
| 57 | }; |
| 58 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 59 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 60 | * Creates a GrContext for a backend context. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 61 | */ |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 62 | static GrContext* Create(GrBackend, GrBackendContext, const Options* opts = NULL); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 63 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 64 | /** |
| 65 | * Only defined in test apps. |
| 66 | */ |
| 67 | static GrContext* CreateMockContext(); |
| 68 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 69 | virtual ~GrContext(); |
| 70 | |
| 71 | /** |
| 72 | * The GrContext normally assumes that no outsider is setting state |
| 73 | * within the underlying 3D API's context/device/whatever. This call informs |
| 74 | * the context that the state was modified and it should resend. Shouldn't |
| 75 | * be called frequently for good performance. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 76 | * The flag bits, state, is dpendent on which backend is used by the |
| 77 | * context, either GL or D3D (possible in future). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 78 | */ |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 79 | void resetContext(uint32_t state = kAll_GrBackendState); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 80 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 81 | /** |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 82 | * Callback function to allow classes to cleanup on GrContext destruction. |
| 83 | * The 'info' field is filled in with the 'info' passed to addCleanUp. |
| 84 | */ |
| 85 | typedef void (*PFCleanUpFunc)(const GrContext* context, void* info); |
| 86 | |
| 87 | /** |
| 88 | * Add a function to be called from within GrContext's destructor. |
| 89 | * This gives classes a chance to free resources held on a per context basis. |
| 90 | * The 'info' parameter will be stored and passed to the callback function. |
| 91 | */ |
| 92 | void addCleanUp(PFCleanUpFunc cleanUp, void* info) { |
| 93 | CleanUpData* entry = fCleanUpData.push(); |
| 94 | |
| 95 | entry->fFunc = cleanUp; |
| 96 | entry->fInfo = info; |
| 97 | } |
| 98 | |
| 99 | /** |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 100 | * Abandons all GPU resources and assumes the underlying backend 3D API |
| 101 | * context is not longer usable. Call this if you have lost the associated |
| 102 | * GPU context, and thus internal texture, buffer, etc. references/IDs are |
| 103 | * now invalid. Should be called even when GrContext is no longer going to |
| 104 | * be used for two reasons: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 105 | * 1) ~GrContext will not try to free the objects in the 3D API. |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 106 | * 2) Any GrGpuResources created by this GrContext that outlive |
| 107 | * will be marked as invalid (GrGpuResource::wasDestroyed()) and |
| 108 | * when they're destroyed no 3D API calls will be made. |
| 109 | * Content drawn since the last GrContext::flush() may be lost. After this |
| 110 | * function is called the only valid action on the GrContext or |
| 111 | * GrGpuResources it created is to destroy them. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 112 | */ |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 113 | void abandonContext(); |
| 114 | void contextDestroyed() { this->abandonContext(); } // legacy alias |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 115 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 116 | /////////////////////////////////////////////////////////////////////////// |
| 117 | // Resource Cache |
| 118 | |
| 119 | /** |
| 120 | * Return the current GPU resource cache limits. |
| 121 | * |
| 122 | * @param maxResources If non-null, returns maximum number of resources that |
| 123 | * can be held in the cache. |
| 124 | * @param maxResourceBytes If non-null, returns maximum number of bytes of |
| 125 | * video memory that can be held in the cache. |
| 126 | */ |
| 127 | void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * Gets the current GPU resource cache usage. |
| 131 | * |
| 132 | * @param resourceCount If non-null, returns the number of resources that are held in the |
| 133 | * cache. |
| 134 | * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held |
| 135 | * in the cache. |
| 136 | */ |
| 137 | void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const; |
| 138 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 139 | /** |
| 140 | * Specify the GPU resource cache limits. If the current cache exceeds either |
| 141 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 142 | * |
| 143 | * @param maxResources The maximum number of resources that can be held in |
| 144 | * the cache. |
| 145 | * @param maxResourceBytes The maximum number of bytes of video memory |
| 146 | * that can be held in the cache. |
| 147 | */ |
| 148 | void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 149 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 150 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 151 | * Frees GPU created by the context. Can be called to reduce GPU memory |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 152 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 153 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 154 | void freeGpuResources(); |
| 155 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 156 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 157 | * This method should be called whenever a GrResource is unreffed or |
| 158 | * switched from exclusive to non-exclusive. This |
| 159 | * gives the resource cache a chance to discard unneeded resources. |
| 160 | * Note: this entry point will be removed once totally ref-driven |
| 161 | * cache maintenance is implemented. |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 162 | */ |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 163 | void purgeCache(); |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 164 | |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 165 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 166 | * Purge all the unlocked resources from the cache. |
| 167 | * This entry point is mainly meant for timing texture uploads |
| 168 | * and is not defined in normal builds of Skia. |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 169 | */ |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 170 | void purgeAllUnlockedResources(); |
| 171 | |
| 172 | /** |
| 173 | * Stores a custom resource in the cache, based on the specified key. |
| 174 | */ |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 175 | void addResourceToCache(const GrResourceKey&, GrGpuResource*); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 176 | |
| 177 | /** |
| 178 | * Finds a resource in the cache, based on the specified key. This is intended for use in |
| 179 | * conjunction with addResourceToCache(). The return value will be NULL if not found. The |
| 180 | * caller must balance with a call to unref(). |
| 181 | */ |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 182 | GrGpuResource* findAndRefCachedResource(const GrResourceKey&); |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 183 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 184 | /** |
| 185 | * Creates a new text rendering context that is optimal for the |
| 186 | * render target and the context. Caller assumes the ownership |
| 187 | * of the returned object. The returned object must be deleted |
| 188 | * before the context is destroyed. |
| 189 | */ |
| 190 | GrTextContext* createTextContext(GrRenderTarget*, |
| 191 | const SkDeviceProperties&, |
| 192 | bool enableDistanceFieldFonts); |
| 193 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 194 | /////////////////////////////////////////////////////////////////////////// |
| 195 | // Textures |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 196 | |
| 197 | /** |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 198 | * Creates a new entry, based on the specified key and texture and returns it. The caller owns a |
| 199 | * ref on the returned texture which must be balanced by a call to unref. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 200 | * |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 201 | * @param params The texture params used to draw a texture may help determine |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 202 | * the cache entry used. (e.g. different versions may exist |
| 203 | * for different wrap modes on GPUs with limited NPOT |
| 204 | * texture support). NULL implies clamp wrap modes. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 205 | * @param desc Description of the texture properties. |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 206 | * @param cacheID Cache-specific properties (e.g., texture gen ID) |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 207 | * @param srcData Pointer to the pixel values. |
| 208 | * @param rowBytes The number of bytes between rows of the texture. Zero |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 209 | * implies tightly packed rows. For compressed pixel configs, this |
| 210 | * field is ignored. |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 211 | * @param cacheKey (optional) If non-NULL, we'll write the cache key we used to cacheKey. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 212 | */ |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 213 | GrTexture* createTexture(const GrTextureParams* params, |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 214 | const GrSurfaceDesc& desc, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 215 | const GrCacheID& cacheID, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 216 | const void* srcData, |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 217 | size_t rowBytes, |
| 218 | GrResourceKey* cacheKey = NULL); |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 219 | /** |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 220 | * Search for an entry based on key and dimensions. If found, ref it and return it. The return |
| 221 | * value will be NULL if not found. The caller must balance with a call to unref. |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 222 | * |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 223 | * @param desc Description of the texture properties. |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 224 | * @param cacheID Cache-specific properties (e.g., texture gen ID) |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 225 | * @param params The texture params used to draw a texture may help determine |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 226 | * the cache entry used. (e.g. different versions may exist |
| 227 | * for different wrap modes on GPUs with limited NPOT |
| 228 | * texture support). NULL implies clamp wrap modes. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 229 | */ |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 230 | GrTexture* findAndRefTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 231 | const GrCacheID& cacheID, |
| 232 | const GrTextureParams* params); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 233 | /** |
| 234 | * Determines whether a texture is in the cache. If the texture is found it |
| 235 | * will not be locked or returned. This call does not affect the priority of |
| 236 | * the texture for deletion. |
| 237 | */ |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 238 | bool isTextureInCache(const GrSurfaceDesc& desc, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 239 | const GrCacheID& cacheID, |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 240 | const GrTextureParams* params) const; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Enum that determines how closely a returned scratch texture must match |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 244 | * a provided GrSurfaceDesc. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 245 | */ |
| 246 | enum ScratchTexMatch { |
| 247 | /** |
| 248 | * Finds a texture that exactly matches the descriptor. |
| 249 | */ |
| 250 | kExact_ScratchTexMatch, |
| 251 | /** |
| 252 | * Finds a texture that approximately matches the descriptor. Will be |
| 253 | * at least as large in width and height as desc specifies. If desc |
| 254 | * specifies that texture is a render target then result will be a |
| 255 | * render target. If desc specifies a render target and doesn't set the |
| 256 | * no stencil flag then result will have a stencil. Format and aa level |
| 257 | * will always match. |
| 258 | */ |
| 259 | kApprox_ScratchTexMatch |
| 260 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 261 | |
| 262 | /** |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 263 | * Returns a texture matching the desc. It's contents are unknown. The caller |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 264 | * owns a ref on the returned texture and must balance with a call to unref. |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 265 | * It is guaranteed that the same texture will not be returned in subsequent |
| 266 | * calls until all refs to the texture are dropped. |
bsalomon@google.com | a39f404 | 2011-04-26 13:18:16 +0000 | [diff] [blame] | 267 | * |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 268 | * Textures created by createTexture() hide the complications of |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 269 | * tiling non-power-of-two textures on APIs that don't support this (e.g. |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 270 | * unextended GLES2). NPOT scratch textures are not tilable on such APIs. |
bsalomon | bcf0a52 | 2014-10-08 08:40:09 -0700 | [diff] [blame] | 271 | * |
| 272 | * internalFlag is a temporary workaround until changes in the internal |
| 273 | * architecture are complete. Use the default value. |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 274 | */ |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 275 | GrTexture* refScratchTexture(const GrSurfaceDesc&, ScratchTexMatch match, |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 276 | bool internalFlag = false); |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 277 | |
| 278 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 279 | * Creates a texture that is outside the cache. Does not count against |
| 280 | * cache's budget. |
bsalomon | e305973 | 2014-10-14 11:47:22 -0700 | [diff] [blame] | 281 | * |
| 282 | * Textures created by createTexture() hide the complications of |
| 283 | * tiling non-power-of-two textures on APIs that don't support this (e.g. |
| 284 | * unextended GLES2). NPOT uncached textures are not tilable on such APIs. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 285 | */ |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 286 | GrTexture* createUncachedTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 287 | void* srcData, |
| 288 | size_t rowBytes); |
| 289 | |
| 290 | /** |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 291 | * Returns true if the specified use of an indexed texture is supported. |
| 292 | * Support may depend upon whether the texture params indicate that the |
| 293 | * texture will be tiled. Passing NULL for the texture params indicates |
| 294 | * clamp mode. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 295 | */ |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 296 | bool supportsIndex8PixelConfig(const GrTextureParams*, |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 297 | int width, |
| 298 | int height) const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 299 | |
| 300 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 301 | * Return the max width or height of a texture supported by the current GPU. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 302 | */ |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 303 | int getMaxTextureSize() const; |
| 304 | |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 305 | /** |
skia.committer@gmail.com | 956b310 | 2013-07-26 07:00:58 +0000 | [diff] [blame] | 306 | * Temporarily override the true max texture size. Note: an override |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 307 | * larger then the true max texture size will have no effect. |
| 308 | * This entry point is mainly meant for testing texture size dependent |
| 309 | * features and is only available if defined outside of Skia (see |
| 310 | * bleed GM. |
| 311 | */ |
| 312 | void setMaxTextureSizeOverride(int maxTextureSizeOverride); |
| 313 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 314 | /////////////////////////////////////////////////////////////////////////// |
| 315 | // Render targets |
| 316 | |
| 317 | /** |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 318 | * Sets the render target. |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 319 | * @param target the render target to set. |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 320 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 321 | void setRenderTarget(GrRenderTarget* target) { |
| 322 | fRenderTarget.reset(SkSafeRef(target)); |
| 323 | } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 324 | |
| 325 | /** |
| 326 | * Gets the current render target. |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 327 | * @return the currently bound render target. |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 328 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 329 | const GrRenderTarget* getRenderTarget() const { return fRenderTarget.get(); } |
| 330 | GrRenderTarget* getRenderTarget() { return fRenderTarget.get(); } |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 331 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 332 | /** |
| 333 | * Can the provided configuration act as a color render target? |
| 334 | */ |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 335 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 336 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 337 | /** |
| 338 | * Return the max width or height of a render target supported by the |
| 339 | * current GPU. |
| 340 | */ |
| 341 | int getMaxRenderTargetSize() const; |
| 342 | |
| 343 | /** |
| 344 | * Returns the max sample count for a render target. It will be 0 if MSAA |
| 345 | * is not supported. |
| 346 | */ |
| 347 | int getMaxSampleCount() const; |
| 348 | |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 349 | /** |
| 350 | * Returns the recommended sample count for a render target when using this |
| 351 | * context. |
| 352 | * |
| 353 | * @param config the configuration of the render target. |
| 354 | * @param dpi the display density in dots per inch. |
| 355 | * |
| 356 | * @return sample count that should be perform well and have good enough |
| 357 | * rendering quality for the display. Alternatively returns 0 if |
| 358 | * MSAA is not supported or recommended to be used by default. |
| 359 | */ |
| 360 | int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; |
| 361 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 362 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 363 | // Backend Surfaces |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 364 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 365 | /** |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 366 | * Wraps an existing texture with a GrTexture object. |
| 367 | * |
| 368 | * OpenGL: if the object is a texture Gr may change its GL texture params |
| 369 | * when it is drawn. |
| 370 | * |
| 371 | * @param desc description of the object to create. |
| 372 | * |
| 373 | * @return GrTexture object or NULL on failure. |
| 374 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 375 | GrTexture* wrapBackendTexture(const GrBackendTextureDesc& desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 376 | |
| 377 | /** |
| 378 | * Wraps an existing render target with a GrRenderTarget object. It is |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 379 | * similar to wrapBackendTexture but can be used to draw into surfaces |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 380 | * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that |
| 381 | * the client will resolve to a texture). |
| 382 | * |
| 383 | * @param desc description of the object to create. |
| 384 | * |
| 385 | * @return GrTexture object or NULL on failure. |
| 386 | */ |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 387 | GrRenderTarget* wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 388 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 389 | /////////////////////////////////////////////////////////////////////////// |
| 390 | // Matrix state |
| 391 | |
| 392 | /** |
| 393 | * Gets the current transformation matrix. |
| 394 | * @return the current matrix. |
| 395 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 396 | const SkMatrix& getMatrix() const { return fViewMatrix; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 397 | |
| 398 | /** |
| 399 | * Sets the transformation matrix. |
| 400 | * @param m the matrix to set. |
| 401 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 402 | void setMatrix(const SkMatrix& m) { fViewMatrix = m; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 403 | |
| 404 | /** |
bsalomon@google.com | 0f11e1a | 2012-10-08 14:48:36 +0000 | [diff] [blame] | 405 | * Sets the current transformation matrix to identity. |
| 406 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 407 | void setIdentityMatrix() { fViewMatrix.reset(); } |
bsalomon@google.com | 0f11e1a | 2012-10-08 14:48:36 +0000 | [diff] [blame] | 408 | |
| 409 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 410 | * Concats the current matrix. The passed matrix is applied before the |
| 411 | * current matrix. |
| 412 | * @param m the matrix to concat. |
| 413 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 414 | void concatMatrix(const SkMatrix& m) { fViewMatrix.preConcat(m); } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 415 | |
| 416 | |
| 417 | /////////////////////////////////////////////////////////////////////////// |
| 418 | // Clip state |
| 419 | /** |
| 420 | * Gets the current clip. |
| 421 | * @return the current clip. |
| 422 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 423 | const GrClipData* getClip() const { return fClip; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 424 | |
| 425 | /** |
| 426 | * Sets the clip. |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 427 | * @param clipData the clip to set. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 428 | */ |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 429 | void setClip(const GrClipData* clipData) { fClip = clipData; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 430 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 431 | /////////////////////////////////////////////////////////////////////////// |
| 432 | // Draws |
| 433 | |
| 434 | /** |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 435 | * Clear the entire or rect of the render target, ignoring any clips. |
| 436 | * @param rect the rect to clear or the whole thing if rect is NULL. |
| 437 | * @param color the color to clear to. |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 438 | * @param canIgnoreRect allows partial clears to be converted to whole |
| 439 | * clears on platforms for which that is cheap |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 440 | * @param target The render target to clear. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 441 | */ |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 442 | void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderTarget* target); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 443 | |
| 444 | /** |
| 445 | * Draw everywhere (respecting the clip) with the paint. |
| 446 | */ |
| 447 | void drawPaint(const GrPaint& paint); |
| 448 | |
| 449 | /** |
| 450 | * Draw the rect using a paint. |
| 451 | * @param paint describes how to color pixels. |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 452 | * @param strokeInfo the stroke information (width, join, cap), and. |
| 453 | * the dash information (intervals, count, phase). |
| 454 | * If strokeInfo == NULL, then the rect is filled. |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 455 | * Otherwise, if stroke width == 0, then the stroke |
skia.committer@gmail.com | 2614418 | 2013-11-07 07:02:19 +0000 | [diff] [blame] | 456 | * is always a single pixel thick, else the rect is |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 457 | * mitered/beveled stroked based on stroke width. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 458 | * The rects coords are used to access the paint (through texture matrix) |
| 459 | */ |
| 460 | void drawRect(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 461 | const SkRect&, |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 462 | const GrStrokeInfo* strokeInfo = NULL); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 463 | |
| 464 | /** |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 465 | * Maps a rect of local coordinates onto the a rect of destination |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 466 | * coordinates. The localRect is stretched over the dstRect. The dstRect is |
| 467 | * transformed by the context's matrix. An additional optional matrix can be |
| 468 | * provided to transform the local rect. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 469 | * |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 470 | * @param paint describes how to color pixels. |
| 471 | * @param dstRect the destination rect to draw. |
| 472 | * @param localRect rect of local coordinates to be mapped onto dstRect |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 473 | * @param localMatrix Optional matrix to transform localRect. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 474 | */ |
| 475 | void drawRectToRect(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 476 | const SkRect& dstRect, |
| 477 | const SkRect& localRect, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 478 | const SkMatrix* localMatrix = NULL); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 479 | |
| 480 | /** |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 481 | * Draw a roundrect using a paint. |
| 482 | * |
| 483 | * @param paint describes how to color pixels. |
| 484 | * @param rrect the roundrect to draw |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 485 | * @param strokeInfo the stroke information (width, join, cap) and |
| 486 | * the dash information (intervals, count, phase). |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 487 | */ |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 488 | void drawRRect(const GrPaint& paint, const SkRRect& rrect, const GrStrokeInfo& strokeInfo); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 489 | |
| 490 | /** |
| 491 | * Shortcut for drawing an SkPath consisting of nested rrects using a paint. |
| 492 | * Does not support stroking. The result is undefined if outer does not contain |
| 493 | * inner. |
| 494 | * |
| 495 | * @param paint describes how to color pixels. |
| 496 | * @param outer the outer roundrect |
| 497 | * @param inner the inner roundrect |
| 498 | */ |
| 499 | void drawDRRect(const GrPaint& paint, const SkRRect& outer, const SkRRect& inner); |
| 500 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 501 | |
| 502 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 503 | * Draws a path. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 504 | * |
| 505 | * @param paint describes how to color pixels. |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 506 | * @param path the path to draw |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 507 | * @param strokeInfo the stroke information (width, join, cap) and |
| 508 | * the dash information (intervals, count, phase). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 509 | */ |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 510 | void drawPath(const GrPaint& paint, const SkPath& path, const GrStrokeInfo& strokeInfo); |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 511 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 512 | /** |
| 513 | * Draws vertices with a paint. |
| 514 | * |
| 515 | * @param paint describes how to color pixels. |
| 516 | * @param primitiveType primitives type to draw. |
| 517 | * @param vertexCount number of vertices. |
| 518 | * @param positions array of vertex positions, required. |
| 519 | * @param texCoords optional array of texture coordinates used |
| 520 | * to access the paint. |
| 521 | * @param colors optional array of per-vertex colors, supercedes |
| 522 | * the paint's color field. |
| 523 | * @param indices optional array of indices. If NULL vertices |
| 524 | * are drawn non-indexed. |
| 525 | * @param indexCount if indices is non-null then this is the |
| 526 | * number of indices. |
| 527 | */ |
| 528 | void drawVertices(const GrPaint& paint, |
| 529 | GrPrimitiveType primitiveType, |
| 530 | int vertexCount, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 531 | const SkPoint positions[], |
| 532 | const SkPoint texs[], |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 533 | const GrColor colors[], |
| 534 | const uint16_t indices[], |
| 535 | int indexCount); |
| 536 | |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 537 | /** |
| 538 | * Draws an oval. |
| 539 | * |
| 540 | * @param paint describes how to color pixels. |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 541 | * @param oval the bounding rect of the oval. |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 542 | * @param strokeInfo the stroke information (width, join, cap) and |
| 543 | * the dash information (intervals, count, phase). |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 544 | */ |
| 545 | void drawOval(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 546 | const SkRect& oval, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 547 | const GrStrokeInfo& strokeInfo); |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 548 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 549 | /////////////////////////////////////////////////////////////////////////// |
| 550 | // Misc. |
| 551 | |
| 552 | /** |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 553 | * Flags that affect flush() behavior. |
| 554 | */ |
| 555 | enum FlushBits { |
| 556 | /** |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 557 | * A client may reach a point where it has partially rendered a frame |
| 558 | * through a GrContext that it knows the user will never see. This flag |
| 559 | * causes the flush to skip submission of deferred content to the 3D API |
| 560 | * during the flush. |
| 561 | */ |
| 562 | kDiscard_FlushBit = 0x2, |
| 563 | }; |
| 564 | |
| 565 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 566 | * Call to ensure all drawing to the context has been issued to the |
| 567 | * underlying 3D API. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 568 | * @param flagsBitfield flags that control the flushing behavior. See |
| 569 | * FlushBits. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 570 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 571 | void flush(int flagsBitfield = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 572 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 573 | /** |
| 574 | * These flags can be used with the read/write pixels functions below. |
| 575 | */ |
| 576 | enum PixelOpsFlags { |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 577 | /** The GrContext will not be flushed before the surface read or write. This means that |
| 578 | the read or write may occur before previous draws have executed. */ |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 579 | kDontFlush_PixelOpsFlag = 0x1, |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 580 | /** Any surface writes should be flushed to the backend 3D API after the surface operation |
| 581 | is complete */ |
| 582 | kFlushWrites_PixelOp = 0x2, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 583 | /** The src for write or dst read is unpremultiplied. This is only respected if both the |
| 584 | config src and dst configs are an RGBA/BGRA 8888 format. */ |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 585 | kUnpremul_PixelOpsFlag = 0x4, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 586 | }; |
| 587 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 588 | /** |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 589 | * Reads a rectangle of pixels from a render target. |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 590 | * @param target the render target to read from. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 591 | * @param left left edge of the rectangle to read (inclusive) |
| 592 | * @param top top edge of the rectangle to read (inclusive) |
| 593 | * @param width width of rectangle to read in pixels. |
| 594 | * @param height height of rectangle to read in pixels. |
| 595 | * @param config the pixel config of the destination buffer |
| 596 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 597 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 598 | * packed. |
| 599 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 600 | * |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 601 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
| 602 | * pixel config or because no render target is currently set and NULL was passed for |
| 603 | * target. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 604 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 605 | bool readRenderTargetPixels(GrRenderTarget* target, |
| 606 | int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 607 | GrPixelConfig config, void* buffer, |
| 608 | size_t rowBytes = 0, |
| 609 | uint32_t pixelOpsFlags = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 610 | |
| 611 | /** |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 612 | * Writes a rectangle of pixels to a surface. |
| 613 | * @param surface the surface to write to. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 614 | * @param left left edge of the rectangle to write (inclusive) |
| 615 | * @param top top edge of the rectangle to write (inclusive) |
| 616 | * @param width width of rectangle to write in pixels. |
| 617 | * @param height height of rectangle to write in pixels. |
| 618 | * @param config the pixel config of the source buffer |
| 619 | * @param buffer memory to read pixels from |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 620 | * @param rowBytes number of bytes between consecutive rows. Zero |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 621 | * means rows are tightly packed. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 622 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 623 | * @return true if the write succeeded, false if not. The write can fail because of an |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 624 | * unsupported combination of surface and src configs. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 625 | */ |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 626 | bool writeSurfacePixels(GrSurface* surface, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 627 | int left, int top, int width, int height, |
| 628 | GrPixelConfig config, const void* buffer, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 629 | size_t rowBytes, |
| 630 | uint32_t pixelOpsFlags = 0); |
| 631 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 632 | /** |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 633 | * Copies a rectangle of texels from src to dst. |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 634 | * bounds. |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 635 | * @param dst the surface to copy to. |
| 636 | * @param src the surface to copy from. |
| 637 | * @param srcRect the rectangle of the src that should be copied. |
| 638 | * @param dstPoint the translation applied when writing the srcRect's pixels to the dst. |
| 639 | * @param pixelOpsFlags see PixelOpsFlags enum above. (kUnpremul_PixelOpsFlag is not allowed). |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 640 | */ |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 641 | void copySurface(GrSurface* dst, |
| 642 | GrSurface* src, |
| 643 | const SkIRect& srcRect, |
| 644 | const SkIPoint& dstPoint, |
| 645 | uint32_t pixelOpsFlags = 0); |
| 646 | |
| 647 | /** Helper that copies the whole surface but fails when the two surfaces are not identically |
| 648 | sized. */ |
| 649 | bool copySurface(GrSurface* dst, GrSurface* src) { |
| 650 | if (NULL == dst || NULL == src || dst->width() != src->width() || |
| 651 | dst->height() != src->height()) { |
| 652 | return false; |
| 653 | } |
| 654 | this->copySurface(dst, src, SkIRect::MakeWH(dst->width(), dst->height()), |
| 655 | SkIPoint::Make(0,0)); |
| 656 | return true; |
| 657 | } |
| 658 | |
| 659 | /** |
| 660 | * After this returns any pending writes to the surface will have been issued to the backend 3D API. |
| 661 | */ |
| 662 | void flushSurfaceWrites(GrSurface* surface); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 663 | |
| 664 | /** |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 665 | * Equivalent to flushSurfaceWrites but also performs MSAA resolve if necessary. This call is |
| 666 | * used to make the surface contents available to be read in the backend 3D API, usually for a |
| 667 | * compositing step external to Skia. |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 668 | * |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 669 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
| 670 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
| 671 | * surface or using it as a texture. |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 672 | */ |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 673 | void prepareSurfaceForExternalRead(GrSurface*); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 674 | |
| 675 | /** |
| 676 | * Provides a perfomance hint that the render target's contents are allowed |
| 677 | * to become undefined. |
| 678 | */ |
| 679 | void discardRenderTarget(GrRenderTarget*); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 680 | |
commit-bot@chromium.org | 03e3e89 | 2013-10-02 18:19:17 +0000 | [diff] [blame] | 681 | #ifdef SK_DEVELOPER |
| 682 | void dumpFontCache() const; |
| 683 | #endif |
| 684 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 685 | /////////////////////////////////////////////////////////////////////////// |
| 686 | // Helpers |
| 687 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 688 | class AutoRenderTarget : public ::SkNoncopyable { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 689 | public: |
| 690 | AutoRenderTarget(GrContext* context, GrRenderTarget* target) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 691 | fPrevTarget = context->getRenderTarget(); |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 692 | SkSafeRef(fPrevTarget); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 693 | context->setRenderTarget(target); |
| 694 | fContext = context; |
| 695 | } |
| 696 | AutoRenderTarget(GrContext* context) { |
| 697 | fPrevTarget = context->getRenderTarget(); |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 698 | SkSafeRef(fPrevTarget); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 699 | fContext = context; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 700 | } |
| 701 | ~AutoRenderTarget() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 702 | if (fContext) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 703 | fContext->setRenderTarget(fPrevTarget); |
| 704 | } |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 705 | SkSafeUnref(fPrevTarget); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 706 | } |
| 707 | private: |
| 708 | GrContext* fContext; |
| 709 | GrRenderTarget* fPrevTarget; |
| 710 | }; |
| 711 | |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 712 | /** |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 713 | * Save/restore the view-matrix in the context. It can optionally adjust a paint to account |
| 714 | * for a coordinate system change. Here is an example of how the paint param can be used: |
| 715 | * |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 716 | * A GrPaint is setup with GrProcessors. The stages will have access to the pre-matrix source |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 717 | * geometry positions when the draw is executed. Later on a decision is made to transform the |
bsalomon@google.com | 6f261be | 2012-10-24 19:07:10 +0000 | [diff] [blame] | 718 | * geometry to device space on the CPU. The effects now need to know that the space in which |
| 719 | * the geometry will be specified has changed. |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 720 | * |
| 721 | * Note that when restore is called (or in the destructor) the context's matrix will be |
| 722 | * restored. However, the paint will not be restored. The caller must make a copy of the |
| 723 | * paint if necessary. Hint: use SkTCopyOnFirstWrite if the AutoMatrix is conditionally |
| 724 | * initialized. |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 725 | */ |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 726 | class AutoMatrix : public ::SkNoncopyable { |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 727 | public: |
| 728 | AutoMatrix() : fContext(NULL) {} |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 729 | |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 730 | ~AutoMatrix() { this->restore(); } |
| 731 | |
| 732 | /** |
| 733 | * Initializes by pre-concat'ing the context's current matrix with the preConcat param. |
| 734 | */ |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 735 | void setPreConcat(GrContext* context, const SkMatrix& preConcat, GrPaint* paint = NULL) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 736 | SkASSERT(context); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 737 | |
| 738 | this->restore(); |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 739 | |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 740 | fContext = context; |
| 741 | fMatrix = context->getMatrix(); |
| 742 | this->preConcat(preConcat, paint); |
| 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Sets the context's matrix to identity. Returns false if the inverse matrix is required to |
| 747 | * update a paint but the matrix cannot be inverted. |
| 748 | */ |
| 749 | bool setIdentity(GrContext* context, GrPaint* paint = NULL) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 750 | SkASSERT(context); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 751 | |
| 752 | this->restore(); |
skia.committer@gmail.com | f57c01b | 2012-10-13 02:01:56 +0000 | [diff] [blame] | 753 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 754 | if (paint) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 755 | if (!paint->localCoordChangeInverse(context->getMatrix())) { |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 756 | return false; |
| 757 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 758 | } |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 759 | fMatrix = context->getMatrix(); |
| 760 | fContext = context; |
| 761 | context->setIdentityMatrix(); |
| 762 | return true; |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 763 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 764 | |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 765 | /** |
| 766 | * Replaces the context's matrix with a new matrix. Returns false if the inverse matrix is |
| 767 | * required to update a paint but the matrix cannot be inverted. |
| 768 | */ |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 769 | bool set(GrContext* context, const SkMatrix& newMatrix, GrPaint* paint = NULL) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 770 | if (paint) { |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 771 | if (!this->setIdentity(context, paint)) { |
| 772 | return false; |
| 773 | } |
| 774 | this->preConcat(newMatrix, paint); |
| 775 | } else { |
| 776 | this->restore(); |
| 777 | fContext = context; |
| 778 | fMatrix = context->getMatrix(); |
| 779 | context->setMatrix(newMatrix); |
| 780 | } |
| 781 | return true; |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 782 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 783 | |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 784 | /** |
| 785 | * If this has been initialized then the context's matrix will be further updated by |
| 786 | * pre-concat'ing the preConcat param. The matrix that will be restored remains unchanged. |
| 787 | * The paint is assumed to be relative to the context's matrix at the time this call is |
| 788 | * made, not the matrix at the time AutoMatrix was first initialized. In other words, this |
| 789 | * performs an incremental update of the paint. |
| 790 | */ |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 791 | void preConcat(const SkMatrix& preConcat, GrPaint* paint = NULL) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 792 | if (paint) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 793 | paint->localCoordChange(preConcat); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 794 | } |
| 795 | fContext->concatMatrix(preConcat); |
| 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Returns false if never initialized or the inverse matrix was required to update a paint |
| 800 | * but the matrix could not be inverted. |
| 801 | */ |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 802 | bool succeeded() const { return SkToBool(fContext); } |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 803 | |
| 804 | /** |
| 805 | * If this has been initialized then the context's original matrix is restored. |
| 806 | */ |
| 807 | void restore() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 808 | if (fContext) { |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 809 | fContext->setMatrix(fMatrix); |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 810 | fContext = NULL; |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
| 814 | private: |
| 815 | GrContext* fContext; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 816 | SkMatrix fMatrix; |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 817 | }; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 818 | |
commit-bot@chromium.org | a0b4028 | 2013-09-18 13:00:55 +0000 | [diff] [blame] | 819 | class AutoClip : public ::SkNoncopyable { |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 820 | public: |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 821 | // This enum exists to require a caller of the constructor to acknowledge that the clip will |
| 822 | // initially be wide open. It also could be extended if there are other desirable initial |
| 823 | // clip states. |
| 824 | enum InitialClip { |
| 825 | kWideOpen_InitialClip, |
| 826 | }; |
| 827 | |
djsollen | c87dd2c | 2014-11-14 11:11:46 -0800 | [diff] [blame] | 828 | AutoClip(GrContext* context, InitialClip SkDEBUGCODE(initialState)) |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 829 | : fContext(context) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 830 | SkASSERT(kWideOpen_InitialClip == initialState); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 831 | fNewClipData.fClipStack = &fNewClipStack; |
robertphillips@google.com | ccb3950 | 2012-10-01 18:25:13 +0000 | [diff] [blame] | 832 | |
| 833 | fOldClip = context->getClip(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 834 | context->setClip(&fNewClipData); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 835 | } |
| 836 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 837 | AutoClip(GrContext* context, const SkRect& newClipRect) |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 838 | : fContext(context) |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 839 | , fNewClipStack(newClipRect) { |
| 840 | fNewClipData.fClipStack = &fNewClipStack; |
| 841 | |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 842 | fOldClip = fContext->getClip(); |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 843 | fContext->setClip(&fNewClipData); |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | ~AutoClip() { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 847 | if (fContext) { |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 848 | fContext->setClip(fOldClip); |
| 849 | } |
| 850 | } |
| 851 | private: |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 852 | GrContext* fContext; |
| 853 | const GrClipData* fOldClip; |
| 854 | |
robertphillips@google.com | 641f8b1 | 2012-07-31 19:15:58 +0000 | [diff] [blame] | 855 | SkClipStack fNewClipStack; |
robertphillips@google.com | beb1af7 | 2012-07-26 18:52:16 +0000 | [diff] [blame] | 856 | GrClipData fNewClipData; |
robertphillips@google.com | 56c79b1 | 2012-07-11 20:57:46 +0000 | [diff] [blame] | 857 | }; |
| 858 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 859 | class AutoWideOpenIdentityDraw { |
| 860 | public: |
| 861 | AutoWideOpenIdentityDraw(GrContext* ctx, GrRenderTarget* rt) |
| 862 | : fAutoClip(ctx, AutoClip::kWideOpen_InitialClip) |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 863 | , fAutoRT(ctx, rt) { |
| 864 | fAutoMatrix.setIdentity(ctx); |
| 865 | // should never fail with no paint param. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 866 | SkASSERT(fAutoMatrix.succeeded()); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 867 | } |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 868 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 869 | private: |
| 870 | AutoClip fAutoClip; |
| 871 | AutoRenderTarget fAutoRT; |
| 872 | AutoMatrix fAutoMatrix; |
| 873 | }; |
| 874 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 875 | /////////////////////////////////////////////////////////////////////////// |
| 876 | // Functions intended for internal use only. |
| 877 | GrGpu* getGpu() { return fGpu; } |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 878 | const GrGpu* getGpu() const { return fGpu; } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 879 | GrFontCache* getFontCache() { return fFontCache; } |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 880 | GrLayerCache* getLayerCache() { return fLayerCache.get(); } |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 881 | GrDrawTarget* getTextTarget(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 882 | const GrIndexBuffer* getQuadIndexBuffer() const; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 883 | GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 884 | GrResourceCache2* getResourceCache2() { return fResourceCache2; } |
bsalomon@google.com | 9923c2b | 2012-06-06 18:21:18 +0000 | [diff] [blame] | 885 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 886 | // Called by tests that draw directly to the context via GrDrawTarget |
| 887 | void getTestTarget(GrTestTarget*); |
| 888 | |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 889 | void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 890 | void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 891 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 892 | GrPathRenderer* getPathRenderer( |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 893 | const GrDrawTarget* target, |
| 894 | const GrDrawState*, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 895 | const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 896 | const SkStrokeRec& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 897 | bool allowSW, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 898 | GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 899 | GrPathRendererChain::StencilSupport* stencilSupport = NULL); |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 900 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 901 | /** |
| 902 | * This returns a copy of the the GrContext::Options that was passed to the |
| 903 | * constructor of this class. |
| 904 | */ |
| 905 | const Options& getOptions() const { return fOptions; } |
| 906 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 907 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 908 | void printCacheStats() const; |
| 909 | #endif |
| 910 | |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 911 | class GPUStats { |
| 912 | public: |
| 913 | #if GR_GPU_STATS |
| 914 | GPUStats() { this->reset(); } |
| 915 | |
| 916 | void reset() { fRenderTargetBinds = 0; fShaderCompilations = 0; } |
| 917 | |
| 918 | int renderTargetBinds() const { return fRenderTargetBinds; } |
| 919 | void incRenderTargetBinds() { fRenderTargetBinds++; } |
| 920 | int shaderCompilations() const { return fShaderCompilations; } |
| 921 | void incShaderCompilations() { fShaderCompilations++; } |
| 922 | private: |
| 923 | int fRenderTargetBinds; |
| 924 | int fShaderCompilations; |
| 925 | #else |
| 926 | void incRenderTargetBinds() {} |
| 927 | void incShaderCompilations() {} |
| 928 | #endif |
| 929 | }; |
| 930 | |
| 931 | #if GR_GPU_STATS |
| 932 | const GPUStats* gpuStats() const; |
| 933 | #endif |
| 934 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 935 | private: |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 936 | GrGpu* fGpu; |
| 937 | SkMatrix fViewMatrix; |
| 938 | SkAutoTUnref<GrRenderTarget> fRenderTarget; |
| 939 | const GrClipData* fClip; // TODO: make this ref counted |
bsalomon@google.com | 10e04bf | 2012-03-30 14:35:04 +0000 | [diff] [blame] | 940 | |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 941 | GrResourceCache2* fResourceCache2; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 942 | GrFontCache* fFontCache; |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 943 | SkAutoTDelete<GrLayerCache> fLayerCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 944 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 945 | GrPathRendererChain* fPathRendererChain; |
| 946 | GrSoftwarePathRenderer* fSoftwarePathRenderer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 947 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 948 | GrVertexBufferAllocPool* fDrawBufferVBAllocPool; |
| 949 | GrIndexBufferAllocPool* fDrawBufferIBAllocPool; |
| 950 | GrInOrderDrawBuffer* fDrawBuffer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 951 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 952 | // Set by OverbudgetCB() to request that GrContext flush before exiting a draw. |
| 953 | bool fFlushToReduceCacheSize; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 954 | GrAARectRenderer* fAARectRenderer; |
| 955 | GrOvalRenderer* fOvalRenderer; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 956 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 957 | bool fDidTestPMConversions; |
| 958 | int fPMToUPMConversion; |
| 959 | int fUPMToPMConversion; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 960 | |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 961 | struct CleanUpData { |
| 962 | PFCleanUpFunc fFunc; |
| 963 | void* fInfo; |
| 964 | }; |
| 965 | |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 966 | SkTDArray<CleanUpData> fCleanUpData; |
| 967 | |
skia.committer@gmail.com | 956b310 | 2013-07-26 07:00:58 +0000 | [diff] [blame] | 968 | int fMaxTextureSizeOverride; |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 969 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 970 | const Options fOptions; |
| 971 | |
| 972 | GrContext(const Options&); // init must be called after the constructor. |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 973 | bool init(GrBackend, GrBackendContext); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 974 | void initMockContext(); |
| 975 | void initCommon(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 976 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 977 | void setupDrawBuffer(); |
| 978 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 979 | class AutoCheckFlush; |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 980 | /// Sets the paint and returns the target to draw into. The paint can be NULL in which case the |
| 981 | /// draw state is left unmodified. |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 982 | GrDrawTarget* prepareToDraw(GrDrawState* ds, const GrPaint* paint, const AutoCheckFlush*); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 983 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 984 | void internalDrawPath(GrDrawTarget*, |
| 985 | GrDrawState*, |
| 986 | bool useAA, |
| 987 | const SkPath&, |
| 988 | const GrStrokeInfo&); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 989 | |
bsalomon | f2703d8 | 2014-10-28 14:33:06 -0700 | [diff] [blame] | 990 | GrTexture* createResizedTexture(const GrSurfaceDesc& desc, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 991 | const GrCacheID& cacheID, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 992 | const void* srcData, |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 993 | size_t rowBytes, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 994 | bool filter); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 995 | |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 996 | /** |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 997 | * These functions create premul <-> unpremul effects if it is possible to generate a pair |
| 998 | * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they |
| 999 | * return NULL. |
| 1000 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1001 | const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&); |
| 1002 | const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1003 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 1004 | /** |
| 1005 | * This callback allows the resource cache to callback into the GrContext |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1006 | * when the cache is still over budget after a purge. |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 1007 | */ |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 1008 | static void OverBudgetCB(void* data); |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 1009 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 1010 | typedef SkRefCnt INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1011 | }; |
| 1012 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1013 | #endif |