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