bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 8 | #include "GrContext.h" |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame^] | 9 | #include "GrContextPriv.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 10 | #include "GrContextOptions.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 11 | #include "GrDrawingManager.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 12 | #include "GrDrawContext.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 13 | #include "GrResourceCache.h" |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 14 | #include "GrResourceProvider.h" |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 15 | #include "GrSoftwarePathRenderer.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 16 | #include "GrSurfacePriv.h" |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 17 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 18 | #include "SkConfig8888.h" |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 19 | #include "SkGrPriv.h" |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 20 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 21 | #include "batches/GrCopySurfaceBatch.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 22 | #include "effects/GrConfigConversionEffect.h" |
brianosman | 2d1ee79 | 2016-05-05 12:24:31 -0700 | [diff] [blame] | 23 | #include "effects/GrGammaEffect.h" |
joshualitt | e804292 | 2015-12-11 06:11:21 -0800 | [diff] [blame] | 24 | #include "text/GrTextBlobCache.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 25 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 26 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 27 | #define ASSERT_SINGLE_OWNER \ |
| 28 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fSingleOwner);) |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame^] | 29 | #define ASSERT_SINGLE_OWNER_PRIV \ |
| 30 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(&fContext->fSingleOwner);) |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 31 | #define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; } |
| 32 | #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; } |
| 33 | #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; } |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 34 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 35 | //////////////////////////////////////////////////////////////////////////////// |
| 36 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 37 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { |
| 38 | GrContextOptions defaultOptions; |
| 39 | return Create(backend, backendContext, defaultOptions); |
| 40 | } |
bsalomon | f28cff7 | 2015-05-22 12:25:41 -0700 | [diff] [blame] | 41 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 42 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
| 43 | const GrContextOptions& options) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 44 | GrContext* context = new GrContext; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 45 | |
| 46 | if (context->init(backend, backendContext, options)) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 47 | return context; |
| 48 | } else { |
| 49 | context->unref(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 50 | return nullptr; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 51 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 52 | } |
| 53 | |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 54 | static int32_t gNextID = 1; |
| 55 | static int32_t next_id() { |
| 56 | int32_t id; |
| 57 | do { |
| 58 | id = sk_atomic_inc(&gNextID); |
| 59 | } while (id == SK_InvalidGenID); |
| 60 | return id; |
| 61 | } |
| 62 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 63 | GrContext::GrContext() : fUniqueID(next_id()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 64 | fGpu = nullptr; |
| 65 | fCaps = nullptr; |
| 66 | fResourceCache = nullptr; |
| 67 | fResourceProvider = nullptr; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 68 | fBatchFontCache = nullptr; |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 69 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 70 | } |
| 71 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 72 | bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 73 | const GrContextOptions& options) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 74 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 75 | SkASSERT(!fGpu); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 76 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 77 | fGpu = GrGpu::Create(backend, backendContext, options, this); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 78 | if (!fGpu) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 79 | return false; |
| 80 | } |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 81 | this->initCommon(options); |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 82 | return true; |
| 83 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 84 | |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 85 | void GrContext::initCommon(const GrContextOptions& options) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 86 | ASSERT_SINGLE_OWNER |
| 87 | |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 88 | fCaps = SkRef(fGpu->caps()); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 89 | fResourceCache = new GrResourceCache(fCaps); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 90 | fResourceCache->setOverBudgetCallback(OverBudgetCB, this); |
joshualitt | 6d0872d | 2016-01-11 08:27:48 -0800 | [diff] [blame] | 91 | fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwner); |
commit-bot@chromium.org | 1836d33 | 2013-07-16 22:55:03 +0000 | [diff] [blame] | 92 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 93 | fDidTestPMConversions = false; |
| 94 | |
bsalomon | 69cfe95 | 2015-11-30 13:27:47 -0800 | [diff] [blame] | 95 | GrDrawTarget::Options dtOptions; |
| 96 | dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; |
bsalomon | 6dea83f | 2015-12-03 12:58:06 -0800 | [diff] [blame] | 97 | dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 98 | dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 99 | dtOptions.fMaxBatchLookahead = options.fMaxBatchLookahead; |
joshualitt | de8dc7e | 2016-01-08 10:09:13 -0800 | [diff] [blame] | 100 | fDrawingManager.reset(new GrDrawingManager(this, dtOptions, &fSingleOwner)); |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 101 | |
| 102 | // GrBatchFontCache will eventually replace GrFontCache |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 103 | fBatchFontCache = new GrBatchFontCache(this); |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 104 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 105 | fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 106 | } |
| 107 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 108 | GrContext::~GrContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 109 | ASSERT_SINGLE_OWNER |
| 110 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 111 | if (!fGpu) { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 112 | SkASSERT(!fCaps); |
bsalomon@google.com | 733c062 | 2013-04-24 17:59:32 +0000 | [diff] [blame] | 113 | return; |
| 114 | } |
| 115 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 116 | this->flush(); |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 117 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 118 | fDrawingManager->cleanup(); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 119 | |
robertphillips@google.com | 950b1b0 | 2013-10-21 17:37:28 +0000 | [diff] [blame] | 120 | for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 121 | (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 122 | } |
| 123 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 124 | delete fResourceProvider; |
| 125 | delete fResourceCache; |
| 126 | delete fBatchFontCache; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 127 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 128 | fGpu->unref(); |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 129 | fCaps->unref(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 130 | } |
| 131 | |
bsalomon | 41b952c | 2016-03-11 06:46:33 -0800 | [diff] [blame] | 132 | GrContextThreadSafeProxy* GrContext::threadSafeProxy() { |
| 133 | if (!fThreadSafeProxy) { |
| 134 | fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->uniqueID())); |
| 135 | } |
| 136 | return SkRef(fThreadSafeProxy.get()); |
| 137 | } |
| 138 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 139 | void GrContext::abandonContext() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 140 | ASSERT_SINGLE_OWNER |
| 141 | |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 142 | fResourceProvider->abandon(); |
robertphillips | 0dfa62c | 2015-11-16 06:23:31 -0800 | [diff] [blame] | 143 | |
| 144 | // Need to abandon the drawing manager first so all the render targets |
| 145 | // will be released/forgotten before they too are abandoned. |
| 146 | fDrawingManager->abandon(); |
| 147 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 148 | // abandon first to so destructors |
| 149 | // don't try to free the resources in the API. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 150 | fResourceCache->abandonAll(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 151 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 152 | fGpu->disconnect(GrGpu::DisconnectType::kAbandon); |
| 153 | |
| 154 | fBatchFontCache->freeAll(); |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 155 | fTextBlobCache->freeAll(); |
| 156 | } |
| 157 | |
| 158 | void GrContext::releaseResourcesAndAbandonContext() { |
| 159 | ASSERT_SINGLE_OWNER |
| 160 | |
| 161 | fResourceProvider->abandon(); |
| 162 | |
| 163 | // Need to abandon the drawing manager first so all the render targets |
| 164 | // will be released/forgotten before they too are abandoned. |
| 165 | fDrawingManager->abandon(); |
| 166 | |
| 167 | // Release all resources in the backend 3D API. |
| 168 | fResourceCache->releaseAll(); |
| 169 | |
| 170 | fGpu->disconnect(GrGpu::DisconnectType::kCleanup); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 171 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 172 | fBatchFontCache->freeAll(); |
joshualitt | 26ffc00 | 2015-04-16 11:24:04 -0700 | [diff] [blame] | 173 | fTextBlobCache->freeAll(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 174 | } |
| 175 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 176 | void GrContext::resetContext(uint32_t state) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 177 | ASSERT_SINGLE_OWNER |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 178 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | void GrContext::freeGpuResources() { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 182 | ASSERT_SINGLE_OWNER |
| 183 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 184 | this->flush(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 185 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 186 | fBatchFontCache->freeAll(); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 187 | |
| 188 | fDrawingManager->freeGpuResources(); |
bsalomon | 3033b9f | 2015-04-13 11:09:56 -0700 | [diff] [blame] | 189 | |
| 190 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 191 | } |
| 192 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 193 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 194 | ASSERT_SINGLE_OWNER |
| 195 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 196 | if (resourceCount) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 197 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 198 | } |
| 199 | if (resourceBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 200 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 201 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 202 | } |
| 203 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 204 | //////////////////////////////////////////////////////////////////////////////// |
| 205 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 206 | void GrContext::OverBudgetCB(void* data) { |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 207 | SkASSERT(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 208 | |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 209 | GrContext* context = reinterpret_cast<GrContext*>(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 210 | |
joshualitt | b542bae | 2015-07-28 09:58:39 -0700 | [diff] [blame] | 211 | // Flush the GrBufferedDrawTarget to possibly free up some textures |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 212 | context->fFlushToReduceCacheSize = true; |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 213 | } |
| 214 | |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 215 | void GrContext::TextBlobCacheOverBudgetCB(void* data) { |
| 216 | SkASSERT(data); |
| 217 | |
| 218 | // Unlike the GrResourceCache, TextBlobs are drawn at the SkGpuDevice level, therefore they |
| 219 | // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The solution is to move |
| 220 | // drawText calls to below the GrContext level, but this is not trivial because they call |
| 221 | // drawPath on SkGpuDevice |
| 222 | GrContext* context = reinterpret_cast<GrContext*>(data); |
| 223 | context->flush(); |
| 224 | } |
| 225 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 226 | //////////////////////////////////////////////////////////////////////////////// |
| 227 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 228 | void GrContext::flush(int flagsBitfield) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 229 | ASSERT_SINGLE_OWNER |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 230 | RETURN_IF_ABANDONED |
robertphillips@google.com | e7db8d6 | 2013-07-04 11:48:52 +0000 | [diff] [blame] | 231 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 232 | if (kDiscard_FlushBit & flagsBitfield) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 233 | fDrawingManager->reset(); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 234 | } else { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 235 | fDrawingManager->flush(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 236 | } |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 237 | fResourceCache->notifyFlushOccurred(); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 238 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 239 | } |
| 240 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 241 | bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, |
| 242 | const void* inPixels, size_t outRowBytes, void* outPixels) { |
| 243 | SkSrcPixelInfo srcPI; |
brianosman | 396fcdb | 2016-07-22 06:26:11 -0700 | [diff] [blame] | 244 | if (!GrPixelConfigToColorType(srcConfig, &srcPI.fColorType)) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 245 | return false; |
| 246 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 247 | srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| 248 | srcPI.fPixels = inPixels; |
| 249 | srcPI.fRowBytes = inRowBytes; |
| 250 | |
| 251 | SkDstPixelInfo dstPI; |
| 252 | dstPI.fColorType = srcPI.fColorType; |
| 253 | dstPI.fAlphaType = kPremul_SkAlphaType; |
| 254 | dstPI.fPixels = outPixels; |
| 255 | dstPI.fRowBytes = outRowBytes; |
| 256 | |
| 257 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 258 | } |
| 259 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 260 | bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 261 | int left, int top, int width, int height, |
| 262 | GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, |
| 263 | uint32_t pixelOpsFlags) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 264 | ASSERT_SINGLE_OWNER |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 265 | RETURN_FALSE_IF_ABANDONED |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 266 | ASSERT_OWNED_RESOURCE(surface); |
| 267 | SkASSERT(surface); |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 268 | GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::writeSurfacePixels"); |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 269 | |
| 270 | this->testPMConversionsIfNecessary(pixelOpsFlags); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 271 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 272 | // Trim the params here so that if we wind up making a temporary surface it can be as small as |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 273 | // necessary and because GrGpu::getWritePixelsInfo requires it. |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 274 | if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height(), |
| 275 | GrBytesPerPixel(srcConfig), &left, &top, &width, |
| 276 | &height, &buffer, &rowBytes)) { |
| 277 | return false; |
| 278 | } |
| 279 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 280 | bool applyPremulToSrc = false; |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 281 | if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
| 282 | if (!GrPixelConfigIs8888(srcConfig)) { |
| 283 | return false; |
| 284 | } |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 285 | applyPremulToSrc = true; |
| 286 | } |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 287 | |
| 288 | GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; |
| 289 | // Don't prefer to draw for the conversion (and thereby access a texture from the cache) when |
| 290 | // we've already determined that there isn't a roundtrip preserving conversion processor pair. |
| 291 | if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { |
| 292 | drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
| 293 | } |
| 294 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 295 | GrGpu::WritePixelTempDrawInfo tempDrawInfo; |
cblume | ed82800 | 2016-02-16 13:00:01 -0800 | [diff] [blame] | 296 | if (!fGpu->getWritePixelsInfo(surface, width, height, srcConfig, &drawPreference, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 297 | &tempDrawInfo)) { |
| 298 | return false; |
| 299 | } |
| 300 | |
| 301 | if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().hasPendingIO()) { |
| 302 | this->flush(); |
| 303 | } |
| 304 | |
| 305 | SkAutoTUnref<GrTexture> tempTexture; |
| 306 | if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 307 | tempTexture.reset( |
| 308 | this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfaceDesc)); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 309 | if (!tempTexture && GrGpu::kRequireDraw_DrawPreference == drawPreference) { |
| 310 | return false; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | // temp buffer for doing sw premul conversion, if needed. |
| 315 | SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 316 | if (tempTexture) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 317 | sk_sp<GrFragmentProcessor> fp; |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 318 | SkMatrix textureMatrix; |
| 319 | textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 320 | if (applyPremulToSrc) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 321 | fp = this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwizzle, textureMatrix); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 322 | // If premultiplying was the only reason for the draw, fall back to a straight write. |
| 323 | if (!fp) { |
| 324 | if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 325 | tempTexture.reset(nullptr); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 326 | } |
| 327 | } else { |
| 328 | applyPremulToSrc = false; |
| 329 | } |
| 330 | } |
| 331 | if (tempTexture) { |
| 332 | if (!fp) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 333 | fp = GrConfigConversionEffect::Make(tempTexture, tempDrawInfo.fSwizzle, |
| 334 | GrConfigConversionEffect::kNone_PMConversion, |
| 335 | textureMatrix); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 336 | if (!fp) { |
| 337 | return false; |
| 338 | } |
| 339 | } |
| 340 | GrRenderTarget* renderTarget = surface->asRenderTarget(); |
| 341 | SkASSERT(renderTarget); |
| 342 | if (tempTexture->surfacePriv().hasPendingIO()) { |
| 343 | this->flush(); |
| 344 | } |
| 345 | if (applyPremulToSrc) { |
| 346 | size_t tmpRowBytes = 4 * width; |
| 347 | tmpPixels.reset(width * height); |
| 348 | if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer, tmpRowBytes, |
| 349 | tmpPixels.get())) { |
| 350 | return false; |
| 351 | } |
| 352 | rowBytes = tmpRowBytes; |
| 353 | buffer = tmpPixels.get(); |
| 354 | applyPremulToSrc = false; |
| 355 | } |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 356 | if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 357 | tempDrawInfo.fWriteConfig, buffer, |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 358 | rowBytes)) { |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | SkMatrix matrix; |
| 362 | matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 363 | // TODO: Need to decide the semantics of this function for color spaces. Do we support |
| 364 | // conversion from a passed-in color space? For now, specifying nullptr means that this |
| 365 | // path will do no conversion, so it will match the behavior of the non-draw path. |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame^] | 366 | sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( |
| 367 | sk_ref_sp(renderTarget), |
| 368 | nullptr)); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 369 | if (!drawContext) { |
| 370 | return false; |
| 371 | } |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 372 | GrPaint paint; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 373 | paint.addColorFragmentProcessor(std::move(fp)); |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 374 | paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
brianosman | a167e74 | 2016-05-24 06:18:48 -0700 | [diff] [blame] | 375 | paint.setAllowSRGBInputs(true); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 376 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
cdalton | 846c051 | 2016-05-13 10:25:00 -0700 | [diff] [blame] | 377 | drawContext->drawRect(GrNoClip(), paint, matrix, rect, nullptr); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 378 | |
| 379 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 380 | this->flushSurfaceWrites(surface); |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | if (!tempTexture) { |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 385 | if (applyPremulToSrc) { |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 386 | size_t tmpRowBytes = 4 * width; |
| 387 | tmpPixels.reset(width * height); |
| 388 | if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer, tmpRowBytes, |
| 389 | tmpPixels.get())) { |
| 390 | return false; |
| 391 | } |
| 392 | rowBytes = tmpRowBytes; |
| 393 | buffer = tmpPixels.get(); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 394 | applyPremulToSrc = false; |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 395 | } |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 396 | return fGpu->writePixels(surface, left, top, width, height, srcConfig, buffer, rowBytes); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 397 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 398 | return true; |
| 399 | } |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 400 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 401 | bool GrContext::readSurfacePixels(GrSurface* src, |
| 402 | int left, int top, int width, int height, |
| 403 | GrPixelConfig dstConfig, void* buffer, size_t rowBytes, |
| 404 | uint32_t flags) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 405 | ASSERT_SINGLE_OWNER |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 406 | RETURN_FALSE_IF_ABANDONED |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 407 | ASSERT_OWNED_RESOURCE(src); |
| 408 | SkASSERT(src); |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 409 | GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::readSurfacePixels"); |
bsalomon | 32ab260 | 2015-09-09 18:57:49 -0700 | [diff] [blame] | 410 | |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 411 | this->testPMConversionsIfNecessary(flags); |
| 412 | SkAutoMutexAcquire ama(fReadPixelsMutex); |
| 413 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 414 | // Adjust the params so that if we wind up using an intermediate surface we've already done |
| 415 | // all the trimming and the temporary can be the min size required. |
| 416 | if (!GrSurfacePriv::AdjustReadPixelParams(src->width(), src->height(), |
| 417 | GrBytesPerPixel(dstConfig), &left, |
| 418 | &top, &width, &height, &buffer, &rowBytes)) { |
| 419 | return false; |
| 420 | } |
| 421 | |
| 422 | if (!(kDontFlush_PixelOpsFlag & flags) && src->surfacePriv().hasPendingWrite()) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 423 | this->flush(); |
| 424 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 425 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 426 | bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 427 | if (unpremul && !GrPixelConfigIs8888(dstConfig)) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 428 | // The unpremul flag is only allowed for 8888 configs. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 429 | return false; |
| 430 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 431 | |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 432 | GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; |
| 433 | // Don't prefer to draw for the conversion (and thereby access a texture from the cache) when |
| 434 | // we've already determined that there isn't a roundtrip preserving conversion processor pair. |
| 435 | if (unpremul && !this->didFailPMUPMConversionTest()) { |
| 436 | drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
| 437 | } |
| 438 | |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 439 | GrGpu::ReadPixelTempDrawInfo tempDrawInfo; |
| 440 | if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawPreference, |
| 441 | &tempDrawInfo)) { |
| 442 | return false; |
| 443 | } |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 444 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 445 | SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 446 | bool didTempDraw = false; |
| 447 | if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 448 | if (SkBackingFit::kExact == tempDrawInfo.fTempSurfaceFit) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 449 | // We only respect this when the entire src is being read. Otherwise we can trigger too |
| 450 | // many odd ball texture sizes and trash the cache. |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 451 | if (width != src->width() || height != src->height()) { |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 452 | tempDrawInfo.fTempSurfaceFit= SkBackingFit::kApprox; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 453 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 454 | } |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 455 | // TODO: Need to decide the semantics of this function for color spaces. Do we support |
| 456 | // conversion to a passed-in color space? For now, specifying nullptr means that this |
| 457 | // path will do no conversion, so it will match the behavior of the non-draw path. |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 458 | sk_sp<GrDrawContext> tempDC = this->makeDrawContext(tempDrawInfo.fTempSurfaceFit, |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 459 | tempDrawInfo.fTempSurfaceDesc.fWidth, |
| 460 | tempDrawInfo.fTempSurfaceDesc.fHeight, |
| 461 | tempDrawInfo.fTempSurfaceDesc.fConfig, |
brianosman | dfe4f2e | 2016-07-21 13:28:36 -0700 | [diff] [blame] | 462 | nullptr, |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 463 | tempDrawInfo.fTempSurfaceDesc.fSampleCnt, |
| 464 | tempDrawInfo.fTempSurfaceDesc.fOrigin); |
| 465 | if (tempDC) { |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 466 | SkMatrix textureMatrix; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 467 | textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 468 | textureMatrix.postIDiv(src->width(), src->height()); |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 469 | sk_sp<GrFragmentProcessor> fp; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 470 | if (unpremul) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 471 | fp = this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fSwizzle, |
| 472 | textureMatrix); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 473 | if (fp) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 474 | unpremul = false; // we no longer need to do this on CPU after the read back. |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 475 | } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) { |
| 476 | // We only wanted to do the draw in order to perform the unpremul so don't |
| 477 | // bother. |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 478 | tempDC.reset(nullptr); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 479 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 480 | } |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 481 | if (!fp && tempDC) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 482 | fp = GrConfigConversionEffect::Make(src->asTexture(), tempDrawInfo.fSwizzle, |
| 483 | GrConfigConversionEffect::kNone_PMConversion, |
| 484 | textureMatrix); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 485 | } |
| 486 | if (fp) { |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 487 | GrPaint paint; |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 488 | paint.addColorFragmentProcessor(std::move(fp)); |
egdaniel | c4b7272 | 2015-11-23 13:20:41 -0800 | [diff] [blame] | 489 | paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
brianosman | a167e74 | 2016-05-24 06:18:48 -0700 | [diff] [blame] | 490 | paint.setAllowSRGBInputs(true); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 491 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
bsalomon | b117ff1 | 2016-07-19 07:24:40 -0700 | [diff] [blame] | 492 | tempDC->drawRect(GrNoClip(), paint, SkMatrix::I(), rect, nullptr); |
| 493 | surfaceToRead.reset(tempDC->asTexture().release()); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 494 | left = 0; |
| 495 | top = 0; |
| 496 | didTempDraw = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 497 | } |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 498 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 499 | } |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 500 | |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 501 | if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 502 | return false; |
| 503 | } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 504 | GrPixelConfig configToRead = dstConfig; |
| 505 | if (didTempDraw) { |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 506 | this->flushSurfaceWrites(surfaceToRead); |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 507 | configToRead = tempDrawInfo.fReadConfig; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 508 | } |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 509 | if (!fGpu->readPixels(surfaceToRead, left, top, width, height, configToRead, buffer, |
| 510 | rowBytes)) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | |
| 514 | // Perform umpremul conversion if we weren't able to perform it as a draw. |
| 515 | if (unpremul) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 516 | SkDstPixelInfo dstPI; |
brianosman | 396fcdb | 2016-07-22 06:26:11 -0700 | [diff] [blame] | 517 | if (!GrPixelConfigToColorType(dstConfig, &dstPI.fColorType)) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 518 | return false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 519 | } |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 520 | dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| 521 | dstPI.fPixels = buffer; |
| 522 | dstPI.fRowBytes = rowBytes; |
| 523 | |
| 524 | SkSrcPixelInfo srcPI; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 525 | srcPI.fColorType = dstPI.fColorType; |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 526 | srcPI.fAlphaType = kPremul_SkAlphaType; |
| 527 | srcPI.fPixels = buffer; |
| 528 | srcPI.fRowBytes = rowBytes; |
| 529 | |
| 530 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 531 | } |
| 532 | return true; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 533 | } |
| 534 | |
bsalomon | c49e868 | 2015-06-30 11:37:35 -0700 | [diff] [blame] | 535 | void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 536 | ASSERT_SINGLE_OWNER |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 537 | RETURN_IF_ABANDONED |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 538 | SkASSERT(surface); |
| 539 | ASSERT_OWNED_RESOURCE(surface); |
| 540 | if (surface->surfacePriv().hasPendingIO()) { |
| 541 | this->flush(); |
| 542 | } |
| 543 | GrRenderTarget* rt = surface->asRenderTarget(); |
| 544 | if (fGpu && rt) { |
| 545 | fGpu->resolveRenderTarget(rt); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 546 | } |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 547 | } |
| 548 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 549 | bool GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 550 | const SkIPoint& dstPoint) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 551 | ASSERT_SINGLE_OWNER |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 552 | RETURN_FALSE_IF_ABANDONED |
joshualitt | bc90735 | 2016-01-13 06:45:40 -0800 | [diff] [blame] | 553 | GR_AUDIT_TRAIL_AUTO_FRAME(&fAuditTrail, "GrContext::copySurface"); |
| 554 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 555 | if (!src || !dst) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 556 | return false; |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 557 | } |
bsalomon | e3d4bf2 | 2014-09-23 09:15:03 -0700 | [diff] [blame] | 558 | ASSERT_OWNED_RESOURCE(src); |
junov | 2bb5210 | 2014-09-29 10:18:59 -0700 | [diff] [blame] | 559 | ASSERT_OWNED_RESOURCE(dst); |
Brian Salomon | 34a9895 | 2014-09-24 11:41:24 -0400 | [diff] [blame] | 560 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 561 | if (!dst->asRenderTarget()) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 562 | SkIRect clippedSrcRect; |
| 563 | SkIPoint clippedDstPoint; |
| 564 | if (!GrCopySurfaceBatch::ClipSrcRectAndDstPoint(dst, src, srcRect, dstPoint, |
| 565 | &clippedSrcRect, &clippedDstPoint)) { |
| 566 | return false; |
| 567 | } |
| 568 | // If we don't have an RT for the dst then we won't have a GrDrawContext to insert the |
| 569 | // the copy surface into. In the future we plan to have a more limited Context type |
| 570 | // (GrCopyContext?) that has the subset of GrDrawContext operations that should be |
| 571 | // allowed on textures that aren't render targets. |
| 572 | // For now we just flush any writes to the src and issue an immediate copy to the dst. |
| 573 | src->flushWrites(); |
| 574 | return fGpu->copySurface(dst, src, clippedSrcRect, clippedDstPoint); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 575 | } |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame^] | 576 | sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( |
| 577 | sk_ref_sp(dst->asRenderTarget()), |
| 578 | nullptr)); |
kjlubick | 0eed945 | 2016-02-11 12:05:24 -0800 | [diff] [blame] | 579 | if (!drawContext) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 580 | return false; |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 581 | } |
kjlubick | 0eed945 | 2016-02-11 12:05:24 -0800 | [diff] [blame] | 582 | |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 583 | if (!drawContext->copySurface(src, srcRect, dstPoint)) { |
| 584 | return false; |
kjlubick | 0eed945 | 2016-02-11 12:05:24 -0800 | [diff] [blame] | 585 | } |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 586 | return true; |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 587 | } |
| 588 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 589 | void GrContext::flushSurfaceWrites(GrSurface* surface) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 590 | ASSERT_SINGLE_OWNER |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 591 | RETURN_IF_ABANDONED |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 592 | if (surface->surfacePriv().hasPendingWrite()) { |
| 593 | this->flush(); |
| 594 | } |
| 595 | } |
| 596 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 597 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 598 | int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 599 | SkScalar dpi) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 600 | ASSERT_SINGLE_OWNER |
| 601 | |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 602 | if (!this->caps()->isConfigRenderable(config, true)) { |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 603 | return 0; |
| 604 | } |
| 605 | int chosenSampleCount = 0; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 606 | if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 607 | if (dpi >= 250.0f) { |
| 608 | chosenSampleCount = 4; |
| 609 | } else { |
| 610 | chosenSampleCount = 16; |
| 611 | } |
| 612 | } |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 613 | return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? chosenSampleCount : 0; |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 614 | } |
| 615 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame^] | 616 | sk_sp<GrDrawContext> GrContextPriv::makeWrappedDrawContext(sk_sp<GrRenderTarget> rt, |
| 617 | sk_sp<SkColorSpace> colorSpace, |
| 618 | const SkSurfaceProps* surfaceProps) { |
| 619 | ASSERT_SINGLE_OWNER_PRIV |
| 620 | return fContext->drawingManager()->drawContext(std::move(rt), std::move(colorSpace), |
| 621 | surfaceProps); |
| 622 | } |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 623 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame^] | 624 | sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureDrawContext(const GrBackendTextureDesc& desc, |
| 625 | sk_sp<SkColorSpace> colorSpace, |
| 626 | const SkSurfaceProps* props, |
| 627 | GrWrapOwnership ownership) { |
| 628 | ASSERT_SINGLE_OWNER_PRIV |
| 629 | SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); |
| 630 | |
| 631 | sk_sp<GrSurface> surface(fContext->textureProvider()->wrapBackendTexture(desc, ownership)); |
| 632 | if (!surface) { |
| 633 | return nullptr; |
| 634 | } |
| 635 | |
| 636 | return fContext->drawingManager()->drawContext(sk_ref_sp(surface->asRenderTarget()), |
| 637 | std::move(colorSpace), props); |
| 638 | } |
| 639 | |
| 640 | sk_sp<GrDrawContext> GrContextPriv::makeBackendRenderTargetDrawContext( |
| 641 | const GrBackendRenderTargetDesc& desc, |
| 642 | sk_sp<SkColorSpace> colorSpace, |
| 643 | const SkSurfaceProps* surfaceProps) { |
| 644 | ASSERT_SINGLE_OWNER_PRIV |
| 645 | |
| 646 | sk_sp<GrRenderTarget> rt(fContext->textureProvider()->wrapBackendRenderTarget(desc)); |
| 647 | if (!rt) { |
| 648 | return nullptr; |
| 649 | } |
| 650 | |
| 651 | return fContext->drawingManager()->drawContext(std::move(rt), std::move(colorSpace), |
| 652 | surfaceProps); |
| 653 | } |
| 654 | |
| 655 | sk_sp<GrDrawContext> GrContextPriv::makeBackendTextureAsRenderTargetDrawContext( |
| 656 | const GrBackendTextureDesc& desc, |
| 657 | sk_sp<SkColorSpace> colorSpace, |
| 658 | const SkSurfaceProps* surfaceProps) { |
| 659 | ASSERT_SINGLE_OWNER_PRIV |
| 660 | SkASSERT(desc.fFlags & kRenderTarget_GrBackendTextureFlag); |
| 661 | |
| 662 | sk_sp<GrSurface> surface(fContext->resourceProvider()->wrapBackendTextureAsRenderTarget(desc)); |
| 663 | if (!surface) { |
| 664 | return nullptr; |
| 665 | } |
| 666 | |
| 667 | return fContext->drawingManager()->drawContext(sk_ref_sp(surface->asRenderTarget()), |
| 668 | std::move(colorSpace), surfaceProps); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 669 | } |
| 670 | |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 671 | sk_sp<GrDrawContext> GrContext::makeDrawContext(SkBackingFit fit, |
| 672 | int width, int height, |
| 673 | GrPixelConfig config, |
| 674 | sk_sp<SkColorSpace> colorSpace, |
| 675 | int sampleCnt, |
| 676 | GrSurfaceOrigin origin, |
| 677 | const SkSurfaceProps* surfaceProps, |
| 678 | SkBudgeted budgeted) { |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 679 | GrSurfaceDesc desc; |
| 680 | desc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 681 | desc.fOrigin = origin; |
| 682 | desc.fWidth = width; |
| 683 | desc.fHeight = height; |
| 684 | desc.fConfig = config; |
| 685 | desc.fSampleCnt = sampleCnt; |
| 686 | |
| 687 | sk_sp<GrTexture> tex; |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 688 | if (SkBackingFit::kExact == fit) { |
robertphillips | ca6eafc | 2016-05-17 09:57:46 -0700 | [diff] [blame] | 689 | tex.reset(this->textureProvider()->createTexture(desc, budgeted)); |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 690 | } else { |
| 691 | tex.reset(this->textureProvider()->createApproxTexture(desc)); |
| 692 | } |
| 693 | if (!tex) { |
| 694 | return nullptr; |
| 695 | } |
| 696 | |
robertphillips | 4fd74ae | 2016-08-03 14:26:53 -0700 | [diff] [blame^] | 697 | sk_sp<GrDrawContext> drawContext(this->contextPriv().makeWrappedDrawContext( |
| 698 | sk_ref_sp(tex->asRenderTarget()), |
robertphillips | 6738c70 | 2016-07-27 12:13:51 -0700 | [diff] [blame] | 699 | std::move(colorSpace), surfaceProps)); |
robertphillips | d4c741e | 2016-04-28 09:55:15 -0700 | [diff] [blame] | 700 | if (!drawContext) { |
| 701 | return nullptr; |
| 702 | } |
| 703 | |
| 704 | return drawContext; |
| 705 | } |
| 706 | |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 707 | bool GrContext::abandoned() const { |
| 708 | ASSERT_SINGLE_OWNER |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 709 | return fDrawingManager->wasAbandoned(); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 710 | } |
| 711 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 712 | namespace { |
| 713 | void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 714 | GrConfigConversionEffect::PMConversion pmToUPM; |
| 715 | GrConfigConversionEffect::PMConversion upmToPM; |
| 716 | GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upmToPM); |
| 717 | *pmToUPMValue = pmToUPM; |
| 718 | *upmToPMValue = upmToPM; |
| 719 | } |
| 720 | } |
| 721 | |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 722 | void GrContext::testPMConversionsIfNecessary(uint32_t flags) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 723 | ASSERT_SINGLE_OWNER |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 724 | if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { |
| 725 | SkAutoMutexAcquire ama(fTestPMConversionsMutex); |
| 726 | if (!fDidTestPMConversions) { |
| 727 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 728 | fDidTestPMConversions = true; |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 733 | sk_sp<GrFragmentProcessor> GrContext::createPMToUPMEffect(GrTexture* texture, |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 734 | const GrSwizzle& swizzle, |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 735 | const SkMatrix& matrix) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 736 | ASSERT_SINGLE_OWNER |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 737 | // We should have already called this->testPMConversionsIfNecessary(). |
| 738 | SkASSERT(fDidTestPMConversions); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 739 | GrConfigConversionEffect::PMConversion pmToUPM = |
| 740 | static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 741 | if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 742 | return GrConfigConversionEffect::Make(texture, swizzle, pmToUPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 743 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 744 | return nullptr; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 748 | sk_sp<GrFragmentProcessor> GrContext::createUPMToPMEffect(GrTexture* texture, |
bsalomon | 6c9cd55 | 2016-01-22 07:17:34 -0800 | [diff] [blame] | 749 | const GrSwizzle& swizzle, |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 750 | const SkMatrix& matrix) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 751 | ASSERT_SINGLE_OWNER |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 752 | // We should have already called this->testPMConversionsIfNecessary(). |
| 753 | SkASSERT(fDidTestPMConversions); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 754 | GrConfigConversionEffect::PMConversion upmToPM = |
| 755 | static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 756 | if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 757 | return GrConfigConversionEffect::Make(texture, swizzle, upmToPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 758 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 759 | return nullptr; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 763 | bool GrContext::didFailPMUPMConversionTest() const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 764 | ASSERT_SINGLE_OWNER |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 765 | // We should have already called this->testPMConversionsIfNecessary(). |
| 766 | SkASSERT(fDidTestPMConversions); |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 767 | // The PM<->UPM tests fail or succeed together so we only need to check one. |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 768 | return GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 769 | } |
| 770 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 771 | ////////////////////////////////////////////////////////////////////////////// |
| 772 | |
| 773 | void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 774 | ASSERT_SINGLE_OWNER |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 775 | if (maxTextures) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 776 | *maxTextures = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 777 | } |
| 778 | if (maxTextureBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 779 | *maxTextureBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 780 | } |
| 781 | } |
| 782 | |
| 783 | void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 784 | ASSERT_SINGLE_OWNER |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 785 | fResourceCache->setLimits(maxTextures, maxTextureBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 786 | } |
| 787 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 788 | ////////////////////////////////////////////////////////////////////////////// |
| 789 | |
| 790 | void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
joshualitt | 1de610a | 2016-01-06 08:26:09 -0800 | [diff] [blame] | 791 | ASSERT_SINGLE_OWNER |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 792 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 793 | } |