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 | |
joshualitt | 44701df | 2015-02-23 14:44:57 -0800 | [diff] [blame] | 11 | #include "GrClip.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 | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 16 | #include "GrTextureProvider.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; |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 22 | class GrBatchFontCache; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame^] | 23 | struct GrContextOptions; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 24 | class GrDrawTarget; |
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; |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 29 | class GrLayerCache; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 30 | class GrOvalRenderer; |
commit-bot@chromium.org | 5c8ee25 | 2013-11-01 15:23:44 +0000 | [diff] [blame] | 31 | class GrPath; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 32 | class GrPathRenderer; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 33 | class GrPipelineBuilder; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 34 | class GrResourceEntry; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 35 | class GrResourceCache; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 36 | class GrResourceProvider; |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 37 | class GrTestTarget; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 38 | class GrTextBlobCache; |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 39 | class GrTextContext; |
bsalomon@google.com | 288d954 | 2012-10-17 12:53:54 +0000 | [diff] [blame] | 40 | class GrTextureParams; |
bsalomon@google.com | 583a1e3 | 2011-08-17 13:42:46 +0000 | [diff] [blame] | 41 | class GrVertexBuffer; |
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; |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 44 | class SkGpuDevice; |
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 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 50 | /** |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 51 | * Creates a GrContext for a backend context. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 52 | */ |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame^] | 53 | static GrContext* Create(GrBackend, GrBackendContext, const GrContextOptions& options); |
| 54 | static GrContext* Create(GrBackend, GrBackendContext); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 55 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 56 | /** |
| 57 | * Only defined in test apps. |
| 58 | */ |
| 59 | static GrContext* CreateMockContext(); |
| 60 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 61 | virtual ~GrContext(); |
| 62 | |
| 63 | /** |
| 64 | * The GrContext normally assumes that no outsider is setting state |
| 65 | * within the underlying 3D API's context/device/whatever. This call informs |
| 66 | * the context that the state was modified and it should resend. Shouldn't |
| 67 | * be called frequently for good performance. |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 68 | * The flag bits, state, is dpendent on which backend is used by the |
| 69 | * context, either GL or D3D (possible in future). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 70 | */ |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 71 | void resetContext(uint32_t state = kAll_GrBackendState); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 72 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 73 | /** |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 74 | * Callback function to allow classes to cleanup on GrContext destruction. |
| 75 | * The 'info' field is filled in with the 'info' passed to addCleanUp. |
| 76 | */ |
| 77 | typedef void (*PFCleanUpFunc)(const GrContext* context, void* info); |
| 78 | |
| 79 | /** |
| 80 | * Add a function to be called from within GrContext's destructor. |
| 81 | * This gives classes a chance to free resources held on a per context basis. |
| 82 | * The 'info' parameter will be stored and passed to the callback function. |
| 83 | */ |
| 84 | void addCleanUp(PFCleanUpFunc cleanUp, void* info) { |
| 85 | CleanUpData* entry = fCleanUpData.push(); |
| 86 | |
| 87 | entry->fFunc = cleanUp; |
| 88 | entry->fInfo = info; |
| 89 | } |
| 90 | |
| 91 | /** |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 92 | * Abandons all GPU resources and assumes the underlying backend 3D API |
| 93 | * context is not longer usable. Call this if you have lost the associated |
| 94 | * GPU context, and thus internal texture, buffer, etc. references/IDs are |
| 95 | * now invalid. Should be called even when GrContext is no longer going to |
| 96 | * be used for two reasons: |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 97 | * 1) ~GrContext will not try to free the objects in the 3D API. |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 98 | * 2) Any GrGpuResources created by this GrContext that outlive |
| 99 | * will be marked as invalid (GrGpuResource::wasDestroyed()) and |
| 100 | * when they're destroyed no 3D API calls will be made. |
| 101 | * Content drawn since the last GrContext::flush() may be lost. After this |
| 102 | * function is called the only valid action on the GrContext or |
| 103 | * GrGpuResources it created is to destroy them. |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 104 | */ |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 105 | void abandonContext(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 106 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 107 | /////////////////////////////////////////////////////////////////////////// |
| 108 | // Resource Cache |
| 109 | |
| 110 | /** |
| 111 | * Return the current GPU resource cache limits. |
| 112 | * |
| 113 | * @param maxResources If non-null, returns maximum number of resources that |
| 114 | * can be held in the cache. |
| 115 | * @param maxResourceBytes If non-null, returns maximum number of bytes of |
| 116 | * video memory that can be held in the cache. |
| 117 | */ |
| 118 | void getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * Gets the current GPU resource cache usage. |
| 122 | * |
| 123 | * @param resourceCount If non-null, returns the number of resources that are held in the |
| 124 | * cache. |
| 125 | * @param maxResourceBytes If non-null, returns the total number of bytes of video memory held |
| 126 | * in the cache. |
| 127 | */ |
| 128 | void getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const; |
| 129 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 130 | /** |
| 131 | * Specify the GPU resource cache limits. If the current cache exceeds either |
| 132 | * of these, it will be purged (LRU) to keep the cache within these limits. |
| 133 | * |
| 134 | * @param maxResources The maximum number of resources that can be held in |
| 135 | * the cache. |
| 136 | * @param maxResourceBytes The maximum number of bytes of video memory |
| 137 | * that can be held in the cache. |
| 138 | */ |
| 139 | void setResourceCacheLimits(int maxResources, size_t maxResourceBytes); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 140 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 141 | GrTextureProvider* textureProvider() { return fTextureProvider; } |
| 142 | const GrTextureProvider* textureProvider() const { return fTextureProvider; } |
| 143 | |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 144 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 145 | * 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] | 146 | * pressure. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 147 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 148 | void freeGpuResources(); |
| 149 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 150 | /** |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 151 | * Purge all the unlocked resources from the cache. |
| 152 | * This entry point is mainly meant for timing texture uploads |
| 153 | * and is not defined in normal builds of Skia. |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 154 | */ |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 155 | void purgeAllUnlockedResources(); |
| 156 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 157 | ////////////////////////////////////////////////////////////////////////// |
| 158 | /// Texture and Render Target Queries |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 159 | |
| 160 | /** |
bsalomon | d2a6f4e | 2015-02-04 10:55:54 -0800 | [diff] [blame] | 161 | * Can the provided configuration act as a texture? |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 162 | */ |
bsalomon | d2a6f4e | 2015-02-04 10:55:54 -0800 | [diff] [blame] | 163 | bool isConfigTexturable(GrPixelConfig) const; |
| 164 | |
| 165 | /** |
| 166 | * Can non-power-of-two textures be used with tile modes other than clamp? |
| 167 | */ |
| 168 | bool npotTextureTileSupport() const; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 169 | |
| 170 | /** |
bsalomon@google.com | 1e269b5 | 2012-10-15 14:25:31 +0000 | [diff] [blame] | 171 | * 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] | 172 | */ |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 173 | int getMaxTextureSize() const; |
| 174 | |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 175 | /** |
skia.committer@gmail.com | 956b310 | 2013-07-26 07:00:58 +0000 | [diff] [blame] | 176 | * Temporarily override the true max texture size. Note: an override |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 177 | * larger then the true max texture size will have no effect. |
| 178 | * This entry point is mainly meant for testing texture size dependent |
| 179 | * features and is only available if defined outside of Skia (see |
| 180 | * bleed GM. |
| 181 | */ |
| 182 | void setMaxTextureSizeOverride(int maxTextureSizeOverride); |
| 183 | |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 184 | /** |
| 185 | * Can the provided configuration act as a color render target? |
| 186 | */ |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 187 | bool isConfigRenderable(GrPixelConfig config, bool withMSAA) const; |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 188 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 189 | /** |
| 190 | * Return the max width or height of a render target supported by the |
| 191 | * current GPU. |
| 192 | */ |
| 193 | int getMaxRenderTargetSize() const; |
| 194 | |
| 195 | /** |
| 196 | * Returns the max sample count for a render target. It will be 0 if MSAA |
| 197 | * is not supported. |
| 198 | */ |
| 199 | int getMaxSampleCount() const; |
| 200 | |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 201 | /** |
| 202 | * Returns the recommended sample count for a render target when using this |
| 203 | * context. |
| 204 | * |
| 205 | * @param config the configuration of the render target. |
| 206 | * @param dpi the display density in dots per inch. |
| 207 | * |
| 208 | * @return sample count that should be perform well and have good enough |
| 209 | * rendering quality for the display. Alternatively returns 0 if |
| 210 | * MSAA is not supported or recommended to be used by default. |
| 211 | */ |
| 212 | int getRecommendedSampleCount(GrPixelConfig config, SkScalar dpi) const; |
| 213 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 214 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 215 | // Draws |
| 216 | |
| 217 | /** |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 218 | * Clear the entire or rect of the render target, ignoring any clips. |
| 219 | * @param rect the rect to clear or the whole thing if rect is NULL. |
| 220 | * @param color the color to clear to. |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 221 | * @param canIgnoreRect allows partial clears to be converted to whole |
| 222 | * clears on platforms for which that is cheap |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 223 | * @param target The render target to clear. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 224 | */ |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 225 | void clear(const SkIRect* rect, GrColor color, bool canIgnoreRect, GrRenderTarget* target); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * Draw everywhere (respecting the clip) with the paint. |
| 229 | */ |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 230 | void drawPaint(GrRenderTarget*, const GrClip&, const GrPaint&, const SkMatrix& viewMatrix); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 231 | |
| 232 | /** |
| 233 | * Draw the rect using a paint. |
| 234 | * @param paint describes how to color pixels. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 235 | * @param viewMatrix transformation matrix |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 236 | * @param strokeInfo the stroke information (width, join, cap), and. |
| 237 | * the dash information (intervals, count, phase). |
| 238 | * If strokeInfo == NULL, then the rect is filled. |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 239 | * Otherwise, if stroke width == 0, then the stroke |
skia.committer@gmail.com | 2614418 | 2013-11-07 07:02:19 +0000 | [diff] [blame] | 240 | * is always a single pixel thick, else the rect is |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 241 | * mitered/beveled stroked based on stroke width. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 242 | * The rects coords are used to access the paint (through texture matrix) |
| 243 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 244 | void drawRect(GrRenderTarget*, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 245 | const GrClip&, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 246 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 247 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 248 | const SkRect&, |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 249 | const GrStrokeInfo* strokeInfo = NULL); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 250 | |
| 251 | /** |
joshualitt | 16b2789 | 2014-12-18 07:47:16 -0800 | [diff] [blame] | 252 | * Maps a rectangle of shader coordinates to a rectangle and draws that rectangle |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 253 | * |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 254 | * @param paint describes how to color pixels. |
joshualitt | 16b2789 | 2014-12-18 07:47:16 -0800 | [diff] [blame] | 255 | * @param viewMatrix transformation matrix which applies to rectToDraw |
| 256 | * @param rectToDraw the rectangle to draw |
| 257 | * @param localRect the rectangle of shader coordinates applied to rectToDraw |
| 258 | * @param localMatrix an optional matrix to transform the shader coordinates before applying |
| 259 | * to rectToDraw |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 260 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 261 | void drawNonAARectToRect(GrRenderTarget*, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 262 | const GrClip&, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 263 | const GrPaint& paint, |
joshualitt | 16b2789 | 2014-12-18 07:47:16 -0800 | [diff] [blame] | 264 | const SkMatrix& viewMatrix, |
| 265 | const SkRect& rectToDraw, |
| 266 | const SkRect& localRect, |
| 267 | const SkMatrix* localMatrix = NULL); |
| 268 | |
| 269 | /** |
| 270 | * Draws a non-AA rect with paint and a localMatrix |
| 271 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 272 | void drawNonAARectWithLocalMatrix(GrRenderTarget* rt, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 273 | const GrClip& clip, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 274 | const GrPaint& paint, |
joshualitt | 16b2789 | 2014-12-18 07:47:16 -0800 | [diff] [blame] | 275 | const SkMatrix& viewMatrix, |
| 276 | const SkRect& rect, |
| 277 | const SkMatrix& localMatrix) { |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 278 | this->drawNonAARectToRect(rt, clip, paint, viewMatrix, rect, rect, &localMatrix); |
joshualitt | 16b2789 | 2014-12-18 07:47:16 -0800 | [diff] [blame] | 279 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 280 | |
| 281 | /** |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 282 | * Draw a roundrect using a paint. |
| 283 | * |
| 284 | * @param paint describes how to color pixels. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 285 | * @param viewMatrix transformation matrix |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 286 | * @param rrect the roundrect to draw |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 287 | * @param strokeInfo the stroke information (width, join, cap) and |
| 288 | * the dash information (intervals, count, phase). |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 289 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 290 | void drawRRect(GrRenderTarget*, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 291 | const GrClip&, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 292 | const GrPaint&, |
| 293 | const SkMatrix& viewMatrix, |
| 294 | const SkRRect& rrect, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 295 | const GrStrokeInfo&); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 296 | |
| 297 | /** |
| 298 | * Shortcut for drawing an SkPath consisting of nested rrects using a paint. |
| 299 | * Does not support stroking. The result is undefined if outer does not contain |
| 300 | * inner. |
| 301 | * |
| 302 | * @param paint describes how to color pixels. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 303 | * @param viewMatrix transformation matrix |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 304 | * @param outer the outer roundrect |
| 305 | * @param inner the inner roundrect |
| 306 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 307 | void drawDRRect(GrRenderTarget*, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 308 | const GrClip&, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 309 | const GrPaint&, |
| 310 | const SkMatrix& viewMatrix, |
| 311 | const SkRRect& outer, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 312 | const SkRRect& inner); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 313 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 314 | |
| 315 | /** |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 316 | * Draws a path. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 317 | * |
| 318 | * @param paint describes how to color pixels. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 319 | * @param viewMatrix transformation matrix |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 320 | * @param path the path to draw |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 321 | * @param strokeInfo the stroke information (width, join, cap) and |
| 322 | * the dash information (intervals, count, phase). |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 323 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 324 | void drawPath(GrRenderTarget*, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 325 | const GrClip&, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 326 | const GrPaint&, |
| 327 | const SkMatrix& viewMatrix, |
| 328 | const SkPath&, |
| 329 | const GrStrokeInfo&); |
reed@google.com | 07f3ee1 | 2011-05-16 17:21:57 +0000 | [diff] [blame] | 330 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 331 | /** |
| 332 | * Draws vertices with a paint. |
| 333 | * |
| 334 | * @param paint describes how to color pixels. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 335 | * @param viewMatrix transformation matrix |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 336 | * @param primitiveType primitives type to draw. |
| 337 | * @param vertexCount number of vertices. |
| 338 | * @param positions array of vertex positions, required. |
| 339 | * @param texCoords optional array of texture coordinates used |
| 340 | * to access the paint. |
| 341 | * @param colors optional array of per-vertex colors, supercedes |
| 342 | * the paint's color field. |
| 343 | * @param indices optional array of indices. If NULL vertices |
| 344 | * are drawn non-indexed. |
| 345 | * @param indexCount if indices is non-null then this is the |
| 346 | * number of indices. |
| 347 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 348 | void drawVertices(GrRenderTarget*, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 349 | const GrClip&, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 350 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 351 | const SkMatrix& viewMatrix, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 352 | GrPrimitiveType primitiveType, |
| 353 | int vertexCount, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 354 | const SkPoint positions[], |
| 355 | const SkPoint texs[], |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 356 | const GrColor colors[], |
| 357 | const uint16_t indices[], |
| 358 | int indexCount); |
| 359 | |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 360 | /** |
| 361 | * Draws an oval. |
| 362 | * |
| 363 | * @param paint describes how to color pixels. |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 364 | * @param viewMatrix transformation matrix |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 365 | * @param oval the bounding rect of the oval. |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 366 | * @param strokeInfo the stroke information (width, join, cap) and |
| 367 | * the dash information (intervals, count, phase). |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 368 | */ |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 369 | void drawOval(GrRenderTarget*, |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 370 | const GrClip&, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 371 | const GrPaint& paint, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 372 | const SkMatrix& viewMatrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 373 | const SkRect& oval, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 374 | const GrStrokeInfo& strokeInfo); |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 375 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 376 | /////////////////////////////////////////////////////////////////////////// |
| 377 | // Misc. |
| 378 | |
| 379 | /** |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 380 | * Flags that affect flush() behavior. |
| 381 | */ |
| 382 | enum FlushBits { |
| 383 | /** |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 384 | * A client may reach a point where it has partially rendered a frame |
| 385 | * through a GrContext that it knows the user will never see. This flag |
| 386 | * causes the flush to skip submission of deferred content to the 3D API |
| 387 | * during the flush. |
| 388 | */ |
| 389 | kDiscard_FlushBit = 0x2, |
| 390 | }; |
| 391 | |
| 392 | /** |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 393 | * Call to ensure all drawing to the context has been issued to the |
| 394 | * underlying 3D API. |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 395 | * @param flagsBitfield flags that control the flushing behavior. See |
| 396 | * FlushBits. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 397 | */ |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 398 | void flush(int flagsBitfield = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 399 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 400 | /** |
| 401 | * These flags can be used with the read/write pixels functions below. |
| 402 | */ |
| 403 | enum PixelOpsFlags { |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 404 | /** The GrContext will not be flushed before the surface read or write. This means that |
| 405 | the read or write may occur before previous draws have executed. */ |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 406 | kDontFlush_PixelOpsFlag = 0x1, |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 407 | /** Any surface writes should be flushed to the backend 3D API after the surface operation |
| 408 | is complete */ |
| 409 | kFlushWrites_PixelOp = 0x2, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 410 | /** The src for write or dst read is unpremultiplied. This is only respected if both the |
| 411 | config src and dst configs are an RGBA/BGRA 8888 format. */ |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 412 | kUnpremul_PixelOpsFlag = 0x4, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 413 | }; |
| 414 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 415 | /** |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 416 | * Reads a rectangle of pixels from a render target. |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 417 | * @param target the render target to read from. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 418 | * @param left left edge of the rectangle to read (inclusive) |
| 419 | * @param top top edge of the rectangle to read (inclusive) |
| 420 | * @param width width of rectangle to read in pixels. |
| 421 | * @param height height of rectangle to read in pixels. |
| 422 | * @param config the pixel config of the destination buffer |
| 423 | * @param buffer memory to read the rectangle into. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 424 | * @param rowBytes number of bytes bewtween consecutive rows. Zero means rows are tightly |
| 425 | * packed. |
| 426 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 427 | * |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 428 | * @return true if the read succeeded, false if not. The read can fail because of an unsupported |
| 429 | * pixel config or because no render target is currently set and NULL was passed for |
| 430 | * target. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 431 | */ |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 432 | bool readRenderTargetPixels(GrRenderTarget* target, |
| 433 | int left, int top, int width, int height, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 434 | GrPixelConfig config, void* buffer, |
| 435 | size_t rowBytes = 0, |
| 436 | uint32_t pixelOpsFlags = 0); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 437 | |
| 438 | /** |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 439 | * Writes a rectangle of pixels to a surface. |
| 440 | * @param surface the surface to write to. |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 441 | * @param left left edge of the rectangle to write (inclusive) |
| 442 | * @param top top edge of the rectangle to write (inclusive) |
| 443 | * @param width width of rectangle to write in pixels. |
| 444 | * @param height height of rectangle to write in pixels. |
| 445 | * @param config the pixel config of the source buffer |
| 446 | * @param buffer memory to read pixels from |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 447 | * @param rowBytes number of bytes between consecutive rows. Zero |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 448 | * means rows are tightly packed. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 449 | * @param pixelOpsFlags see PixelOpsFlags enum above. |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 450 | * @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] | 451 | * unsupported combination of surface and src configs. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 452 | */ |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 453 | bool writeSurfacePixels(GrSurface* surface, |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 454 | int left, int top, int width, int height, |
| 455 | GrPixelConfig config, const void* buffer, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 456 | size_t rowBytes, |
| 457 | uint32_t pixelOpsFlags = 0); |
| 458 | |
senorblanco@chromium.org | 027de5f | 2011-07-08 18:03:33 +0000 | [diff] [blame] | 459 | /** |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 460 | * Copies a rectangle of texels from src to dst. |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 461 | * bounds. |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 462 | * @param dst the surface to copy to. |
| 463 | * @param src the surface to copy from. |
| 464 | * @param srcRect the rectangle of the src that should be copied. |
| 465 | * @param dstPoint the translation applied when writing the srcRect's pixels to the dst. |
| 466 | * @param pixelOpsFlags see PixelOpsFlags enum above. (kUnpremul_PixelOpsFlag is not allowed). |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 467 | */ |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 468 | void copySurface(GrSurface* dst, |
| 469 | GrSurface* src, |
| 470 | const SkIRect& srcRect, |
| 471 | const SkIPoint& dstPoint, |
| 472 | uint32_t pixelOpsFlags = 0); |
| 473 | |
| 474 | /** Helper that copies the whole surface but fails when the two surfaces are not identically |
| 475 | sized. */ |
| 476 | bool copySurface(GrSurface* dst, GrSurface* src) { |
| 477 | if (NULL == dst || NULL == src || dst->width() != src->width() || |
| 478 | dst->height() != src->height()) { |
| 479 | return false; |
| 480 | } |
| 481 | this->copySurface(dst, src, SkIRect::MakeWH(dst->width(), dst->height()), |
| 482 | SkIPoint::Make(0,0)); |
| 483 | return true; |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * After this returns any pending writes to the surface will have been issued to the backend 3D API. |
| 488 | */ |
| 489 | void flushSurfaceWrites(GrSurface* surface); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 490 | |
| 491 | /** |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 492 | * Equivalent to flushSurfaceWrites but also performs MSAA resolve if necessary. This call is |
| 493 | * used to make the surface contents available to be read in the backend 3D API, usually for a |
| 494 | * compositing step external to Skia. |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 495 | * |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 496 | * It is not necessary to call this before reading the render target via Skia/GrContext. |
| 497 | * GrContext will detect when it must perform a resolve before reading pixels back from the |
| 498 | * surface or using it as a texture. |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 499 | */ |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 500 | void prepareSurfaceForExternalRead(GrSurface*); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 501 | |
| 502 | /** |
| 503 | * Provides a perfomance hint that the render target's contents are allowed |
| 504 | * to become undefined. |
| 505 | */ |
| 506 | void discardRenderTarget(GrRenderTarget*); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 507 | |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 508 | /** |
| 509 | * An ID associated with this context, guaranteed to be unique. |
| 510 | */ |
| 511 | uint32_t uniqueID() { return fUniqueID; } |
| 512 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 513 | /////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 514 | // Functions intended for internal use only. |
| 515 | GrGpu* getGpu() { return fGpu; } |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 516 | const GrGpu* getGpu() const { return fGpu; } |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 517 | GrBatchFontCache* getBatchFontCache() { return fBatchFontCache; } |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 518 | GrLayerCache* getLayerCache() { return fLayerCache.get(); } |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 519 | GrTextBlobCache* getTextBlobCache() { return fTextBlobCache; } |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 520 | GrDrawTarget* getTextTarget(); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 521 | GrAARectRenderer* getAARectRenderer() { return fAARectRenderer; } |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 522 | GrResourceProvider* resourceProvider() { return fResourceProvider; } |
| 523 | const GrResourceProvider* resourceProvider() const { return fResourceProvider; } |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 524 | GrResourceCache* getResourceCache() { return fResourceCache; } |
bsalomon@google.com | 9923c2b | 2012-06-06 18:21:18 +0000 | [diff] [blame] | 525 | |
commit-bot@chromium.org | 78a1078 | 2013-08-21 19:27:48 +0000 | [diff] [blame] | 526 | // Called by tests that draw directly to the context via GrDrawTarget |
| 527 | void getTestTarget(GrTestTarget*); |
| 528 | |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 529 | void addGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 530 | void removeGpuTraceMarker(const GrGpuTraceMarker* marker); |
| 531 | |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 532 | GrPathRenderer* getPathRenderer( |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 533 | const GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 534 | const GrPipelineBuilder*, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 535 | const SkMatrix& viewMatrix, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 536 | const SkPath& path, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 537 | const GrStrokeInfo& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 538 | bool allowSW, |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 539 | GrPathRendererChain::DrawType drawType = GrPathRendererChain::kColor_DrawType, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 540 | GrPathRendererChain::StencilSupport* stencilSupport = NULL); |
robertphillips@google.com | 2c75681 | 2012-05-22 20:28:23 +0000 | [diff] [blame] | 541 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 542 | /** Prints cache stats to the string if GR_CACHE_STATS == 1. */ |
| 543 | void dumpCacheStats(SkString*) const; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 544 | void printCacheStats() const; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 545 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 546 | /** Prints GPU stats to the string if GR_GPU_STATS == 1. */ |
| 547 | void dumpGpuStats(SkString*) const; |
| 548 | void printGpuStats() const; |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 549 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 550 | private: |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 551 | GrGpu* fGpu; |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 552 | GrResourceCache* fResourceCache; |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 553 | // this union exists because the inheritance of GrTextureProvider->GrResourceProvider |
| 554 | // is in a private header. |
| 555 | union { |
| 556 | GrResourceProvider* fResourceProvider; |
| 557 | GrTextureProvider* fTextureProvider; |
| 558 | }; |
| 559 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 560 | GrBatchFontCache* fBatchFontCache; |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 561 | SkAutoTDelete<GrLayerCache> fLayerCache; |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 562 | SkAutoTDelete<GrTextBlobCache> fTextBlobCache; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 563 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 564 | GrPathRendererChain* fPathRendererChain; |
| 565 | GrSoftwarePathRenderer* fSoftwarePathRenderer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 566 | |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 567 | GrDrawTarget* fDrawBuffer; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 568 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 569 | // Set by OverbudgetCB() to request that GrContext flush before exiting a draw. |
| 570 | bool fFlushToReduceCacheSize; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 571 | GrAARectRenderer* fAARectRenderer; |
| 572 | GrOvalRenderer* fOvalRenderer; |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 573 | |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 574 | bool fDidTestPMConversions; |
| 575 | int fPMToUPMConversion; |
| 576 | int fUPMToPMConversion; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 577 | |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 578 | struct CleanUpData { |
| 579 | PFCleanUpFunc fFunc; |
| 580 | void* fInfo; |
| 581 | }; |
| 582 | |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 583 | SkTDArray<CleanUpData> fCleanUpData; |
| 584 | |
skia.committer@gmail.com | 956b310 | 2013-07-26 07:00:58 +0000 | [diff] [blame] | 585 | int fMaxTextureSizeOverride; |
robertphillips@google.com | cdb426d | 2012-09-24 19:33:59 +0000 | [diff] [blame] | 586 | |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 587 | const uint32_t fUniqueID; |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 588 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame^] | 589 | GrContext(); // init must be called after the constructor. |
| 590 | bool init(GrBackend, GrBackendContext, const GrContextOptions& options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 591 | void initMockContext(); |
| 592 | void initCommon(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 593 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 594 | class AutoCheckFlush; |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 595 | // Sets the paint and returns the target to draw into. |
| 596 | GrDrawTarget* prepareToDraw(GrPipelineBuilder*, |
| 597 | GrRenderTarget* rt, |
| 598 | const GrClip&, |
| 599 | const GrPaint* paint, |
joshualitt | 25d9c15 | 2015-02-18 12:29:52 -0800 | [diff] [blame] | 600 | const AutoCheckFlush*); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 601 | |
joshualitt | 570d2f8 | 2015-02-25 13:19:48 -0800 | [diff] [blame] | 602 | // A simpler version of the above which just returns the draw target. Clip is *NOT* set |
| 603 | GrDrawTarget* prepareToDraw(); |
| 604 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 605 | void internalDrawPath(GrDrawTarget*, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 606 | GrPipelineBuilder*, |
joshualitt | 5531d51 | 2014-12-17 15:50:11 -0800 | [diff] [blame] | 607 | const SkMatrix& viewMatrix, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 608 | GrColor, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 609 | bool useAA, |
| 610 | const SkPath&, |
| 611 | const GrStrokeInfo&); |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 612 | |
skia.committer@gmail.com | cdcb2ce | 2013-01-29 07:05:52 +0000 | [diff] [blame] | 613 | /** |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 614 | * Creates a new text rendering context that is optimal for the |
| 615 | * render target and the context. Caller assumes the ownership |
| 616 | * of the returned object. The returned object must be deleted |
| 617 | * before the context is destroyed. |
| 618 | * TODO we can possibly bury this behind context, but we need to be able to use the |
| 619 | * drawText_asPaths logic on SkGpuDevice |
| 620 | */ |
| 621 | GrTextContext* createTextContext(GrRenderTarget*, |
| 622 | SkGpuDevice*, |
| 623 | const SkDeviceProperties&, |
| 624 | bool enableDistanceFieldFonts); |
| 625 | |
| 626 | |
| 627 | /** |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 628 | * These functions create premul <-> unpremul effects if it is possible to generate a pair |
| 629 | * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they |
| 630 | * return NULL. |
| 631 | */ |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 632 | const GrFragmentProcessor* createPMToUPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&); |
| 633 | const GrFragmentProcessor* createUPMToPMEffect(GrTexture*, bool swapRAndB, const SkMatrix&); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 634 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 635 | /** |
| 636 | * This callback allows the resource cache to callback into the GrContext |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 637 | * when the cache is still over budget after a purge. |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 638 | */ |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 639 | static void OverBudgetCB(void* data); |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 640 | |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 641 | /** |
| 642 | * A callback similar to the above for use by the TextBlobCache |
| 643 | * TODO move textblob draw calls below context so we can use the call above. |
| 644 | */ |
| 645 | static void TextBlobCacheOverBudgetCB(void* data); |
| 646 | |
joshualitt | 6e8cd96 | 2015-03-20 10:30:14 -0700 | [diff] [blame] | 647 | // TODO see note on createTextContext |
| 648 | friend class SkGpuDevice; |
| 649 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 650 | typedef SkRefCnt INHERITED; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 651 | }; |
| 652 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 653 | #endif |