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