epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 9 | |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 10 | #include "GrContext.h" |
| 11 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 12 | #include "effects/GrConfigConversionEffect.h" |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 13 | #include "effects/GrDashingEffect.h" |
| 14 | #include "effects/GrSingleTextureEffect.h" |
bsalomon@google.com | b505a12 | 2012-05-31 18:40:36 +0000 | [diff] [blame] | 15 | |
jvanverth@google.com | bfe2b9d | 2013-09-06 16:57:29 +0000 | [diff] [blame] | 16 | #include "GrAARectRenderer.h" |
tomhudson@google.com | 278cbb4 | 2011-06-30 19:37:01 +0000 | [diff] [blame] | 17 | #include "GrBufferAllocPool.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 18 | #include "GrGpu.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 19 | #include "GrDistanceFieldTextContext.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 20 | #include "GrDrawTargetCaps.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 21 | #include "GrIndexBuffer.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 22 | #include "GrInOrderDrawBuffer.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 23 | #include "GrLayerCache.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 24 | #include "GrOvalRenderer.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 25 | #include "GrPathRenderer.h" |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 26 | #include "GrPathUtils.h" |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 27 | #include "GrResourceCache.h" |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 28 | #include "GrResourceCache2.h" |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 29 | #include "GrSoftwarePathRenderer.h" |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 30 | #include "GrStencilBuffer.h" |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 31 | #include "GrStencilAndCoverTextContext.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 32 | #include "GrStrokeInfo.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 33 | #include "GrSurfacePriv.h" |
tomhudson@google.com | 278cbb4 | 2011-06-30 19:37:01 +0000 | [diff] [blame] | 34 | #include "GrTextStrike.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 35 | #include "GrTexturePriv.h" |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 36 | #include "GrTraceMarker.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 37 | #include "GrTracing.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 38 | #include "SkDashPathPriv.h" |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 39 | #include "SkGr.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 40 | #include "SkRTConf.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 41 | #include "SkRRect.h" |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 42 | #include "SkStrokeRec.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 43 | #include "SkTLazy.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 44 | #include "SkTLS.h" |
commit-bot@chromium.org | 933e65d | 2014-03-20 20:00:24 +0000 | [diff] [blame] | 45 | #include "SkTraceEvent.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 46 | |
bsalomon@google.com | 82b0ec6 | 2013-02-07 21:02:36 +0000 | [diff] [blame] | 47 | // It can be useful to set this to false to test whether a bug is caused by using the |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 48 | // InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffer, or to make |
bsalomon@google.com | 82b0ec6 | 2013-02-07 21:02:36 +0000 | [diff] [blame] | 49 | // debugging simpler. |
bsalomon@google.com | e932c98 | 2013-09-10 19:47:01 +0000 | [diff] [blame] | 50 | SK_CONF_DECLARE(bool, c_Defer, "gpu.deferContext", true, |
jvanverth@google.com | 65eb4d5 | 2013-03-19 18:51:02 +0000 | [diff] [blame] | 51 | "Defers rendering in GrContext via GrInOrderDrawBuffer."); |
bsalomon@google.com | 82b0ec6 | 2013-02-07 21:02:36 +0000 | [diff] [blame] | 52 | |
| 53 | #define BUFFERED_DRAW (c_Defer ? kYes_BufferedDraw : kNo_BufferedDraw) |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 54 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 55 | #ifdef SK_DEBUG |
reed@google.com | 4b2d3f3 | 2012-05-15 18:05:50 +0000 | [diff] [blame] | 56 | // change this to a 1 to see notifications when partial coverage fails |
| 57 | #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 58 | #else |
| 59 | #define GR_DEBUG_PARTIAL_COVERAGE_CHECK 0 |
| 60 | #endif |
| 61 | |
robertphillips@google.com | 4e5559a | 2013-10-30 17:04:16 +0000 | [diff] [blame] | 62 | static const size_t MAX_RESOURCE_CACHE_COUNT = GR_DEFAULT_RESOURCE_CACHE_COUNT_LIMIT; |
| 63 | static const size_t MAX_RESOURCE_CACHE_BYTES = GR_DEFAULT_RESOURCE_CACHE_MB_LIMIT * 1024 * 1024; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 64 | |
bsalomon@google.com | 6036149 | 2012-03-15 17:47:06 +0000 | [diff] [blame] | 65 | static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 66 | static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4; |
| 67 | |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 68 | static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11; |
| 69 | static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 70 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 71 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 72 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 73 | GrTexture* GrAutoScratchTexture::detach() { |
| 74 | if (NULL == fTexture) { |
| 75 | return NULL; |
| 76 | } |
| 77 | GrTexture* texture = fTexture; |
| 78 | fTexture = NULL; |
| 79 | |
| 80 | // This GrAutoScratchTexture has a ref from lockAndRefScratchTexture, which we give up now. |
| 81 | // The cache also has a ref which we are lending to the caller of detach(). When the caller |
| 82 | // lets go of the ref and the ref count goes to 0 internal_dispose will see this flag is |
| 83 | // set and re-ref the texture, thereby restoring the cache's ref. |
| 84 | SkASSERT(!texture->unique()); |
| 85 | texture->texturePriv().setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); |
| 86 | texture->unref(); |
| 87 | SkASSERT(texture->getCacheEntry()); |
| 88 | |
| 89 | return texture; |
| 90 | } |
| 91 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 92 | // Glorified typedef to avoid including GrDrawState.h in GrContext.h |
| 93 | class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {}; |
| 94 | |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 95 | class GrContext::AutoCheckFlush { |
| 96 | public: |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 97 | AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(context); } |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 98 | |
| 99 | ~AutoCheckFlush() { |
| 100 | if (fContext->fFlushToReduceCacheSize) { |
| 101 | fContext->flush(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | private: |
| 106 | GrContext* fContext; |
| 107 | }; |
| 108 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 109 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
| 110 | const Options* opts) { |
| 111 | GrContext* context; |
| 112 | if (NULL == opts) { |
| 113 | context = SkNEW_ARGS(GrContext, (Options())); |
| 114 | } else { |
| 115 | context = SkNEW_ARGS(GrContext, (*opts)); |
| 116 | } |
| 117 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 118 | if (context->init(backend, backendContext)) { |
| 119 | return context; |
| 120 | } else { |
| 121 | context->unref(); |
| 122 | return NULL; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 123 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 124 | } |
| 125 | |
krajcevski | 9c6d4d7 | 2014-08-12 07:26:25 -0700 | [diff] [blame] | 126 | GrContext::GrContext(const Options& opts) : fOptions(opts) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 127 | fDrawState = NULL; |
| 128 | fGpu = NULL; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 129 | fClip = NULL; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 130 | fPathRendererChain = NULL; |
| 131 | fSoftwarePathRenderer = NULL; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 132 | fResourceCache = NULL; |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 133 | fResourceCache2 = NULL; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 134 | fFontCache = NULL; |
| 135 | fDrawBuffer = NULL; |
| 136 | fDrawBufferVBAllocPool = NULL; |
| 137 | fDrawBufferIBAllocPool = NULL; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 138 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 139 | fAARectRenderer = NULL; |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 140 | fOvalRenderer = NULL; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 141 | fViewMatrix.reset(); |
robertphillips@google.com | 44a91dc | 2013-07-25 15:32:06 +0000 | [diff] [blame] | 142 | fMaxTextureSizeOverride = 1 << 20; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | bool GrContext::init(GrBackend backend, GrBackendContext backendContext) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 146 | SkASSERT(NULL == fGpu); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 147 | |
| 148 | fGpu = GrGpu::Create(backend, backendContext, this); |
| 149 | if (NULL == fGpu) { |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | fDrawState = SkNEW(GrDrawState); |
| 154 | fGpu->setDrawState(fDrawState); |
| 155 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 156 | fResourceCache = SkNEW_ARGS(GrResourceCache, (MAX_RESOURCE_CACHE_COUNT, |
| 157 | MAX_RESOURCE_CACHE_BYTES)); |
| 158 | fResourceCache->setOverbudgetCallback(OverbudgetCB, this); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 159 | fResourceCache2 = SkNEW(GrResourceCache2); |
commit-bot@chromium.org | 1836d33 | 2013-07-16 22:55:03 +0000 | [diff] [blame] | 160 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 161 | fFontCache = SkNEW_ARGS(GrFontCache, (fGpu)); |
| 162 | |
robertphillips | 4ec84da | 2014-06-24 13:10:43 -0700 | [diff] [blame] | 163 | fLayerCache.reset(SkNEW_ARGS(GrLayerCache, (this))); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 164 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 165 | fLastDrawWasBuffered = kNo_BufferedDraw; |
| 166 | |
| 167 | fAARectRenderer = SkNEW(GrAARectRenderer); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 168 | fOvalRenderer = SkNEW(GrOvalRenderer); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 169 | |
| 170 | fDidTestPMConversions = false; |
| 171 | |
| 172 | this->setupDrawBuffer(); |
| 173 | |
| 174 | return true; |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 175 | } |
| 176 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 177 | GrContext::~GrContext() { |
bsalomon@google.com | 733c062 | 2013-04-24 17:59:32 +0000 | [diff] [blame] | 178 | if (NULL == fGpu) { |
| 179 | return; |
| 180 | } |
| 181 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 182 | this->flush(); |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 183 | |
robertphillips@google.com | 950b1b0 | 2013-10-21 17:37:28 +0000 | [diff] [blame] | 184 | for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 185 | (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 186 | } |
| 187 | |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 188 | delete fResourceCache2; |
| 189 | fResourceCache2 = NULL; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 190 | delete fResourceCache; |
| 191 | fResourceCache = NULL; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 192 | delete fFontCache; |
| 193 | delete fDrawBuffer; |
| 194 | delete fDrawBufferVBAllocPool; |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 195 | delete fDrawBufferIBAllocPool; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 196 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 197 | fAARectRenderer->unref(); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 198 | fOvalRenderer->unref(); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 199 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 200 | fGpu->unref(); |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 201 | SkSafeUnref(fPathRendererChain); |
| 202 | SkSafeUnref(fSoftwarePathRenderer); |
bsalomon@google.com | 10e04bf | 2012-03-30 14:35:04 +0000 | [diff] [blame] | 203 | fDrawState->unref(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 204 | } |
| 205 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 206 | void GrContext::abandonContext() { |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 207 | // abandon first to so destructors |
| 208 | // don't try to free the resources in the API. |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 209 | fResourceCache2->abandonAll(); |
| 210 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 211 | fGpu->contextAbandoned(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 212 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 213 | // a path renderer may be holding onto resources that |
| 214 | // are now unusable |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 215 | SkSafeSetNull(fPathRendererChain); |
| 216 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 217 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 218 | delete fDrawBuffer; |
| 219 | fDrawBuffer = NULL; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 220 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 221 | delete fDrawBufferVBAllocPool; |
| 222 | fDrawBufferVBAllocPool = NULL; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 223 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 224 | delete fDrawBufferIBAllocPool; |
| 225 | fDrawBufferIBAllocPool = NULL; |
| 226 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 227 | fAARectRenderer->reset(); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 228 | fOvalRenderer->reset(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 229 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 230 | fResourceCache->purgeAllUnlocked(); |
commit-bot@chromium.org | 5c8ee25 | 2013-11-01 15:23:44 +0000 | [diff] [blame] | 231 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 232 | fFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 233 | fLayerCache->freeAll(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 234 | } |
| 235 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 236 | void GrContext::resetContext(uint32_t state) { |
| 237 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | void GrContext::freeGpuResources() { |
| 241 | this->flush(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 242 | |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 243 | fGpu->purgeResources(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 244 | if (fDrawBuffer) { |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 245 | fDrawBuffer->purgeResources(); |
| 246 | } |
robertphillips@google.com | ff17584 | 2012-05-14 19:31:39 +0000 | [diff] [blame] | 247 | |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 248 | fAARectRenderer->reset(); |
commit-bot@chromium.org | ef284a8 | 2013-07-11 22:29:29 +0000 | [diff] [blame] | 249 | fOvalRenderer->reset(); |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 250 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 251 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 252 | fFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 253 | fLayerCache->freeAll(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 254 | // a path renderer may be holding onto resources |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 255 | SkSafeSetNull(fPathRendererChain); |
| 256 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 257 | } |
| 258 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 259 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 260 | if (resourceCount) { |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 261 | *resourceCount = fResourceCache->getCachedResourceCount(); |
| 262 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 263 | if (resourceBytes) { |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 264 | *resourceBytes = fResourceCache->getCachedResourceBytes(); |
| 265 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 266 | } |
| 267 | |
kkinnunen | c6cb56f | 2014-06-24 00:12:27 -0700 | [diff] [blame] | 268 | GrTextContext* GrContext::createTextContext(GrRenderTarget* renderTarget, |
| 269 | const SkDeviceProperties& |
| 270 | leakyProperties, |
| 271 | bool enableDistanceFieldFonts) { |
| 272 | if (fGpu->caps()->pathRenderingSupport()) { |
| 273 | if (renderTarget->getStencilBuffer() && renderTarget->isMultisampled()) { |
| 274 | return SkNEW_ARGS(GrStencilAndCoverTextContext, (this, leakyProperties)); |
| 275 | } |
| 276 | } |
| 277 | return SkNEW_ARGS(GrDistanceFieldTextContext, (this, leakyProperties, |
| 278 | enableDistanceFieldFonts)); |
| 279 | } |
| 280 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 281 | //////////////////////////////////////////////////////////////////////////////// |
| 282 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 283 | GrTexture* GrContext::findAndRefTexture(const GrTextureDesc& desc, |
| 284 | const GrCacheID& cacheID, |
| 285 | const GrTextureParams* params) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 286 | GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID); |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 287 | GrGpuResource* resource = fResourceCache->find(resourceKey); |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 288 | SkSafeRef(resource); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 289 | return static_cast<GrTexture*>(resource); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 290 | } |
| 291 | |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 292 | bool GrContext::isTextureInCache(const GrTextureDesc& desc, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 293 | const GrCacheID& cacheID, |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 294 | const GrTextureParams* params) const { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 295 | GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 296 | return fResourceCache->hasKey(resourceKey); |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 297 | } |
| 298 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 299 | void GrContext::addStencilBuffer(GrStencilBuffer* sb) { |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 300 | ASSERT_OWNED_RESOURCE(sb); |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 301 | |
| 302 | GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(sb->width(), |
| 303 | sb->height(), |
| 304 | sb->numSamples()); |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 305 | fResourceCache->addResource(resourceKey, sb); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 306 | } |
| 307 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 308 | GrStencilBuffer* GrContext::findStencilBuffer(int width, int height, |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 309 | int sampleCnt) { |
robertphillips@google.com | 46a8600 | 2012-08-08 10:42:44 +0000 | [diff] [blame] | 310 | GrResourceKey resourceKey = GrStencilBuffer::ComputeKey(width, |
| 311 | height, |
| 312 | sampleCnt); |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 313 | GrGpuResource* resource = fResourceCache->find(resourceKey); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 314 | return static_cast<GrStencilBuffer*>(resource); |
bsalomon@google.com | 558a75b | 2011-08-08 17:01:14 +0000 | [diff] [blame] | 315 | } |
| 316 | |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 317 | static void stretch_image(void* dst, |
| 318 | int dstW, |
| 319 | int dstH, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 320 | const void* src, |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 321 | int srcW, |
| 322 | int srcH, |
| 323 | size_t bpp) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 324 | SkFixed dx = (srcW << 16) / dstW; |
| 325 | SkFixed dy = (srcH << 16) / dstH; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 326 | |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 327 | SkFixed y = dy >> 1; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 328 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 329 | size_t dstXLimit = dstW*bpp; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 330 | for (int j = 0; j < dstH; ++j) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 331 | SkFixed x = dx >> 1; |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 332 | const uint8_t* srcRow = reinterpret_cast<const uint8_t *>(src) + (y>>16)*srcW*bpp; |
| 333 | uint8_t* dstRow = reinterpret_cast<uint8_t *>(dst) + j*dstW*bpp; |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 334 | for (size_t i = 0; i < dstXLimit; i += bpp) { |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 335 | memcpy(dstRow + i, srcRow + (x>>16)*bpp, bpp); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 336 | x += dx; |
| 337 | } |
| 338 | y += dy; |
| 339 | } |
| 340 | } |
| 341 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 342 | namespace { |
| 343 | |
| 344 | // position + local coordinate |
| 345 | extern const GrVertexAttrib gVertexAttribs[] = { |
| 346 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 347 | {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBinding} |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | }; |
| 351 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 352 | // The desired texture is NPOT and tiled but that isn't supported by |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 353 | // the current hardware. Resize the texture to be a POT |
| 354 | GrTexture* GrContext::createResizedTexture(const GrTextureDesc& desc, |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 355 | const GrCacheID& cacheID, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 356 | const void* srcData, |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 357 | size_t rowBytes, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 358 | bool filter) { |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 359 | SkAutoTUnref<GrTexture> clampedTexture(this->findAndRefTexture(desc, cacheID, NULL)); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 360 | if (NULL == clampedTexture) { |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 361 | clampedTexture.reset(this->createTexture(NULL, desc, cacheID, srcData, rowBytes)); |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 362 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 363 | if (NULL == clampedTexture) { |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 364 | return NULL; |
| 365 | } |
| 366 | } |
robertphillips@google.com | 0d25eef | 2012-09-11 21:25:51 +0000 | [diff] [blame] | 367 | |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 368 | GrTextureDesc rtDesc = desc; |
| 369 | rtDesc.fFlags = rtDesc.fFlags | |
| 370 | kRenderTarget_GrTextureFlagBit | |
| 371 | kNoStencil_GrTextureFlagBit; |
commit-bot@chromium.org | 5898dce | 2013-09-18 18:52:16 +0000 | [diff] [blame] | 372 | rtDesc.fWidth = GrNextPow2(desc.fWidth); |
| 373 | rtDesc.fHeight = GrNextPow2(desc.fHeight); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 374 | |
| 375 | GrTexture* texture = fGpu->createTexture(rtDesc, NULL, 0); |
| 376 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 377 | if (texture) { |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 378 | GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit); |
| 379 | GrDrawState* drawState = fGpu->drawState(); |
| 380 | drawState->setRenderTarget(texture->asRenderTarget()); |
| 381 | |
| 382 | // if filtering is not desired then we want to ensure all |
| 383 | // texels in the resampled image are copies of texels from |
| 384 | // the original. |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 385 | GrTextureParams params(SkShader::kClamp_TileMode, filter ? GrTextureParams::kBilerp_FilterMode : |
| 386 | GrTextureParams::kNone_FilterMode); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 387 | drawState->addColorTextureProcessor(clampedTexture, SkMatrix::I(), params); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 388 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 389 | drawState->setVertexAttribs<gVertexAttribs>(SK_ARRAY_COUNT(gVertexAttribs), |
| 390 | 2 * sizeof(SkPoint)); |
jvanverth@google.com | 054ae99 | 2013-04-01 20:06:51 +0000 | [diff] [blame] | 391 | |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 392 | GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 393 | |
| 394 | if (arg.succeeded()) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 395 | SkPoint* verts = (SkPoint*) arg.vertices(); |
| 396 | verts[0].setIRectFan(0, 0, texture->width(), texture->height(), 2 * sizeof(SkPoint)); |
| 397 | verts[1].setIRectFan(0, 0, 1, 1, 2 * sizeof(SkPoint)); |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 398 | fGpu->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 399 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 400 | } else { |
| 401 | // TODO: Our CPU stretch doesn't filter. But we create separate |
bsalomon@google.com | 08283af | 2012-10-26 13:01:20 +0000 | [diff] [blame] | 402 | // stretched textures when the texture params is either filtered or |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 403 | // not. Either implement filtered stretch blit on CPU or just create |
| 404 | // one when FBO case fails. |
| 405 | |
| 406 | rtDesc.fFlags = kNone_GrTextureFlags; |
| 407 | // no longer need to clamp at min RT size. |
| 408 | rtDesc.fWidth = GrNextPow2(desc.fWidth); |
| 409 | rtDesc.fHeight = GrNextPow2(desc.fHeight); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 410 | |
| 411 | // We shouldn't be resizing a compressed texture. |
| 412 | SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); |
| 413 | |
robertphillips@google.com | 8b16931 | 2013-10-15 17:47:36 +0000 | [diff] [blame] | 414 | size_t bpp = GrBytesPerPixel(desc.fConfig); |
george | b62508b | 2014-08-12 18:00:47 -0700 | [diff] [blame] | 415 | GrAutoMalloc<128*128*4> stretchedPixels(bpp * rtDesc.fWidth * rtDesc.fHeight); |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 416 | stretch_image(stretchedPixels.get(), rtDesc.fWidth, rtDesc.fHeight, |
| 417 | srcData, desc.fWidth, desc.fHeight, bpp); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 418 | |
| 419 | size_t stretchedRowBytes = rtDesc.fWidth * bpp; |
| 420 | |
commit-bot@chromium.org | b0ce4b6 | 2014-05-16 17:22:51 +0000 | [diff] [blame] | 421 | texture = fGpu->createTexture(rtDesc, stretchedPixels.get(), stretchedRowBytes); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 422 | SkASSERT(texture); |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 423 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 424 | |
| 425 | return texture; |
| 426 | } |
| 427 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 428 | GrTexture* GrContext::createTexture(const GrTextureParams* params, |
| 429 | const GrTextureDesc& desc, |
| 430 | const GrCacheID& cacheID, |
commit-bot@chromium.org | f9bd04f | 2014-05-29 19:26:48 +0000 | [diff] [blame] | 431 | const void* srcData, |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 432 | size_t rowBytes, |
| 433 | GrResourceKey* cacheKey) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 434 | GrResourceKey resourceKey = GrTexturePriv::ComputeKey(fGpu, params, desc, cacheID); |
robertphillips@google.com | a1e5795 | 2012-06-04 20:05:28 +0000 | [diff] [blame] | 435 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 436 | GrTexture* texture; |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 437 | if (GrTexturePriv::NeedsResizing(resourceKey)) { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 438 | // We do not know how to resize compressed textures. |
| 439 | SkASSERT(!GrPixelConfigIsCompressed(desc.fConfig)); |
| 440 | |
bsalomon@google.com | 95ed55a | 2013-01-24 14:46:47 +0000 | [diff] [blame] | 441 | texture = this->createResizedTexture(desc, cacheID, |
| 442 | srcData, rowBytes, |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 443 | GrTexturePriv::NeedsBilerp(resourceKey)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 444 | } else { |
krajcevski | 9c0e629 | 2014-06-02 07:38:14 -0700 | [diff] [blame] | 445 | texture = fGpu->createTexture(desc, srcData, rowBytes); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 446 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 447 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 448 | if (texture) { |
robertphillips@google.com | 1622a6d | 2013-07-18 17:11:45 +0000 | [diff] [blame] | 449 | // Adding a resource could put us overbudget. Try to free up the |
| 450 | // necessary space before adding it. |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 451 | fResourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
| 452 | fResourceCache->addResource(resourceKey, texture); |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 453 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 454 | if (cacheKey) { |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 455 | *cacheKey = resourceKey; |
| 456 | } |
robertphillips@google.com | 3319f33 | 2012-08-13 18:00:36 +0000 | [diff] [blame] | 457 | } |
| 458 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 459 | return texture; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 460 | } |
| 461 | |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 462 | static GrTexture* create_scratch_texture(GrGpu* gpu, |
| 463 | GrResourceCache* resourceCache, |
| 464 | const GrTextureDesc& desc) { |
| 465 | GrTexture* texture = gpu->createTexture(desc, NULL, 0); |
| 466 | if (texture) { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 467 | GrResourceKey key = GrTexturePriv::ComputeScratchKey(texture->desc()); |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 468 | // Adding a resource could put us overbudget. Try to free up the |
| 469 | // necessary space before adding it. |
| 470 | resourceCache->purgeAsNeeded(1, texture->gpuMemorySize()); |
| 471 | // Make the resource exclusive so future 'find' calls don't return it |
| 472 | resourceCache->addResource(key, texture, GrResourceCache::kHide_OwnershipFlag); |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 473 | } |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 474 | return texture; |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 475 | } |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 476 | |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 477 | GrTexture* GrContext::lockAndRefScratchTexture(const GrTextureDesc& inDesc, ScratchTexMatch match) { |
| 478 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 479 | SkASSERT((inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 480 | !(inDesc.fFlags & kNoStencil_GrTextureFlagBit)); |
| 481 | |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 482 | // Renderable A8 targets are not universally supported (e.g., not on ANGLE) |
| 483 | SkASSERT(this->isConfigRenderable(kAlpha_8_GrPixelConfig, inDesc.fSampleCnt > 0) || |
| 484 | !(inDesc.fFlags & kRenderTarget_GrTextureFlagBit) || |
| 485 | (inDesc.fConfig != kAlpha_8_GrPixelConfig)); |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 486 | |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 487 | if (!fGpu->caps()->reuseScratchTextures() && |
| 488 | !(inDesc.fFlags & kRenderTarget_GrTextureFlagBit)) { |
| 489 | // If we're never recycling this texture we can always make it the right size |
| 490 | return create_scratch_texture(fGpu, fResourceCache, inDesc); |
| 491 | } |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 492 | |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 493 | GrTextureDesc desc = inDesc; |
| 494 | |
| 495 | if (kApprox_ScratchTexMatch == match) { |
| 496 | // bin by pow2 with a reasonable min |
| 497 | static const int MIN_SIZE = 16; |
| 498 | desc.fWidth = SkTMax(MIN_SIZE, GrNextPow2(desc.fWidth)); |
| 499 | desc.fHeight = SkTMax(MIN_SIZE, GrNextPow2(desc.fHeight)); |
| 500 | } |
| 501 | |
| 502 | GrGpuResource* resource = NULL; |
| 503 | int origWidth = desc.fWidth; |
| 504 | int origHeight = desc.fHeight; |
| 505 | |
| 506 | do { |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 507 | GrResourceKey key = GrTexturePriv::ComputeScratchKey(desc); |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 508 | // Ensure we have exclusive access to the texture so future 'find' calls don't return it |
| 509 | resource = fResourceCache->find(key, GrResourceCache::kHide_OwnershipFlag); |
| 510 | if (resource) { |
| 511 | resource->ref(); |
| 512 | break; |
| 513 | } |
| 514 | if (kExact_ScratchTexMatch == match) { |
| 515 | break; |
| 516 | } |
| 517 | // We had a cache miss and we are in approx mode, relax the fit of the flags. |
| 518 | |
| 519 | // We no longer try to reuse textures that were previously used as render targets in |
| 520 | // situations where no RT is needed; doing otherwise can confuse the video driver and |
| 521 | // cause significant performance problems in some cases. |
| 522 | if (desc.fFlags & kNoStencil_GrTextureFlagBit) { |
| 523 | desc.fFlags = desc.fFlags & ~kNoStencil_GrTextureFlagBit; |
| 524 | } else { |
| 525 | break; |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 526 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 527 | |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 528 | } while (true); |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 529 | |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 530 | if (NULL == resource) { |
| 531 | desc.fFlags = inDesc.fFlags; |
| 532 | desc.fWidth = origWidth; |
| 533 | desc.fHeight = origHeight; |
| 534 | resource = create_scratch_texture(fGpu, fResourceCache, desc); |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 535 | } |
| 536 | |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 537 | return static_cast<GrTexture*>(resource); |
bsalomon@google.com | b5b3168 | 2011-06-16 18:05:35 +0000 | [diff] [blame] | 538 | } |
| 539 | |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 540 | void GrContext::addExistingTextureToCache(GrTexture* texture) { |
| 541 | |
| 542 | if (NULL == texture) { |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | // This texture should already have a cache entry since it was once |
| 547 | // attached |
| 548 | SkASSERT(texture->getCacheEntry()); |
| 549 | |
| 550 | // Conceptually, the cache entry is going to assume responsibility |
| 551 | // for the creation ref. Assert refcnt == 1. |
| 552 | // Except that this also gets called when the texture is prematurely |
| 553 | // abandoned. In that case the ref count may be > 1. |
| 554 | // SkASSERT(texture->unique()); |
| 555 | |
| 556 | if (fGpu->caps()->reuseScratchTextures() || texture->asRenderTarget()) { |
| 557 | // Since this texture came from an AutoScratchTexture it should |
| 558 | // still be in the exclusive pile. Recycle it. |
| 559 | fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 560 | this->purgeCache(); |
| 561 | } else { |
| 562 | // When we aren't reusing textures we know this scratch texture |
| 563 | // will never be reused and would be just wasting time in the cache |
| 564 | fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 565 | fResourceCache->deleteResource(texture->getCacheEntry()); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | void GrContext::unlockScratchTexture(GrTexture* texture) { |
| 570 | if (texture->wasDestroyed()) { |
| 571 | if (texture->getCacheEntry()->key().isScratch()) { |
| 572 | // This texture was detached from the cache but the cache still had a ref to it but |
| 573 | // not a pointer to it. This will unref the texture and delete its resource cache |
| 574 | // entry. |
| 575 | delete texture->getCacheEntry(); |
| 576 | } |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | ASSERT_OWNED_RESOURCE(texture); |
| 581 | SkASSERT(texture->getCacheEntry()); |
| 582 | |
| 583 | // If this is a scratch texture we detached it from the cache |
| 584 | // while it was locked (to avoid two callers simultaneously getting |
| 585 | // the same texture). |
| 586 | if (texture->getCacheEntry()->key().isScratch()) { |
| 587 | if (fGpu->caps()->reuseScratchTextures() || texture->asRenderTarget()) { |
| 588 | fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 589 | this->purgeCache(); |
| 590 | } else if (texture->unique()) { |
| 591 | // Only the cache now knows about this texture. Since we're never |
| 592 | // reusing scratch textures (in this code path) it would just be |
| 593 | // wasting time sitting in the cache. |
| 594 | fResourceCache->makeNonExclusive(texture->getCacheEntry()); |
| 595 | fResourceCache->deleteResource(texture->getCacheEntry()); |
| 596 | } else { |
| 597 | // In this case (there is still a non-cache ref) but we don't really |
| 598 | // want to readd it to the cache (since it will never be reused). |
| 599 | // Instead, give up the cache's ref and leave the decision up to |
| 600 | // addExistingTextureToCache once its ref count reaches 0. For |
| 601 | // this to work we need to leave it in the exclusive list. |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 602 | texture->texturePriv().setFlag((GrTextureFlags) GrTexture::kReturnToCache_FlagBit); |
robertphillips | dbe6074 | 2014-09-30 06:54:17 -0700 | [diff] [blame] | 603 | // Give up the cache's ref to the texture |
| 604 | texture->unref(); |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | void GrContext::purgeCache() { |
| 610 | if (fResourceCache) { |
| 611 | fResourceCache->purgeAsNeeded(); |
| 612 | } |
| 613 | } |
| 614 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 615 | bool GrContext::OverbudgetCB(void* data) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 616 | SkASSERT(data); |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 617 | |
| 618 | GrContext* context = reinterpret_cast<GrContext*>(data); |
| 619 | |
| 620 | // Flush the InOrderDrawBuffer to possibly free up some textures |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 621 | context->fFlushToReduceCacheSize = true; |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 622 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 623 | return true; |
| 624 | } |
| 625 | |
| 626 | |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 627 | GrTexture* GrContext::createUncachedTexture(const GrTextureDesc& descIn, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 628 | void* srcData, |
| 629 | size_t rowBytes) { |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 630 | GrTextureDesc descCopy = descIn; |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 631 | return fGpu->createTexture(descCopy, srcData, rowBytes); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 632 | } |
| 633 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 634 | void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
| 635 | fResourceCache->getLimits(maxTextures, maxTextureBytes); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 636 | } |
| 637 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 638 | void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
| 639 | fResourceCache->setLimits(maxTextures, maxTextureBytes); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 640 | } |
| 641 | |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 642 | int GrContext::getMaxTextureSize() const { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 643 | return SkTMin(fGpu->caps()->maxTextureSize(), fMaxTextureSizeOverride); |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | int GrContext::getMaxRenderTargetSize() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 647 | return fGpu->caps()->maxRenderTargetSize(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 648 | } |
| 649 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 650 | int GrContext::getMaxSampleCount() const { |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 651 | return fGpu->caps()->maxSampleCount(); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 652 | } |
| 653 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 654 | /////////////////////////////////////////////////////////////////////////////// |
| 655 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 656 | GrTexture* GrContext::wrapBackendTexture(const GrBackendTextureDesc& desc) { |
| 657 | return fGpu->wrapBackendTexture(desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 658 | } |
| 659 | |
bsalomon@google.com | 16e3dde | 2012-10-25 18:43:28 +0000 | [diff] [blame] | 660 | GrRenderTarget* GrContext::wrapBackendRenderTarget(const GrBackendRenderTargetDesc& desc) { |
| 661 | return fGpu->wrapBackendRenderTarget(desc); |
bsalomon@google.com | e269f21 | 2011-11-07 13:29:52 +0000 | [diff] [blame] | 662 | } |
| 663 | |
bsalomon@google.com | 5877ffd | 2011-04-11 17:58:48 +0000 | [diff] [blame] | 664 | /////////////////////////////////////////////////////////////////////////////// |
| 665 | |
bsalomon@google.com | b867099 | 2012-07-25 21:27:09 +0000 | [diff] [blame] | 666 | bool GrContext::supportsIndex8PixelConfig(const GrTextureParams* params, |
bsalomon@google.com | 1f221a7 | 2011-08-23 20:54:07 +0000 | [diff] [blame] | 667 | int width, int height) const { |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 668 | const GrDrawTargetCaps* caps = fGpu->caps(); |
commit-bot@chromium.org | 6e7ddaa | 2014-05-30 13:55:58 +0000 | [diff] [blame] | 669 | if (!caps->isConfigTexturable(kIndex_8_GrPixelConfig)) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 670 | return false; |
| 671 | } |
| 672 | |
tfarina | f9dae78 | 2014-06-06 06:35:28 -0700 | [diff] [blame] | 673 | bool isPow2 = SkIsPow2(width) && SkIsPow2(height); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 674 | |
| 675 | if (!isPow2) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 676 | bool tiled = params && params->isTiled(); |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 677 | if (tiled && !caps->npotTextureTileSupport()) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 678 | return false; |
| 679 | } |
| 680 | } |
| 681 | return true; |
| 682 | } |
| 683 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 684 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 685 | //////////////////////////////////////////////////////////////////////////////// |
| 686 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 687 | void GrContext::clear(const SkIRect* rect, |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 688 | const GrColor color, |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 689 | bool canIgnoreRect, |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 690 | GrRenderTarget* renderTarget) { |
| 691 | ASSERT_OWNED_RESOURCE(renderTarget); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 692 | AutoRestoreEffects are; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 693 | AutoCheckFlush acf(this); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 694 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::clear", this); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 695 | GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); |
| 696 | if (NULL == target) { |
| 697 | return; |
| 698 | } |
| 699 | target->clear(rect, color, canIgnoreRect, renderTarget); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 700 | } |
| 701 | |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 702 | void GrContext::drawPaint(const GrPaint& origPaint) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 703 | // set rect to be big enough to fill the space, but not super-huge, so we |
| 704 | // don't overflow fixed-point implementations |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 705 | SkRect r; |
bsalomon@google.com | d302f14 | 2011-03-03 13:54:13 +0000 | [diff] [blame] | 706 | r.setLTRB(0, 0, |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 707 | SkIntToScalar(getRenderTarget()->width()), |
| 708 | SkIntToScalar(getRenderTarget()->height())); |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 709 | SkMatrix inverse; |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 710 | SkTCopyOnFirstWrite<GrPaint> paint(origPaint); |
robertphillips@google.com | fea85ac | 2012-07-11 18:53:23 +0000 | [diff] [blame] | 711 | AutoMatrix am; |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 712 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContext::drawPaint", this); |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 713 | |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 714 | // We attempt to map r by the inverse matrix and draw that. mapRect will |
| 715 | // map the four corners and bound them with a new rect. This will not |
| 716 | // produce a correct result for some perspective matrices. |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 717 | if (!this->getMatrix().hasPerspective()) { |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 718 | if (!fViewMatrix.invert(&inverse)) { |
bsalomon@google.com | e3d3216 | 2012-07-20 13:37:06 +0000 | [diff] [blame] | 719 | GrPrintf("Could not invert matrix\n"); |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 720 | return; |
| 721 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 722 | inverse.mapRect(&r); |
| 723 | } else { |
bsalomon@google.com | 3cbaa2d | 2012-10-12 14:51:52 +0000 | [diff] [blame] | 724 | if (!am.setIdentity(this, paint.writable())) { |
| 725 | GrPrintf("Could not invert matrix\n"); |
| 726 | return; |
bsalomon@google.com | 8c2fe99 | 2011-09-13 15:27:18 +0000 | [diff] [blame] | 727 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 728 | } |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 729 | // by definition this fills the entire clip, no need for AA |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 730 | if (paint->isAntiAlias()) { |
| 731 | paint.writable()->setAntiAlias(false); |
bsalomon@google.com | 4f83be8 | 2011-09-12 13:52:51 +0000 | [diff] [blame] | 732 | } |
bsalomon@google.com | 5dc26b9 | 2012-10-11 19:32:32 +0000 | [diff] [blame] | 733 | this->drawRect(*paint, r); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 734 | } |
| 735 | |
commit-bot@chromium.org | 03e3e89 | 2013-10-02 18:19:17 +0000 | [diff] [blame] | 736 | #ifdef SK_DEVELOPER |
| 737 | void GrContext::dumpFontCache() const { |
| 738 | fFontCache->dump(); |
| 739 | } |
| 740 | #endif |
| 741 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 742 | //////////////////////////////////////////////////////////////////////////////// |
| 743 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 744 | /* create a triangle strip that strokes the specified triangle. There are 8 |
| 745 | unique vertices, but we repreat the last 2 to close up. Alternatively we |
| 746 | could use an indices array, and then only send 8 verts, but not sure that |
| 747 | would be faster. |
| 748 | */ |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 749 | static void setStrokeRectStrip(SkPoint verts[10], SkRect rect, |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 750 | SkScalar width) { |
| 751 | const SkScalar rad = SkScalarHalf(width); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 752 | rect.sort(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 753 | |
| 754 | verts[0].set(rect.fLeft + rad, rect.fTop + rad); |
| 755 | verts[1].set(rect.fLeft - rad, rect.fTop - rad); |
| 756 | verts[2].set(rect.fRight - rad, rect.fTop + rad); |
| 757 | verts[3].set(rect.fRight + rad, rect.fTop - rad); |
| 758 | verts[4].set(rect.fRight - rad, rect.fBottom - rad); |
| 759 | verts[5].set(rect.fRight + rad, rect.fBottom + rad); |
| 760 | verts[6].set(rect.fLeft + rad, rect.fBottom - rad); |
| 761 | verts[7].set(rect.fLeft - rad, rect.fBottom + rad); |
| 762 | verts[8] = verts[0]; |
| 763 | verts[9] = verts[1]; |
| 764 | } |
| 765 | |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 766 | static inline bool is_irect(const SkRect& r) { |
| 767 | return SkScalarIsInt(r.fLeft) && SkScalarIsInt(r.fTop) && |
| 768 | SkScalarIsInt(r.fRight) && SkScalarIsInt(r.fBottom); |
| 769 | } |
| 770 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 771 | static bool apply_aa_to_rect(GrDrawTarget* target, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 772 | const SkRect& rect, |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 773 | SkScalar strokeWidth, |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 774 | const SkMatrix& combinedMatrix, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 775 | SkRect* devBoundRect) { |
| 776 | if (!target->getDrawState().canTweakAlphaForCoverage() && |
| 777 | target->shouldDisableCoverageAAForBlend()) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 778 | #ifdef SK_DEBUG |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 779 | //GrPrintf("Turning off AA to correctly apply blend.\n"); |
bsalomon@google.com | 1983f39 | 2011-10-10 15:17:58 +0000 | [diff] [blame] | 780 | #endif |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 781 | return false; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 782 | } |
bsalomon@google.com | 8f9cbd6 | 2011-12-09 15:55:34 +0000 | [diff] [blame] | 783 | const GrDrawState& drawState = target->getDrawState(); |
| 784 | if (drawState.getRenderTarget()->isMultisampled()) { |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 785 | return false; |
| 786 | } |
| 787 | |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 788 | #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 789 | if (strokeWidth >= 0) { |
| 790 | #endif |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 791 | if (!combinedMatrix.preservesAxisAlignment()) { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 792 | return false; |
| 793 | } |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 794 | |
robertphillips@google.com | 4b140b5 | 2013-05-02 17:13:13 +0000 | [diff] [blame] | 795 | #if defined(SHADER_AA_FILL_RECT) || !defined(IGNORE_ROT_AA_RECT_OPT) |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 796 | } else { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 797 | if (!combinedMatrix.preservesRightAngles()) { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 798 | return false; |
| 799 | } |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 800 | } |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 801 | #endif |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 802 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 803 | combinedMatrix.mapRect(devBoundRect, rect); |
bsalomon | c30aaa0 | 2014-08-13 07:15:29 -0700 | [diff] [blame] | 804 | if (strokeWidth < 0) { |
| 805 | return !is_irect(*devBoundRect); |
| 806 | } |
robertphillips@google.com | 28ac96e | 2013-05-13 13:38:35 +0000 | [diff] [blame] | 807 | |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 808 | return true; |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 809 | } |
| 810 | |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 811 | static inline bool rect_contains_inclusive(const SkRect& rect, const SkPoint& point) { |
| 812 | return point.fX >= rect.fLeft && point.fX <= rect.fRight && |
| 813 | point.fY >= rect.fTop && point.fY <= rect.fBottom; |
| 814 | } |
| 815 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 816 | void GrContext::drawRect(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 817 | const SkRect& rect, |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 818 | const GrStrokeInfo* strokeInfo) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 819 | if (strokeInfo && strokeInfo->isDashed()) { |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 820 | SkPath path; |
| 821 | path.addRect(rect); |
| 822 | this->drawPath(paint, path, *strokeInfo); |
| 823 | return; |
| 824 | } |
| 825 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 826 | AutoRestoreEffects are; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 827 | AutoCheckFlush acf(this); |
| 828 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 829 | if (NULL == target) { |
| 830 | return; |
| 831 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 832 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 833 | GR_CREATE_TRACE_MARKER("GrContext::drawRect", target); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 834 | SkScalar width = NULL == strokeInfo ? -1 : strokeInfo->getStrokeRec().getWidth(); |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 835 | SkMatrix matrix = target->drawState()->getViewMatrix(); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 836 | |
| 837 | // Check if this is a full RT draw and can be replaced with a clear. We don't bother checking |
| 838 | // cases where the RT is fully inside a stroke. |
| 839 | if (width < 0) { |
| 840 | SkRect rtRect; |
| 841 | target->getDrawState().getRenderTarget()->getBoundsRect(&rtRect); |
| 842 | SkRect clipSpaceRTRect = rtRect; |
| 843 | bool checkClip = false; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 844 | if (this->getClip()) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 845 | checkClip = true; |
| 846 | clipSpaceRTRect.offset(SkIntToScalar(this->getClip()->fOrigin.fX), |
| 847 | SkIntToScalar(this->getClip()->fOrigin.fY)); |
| 848 | } |
| 849 | // Does the clip contain the entire RT? |
| 850 | if (!checkClip || target->getClip()->fClipStack->quickContains(clipSpaceRTRect)) { |
| 851 | SkMatrix invM; |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 852 | if (!matrix.invert(&invM)) { |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 853 | return; |
| 854 | } |
| 855 | // Does the rect bound the RT? |
| 856 | SkPoint srcSpaceRTQuad[4]; |
| 857 | invM.mapRectToQuad(srcSpaceRTQuad, rtRect); |
| 858 | if (rect_contains_inclusive(rect, srcSpaceRTQuad[0]) && |
| 859 | rect_contains_inclusive(rect, srcSpaceRTQuad[1]) && |
| 860 | rect_contains_inclusive(rect, srcSpaceRTQuad[2]) && |
| 861 | rect_contains_inclusive(rect, srcSpaceRTQuad[3])) { |
| 862 | // Will it blend? |
| 863 | GrColor clearColor; |
| 864 | if (paint.isOpaqueAndConstantColor(&clearColor)) { |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 865 | target->clear(NULL, clearColor, true); |
commit-bot@chromium.org | 24ab3b0 | 2013-08-14 21:56:37 +0000 | [diff] [blame] | 866 | return; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | } |
| 871 | |
| 872 | SkRect devBoundRect; |
bsalomon@google.com | c7448ce | 2012-10-05 19:04:13 +0000 | [diff] [blame] | 873 | bool needAA = paint.isAntiAlias() && |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 874 | !target->getDrawState().getRenderTarget()->isMultisampled(); |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 875 | bool doAA = needAA && apply_aa_to_rect(target, rect, width, matrix, &devBoundRect); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 876 | |
| 877 | const SkStrokeRec& strokeRec = strokeInfo->getStrokeRec(); |
| 878 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 879 | if (doAA) { |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 880 | GrDrawState::AutoViewMatrixRestore avmr; |
| 881 | if (!avmr.setIdentity(target->drawState())) { |
bsalomon@google.com | e3d3216 | 2012-07-20 13:37:06 +0000 | [diff] [blame] | 882 | return; |
| 883 | } |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 884 | if (width >= 0) { |
commit-bot@chromium.org | 6006d0f | 2013-11-06 10:08:21 +0000 | [diff] [blame] | 885 | fAARectRenderer->strokeAARect(this->getGpu(), target, rect, |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 886 | matrix, devBoundRect, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 887 | strokeRec); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 888 | } else { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 889 | // filled AA rect |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 890 | fAARectRenderer->fillAARect(this->getGpu(), target, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 891 | rect, matrix, devBoundRect); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 892 | } |
| 893 | return; |
| 894 | } |
| 895 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 896 | if (width >= 0) { |
| 897 | // TODO: consider making static vertex buffers for these cases. |
bsalomon@google.com | 6438695 | 2013-02-08 21:22:44 +0000 | [diff] [blame] | 898 | // Hairline could be done by just adding closing vertex to |
| 899 | // unitSquareVertexBuffer() |
bsalomon@google.com | 26c2d0a | 2011-05-17 20:15:30 +0000 | [diff] [blame] | 900 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 901 | static const int worstCaseVertCount = 10; |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 902 | target->drawState()->setDefaultVertexAttribs(); |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 903 | GrDrawTarget::AutoReleaseGeometry geo(target, worstCaseVertCount, 0); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 904 | |
| 905 | if (!geo.succeeded()) { |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 906 | GrPrintf("Failed to get space for vertices!\n"); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 907 | return; |
| 908 | } |
| 909 | |
| 910 | GrPrimitiveType primType; |
| 911 | int vertCount; |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 912 | SkPoint* vertex = geo.positions(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 913 | |
| 914 | if (width > 0) { |
| 915 | vertCount = 10; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 916 | primType = kTriangleStrip_GrPrimitiveType; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 917 | setStrokeRectStrip(vertex, rect, width); |
| 918 | } else { |
| 919 | // hairline |
| 920 | vertCount = 5; |
bsalomon@google.com | 4705954 | 2012-06-06 20:51:20 +0000 | [diff] [blame] | 921 | primType = kLineStrip_GrPrimitiveType; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 922 | vertex[0].set(rect.fLeft, rect.fTop); |
| 923 | vertex[1].set(rect.fRight, rect.fTop); |
| 924 | vertex[2].set(rect.fRight, rect.fBottom); |
| 925 | vertex[3].set(rect.fLeft, rect.fBottom); |
| 926 | vertex[4].set(rect.fLeft, rect.fTop); |
| 927 | } |
| 928 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 929 | target->drawNonIndexed(primType, 0, vertCount); |
| 930 | } else { |
robertphillips@google.com | df3695e | 2013-04-09 14:01:44 +0000 | [diff] [blame] | 931 | // filled BW rect |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 932 | target->drawSimpleRect(rect); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
| 936 | void GrContext::drawRectToRect(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 937 | const SkRect& dstRect, |
| 938 | const SkRect& localRect, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 939 | const SkMatrix* localMatrix) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 940 | AutoRestoreEffects are; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 941 | AutoCheckFlush acf(this); |
| 942 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 943 | if (NULL == target) { |
| 944 | return; |
| 945 | } |
bsalomon@google.com | 6438695 | 2013-02-08 21:22:44 +0000 | [diff] [blame] | 946 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 947 | GR_CREATE_TRACE_MARKER("GrContext::drawRectToRect", target); |
| 948 | |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 949 | target->drawRect(dstRect, &localRect, localMatrix); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 950 | } |
| 951 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 952 | namespace { |
| 953 | |
| 954 | extern const GrVertexAttrib gPosUVColorAttribs[] = { |
| 955 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding }, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 956 | {kVec2f_GrVertexAttribType, sizeof(SkPoint), kLocalCoord_GrVertexAttribBinding }, |
| 957 | {kVec4ub_GrVertexAttribType, 2*sizeof(SkPoint), kColor_GrVertexAttribBinding} |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 958 | }; |
| 959 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 960 | static const size_t kPosUVAttribsSize = 2 * sizeof(SkPoint); |
| 961 | static const size_t kPosUVColorAttribsSize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
| 962 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 963 | extern const GrVertexAttrib gPosColorAttribs[] = { |
| 964 | {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 965 | {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVertexAttribBinding}, |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 966 | }; |
| 967 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 968 | static const size_t kPosAttribsSize = sizeof(SkPoint); |
| 969 | static const size_t kPosColorAttribsSize = sizeof(SkPoint) + sizeof(GrColor); |
| 970 | |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 971 | static void set_vertex_attributes(GrDrawState* drawState, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 972 | const SkPoint* texCoords, |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 973 | const GrColor* colors, |
| 974 | int* colorOffset, |
| 975 | int* texOffset) { |
| 976 | *texOffset = -1; |
| 977 | *colorOffset = -1; |
| 978 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 979 | if (texCoords && colors) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 980 | *texOffset = sizeof(SkPoint); |
| 981 | *colorOffset = 2*sizeof(SkPoint); |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 982 | drawState->setVertexAttribs<gPosUVColorAttribs>(3, kPosUVColorAttribsSize); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 983 | } else if (texCoords) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 984 | *texOffset = sizeof(SkPoint); |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 985 | drawState->setVertexAttribs<gPosUVColorAttribs>(2, kPosUVAttribsSize); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 986 | } else if (colors) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 987 | *colorOffset = sizeof(SkPoint); |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 988 | drawState->setVertexAttribs<gPosColorAttribs>(2, kPosColorAttribsSize); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 989 | } else { |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 990 | drawState->setVertexAttribs<gPosColorAttribs>(1, kPosAttribsSize); |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 991 | } |
| 992 | } |
| 993 | |
| 994 | }; |
| 995 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 996 | void GrContext::drawVertices(const GrPaint& paint, |
| 997 | GrPrimitiveType primitiveType, |
| 998 | int vertexCount, |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 999 | const SkPoint positions[], |
| 1000 | const SkPoint texCoords[], |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1001 | const GrColor colors[], |
| 1002 | const uint16_t indices[], |
| 1003 | int indexCount) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1004 | AutoRestoreEffects are; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1005 | AutoCheckFlush acf(this); |
commit-bot@chromium.org | 5a56793 | 2014-01-08 21:26:09 +0000 | [diff] [blame] | 1006 | GrDrawTarget::AutoReleaseGeometry geo; // must be inside AutoCheckFlush scope |
| 1007 | |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1008 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1009 | if (NULL == target) { |
| 1010 | return; |
| 1011 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 1012 | GrDrawState* drawState = target->drawState(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1013 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1014 | GR_CREATE_TRACE_MARKER("GrContext::drawVertices", target); |
| 1015 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1016 | int colorOffset = -1, texOffset = -1; |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 1017 | set_vertex_attributes(drawState, texCoords, colors, &colorOffset, &texOffset); |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1018 | |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 1019 | size_t VertexStride = drawState->getVertexStride(); |
| 1020 | if (sizeof(SkPoint) != VertexStride) { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 1021 | if (!geo.set(target, vertexCount, 0)) { |
bsalomon@google.com | 6513cd0 | 2011-08-05 20:12:30 +0000 | [diff] [blame] | 1022 | GrPrintf("Failed to get space for vertices!\n"); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1023 | return; |
| 1024 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1025 | void* curVertex = geo.vertices(); |
| 1026 | |
| 1027 | for (int i = 0; i < vertexCount; ++i) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1028 | *((SkPoint*)curVertex) = positions[i]; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1029 | |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1030 | if (texOffset >= 0) { |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 1031 | *(SkPoint*)((intptr_t)curVertex + texOffset) = texCoords[i]; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1032 | } |
jvanverth@google.com | 9b855c7 | 2013-03-01 18:21:22 +0000 | [diff] [blame] | 1033 | if (colorOffset >= 0) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1034 | *(GrColor*)((intptr_t)curVertex + colorOffset) = colors[i]; |
| 1035 | } |
egdaniel | 7b3d5ee | 2014-08-28 05:41:14 -0700 | [diff] [blame] | 1036 | curVertex = (void*)((intptr_t)curVertex + VertexStride); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1037 | } |
| 1038 | } else { |
jvanverth@google.com | b75b0a0 | 2013-02-05 20:33:30 +0000 | [diff] [blame] | 1039 | target->setVertexSourceToArray(positions, vertexCount); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1042 | // we don't currently apply offscreen AA to this path. Need improved |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 1043 | // management of GrDrawTarget's geometry to avoid copying points per-tile. |
bsalomon@google.com | a47a48d | 2011-04-26 20:22:11 +0000 | [diff] [blame] | 1044 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1045 | if (indices) { |
bsalomon@google.com | 9195836 | 2011-06-13 17:58:13 +0000 | [diff] [blame] | 1046 | target->setIndexSourceToArray(indices, indexCount); |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1047 | target->drawIndexed(primitiveType, 0, 0, vertexCount, indexCount); |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 1048 | target->resetIndexSource(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1049 | } else { |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1050 | target->drawNonIndexed(primitiveType, 0, vertexCount); |
| 1051 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
bsalomon@google.com | 06afe7b | 2011-04-26 15:31:40 +0000 | [diff] [blame] | 1054 | /////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 1055 | |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1056 | void GrContext::drawRRect(const GrPaint& paint, |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1057 | const SkRRect& rrect, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1058 | const GrStrokeInfo& strokeInfo) { |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1059 | if (rrect.isEmpty()) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1060 | return; |
| 1061 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1062 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1063 | if (strokeInfo.isDashed()) { |
| 1064 | SkPath path; |
| 1065 | path.addRRect(rrect); |
| 1066 | this->drawPath(paint, path, strokeInfo); |
| 1067 | return; |
| 1068 | } |
| 1069 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1070 | AutoRestoreEffects are; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1071 | AutoCheckFlush acf(this); |
| 1072 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1073 | if (NULL == target) { |
| 1074 | return; |
| 1075 | } |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1076 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1077 | GR_CREATE_TRACE_MARKER("GrContext::drawRRect", target); |
| 1078 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1079 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1080 | |
| 1081 | if (!fOvalRenderer->drawRRect(target, this, paint.isAntiAlias(), rrect, strokeRec)) { |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1082 | SkPath path; |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1083 | path.addRRect(rrect); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1084 | this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo); |
commit-bot@chromium.org | f2bfd54 | 2013-04-25 15:27:00 +0000 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
| 1088 | /////////////////////////////////////////////////////////////////////////////// |
| 1089 | |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1090 | void GrContext::drawDRRect(const GrPaint& paint, |
| 1091 | const SkRRect& outer, |
| 1092 | const SkRRect& inner) { |
| 1093 | if (outer.isEmpty()) { |
| 1094 | return; |
| 1095 | } |
| 1096 | |
| 1097 | AutoRestoreEffects are; |
| 1098 | AutoCheckFlush acf(this); |
| 1099 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
| 1100 | |
| 1101 | GR_CREATE_TRACE_MARKER("GrContext::drawDRRect", target); |
| 1102 | |
| 1103 | if (!fOvalRenderer->drawDRRect(target, this, paint.isAntiAlias(), outer, inner)) { |
| 1104 | SkPath path; |
| 1105 | path.addRRect(inner); |
| 1106 | path.addRRect(outer); |
| 1107 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 1108 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1109 | GrStrokeInfo fillRec(SkStrokeRec::kFill_InitStyle); |
commit-bot@chromium.org | 0a09d71 | 2014-04-09 21:26:11 +0000 | [diff] [blame] | 1110 | this->internalDrawPath(target, paint.isAntiAlias(), path, fillRec); |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | /////////////////////////////////////////////////////////////////////////////// |
| 1115 | |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 1116 | void GrContext::drawOval(const GrPaint& paint, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 1117 | const SkRect& oval, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1118 | const GrStrokeInfo& strokeInfo) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1119 | if (oval.isEmpty()) { |
| 1120 | return; |
| 1121 | } |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 1122 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1123 | if (strokeInfo.isDashed()) { |
| 1124 | SkPath path; |
| 1125 | path.addOval(oval); |
| 1126 | this->drawPath(paint, path, strokeInfo); |
| 1127 | return; |
| 1128 | } |
| 1129 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1130 | AutoRestoreEffects are; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1131 | AutoCheckFlush acf(this); |
| 1132 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1133 | if (NULL == target) { |
| 1134 | return; |
| 1135 | } |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1136 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1137 | GR_CREATE_TRACE_MARKER("GrContext::drawOval", target); |
| 1138 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1139 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1140 | |
| 1141 | |
| 1142 | if (!fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), oval, strokeRec)) { |
bsalomon@google.com | 93c9660 | 2012-04-27 13:05:21 +0000 | [diff] [blame] | 1143 | SkPath path; |
jvanverth@google.com | 46d3d39 | 2013-01-22 13:34:01 +0000 | [diff] [blame] | 1144 | path.addOval(oval); |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1145 | this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo); |
skia.committer@gmail.com | 98ded84 | 2013-01-23 07:06:17 +0000 | [diff] [blame] | 1146 | } |
bsalomon@google.com | 150d284 | 2012-01-12 20:19:56 +0000 | [diff] [blame] | 1147 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1148 | |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1149 | // Can 'path' be drawn as a pair of filled nested rectangles? |
| 1150 | static bool is_nested_rects(GrDrawTarget* target, |
| 1151 | const SkPath& path, |
| 1152 | const SkStrokeRec& stroke, |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 1153 | SkRect rects[2]) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1154 | SkASSERT(stroke.isFillStyle()); |
| 1155 | |
| 1156 | if (path.isInverseFillType()) { |
| 1157 | return false; |
| 1158 | } |
| 1159 | |
| 1160 | const GrDrawState& drawState = target->getDrawState(); |
| 1161 | |
| 1162 | // TODO: this restriction could be lifted if we were willing to apply |
| 1163 | // the matrix to all the points individually rather than just to the rect |
| 1164 | if (!drawState.getViewMatrix().preservesAxisAlignment()) { |
| 1165 | return false; |
| 1166 | } |
| 1167 | |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 1168 | if (!target->getDrawState().canTweakAlphaForCoverage() && |
| 1169 | target->shouldDisableCoverageAAForBlend()) { |
| 1170 | return false; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | SkPath::Direction dirs[2]; |
| 1174 | if (!path.isNestedRects(rects, dirs)) { |
| 1175 | return false; |
| 1176 | } |
| 1177 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1178 | if (SkPath::kWinding_FillType == path.getFillType() && dirs[0] == dirs[1]) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1179 | // The two rects need to be wound opposite to each other |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1180 | return false; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1181 | } |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1182 | |
robertphillips@google.com | 8d3c640 | 2013-08-20 12:11:31 +0000 | [diff] [blame] | 1183 | // Right now, nested rects where the margin is not the same width |
| 1184 | // all around do not render correctly |
| 1185 | const SkScalar* outer = rects[0].asScalars(); |
| 1186 | const SkScalar* inner = rects[1].asScalars(); |
| 1187 | |
| 1188 | SkScalar margin = SkScalarAbs(outer[0] - inner[0]); |
| 1189 | for (int i = 1; i < 4; ++i) { |
| 1190 | SkScalar temp = SkScalarAbs(outer[i] - inner[i]); |
| 1191 | if (!SkScalarNearlyEqual(margin, temp)) { |
| 1192 | return false; |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | return true; |
| 1197 | } |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1198 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1199 | void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const GrStrokeInfo& strokeInfo) { |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1200 | |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1201 | if (path.isEmpty()) { |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1202 | if (path.isInverseFillType()) { |
bsalomon@google.com | fa6ac93 | 2011-10-05 19:57:55 +0000 | [diff] [blame] | 1203 | this->drawPaint(paint); |
| 1204 | } |
| 1205 | return; |
| 1206 | } |
| 1207 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1208 | if (strokeInfo.isDashed()) { |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 1209 | SkPoint pts[2]; |
| 1210 | if (path.isLine(pts)) { |
| 1211 | AutoRestoreEffects are; |
| 1212 | AutoCheckFlush acf(this); |
| 1213 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1214 | if (NULL == target) { |
| 1215 | return; |
| 1216 | } |
egdaniel | e61c411 | 2014-06-12 10:24:21 -0700 | [diff] [blame] | 1217 | GrDrawState* drawState = target->drawState(); |
| 1218 | |
| 1219 | SkMatrix origViewMatrix = drawState->getViewMatrix(); |
| 1220 | GrDrawState::AutoViewMatrixRestore avmr; |
| 1221 | if (avmr.setIdentity(target->drawState())) { |
| 1222 | if (GrDashingEffect::DrawDashLine(pts, paint, strokeInfo, fGpu, target, |
| 1223 | origViewMatrix)) { |
| 1224 | return; |
| 1225 | } |
| 1226 | } |
| 1227 | } |
| 1228 | |
| 1229 | // Filter dashed path into new path with the dashing applied |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1230 | const SkPathEffect::DashInfo& info = strokeInfo.getDashInfo(); |
| 1231 | SkTLazy<SkPath> effectPath; |
| 1232 | GrStrokeInfo newStrokeInfo(strokeInfo, false); |
| 1233 | SkStrokeRec* stroke = newStrokeInfo.getStrokeRecPtr(); |
| 1234 | if (SkDashPath::FilterDashPath(effectPath.init(), path, stroke, NULL, info)) { |
| 1235 | this->drawPath(paint, *effectPath.get(), newStrokeInfo); |
| 1236 | return; |
| 1237 | } |
| 1238 | |
| 1239 | this->drawPath(paint, path, newStrokeInfo); |
| 1240 | return; |
| 1241 | } |
| 1242 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1243 | // Note that internalDrawPath may sw-rasterize the path into a scratch texture. |
bsalomon@google.com | fb4ce6f | 2012-03-14 13:27:54 +0000 | [diff] [blame] | 1244 | // Scratch textures can be recycled after they are returned to the texture |
| 1245 | // cache. This presents a potential hazard for buffered drawing. However, |
| 1246 | // the writePixels that uploads to the scratch will perform a flush so we're |
| 1247 | // OK. |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1248 | AutoRestoreEffects are; |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1249 | AutoCheckFlush acf(this); |
| 1250 | GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1251 | if (NULL == target) { |
| 1252 | return; |
| 1253 | } |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1254 | GrDrawState* drawState = target->drawState(); |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1255 | |
egdaniel | 93a37bc | 2014-07-21 13:47:57 -0700 | [diff] [blame] | 1256 | GR_CREATE_TRACE_MARKER1("GrContext::drawPath", target, "Is Convex", path.isConvex()); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1257 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1258 | const SkStrokeRec& strokeRec = strokeInfo.getStrokeRec(); |
| 1259 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1260 | bool useCoverageAA = paint.isAntiAlias() && !drawState->getRenderTarget()->isMultisampled(); |
| 1261 | |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1262 | if (useCoverageAA && strokeRec.getWidth() < 0 && !path.isConvex()) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1263 | // Concave AA paths are expensive - try to avoid them for special cases |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1264 | SkRect rects[2]; |
| 1265 | |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 1266 | if (is_nested_rects(target, path, strokeRec, rects)) { |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1267 | SkMatrix origViewMatrix = drawState->getViewMatrix(); |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1268 | GrDrawState::AutoViewMatrixRestore avmr; |
| 1269 | if (!avmr.setIdentity(target->drawState())) { |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1270 | return; |
| 1271 | } |
| 1272 | |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 1273 | fAARectRenderer->fillAANestedRects(this->getGpu(), target, rects, origViewMatrix); |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1274 | return; |
| 1275 | } |
| 1276 | } |
| 1277 | |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1278 | SkRect ovalRect; |
| 1279 | bool isOval = path.isOval(&ovalRect); |
| 1280 | |
skia.committer@gmail.com | 7e32851 | 2013-03-23 07:01:28 +0000 | [diff] [blame] | 1281 | if (!isOval || path.isInverseFillType() |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1282 | || !fOvalRenderer->drawOval(target, this, paint.isAntiAlias(), ovalRect, strokeRec)) { |
| 1283 | this->internalDrawPath(target, paint.isAntiAlias(), path, strokeInfo); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1284 | } |
| 1285 | } |
| 1286 | |
bsalomon@google.com | 1b20a10 | 2013-11-08 14:42:56 +0000 | [diff] [blame] | 1287 | void GrContext::internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path, |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1288 | const GrStrokeInfo& strokeInfo) { |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1289 | SkASSERT(!path.isEmpty()); |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 1290 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 1291 | GR_CREATE_TRACE_MARKER("GrContext::internalDrawPath", target); |
| 1292 | |
| 1293 | |
bsalomon@google.com | d46e242 | 2011-09-23 17:40:07 +0000 | [diff] [blame] | 1294 | // An Assumption here is that path renderer would use some form of tweaking |
| 1295 | // the src color (either the input alpha or in the frag shader) to implement |
| 1296 | // aa. If we have some future driver-mojo path AA that can do the right |
| 1297 | // thing WRT to the blend then we'll need some query on the PR. |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1298 | bool useCoverageAA = useAA && |
| 1299 | !target->getDrawState().getRenderTarget()->isMultisampled() && |
| 1300 | !target->shouldDisableCoverageAAForBlend(); |
bsalomon@google.com | 289533a | 2011-10-27 12:34:25 +0000 | [diff] [blame] | 1301 | |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1302 | |
| 1303 | GrPathRendererChain::DrawType type = |
| 1304 | useCoverageAA ? GrPathRendererChain::kColorAntiAlias_DrawType : |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1305 | GrPathRendererChain::kColor_DrawType; |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1306 | |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1307 | const SkPath* pathPtr = &path; |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1308 | SkTLazy<SkPath> tmpPath; |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 1309 | SkTCopyOnFirstWrite<SkStrokeRec> stroke(strokeInfo.getStrokeRec()); |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1310 | |
| 1311 | // Try a 1st time without stroking the path and without allowing the SW renderer |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1312 | GrPathRenderer* pr = this->getPathRenderer(*pathPtr, *stroke, target, false, type); |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1313 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1314 | if (NULL == pr) { |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1315 | if (!GrPathRenderer::IsStrokeHairlineOrEquivalent(*stroke, this->getMatrix(), NULL)) { |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1316 | // It didn't work the 1st time, so try again with the stroked path |
commit-bot@chromium.org | f0c41e2 | 2014-01-14 18:42:34 +0000 | [diff] [blame] | 1317 | if (stroke->applyToPath(tmpPath.init(), *pathPtr)) { |
| 1318 | pathPtr = tmpPath.get(); |
| 1319 | stroke.writable()->setFillStyle(); |
commit-bot@chromium.org | e0a868c | 2013-11-22 07:02:11 +0000 | [diff] [blame] | 1320 | if (pathPtr->isEmpty()) { |
| 1321 | return; |
| 1322 | } |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1323 | } |
| 1324 | } |
commit-bot@chromium.org | 19dd017 | 2013-08-05 13:28:55 +0000 | [diff] [blame] | 1325 | |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1326 | // This time, allow SW renderer |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1327 | pr = this->getPathRenderer(*pathPtr, *stroke, target, true, type); |
robertphillips@google.com | eb928ea | 2013-01-08 13:45:09 +0000 | [diff] [blame] | 1328 | } |
| 1329 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1330 | if (NULL == pr) { |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 1331 | #ifdef SK_DEBUG |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1332 | GrPrintf("Unable to find path renderer compatible with path.\n"); |
bsalomon@google.com | 1983f39 | 2011-10-10 15:17:58 +0000 | [diff] [blame] | 1333 | #endif |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1334 | return; |
| 1335 | } |
| 1336 | |
robertphillips@google.com | e79f320 | 2014-02-11 16:30:21 +0000 | [diff] [blame] | 1337 | pr->drawPath(*pathPtr, *stroke, target, useCoverageAA); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1338 | } |
bsalomon@google.com | 8295dc1 | 2011-05-02 12:53:34 +0000 | [diff] [blame] | 1339 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1340 | //////////////////////////////////////////////////////////////////////////////// |
| 1341 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1342 | void GrContext::flush(int flagsBitfield) { |
robertphillips@google.com | e7db8d6 | 2013-07-04 11:48:52 +0000 | [diff] [blame] | 1343 | if (NULL == fDrawBuffer) { |
| 1344 | return; |
| 1345 | } |
| 1346 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 1347 | if (kDiscard_FlushBit & flagsBitfield) { |
| 1348 | fDrawBuffer->reset(); |
| 1349 | } else { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1350 | fDrawBuffer->flush(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 1351 | } |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1352 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1353 | } |
| 1354 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1355 | bool GrContext::writeTexturePixels(GrTexture* texture, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1356 | int left, int top, int width, int height, |
| 1357 | GrPixelConfig config, const void* buffer, size_t rowBytes, |
| 1358 | uint32_t flags) { |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 1359 | ASSERT_OWNED_RESOURCE(texture); |
| 1360 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1361 | if ((kUnpremul_PixelOpsFlag & flags) || !fGpu->canWriteTexturePixels(texture, config)) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1362 | if (texture->asRenderTarget()) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1363 | return this->writeRenderTargetPixels(texture->asRenderTarget(), |
| 1364 | left, top, width, height, |
| 1365 | config, buffer, rowBytes, flags); |
| 1366 | } else { |
| 1367 | return false; |
| 1368 | } |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1369 | } |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1370 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 1371 | if (!(kDontFlush_PixelOpsFlag & flags) && texture->surfacePriv().hasPendingIO()) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1372 | this->flush(); |
| 1373 | } |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1374 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1375 | return fGpu->writeTexturePixels(texture, left, top, width, height, |
| 1376 | config, buffer, rowBytes); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1377 | } |
| 1378 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1379 | bool GrContext::readTexturePixels(GrTexture* texture, |
| 1380 | int left, int top, int width, int height, |
| 1381 | GrPixelConfig config, void* buffer, size_t rowBytes, |
| 1382 | uint32_t flags) { |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 1383 | ASSERT_OWNED_RESOURCE(texture); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1384 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1385 | GrRenderTarget* target = texture->asRenderTarget(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1386 | if (target) { |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1387 | return this->readRenderTargetPixels(target, |
| 1388 | left, top, width, height, |
| 1389 | config, buffer, rowBytes, |
| 1390 | flags); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1391 | } else { |
commit-bot@chromium.org | 3f80dd5 | 2013-10-23 15:32:39 +0000 | [diff] [blame] | 1392 | // TODO: make this more efficient for cases where we're reading the entire |
| 1393 | // texture, i.e., use GetTexImage() instead |
| 1394 | |
| 1395 | // create scratch rendertarget and read from that |
| 1396 | GrAutoScratchTexture ast; |
| 1397 | GrTextureDesc desc; |
| 1398 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1399 | desc.fWidth = width; |
| 1400 | desc.fHeight = height; |
| 1401 | desc.fConfig = config; |
| 1402 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
| 1403 | ast.set(this, desc, kExact_ScratchTexMatch); |
| 1404 | GrTexture* dst = ast.texture(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1405 | if (dst && (target = dst->asRenderTarget())) { |
commit-bot@chromium.org | 3f80dd5 | 2013-10-23 15:32:39 +0000 | [diff] [blame] | 1406 | this->copyTexture(texture, target, NULL); |
| 1407 | return this->readRenderTargetPixels(target, |
| 1408 | left, top, width, height, |
| 1409 | config, buffer, rowBytes, |
| 1410 | flags); |
| 1411 | } |
skia.committer@gmail.com | 583b18a | 2013-10-24 07:01:59 +0000 | [diff] [blame] | 1412 | |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1413 | return false; |
| 1414 | } |
| 1415 | } |
| 1416 | |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1417 | #include "SkConfig8888.h" |
| 1418 | |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1419 | // toggles between RGBA and BGRA |
| 1420 | static SkColorType toggle_colortype32(SkColorType ct) { |
| 1421 | if (kRGBA_8888_SkColorType == ct) { |
| 1422 | return kBGRA_8888_SkColorType; |
| 1423 | } else { |
| 1424 | SkASSERT(kBGRA_8888_SkColorType == ct); |
| 1425 | return kRGBA_8888_SkColorType; |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 1426 | } |
| 1427 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1428 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1429 | bool GrContext::readRenderTargetPixels(GrRenderTarget* target, |
| 1430 | int left, int top, int width, int height, |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1431 | GrPixelConfig dstConfig, void* buffer, size_t rowBytes, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1432 | uint32_t flags) { |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 1433 | ASSERT_OWNED_RESOURCE(target); |
| 1434 | |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1435 | if (NULL == target) { |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1436 | target = fRenderTarget.get(); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1437 | if (NULL == target) { |
| 1438 | return false; |
| 1439 | } |
| 1440 | } |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 1441 | |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame^] | 1442 | if (!(kDontFlush_PixelOpsFlag & flags) && target->surfacePriv().hasPendingWrite()) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1443 | this->flush(); |
| 1444 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1445 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1446 | // Determine which conversions have to be applied: flipY, swapRAnd, and/or unpremul. |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1447 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1448 | // If fGpu->readPixels would incur a y-flip cost then we will read the pixels upside down. We'll |
| 1449 | // either do the flipY by drawing into a scratch with a matrix or on the cpu after the read. |
| 1450 | bool flipY = fGpu->readPixelsWillPayForYFlip(target, left, top, |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1451 | width, height, dstConfig, |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1452 | rowBytes); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1453 | // We ignore the preferred config if it is different than our config unless it is an R/B swap. |
| 1454 | // In that case we'll perform an R and B swap while drawing to a scratch texture of the swapped |
| 1455 | // config. Then we will call readPixels on the scratch with the swapped config. The swaps during |
| 1456 | // the draw cancels out the fact that we call readPixels with a config that is R/B swapped from |
| 1457 | // dstConfig. |
| 1458 | GrPixelConfig readConfig = dstConfig; |
| 1459 | bool swapRAndB = false; |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 1460 | if (GrPixelConfigSwapRAndB(dstConfig) == |
| 1461 | fGpu->preferredReadPixelsConfig(dstConfig, target->config())) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1462 | readConfig = GrPixelConfigSwapRAndB(readConfig); |
| 1463 | swapRAndB = true; |
| 1464 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1465 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1466 | bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1467 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1468 | if (unpremul && !GrPixelConfigIs8888(dstConfig)) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1469 | // The unpremul flag is only allowed for these two configs. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 1470 | return false; |
| 1471 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1472 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1473 | // If the src is a texture and we would have to do conversions after read pixels, we instead |
| 1474 | // do the conversions by drawing the src to a scratch texture. If we handle any of the |
| 1475 | // conversions in the draw we set the corresponding bool to false so that we don't reapply it |
| 1476 | // on the read back pixels. |
| 1477 | GrTexture* src = target->asTexture(); |
bsalomon@google.com | c4ff22a | 2011-11-10 21:56:21 +0000 | [diff] [blame] | 1478 | GrAutoScratchTexture ast; |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1479 | if (src && (swapRAndB || unpremul || flipY)) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1480 | // Make the scratch a render target because we don't have a robust readTexturePixels as of |
| 1481 | // yet. It calls this function. |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 1482 | GrTextureDesc desc; |
| 1483 | desc.fFlags = kRenderTarget_GrTextureFlagBit; |
| 1484 | desc.fWidth = width; |
| 1485 | desc.fHeight = height; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1486 | desc.fConfig = readConfig; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1487 | desc.fOrigin = kTopLeft_GrSurfaceOrigin; |
bsalomon@google.com | c4ff22a | 2011-11-10 21:56:21 +0000 | [diff] [blame] | 1488 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1489 | // When a full read back is faster than a partial we could always make the scratch exactly |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1490 | // match the passed rect. However, if we see many different size rectangles we will trash |
| 1491 | // our texture cache and pay the cost of creating and destroying many textures. So, we only |
| 1492 | // request an exact match when the caller is reading an entire RT. |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 1493 | ScratchTexMatch match = kApprox_ScratchTexMatch; |
| 1494 | if (0 == left && |
| 1495 | 0 == top && |
| 1496 | target->width() == width && |
| 1497 | target->height() == height && |
| 1498 | fGpu->fullReadPixelsIsFasterThanPartial()) { |
| 1499 | match = kExact_ScratchTexMatch; |
| 1500 | } |
| 1501 | ast.set(this, desc, match); |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1502 | GrTexture* texture = ast.texture(); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1503 | if (texture) { |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1504 | // compute a matrix to perform the draw |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 1505 | SkMatrix textureMatrix; |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1506 | textureMatrix.setTranslate(SK_Scalar1 *left, SK_Scalar1 *top); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1507 | textureMatrix.postIDiv(src->width(), src->height()); |
| 1508 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1509 | SkAutoTUnref<const GrFragmentProcessor> fp; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1510 | if (unpremul) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1511 | fp.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix)); |
| 1512 | if (fp) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1513 | unpremul = false; // we no longer need to do this on CPU after the read back. |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1514 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1515 | } |
| 1516 | // If we failed to create a PM->UPM effect and have no other conversions to perform then |
| 1517 | // there is no longer any point to using the scratch. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1518 | if (fp || flipY || swapRAndB) { |
| 1519 | if (!fp) { |
| 1520 | fp.reset(GrConfigConversionEffect::Create( |
| 1521 | src, swapRAndB, GrConfigConversionEffect::kNone_PMConversion, |
| 1522 | textureMatrix)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1523 | } |
| 1524 | swapRAndB = false; // we will handle the swap in the draw. |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1525 | |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 1526 | // We protect the existing geometry here since it may not be |
| 1527 | // clear to the caller that a draw operation (i.e., drawSimpleRect) |
| 1528 | // can be invoked in this method |
| 1529 | GrDrawTarget::AutoGeometryAndStatePush agasp(fGpu, GrDrawTarget::kReset_ASRInit); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1530 | GrDrawState* drawState = fGpu->drawState(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1531 | SkASSERT(fp); |
| 1532 | drawState->addColorProcessor(fp); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1533 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1534 | drawState->setRenderTarget(texture->asRenderTarget()); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 1535 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
bsalomon | 01c8da1 | 2014-08-04 09:21:30 -0700 | [diff] [blame] | 1536 | fGpu->drawSimpleRect(rect); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1537 | // we want to read back from the scratch's origin |
| 1538 | left = 0; |
| 1539 | top = 0; |
| 1540 | target = texture->asRenderTarget(); |
| 1541 | } |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1542 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1543 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1544 | if (!fGpu->readPixels(target, |
| 1545 | left, top, width, height, |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1546 | readConfig, buffer, rowBytes)) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1549 | // Perform any conversions we weren't able to perform using a scratch texture. |
senorblanco@chromium.org | 3cb406b | 2013-02-05 19:50:46 +0000 | [diff] [blame] | 1550 | if (unpremul || swapRAndB) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1551 | SkDstPixelInfo dstPI; |
| 1552 | if (!GrPixelConfig2ColorType(dstConfig, &dstPI.fColorType)) { |
| 1553 | return false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1554 | } |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1555 | dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1556 | dstPI.fPixels = buffer; |
| 1557 | dstPI.fRowBytes = rowBytes; |
| 1558 | |
| 1559 | SkSrcPixelInfo srcPI; |
| 1560 | srcPI.fColorType = swapRAndB ? toggle_colortype32(dstPI.fColorType) : dstPI.fColorType; |
| 1561 | srcPI.fAlphaType = kPremul_SkAlphaType; |
| 1562 | srcPI.fPixels = buffer; |
| 1563 | srcPI.fRowBytes = rowBytes; |
| 1564 | |
| 1565 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1566 | } |
| 1567 | return true; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1570 | void GrContext::resolveRenderTarget(GrRenderTarget* target) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1571 | SkASSERT(target); |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1572 | ASSERT_OWNED_RESOURCE(target); |
| 1573 | // In the future we may track whether there are any pending draws to this |
| 1574 | // target. We don't today so we always perform a flush. We don't promise |
| 1575 | // this to our clients, though. |
| 1576 | this->flush(); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1577 | if (fGpu) { |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1578 | fGpu->resolveRenderTarget(target); |
| 1579 | } |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1582 | void GrContext::discardRenderTarget(GrRenderTarget* renderTarget) { |
| 1583 | SkASSERT(renderTarget); |
| 1584 | ASSERT_OWNED_RESOURCE(renderTarget); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1585 | AutoRestoreEffects are; |
| 1586 | AutoCheckFlush acf(this); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1587 | GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf); |
| 1588 | if (NULL == target) { |
| 1589 | return; |
| 1590 | } |
| 1591 | target->discard(renderTarget); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 1592 | } |
| 1593 | |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 1594 | void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst, const SkIPoint* topLeft) { |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1595 | if (NULL == src || NULL == dst) { |
| 1596 | return; |
| 1597 | } |
bsalomon | e3d4bf2 | 2014-09-23 09:15:03 -0700 | [diff] [blame] | 1598 | ASSERT_OWNED_RESOURCE(src); |
junov | 2bb5210 | 2014-09-29 10:18:59 -0700 | [diff] [blame] | 1599 | ASSERT_OWNED_RESOURCE(dst); |
Brian Salomon | 34a9895 | 2014-09-24 11:41:24 -0400 | [diff] [blame] | 1600 | |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 1601 | SkIRect srcRect = SkIRect::MakeWH(dst->width(), dst->height()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1602 | if (topLeft) { |
scroggo@google.com | a2a3192 | 2012-12-07 19:14:45 +0000 | [diff] [blame] | 1603 | srcRect.offset(*topLeft); |
| 1604 | } |
| 1605 | SkIRect srcBounds = SkIRect::MakeWH(src->width(), src->height()); |
| 1606 | if (!srcRect.intersect(srcBounds)) { |
| 1607 | return; |
| 1608 | } |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 1609 | |
| 1610 | GrDrawTarget* target = this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); |
| 1611 | if (NULL == target) { |
| 1612 | return; |
| 1613 | } |
| 1614 | SkIPoint dstPoint; |
| 1615 | dstPoint.setZero(); |
| 1616 | target->copySurface(dst, src, srcRect, dstPoint); |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 1617 | } |
| 1618 | |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1619 | bool GrContext::writeRenderTargetPixels(GrRenderTarget* renderTarget, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1620 | int left, int top, int width, int height, |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1621 | GrPixelConfig srcConfig, |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1622 | const void* buffer, |
| 1623 | size_t rowBytes, |
| 1624 | uint32_t flags) { |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1625 | ASSERT_OWNED_RESOURCE(renderTarget); |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1626 | |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1627 | if (NULL == renderTarget) { |
| 1628 | renderTarget = fRenderTarget.get(); |
| 1629 | if (NULL == renderTarget) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1630 | return false; |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 1631 | } |
| 1632 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1633 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1634 | // TODO: when underlying api has a direct way to do this we should use it (e.g. glDrawPixels on |
| 1635 | // desktop GL). |
| 1636 | |
| 1637 | // We will always call some form of writeTexturePixels and we will pass our flags on to it. |
| 1638 | // Thus, we don't perform a flush here since that call will do it (if the kNoFlush flag isn't |
| 1639 | // set.) |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1640 | |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 1641 | // If the RT is also a texture and we don't have to premultiply then take the texture path. |
| 1642 | // We expect to be at least as fast or faster since it doesn't use an intermediate texture as |
| 1643 | // we do below. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1644 | |
commit-bot@chromium.org | 4382330 | 2013-09-25 20:57:51 +0000 | [diff] [blame] | 1645 | #if !defined(SK_BUILD_FOR_MAC) |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1646 | // At least some drivers on the Mac get confused when glTexImage2D is called on a texture |
| 1647 | // attached to an FBO. The FBO still sees the old image. TODO: determine what OS versions and/or |
| 1648 | // HW is affected. |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1649 | if (renderTarget->asTexture() && !(kUnpremul_PixelOpsFlag & flags) && |
| 1650 | fGpu->canWriteTexturePixels(renderTarget->asTexture(), srcConfig)) { |
| 1651 | return this->writeTexturePixels(renderTarget->asTexture(), |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1652 | left, top, width, height, |
| 1653 | srcConfig, buffer, rowBytes, flags); |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1654 | } |
| 1655 | #endif |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1656 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1657 | // We ignore the preferred config unless it is a R/B swap of the src config. In that case |
| 1658 | // we will upload the original src data to a scratch texture but we will spoof it as the swapped |
| 1659 | // config. This scratch will then have R and B swapped. We correct for this by swapping again |
| 1660 | // when drawing the scratch to the dst using a conversion effect. |
| 1661 | bool swapRAndB = false; |
| 1662 | GrPixelConfig writeConfig = srcConfig; |
commit-bot@chromium.org | 5d1d79a | 2013-05-24 18:52:52 +0000 | [diff] [blame] | 1663 | if (GrPixelConfigSwapRAndB(srcConfig) == |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1664 | fGpu->preferredWritePixelsConfig(srcConfig, renderTarget->config())) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1665 | writeConfig = GrPixelConfigSwapRAndB(srcConfig); |
| 1666 | swapRAndB = true; |
bsalomon@google.com | a85449d | 2011-11-19 02:36:05 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
robertphillips@google.com | 75b3c96 | 2012-06-07 12:08:45 +0000 | [diff] [blame] | 1669 | GrTextureDesc desc; |
| 1670 | desc.fWidth = width; |
| 1671 | desc.fHeight = height; |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1672 | desc.fConfig = writeConfig; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 1673 | GrAutoScratchTexture ast(this, desc); |
| 1674 | GrTexture* texture = ast.texture(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1675 | if (NULL == texture) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1676 | return false; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1677 | } |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1678 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1679 | SkAutoTUnref<const GrFragmentProcessor> fp; |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 1680 | SkMatrix textureMatrix; |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 1681 | textureMatrix.setIDiv(texture->width(), texture->height()); |
| 1682 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1683 | // allocate a tmp buffer and sw convert the pixels to premul |
| 1684 | SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 1685 | |
| 1686 | if (kUnpremul_PixelOpsFlag & flags) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1687 | if (!GrPixelConfigIs8888(srcConfig)) { |
| 1688 | return false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1689 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1690 | fp.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix)); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1691 | // handle the unpremul step on the CPU if we couldn't create an effect to do it. |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1692 | if (NULL == fp) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1693 | SkSrcPixelInfo srcPI; |
| 1694 | if (!GrPixelConfig2ColorType(srcConfig, &srcPI.fColorType)) { |
| 1695 | return false; |
| 1696 | } |
| 1697 | srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| 1698 | srcPI.fPixels = buffer; |
| 1699 | srcPI.fRowBytes = rowBytes; |
| 1700 | |
commit-bot@chromium.org | 231f6b8 | 2014-03-25 13:38:44 +0000 | [diff] [blame] | 1701 | tmpPixels.reset(width * height); |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 1702 | |
| 1703 | SkDstPixelInfo dstPI; |
| 1704 | dstPI.fColorType = srcPI.fColorType; |
| 1705 | dstPI.fAlphaType = kPremul_SkAlphaType; |
| 1706 | dstPI.fPixels = tmpPixels.get(); |
| 1707 | dstPI.fRowBytes = 4 * width; |
| 1708 | |
| 1709 | if (!srcPI.convertPixelsTo(&dstPI, width, height)) { |
| 1710 | return false; |
| 1711 | } |
| 1712 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1713 | buffer = tmpPixels.get(); |
| 1714 | rowBytes = 4 * width; |
| 1715 | } |
| 1716 | } |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1717 | if (NULL == fp) { |
| 1718 | fp.reset(GrConfigConversionEffect::Create(texture, |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1719 | swapRAndB, |
| 1720 | GrConfigConversionEffect::kNone_PMConversion, |
| 1721 | textureMatrix)); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1724 | if (!this->writeTexturePixels(texture, |
| 1725 | 0, 0, width, height, |
| 1726 | writeConfig, buffer, rowBytes, |
| 1727 | flags & ~kUnpremul_PixelOpsFlag)) { |
| 1728 | return false; |
| 1729 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1730 | |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1731 | SkMatrix matrix; |
| 1732 | matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1733 | |
| 1734 | // This function can be called in the midst of drawing another object (e.g., when uploading a |
| 1735 | // SW-rasterized clip while issuing a draw). So we push the current geometry state before |
| 1736 | // drawing a rect to the render target. |
| 1737 | GrDrawTarget* drawTarget = this->prepareToDraw(NULL, kYes_BufferedDraw, NULL, NULL); |
| 1738 | GrDrawTarget::AutoGeometryAndStatePush agasp(drawTarget, GrDrawTarget::kReset_ASRInit, &matrix); |
| 1739 | GrDrawState* drawState = drawTarget->drawState(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1740 | drawState->addColorProcessor(fp); |
bsalomon | 656f2cd | 2014-09-29 11:01:58 -0700 | [diff] [blame] | 1741 | drawState->setRenderTarget(renderTarget); |
| 1742 | drawState->disableState(GrDrawState::kClip_StateBit); |
| 1743 | drawTarget->drawSimpleRect(SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height))); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 1744 | return true; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1745 | } |
| 1746 | //////////////////////////////////////////////////////////////////////////////// |
| 1747 | |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1748 | GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint, |
| 1749 | BufferedDraw buffered, |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1750 | AutoRestoreEffects* are, |
| 1751 | AutoCheckFlush* acf) { |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1752 | // All users of this draw state should be freeing up all effects when they're done. |
| 1753 | // Otherwise effects that own resources may keep those resources alive indefinitely. |
joshualitt | bd769d0 | 2014-09-04 08:56:46 -0700 | [diff] [blame] | 1754 | SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageStages() && |
| 1755 | !fDrawState->hasGeometryProcessor()); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1756 | |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 1757 | if (NULL == fGpu) { |
| 1758 | return NULL; |
| 1759 | } |
| 1760 | |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 1761 | if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffered) { |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 1762 | fDrawBuffer->flush(); |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 1763 | fLastDrawWasBuffered = kNo_BufferedDraw; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1764 | } |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1765 | ASSERT_OWNED_RESOURCE(fRenderTarget.get()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1766 | if (paint) { |
| 1767 | SkASSERT(are); |
| 1768 | SkASSERT(acf); |
bsalomon@google.com | eb6879f | 2013-06-13 19:34:18 +0000 | [diff] [blame] | 1769 | are->set(fDrawState); |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1770 | fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get()); |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1771 | #if GR_DEBUG_PARTIAL_COVERAGE_CHECK |
| 1772 | if ((paint->hasMask() || 0xff != paint->fCoverage) && |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 1773 | !fDrawState->couldApplyCoverage(fGpu->caps())) { |
bsalomon@google.com | af84e74 | 2012-10-05 13:23:24 +0000 | [diff] [blame] | 1774 | GrPrintf("Partial pixel coverage will be incorrectly blended.\n"); |
| 1775 | } |
| 1776 | #endif |
bsalomon | 9c0822a | 2014-08-11 11:07:48 -0700 | [diff] [blame] | 1777 | // Clear any vertex attributes configured for the previous use of the |
| 1778 | // GrDrawState which can effect which blend optimizations are in effect. |
| 1779 | fDrawState->setDefaultVertexAttribs(); |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1780 | } else { |
bsalomon@google.com | 137f134 | 2013-05-29 21:27:53 +0000 | [diff] [blame] | 1781 | fDrawState->reset(fViewMatrix); |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1782 | fDrawState->setRenderTarget(fRenderTarget.get()); |
bsalomon@google.com | 07ea2db | 2012-08-17 14:06:49 +0000 | [diff] [blame] | 1783 | } |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1784 | GrDrawTarget* target; |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 1785 | if (kYes_BufferedDraw == buffered) { |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 1786 | fLastDrawWasBuffered = kYes_BufferedDraw; |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1787 | target = fDrawBuffer; |
bsalomon@google.com | 1d4edd3 | 2012-08-16 18:36:06 +0000 | [diff] [blame] | 1788 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1789 | SkASSERT(kNo_BufferedDraw == buffered); |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1790 | fLastDrawWasBuffered = kNo_BufferedDraw; |
| 1791 | target = fGpu; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1792 | } |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1793 | fDrawState->setState(GrDrawState::kClip_StateBit, fClip && |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1794 | !fClip->fClipStack->isWideOpen()); |
| 1795 | target->setClip(fClip); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1796 | SkASSERT(fDrawState == target->drawState()); |
commit-bot@chromium.org | bb6a317 | 2013-05-28 17:25:49 +0000 | [diff] [blame] | 1797 | return target; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1798 | } |
| 1799 | |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1800 | /* |
| 1801 | * This method finds a path renderer that can draw the specified path on |
| 1802 | * the provided target. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 1803 | * Due to its expense, the software path renderer has split out so it can |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1804 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 1805 | */ |
bsalomon@google.com | 8d033a1 | 2012-04-27 15:52:53 +0000 | [diff] [blame] | 1806 | GrPathRenderer* GrContext::getPathRenderer(const SkPath& path, |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 1807 | const SkStrokeRec& stroke, |
bsalomon@google.com | c2099d2 | 2012-03-02 21:26:50 +0000 | [diff] [blame] | 1808 | const GrDrawTarget* target, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1809 | bool allowSW, |
| 1810 | GrPathRendererChain::DrawType drawType, |
| 1811 | GrPathRendererChain::StencilSupport* stencilSupport) { |
| 1812 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1813 | if (NULL == fPathRendererChain) { |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1814 | fPathRendererChain = SkNEW_ARGS(GrPathRendererChain, (this)); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1815 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1816 | |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 1817 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(path, |
| 1818 | stroke, |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1819 | target, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 1820 | drawType, |
| 1821 | stencilSupport); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1822 | |
| 1823 | if (NULL == pr && allowSW) { |
| 1824 | if (NULL == fSoftwarePathRenderer) { |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1825 | fSoftwarePathRenderer = SkNEW_ARGS(GrSoftwarePathRenderer, (this)); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1826 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 1827 | pr = fSoftwarePathRenderer; |
| 1828 | } |
| 1829 | |
| 1830 | return pr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 1831 | } |
| 1832 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1833 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | 6b7938f | 2013-10-15 14:18:16 +0000 | [diff] [blame] | 1834 | bool GrContext::isConfigRenderable(GrPixelConfig config, bool withMSAA) const { |
| 1835 | return fGpu->caps()->isConfigRenderable(config, withMSAA); |
robertphillips@google.com | 99a5ac0 | 2012-04-10 19:26:38 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 1838 | int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 1839 | SkScalar dpi) const { |
| 1840 | if (!this->isConfigRenderable(config, true)) { |
| 1841 | return 0; |
| 1842 | } |
| 1843 | int chosenSampleCount = 0; |
| 1844 | if (fGpu->caps()->pathRenderingSupport()) { |
| 1845 | if (dpi >= 250.0f) { |
| 1846 | chosenSampleCount = 4; |
| 1847 | } else { |
| 1848 | chosenSampleCount = 16; |
| 1849 | } |
| 1850 | } |
| 1851 | return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? |
| 1852 | chosenSampleCount : 0; |
| 1853 | } |
| 1854 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1855 | void GrContext::setupDrawBuffer() { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 1856 | SkASSERT(NULL == fDrawBuffer); |
| 1857 | SkASSERT(NULL == fDrawBufferVBAllocPool); |
| 1858 | SkASSERT(NULL == fDrawBufferIBAllocPool); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 1859 | |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1860 | fDrawBufferVBAllocPool = |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1861 | SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu, false, |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1862 | DRAW_BUFFER_VBPOOL_BUFFER_SIZE, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1863 | DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS)); |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1864 | fDrawBufferIBAllocPool = |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1865 | SkNEW_ARGS(GrIndexBufferAllocPool, (fGpu, false, |
bsalomon@google.com | de6ac2d | 2011-02-25 21:50:42 +0000 | [diff] [blame] | 1866 | DRAW_BUFFER_IBPOOL_BUFFER_SIZE, |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1867 | DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS)); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1868 | |
tomhudson@google.com | c377baf | 2012-07-09 20:17:56 +0000 | [diff] [blame] | 1869 | fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu, |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1870 | fDrawBufferVBAllocPool, |
| 1871 | fDrawBufferIBAllocPool)); |
bsalomon@google.com | 3c4d032 | 2012-04-03 18:04:51 +0000 | [diff] [blame] | 1872 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 1873 | fDrawBuffer->setDrawState(fDrawState); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
bsalomon@google.com | 21c10c5 | 2013-06-13 17:44:07 +0000 | [diff] [blame] | 1876 | GrDrawTarget* GrContext::getTextTarget() { |
commit-bot@chromium.org | 5dbb149 | 2013-10-04 16:23:58 +0000 | [diff] [blame] | 1877 | return this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | const GrIndexBuffer* GrContext::getQuadIndexBuffer() const { |
| 1881 | return fGpu->getQuadIndexBuffer(); |
| 1882 | } |
bsalomon@google.com | dfe75bc | 2011-03-25 12:31:16 +0000 | [diff] [blame] | 1883 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1884 | namespace { |
| 1885 | void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 1886 | GrConfigConversionEffect::PMConversion pmToUPM; |
| 1887 | GrConfigConversionEffect::PMConversion upmToPM; |
| 1888 | GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upmToPM); |
| 1889 | *pmToUPMValue = pmToUPM; |
| 1890 | *upmToPMValue = upmToPM; |
| 1891 | } |
| 1892 | } |
| 1893 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1894 | const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
| 1895 | bool swapRAndB, |
| 1896 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1897 | if (!fDidTestPMConversions) { |
| 1898 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
bsalomon@google.com | d0f3f68 | 2012-08-28 13:08:14 +0000 | [diff] [blame] | 1899 | fDidTestPMConversions = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1900 | } |
| 1901 | GrConfigConversionEffect::PMConversion pmToUPM = |
| 1902 | static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 1903 | if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1904 | return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1905 | } else { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1906 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1910 | const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
| 1911 | bool swapRAndB, |
| 1912 | const SkMatrix& matrix) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1913 | if (!fDidTestPMConversions) { |
| 1914 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
bsalomon@google.com | d0f3f68 | 2012-08-28 13:08:14 +0000 | [diff] [blame] | 1915 | fDidTestPMConversions = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1916 | } |
| 1917 | GrConfigConversionEffect::PMConversion upmToPM = |
| 1918 | static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 1919 | if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1920 | return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1921 | } else { |
bsalomon@google.com | adc6536 | 2013-01-28 14:26:09 +0000 | [diff] [blame] | 1922 | return NULL; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 1923 | } |
| 1924 | } |
| 1925 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 1926 | void GrContext::addResourceToCache(const GrResourceKey& resourceKey, GrGpuResource* resource) { |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 1927 | fResourceCache->purgeAsNeeded(1, resource->gpuMemorySize()); |
| 1928 | fResourceCache->addResource(resourceKey, resource); |
commit-bot@chromium.org | 95a2b0e | 2014-05-05 19:21:16 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
bsalomon | 6d3fe02 | 2014-07-25 08:35:45 -0700 | [diff] [blame] | 1931 | GrGpuResource* GrContext::findAndRefCachedResource(const GrResourceKey& resourceKey) { |
| 1932 | GrGpuResource* resource = fResourceCache->find(resourceKey); |
commit-bot@chromium.org | 95a2b0e | 2014-05-05 19:21:16 +0000 | [diff] [blame] | 1933 | SkSafeRef(resource); |
| 1934 | return resource; |
| 1935 | } |
| 1936 | |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1937 | void GrContext::addGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1938 | fGpu->addGpuTraceMarker(marker); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1939 | if (fDrawBuffer) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1940 | fDrawBuffer->addGpuTraceMarker(marker); |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | void GrContext::removeGpuTraceMarker(const GrGpuTraceMarker* marker) { |
| 1945 | fGpu->removeGpuTraceMarker(marker); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 1946 | if (fDrawBuffer) { |
egdaniel | bbcb38d | 2014-06-19 10:19:29 -0700 | [diff] [blame] | 1947 | fDrawBuffer->removeGpuTraceMarker(marker); |
| 1948 | } |
| 1949 | } |
| 1950 | |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 1951 | /////////////////////////////////////////////////////////////////////////////// |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 1952 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1953 | void GrContext::printCacheStats() const { |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 1954 | fResourceCache->printStats(); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 1955 | } |
| 1956 | #endif |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 1957 | |
| 1958 | #if GR_GPU_STATS |
| 1959 | const GrContext::GPUStats* GrContext::gpuStats() const { |
| 1960 | return fGpu->gpuStats(); |
| 1961 | } |
| 1962 | #endif |
| 1963 | |