epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
bsalomon@google.com | 1fadb20 | 2011-12-12 16:10:08 +0000 | [diff] [blame] | 9 | #include "GrContext.h" |
| 10 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 11 | #include "GrBatchFontCache.h" |
bsalomon | 7539856 | 2015-08-17 12:55:38 -0700 | [diff] [blame] | 12 | #include "GrBatchFlushState.h" |
joshualitt | e590266 | 2015-05-11 08:18:35 -0700 | [diff] [blame] | 13 | #include "GrBatchTest.h" |
bsalomon | eb1cb5c | 2015-05-22 08:01:09 -0700 | [diff] [blame] | 14 | #include "GrCaps.h" |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 15 | #include "GrContextOptions.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 16 | #include "GrDefaultGeoProcFactory.h" |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 17 | #include "GrDrawingManager.h" |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 18 | #include "GrDrawContext.h" |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 19 | #include "GrDrawTarget.h" |
bsalomon | 453cf40 | 2014-11-11 14:15:57 -0800 | [diff] [blame] | 20 | #include "GrGpuResource.h" |
bsalomon | 3582d3e | 2015-02-13 14:20:05 -0800 | [diff] [blame] | 21 | #include "GrGpuResourcePriv.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 22 | #include "GrGpu.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 23 | #include "GrIndexBuffer.h" |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 24 | #include "GrLayerCache.h" |
commit-bot@chromium.org | 8131283 | 2013-03-22 18:34:09 +0000 | [diff] [blame] | 25 | #include "GrOvalRenderer.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 26 | #include "GrPathRenderer.h" |
tomhudson@google.com | d22b6e4 | 2011-06-24 15:53:40 +0000 | [diff] [blame] | 27 | #include "GrPathUtils.h" |
bsalomon | 6bc1b5f | 2015-02-23 09:06:38 -0800 | [diff] [blame] | 28 | #include "GrRenderTargetPriv.h" |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 29 | #include "GrResourceCache.h" |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 30 | #include "GrResourceProvider.h" |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 31 | #include "GrSoftwarePathRenderer.h" |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 32 | #include "GrStencilAndCoverTextContext.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 33 | #include "GrStrokeInfo.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 34 | #include "GrSurfacePriv.h" |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 35 | #include "GrTextBlobCache.h" |
bsalomon | afbf2d6 | 2014-09-30 12:18:44 -0700 | [diff] [blame] | 36 | #include "GrTexturePriv.h" |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 37 | #include "GrTracing.h" |
bsalomon | cb8979d | 2015-05-05 09:51:38 -0700 | [diff] [blame] | 38 | #include "GrVertices.h" |
egdaniel | d58a0ba | 2014-06-11 10:30:05 -0700 | [diff] [blame] | 39 | #include "SkDashPathPriv.h" |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 40 | #include "SkConfig8888.h" |
bsalomon | f276ac5 | 2015-10-09 13:36:42 -0700 | [diff] [blame] | 41 | #include "SkGrPriv.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 42 | #include "SkRRect.h" |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 43 | #include "SkStrokeRec.h" |
robertphillips | fcf7829 | 2015-06-19 11:49:52 -0700 | [diff] [blame] | 44 | #include "SkSurfacePriv.h" |
commit-bot@chromium.org | dcb8ef9 | 2014-03-27 11:26:10 +0000 | [diff] [blame] | 45 | #include "SkTLazy.h" |
commit-bot@chromium.org | 4784182 | 2014-03-27 14:19:17 +0000 | [diff] [blame] | 46 | #include "SkTLS.h" |
commit-bot@chromium.org | 933e65d | 2014-03-20 20:00:24 +0000 | [diff] [blame] | 47 | #include "SkTraceEvent.h" |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 48 | |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 49 | |
joshualitt | 7441782 | 2015-08-07 11:42:16 -0700 | [diff] [blame] | 50 | #include "batches/GrBatch.h" |
| 51 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 52 | #include "effects/GrConfigConversionEffect.h" |
| 53 | #include "effects/GrDashingEffect.h" |
| 54 | #include "effects/GrSingleTextureEffect.h" |
| 55 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 56 | #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this) |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 57 | #define RETURN_IF_ABANDONED if (fDrawingManager->abandoned()) { return; } |
| 58 | #define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->abandoned()) { return false; } |
| 59 | #define RETURN_NULL_IF_ABANDONED if (fDrawingManager->abandoned()) { return nullptr; } |
bsalomon@google.com | bc4b654 | 2011-11-19 13:56:11 +0000 | [diff] [blame] | 60 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 61 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 62 | //////////////////////////////////////////////////////////////////////////////// |
| 63 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 64 | void GrDrawingManager::cleanup() { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 65 | for (int i = 0; i < fDrawTargets.count(); ++i) { |
| 66 | fDrawTargets[i]->unref(); |
| 67 | } |
| 68 | |
| 69 | fDrawTargets.reset(); |
| 70 | |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 71 | delete fNVPRTextContext; |
| 72 | fNVPRTextContext = nullptr; |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 73 | |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 74 | for (int i = 0; i < kNumPixelGeometries; ++i) { |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 75 | delete fTextContexts[i][0]; |
| 76 | fTextContexts[i][0] = nullptr; |
| 77 | delete fTextContexts[i][1]; |
| 78 | fTextContexts[i][1] = nullptr; |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 79 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 80 | } |
| 81 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 82 | GrDrawingManager::~GrDrawingManager() { |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 83 | this->cleanup(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 84 | } |
| 85 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 86 | void GrDrawingManager::abandon() { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 87 | fAbandoned = true; |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 88 | this->cleanup(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 89 | } |
| 90 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 91 | void GrDrawingManager::reset() { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 92 | for (int i = 0; i < fDrawTargets.count(); ++i) { |
| 93 | fDrawTargets[i]->reset(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 97 | void GrDrawingManager::flush() { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 98 | for (int i = 0; i < fDrawTargets.count(); ++i) { |
| 99 | fDrawTargets[i]->flush(); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 103 | GrTextContext* GrDrawingManager::textContext(const SkSurfaceProps& props, |
| 104 | GrRenderTarget* rt) { |
robertphillips | 2d70dcb | 2015-10-06 07:38:23 -0700 | [diff] [blame] | 105 | if (this->abandoned()) { |
| 106 | return nullptr; |
| 107 | } |
| 108 | |
| 109 | SkASSERT(props.pixelGeometry() < kNumPixelGeometries); |
| 110 | bool useDIF = props.isUseDeviceIndependentFonts(); |
| 111 | |
| 112 | if (useDIF && fContext->caps()->shaderCaps()->pathRenderingSupport() && |
| 113 | rt->isStencilBufferMultisampled()) { |
| 114 | GrStencilAttachment* sb = fContext->resourceProvider()->attachStencilAttachment(rt); |
| 115 | if (sb) { |
| 116 | if (!fNVPRTextContext) { |
| 117 | fNVPRTextContext = GrStencilAndCoverTextContext::Create(fContext, props); |
| 118 | } |
| 119 | |
| 120 | return fNVPRTextContext; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | if (!fTextContexts[props.pixelGeometry()][useDIF]) { |
| 125 | fTextContexts[props.pixelGeometry()][useDIF] = GrAtlasTextContext::Create(fContext, props); |
| 126 | } |
| 127 | |
| 128 | return fTextContexts[props.pixelGeometry()][useDIF]; |
| 129 | } |
| 130 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 131 | GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) { |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 132 | SkASSERT(fContext); |
| 133 | |
| 134 | // When MDB is disabled we always just return the single drawTarget |
| 135 | #ifndef ENABLE_MDB |
| 136 | if (fDrawTargets.count()) { |
| 137 | SkASSERT(fDrawTargets.count() == 1); |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 138 | // DrawingManager gets the creation ref - this ref is for the caller |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 139 | return SkRef(fDrawTargets[0]); |
| 140 | } |
| 141 | #endif |
| 142 | |
| 143 | GrDrawTarget* dt = new GrDrawTarget(fContext->getGpu(), fContext->resourceProvider()); |
| 144 | |
| 145 | *fDrawTargets.append() = dt; |
| 146 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 147 | // DrawingManager gets the creation ref - this ref is for the caller |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 148 | return SkRef(dt); |
| 149 | } |
| 150 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 151 | GrDrawContext* GrDrawingManager::drawContext(GrRenderTarget* rt, |
| 152 | const SkSurfaceProps* surfaceProps) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 153 | if (this->abandoned()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 154 | return nullptr; |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 155 | } |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 156 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 157 | return new GrDrawContext(this, rt, surfaceProps); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | //////////////////////////////////////////////////////////////////////////////// |
| 161 | |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 162 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 163 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) { |
| 164 | GrContextOptions defaultOptions; |
| 165 | return Create(backend, backendContext, defaultOptions); |
| 166 | } |
bsalomon | f28cff7 | 2015-05-22 12:25:41 -0700 | [diff] [blame] | 167 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 168 | GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext, |
| 169 | const GrContextOptions& options) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 170 | GrContext* context = new GrContext; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 171 | |
| 172 | if (context->init(backend, backendContext, options)) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 173 | return context; |
| 174 | } else { |
| 175 | context->unref(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 176 | return nullptr; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 177 | } |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 178 | } |
| 179 | |
joshualitt | 0acd0d3 | 2015-05-07 08:23:19 -0700 | [diff] [blame] | 180 | static int32_t gNextID = 1; |
| 181 | static int32_t next_id() { |
| 182 | int32_t id; |
| 183 | do { |
| 184 | id = sk_atomic_inc(&gNextID); |
| 185 | } while (id == SK_InvalidGenID); |
| 186 | return id; |
| 187 | } |
| 188 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 189 | GrContext::GrContext() : fUniqueID(next_id()) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 190 | fGpu = nullptr; |
| 191 | fCaps = nullptr; |
| 192 | fResourceCache = nullptr; |
| 193 | fResourceProvider = nullptr; |
| 194 | fPathRendererChain = nullptr; |
| 195 | fSoftwarePathRenderer = nullptr; |
| 196 | fBatchFontCache = nullptr; |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 197 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 198 | } |
| 199 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 200 | bool GrContext::init(GrBackend backend, GrBackendContext backendContext, |
| 201 | const GrContextOptions& options) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 202 | SkASSERT(!fGpu); |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 203 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 204 | fGpu = GrGpu::Create(backend, backendContext, options, this); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 205 | if (!fGpu) { |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 206 | return false; |
| 207 | } |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 208 | this->initCommon(); |
| 209 | return true; |
| 210 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 211 | |
bsalomon | 3343557 | 2014-11-05 14:47:41 -0800 | [diff] [blame] | 212 | void GrContext::initCommon() { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 213 | fCaps = SkRef(fGpu->caps()); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 214 | fResourceCache = new GrResourceCache(fCaps); |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 215 | fResourceCache->setOverBudgetCallback(OverBudgetCB, this); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 216 | fResourceProvider = new GrResourceProvider(fGpu, fResourceCache); |
commit-bot@chromium.org | 1836d33 | 2013-07-16 22:55:03 +0000 | [diff] [blame] | 217 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 218 | fLayerCache.reset(new GrLayerCache(this)); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 219 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 220 | fDidTestPMConversions = false; |
| 221 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 222 | fDrawingManager.reset(new GrDrawingManager(this)); |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 223 | |
| 224 | // GrBatchFontCache will eventually replace GrFontCache |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 225 | fBatchFontCache = new GrBatchFontCache(this); |
joshualitt | b7133be | 2015-04-08 09:08:31 -0700 | [diff] [blame] | 226 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 227 | fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this)); |
bsalomon@google.com | c0af317 | 2012-06-15 14:10:09 +0000 | [diff] [blame] | 228 | } |
| 229 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 230 | GrContext::~GrContext() { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 231 | if (!fGpu) { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 232 | SkASSERT(!fCaps); |
bsalomon@google.com | 733c062 | 2013-04-24 17:59:32 +0000 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 236 | this->flush(); |
robertphillips@google.com | 5acc0e3 | 2012-05-17 12:01:02 +0000 | [diff] [blame] | 237 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 238 | fDrawingManager->cleanup(); |
robertphillips | 2334fb6 | 2015-06-17 05:43:33 -0700 | [diff] [blame] | 239 | |
robertphillips@google.com | 950b1b0 | 2013-10-21 17:37:28 +0000 | [diff] [blame] | 240 | for (int i = 0; i < fCleanUpData.count(); ++i) { |
| 241 | (*fCleanUpData[i].fFunc)(this, fCleanUpData[i].fInfo); |
| 242 | } |
| 243 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 244 | delete fResourceProvider; |
| 245 | delete fResourceCache; |
| 246 | delete fBatchFontCache; |
robertphillips@google.com | f6747b0 | 2012-06-12 00:32:28 +0000 | [diff] [blame] | 247 | |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 248 | fGpu->unref(); |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 249 | fCaps->unref(); |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 250 | SkSafeUnref(fPathRendererChain); |
| 251 | SkSafeUnref(fSoftwarePathRenderer); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 252 | } |
| 253 | |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 254 | void GrContext::abandonContext() { |
bsalomon | d309e7a | 2015-04-30 14:18:54 -0700 | [diff] [blame] | 255 | fResourceProvider->abandon(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 256 | // abandon first to so destructors |
| 257 | // don't try to free the resources in the API. |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 258 | fResourceCache->abandonAll(); |
bsalomon | c8dc1f7 | 2014-08-21 13:02:13 -0700 | [diff] [blame] | 259 | |
robertphillips | e337130 | 2014-09-17 06:01:06 -0700 | [diff] [blame] | 260 | fGpu->contextAbandoned(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 261 | |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 262 | // a path renderer may be holding onto resources that |
| 263 | // are now unusable |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 264 | SkSafeSetNull(fPathRendererChain); |
| 265 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 266 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 267 | fDrawingManager->abandon(); |
bsalomon@google.com | 205d460 | 2011-04-25 12:43:45 +0000 | [diff] [blame] | 268 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 269 | fBatchFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 270 | fLayerCache->freeAll(); |
joshualitt | 26ffc00 | 2015-04-16 11:24:04 -0700 | [diff] [blame] | 271 | fTextBlobCache->freeAll(); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 272 | } |
| 273 | |
bsalomon@google.com | 0a208a1 | 2013-06-28 18:57:35 +0000 | [diff] [blame] | 274 | void GrContext::resetContext(uint32_t state) { |
| 275 | fGpu->markContextDirty(state); |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | void GrContext::freeGpuResources() { |
| 279 | this->flush(); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 280 | |
joshualitt | 7c3a2f8 | 2015-03-31 13:32:05 -0700 | [diff] [blame] | 281 | fBatchFontCache->freeAll(); |
robertphillips@google.com | e930a07 | 2014-04-03 00:34:27 +0000 | [diff] [blame] | 282 | fLayerCache->freeAll(); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 283 | // a path renderer may be holding onto resources |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 284 | SkSafeSetNull(fPathRendererChain); |
| 285 | SkSafeSetNull(fSoftwarePathRenderer); |
bsalomon | 3033b9f | 2015-04-13 11:09:56 -0700 | [diff] [blame] | 286 | |
| 287 | fResourceCache->purgeAllUnlocked(); |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 288 | } |
| 289 | |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 290 | void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const { |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 291 | if (resourceCount) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 292 | *resourceCount = fResourceCache->getBudgetedResourceCount(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 293 | } |
| 294 | if (resourceBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 295 | *resourceBytes = fResourceCache->getBudgetedResourceBytes(); |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 296 | } |
commit-bot@chromium.org | d8a57af | 2014-03-19 21:19:16 +0000 | [diff] [blame] | 297 | } |
| 298 | |
bsalomon@google.com | fea37b5 | 2011-04-25 15:51:06 +0000 | [diff] [blame] | 299 | //////////////////////////////////////////////////////////////////////////////// |
| 300 | |
bsalomon | 71cb0c2 | 2014-11-14 12:10:14 -0800 | [diff] [blame] | 301 | void GrContext::OverBudgetCB(void* data) { |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 302 | SkASSERT(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 303 | |
bsalomon | 66a450f | 2014-11-13 13:19:10 -0800 | [diff] [blame] | 304 | GrContext* context = reinterpret_cast<GrContext*>(data); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 305 | |
joshualitt | b542bae | 2015-07-28 09:58:39 -0700 | [diff] [blame] | 306 | // Flush the GrBufferedDrawTarget to possibly free up some textures |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 307 | context->fFlushToReduceCacheSize = true; |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 308 | } |
| 309 | |
joshualitt | 0db6dfa | 2015-04-10 07:01:30 -0700 | [diff] [blame] | 310 | void GrContext::TextBlobCacheOverBudgetCB(void* data) { |
| 311 | SkASSERT(data); |
| 312 | |
| 313 | // Unlike the GrResourceCache, TextBlobs are drawn at the SkGpuDevice level, therefore they |
| 314 | // cannot use fFlushTorReduceCacheSize because it uses AutoCheckFlush. The solution is to move |
| 315 | // drawText calls to below the GrContext level, but this is not trivial because they call |
| 316 | // drawPath on SkGpuDevice |
| 317 | GrContext* context = reinterpret_cast<GrContext*>(data); |
| 318 | context->flush(); |
| 319 | } |
| 320 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 321 | //////////////////////////////////////////////////////////////////////////////// |
| 322 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 323 | void GrContext::flush(int flagsBitfield) { |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 324 | RETURN_IF_ABANDONED |
robertphillips@google.com | e7db8d6 | 2013-07-04 11:48:52 +0000 | [diff] [blame] | 325 | |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 326 | if (kDiscard_FlushBit & flagsBitfield) { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 327 | fDrawingManager->reset(); |
bsalomon@google.com | a7f84e1 | 2011-03-10 14:13:19 +0000 | [diff] [blame] | 328 | } else { |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 329 | fDrawingManager->flush(); |
junov@google.com | 53a5584 | 2011-06-08 22:55:10 +0000 | [diff] [blame] | 330 | } |
bsalomon | 3f32432 | 2015-04-08 11:01:54 -0700 | [diff] [blame] | 331 | fResourceCache->notifyFlushOccurred(); |
bsalomon | f21dab9 | 2014-11-13 13:33:28 -0800 | [diff] [blame] | 332 | fFlushToReduceCacheSize = false; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 333 | } |
| 334 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 335 | bool sw_convert_to_premul(GrPixelConfig srcConfig, int width, int height, size_t inRowBytes, |
| 336 | const void* inPixels, size_t outRowBytes, void* outPixels) { |
| 337 | SkSrcPixelInfo srcPI; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 338 | if (!GrPixelConfig2ColorAndProfileType(srcConfig, &srcPI.fColorType, nullptr)) { |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 339 | return false; |
| 340 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 341 | srcPI.fAlphaType = kUnpremul_SkAlphaType; |
| 342 | srcPI.fPixels = inPixels; |
| 343 | srcPI.fRowBytes = inRowBytes; |
| 344 | |
| 345 | SkDstPixelInfo dstPI; |
| 346 | dstPI.fColorType = srcPI.fColorType; |
| 347 | dstPI.fAlphaType = kPremul_SkAlphaType; |
| 348 | dstPI.fPixels = outPixels; |
| 349 | dstPI.fRowBytes = outRowBytes; |
| 350 | |
| 351 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | 669fdc4 | 2011-04-05 17:08:27 +0000 | [diff] [blame] | 352 | } |
| 353 | |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 354 | bool GrContext::writeSurfacePixels(GrSurface* surface, |
| 355 | int left, int top, int width, int height, |
| 356 | GrPixelConfig srcConfig, const void* buffer, size_t rowBytes, |
| 357 | uint32_t pixelOpsFlags) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 358 | RETURN_FALSE_IF_ABANDONED |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 359 | ASSERT_OWNED_RESOURCE(surface); |
| 360 | SkASSERT(surface); |
| 361 | |
| 362 | this->testPMConversionsIfNecessary(pixelOpsFlags); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 363 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 364 | // 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] | 365 | // necessary and because GrGpu::getWritePixelsInfo requires it. |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 366 | if (!GrSurfacePriv::AdjustWritePixelParams(surface->width(), surface->height(), |
| 367 | GrBytesPerPixel(srcConfig), &left, &top, &width, |
| 368 | &height, &buffer, &rowBytes)) { |
| 369 | return false; |
| 370 | } |
| 371 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 372 | bool applyPremulToSrc = false; |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 373 | if (kUnpremul_PixelOpsFlag & pixelOpsFlags) { |
| 374 | if (!GrPixelConfigIs8888(srcConfig)) { |
| 375 | return false; |
| 376 | } |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 377 | applyPremulToSrc = true; |
| 378 | } |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 379 | |
| 380 | GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; |
| 381 | // Don't prefer to draw for the conversion (and thereby access a texture from the cache) when |
| 382 | // we've already determined that there isn't a roundtrip preserving conversion processor pair. |
| 383 | if (applyPremulToSrc && !this->didFailPMUPMConversionTest()) { |
| 384 | drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
| 385 | } |
| 386 | |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 387 | GrGpu::WritePixelTempDrawInfo tempDrawInfo; |
| 388 | if (!fGpu->getWritePixelsInfo(surface, width, height, rowBytes, srcConfig, &drawPreference, |
| 389 | &tempDrawInfo)) { |
| 390 | return false; |
| 391 | } |
| 392 | |
| 393 | if (!(kDontFlush_PixelOpsFlag & pixelOpsFlags) && surface->surfacePriv().hasPendingIO()) { |
| 394 | this->flush(); |
| 395 | } |
| 396 | |
| 397 | SkAutoTUnref<GrTexture> tempTexture; |
| 398 | if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 399 | tempTexture.reset( |
| 400 | this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfaceDesc)); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 401 | if (!tempTexture && GrGpu::kRequireDraw_DrawPreference == drawPreference) { |
| 402 | return false; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | // temp buffer for doing sw premul conversion, if needed. |
| 407 | SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0); |
| 408 | if (tempTexture) { |
| 409 | SkAutoTUnref<const GrFragmentProcessor> fp; |
| 410 | SkMatrix textureMatrix; |
| 411 | textureMatrix.setIDiv(tempTexture->width(), tempTexture->height()); |
| 412 | GrPaint paint; |
| 413 | if (applyPremulToSrc) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 414 | fp.reset(this->createUPMToPMEffect(tempTexture, tempDrawInfo.fSwapRAndB, |
| 415 | textureMatrix)); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 416 | // If premultiplying was the only reason for the draw, fall back to a straight write. |
| 417 | if (!fp) { |
| 418 | if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 419 | tempTexture.reset(nullptr); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 420 | } |
| 421 | } else { |
| 422 | applyPremulToSrc = false; |
| 423 | } |
| 424 | } |
| 425 | if (tempTexture) { |
| 426 | if (!fp) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 427 | fp.reset(GrConfigConversionEffect::Create(tempTexture, tempDrawInfo.fSwapRAndB, |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 428 | GrConfigConversionEffect::kNone_PMConversion, textureMatrix)); |
| 429 | if (!fp) { |
| 430 | return false; |
| 431 | } |
| 432 | } |
| 433 | GrRenderTarget* renderTarget = surface->asRenderTarget(); |
| 434 | SkASSERT(renderTarget); |
| 435 | if (tempTexture->surfacePriv().hasPendingIO()) { |
| 436 | this->flush(); |
| 437 | } |
| 438 | if (applyPremulToSrc) { |
| 439 | size_t tmpRowBytes = 4 * width; |
| 440 | tmpPixels.reset(width * height); |
| 441 | if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer, tmpRowBytes, |
| 442 | tmpPixels.get())) { |
| 443 | return false; |
| 444 | } |
| 445 | rowBytes = tmpRowBytes; |
| 446 | buffer = tmpPixels.get(); |
| 447 | applyPremulToSrc = false; |
| 448 | } |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 449 | if (!fGpu->writePixels(tempTexture, 0, 0, width, height, |
| 450 | tempDrawInfo.fTempSurfaceDesc.fConfig, buffer, |
| 451 | rowBytes)) { |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 452 | return false; |
| 453 | } |
| 454 | SkMatrix matrix; |
| 455 | matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 456 | SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(renderTarget)); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 457 | if (!drawContext) { |
| 458 | return false; |
| 459 | } |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 460 | paint.addColorFragmentProcessor(fp); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 461 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 462 | drawContext->drawRect(GrClip::WideOpen(), paint, matrix, rect, nullptr); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 463 | |
| 464 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 465 | this->flushSurfaceWrites(surface); |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | if (!tempTexture) { |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 470 | if (applyPremulToSrc) { |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 471 | size_t tmpRowBytes = 4 * width; |
| 472 | tmpPixels.reset(width * height); |
| 473 | if (!sw_convert_to_premul(srcConfig, width, height, rowBytes, buffer, tmpRowBytes, |
| 474 | tmpPixels.get())) { |
| 475 | return false; |
| 476 | } |
| 477 | rowBytes = tmpRowBytes; |
| 478 | buffer = tmpPixels.get(); |
bsalomon | f067451 | 2015-07-28 13:26:15 -0700 | [diff] [blame] | 479 | applyPremulToSrc = false; |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 480 | } |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 481 | return fGpu->writePixels(surface, left, top, width, height, srcConfig, buffer, rowBytes); |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 482 | } |
bsalomon | 81beccc | 2014-10-13 12:32:55 -0700 | [diff] [blame] | 483 | return true; |
| 484 | } |
bsalomon@google.com | a91e923 | 2012-02-23 15:39:54 +0000 | [diff] [blame] | 485 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 486 | bool GrContext::readSurfacePixels(GrSurface* src, |
| 487 | int left, int top, int width, int height, |
| 488 | GrPixelConfig dstConfig, void* buffer, size_t rowBytes, |
| 489 | uint32_t flags) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 490 | RETURN_FALSE_IF_ABANDONED |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 491 | ASSERT_OWNED_RESOURCE(src); |
| 492 | SkASSERT(src); |
bsalomon | 32ab260 | 2015-09-09 18:57:49 -0700 | [diff] [blame] | 493 | |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 494 | this->testPMConversionsIfNecessary(flags); |
| 495 | SkAutoMutexAcquire ama(fReadPixelsMutex); |
| 496 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 497 | // Adjust the params so that if we wind up using an intermediate surface we've already done |
| 498 | // all the trimming and the temporary can be the min size required. |
| 499 | if (!GrSurfacePriv::AdjustReadPixelParams(src->width(), src->height(), |
| 500 | GrBytesPerPixel(dstConfig), &left, |
| 501 | &top, &width, &height, &buffer, &rowBytes)) { |
| 502 | return false; |
| 503 | } |
| 504 | |
| 505 | if (!(kDontFlush_PixelOpsFlag & flags) && src->surfacePriv().hasPendingWrite()) { |
bsalomon@google.com | 6f37951 | 2011-11-16 20:36:03 +0000 | [diff] [blame] | 506 | this->flush(); |
| 507 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 508 | |
bsalomon | e8d21e8 | 2015-07-16 08:23:13 -0700 | [diff] [blame] | 509 | bool unpremul = SkToBool(kUnpremul_PixelOpsFlag & flags); |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 510 | if (unpremul && !GrPixelConfigIs8888(dstConfig)) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 511 | // The unpremul flag is only allowed for 8888 configs. |
bsalomon@google.com | 0a97be2 | 2011-11-08 19:20:57 +0000 | [diff] [blame] | 512 | return false; |
| 513 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 514 | |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 515 | GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference; |
| 516 | // Don't prefer to draw for the conversion (and thereby access a texture from the cache) when |
| 517 | // we've already determined that there isn't a roundtrip preserving conversion processor pair. |
| 518 | if (unpremul && !this->didFailPMUPMConversionTest()) { |
| 519 | drawPreference = GrGpu::kCallerPrefersDraw_DrawPreference; |
| 520 | } |
| 521 | |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 522 | GrGpu::ReadPixelTempDrawInfo tempDrawInfo; |
| 523 | if (!fGpu->getReadPixelsInfo(src, width, height, rowBytes, dstConfig, &drawPreference, |
| 524 | &tempDrawInfo)) { |
| 525 | return false; |
| 526 | } |
bsalomon | 191bcc0 | 2014-11-14 11:31:13 -0800 | [diff] [blame] | 527 | |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 528 | SkAutoTUnref<GrSurface> surfaceToRead(SkRef(src)); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 529 | bool didTempDraw = false; |
| 530 | if (GrGpu::kNoDraw_DrawPreference != drawPreference) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 531 | if (tempDrawInfo.fUseExactScratch) { |
| 532 | // We only respect this when the entire src is being read. Otherwise we can trigger too |
| 533 | // many odd ball texture sizes and trash the cache. |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 534 | if (width != src->width() || height != src->height()) { |
| 535 | tempDrawInfo.fUseExactScratch = false; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 536 | } |
bsalomon@google.com | 56d11e0 | 2011-11-30 19:59:08 +0000 | [diff] [blame] | 537 | } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 538 | SkAutoTUnref<GrTexture> temp; |
bsalomon | eae6200 | 2015-07-31 13:59:30 -0700 | [diff] [blame] | 539 | if (tempDrawInfo.fUseExactScratch) { |
| 540 | temp.reset(this->textureProvider()->createTexture(tempDrawInfo.fTempSurfaceDesc, true)); |
| 541 | } else { |
| 542 | temp.reset(this->textureProvider()->createApproxTexture(tempDrawInfo.fTempSurfaceDesc)); |
| 543 | } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 544 | if (temp) { |
bsalomon@google.com | b9086a0 | 2012-11-01 18:02:54 +0000 | [diff] [blame] | 545 | SkMatrix textureMatrix; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 546 | textureMatrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top)); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 547 | textureMatrix.postIDiv(src->width(), src->height()); |
joshualitt | 5f10b5c | 2015-07-09 10:24:35 -0700 | [diff] [blame] | 548 | GrPaint paint; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 549 | SkAutoTUnref<const GrFragmentProcessor> fp; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 550 | if (unpremul) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 551 | fp.reset(this->createPMToUPMEffect(src->asTexture(), tempDrawInfo.fSwapRAndB, |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 552 | textureMatrix)); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 553 | if (fp) { |
bsalomon@google.com | 9c68058 | 2013-02-06 18:17:50 +0000 | [diff] [blame] | 554 | 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] | 555 | } else if (GrGpu::kCallerPrefersDraw_DrawPreference == drawPreference) { |
| 556 | // We only wanted to do the draw in order to perform the unpremul so don't |
| 557 | // bother. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 558 | temp.reset(nullptr); |
bsalomon@google.com | d8b5fac | 2012-11-01 17:02:46 +0000 | [diff] [blame] | 559 | } |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 560 | } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 561 | if (!fp && temp) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 562 | fp.reset(GrConfigConversionEffect::Create(src->asTexture(), tempDrawInfo.fSwapRAndB, |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 563 | GrConfigConversionEffect::kNone_PMConversion, textureMatrix)); |
| 564 | } |
| 565 | if (fp) { |
bsalomon | ac856c9 | 2015-08-27 06:30:17 -0700 | [diff] [blame] | 566 | paint.addColorFragmentProcessor(fp); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 567 | SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height)); |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 568 | SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(temp->asRenderTarget())); |
| 569 | drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect, nullptr); |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 570 | surfaceToRead.reset(SkRef(temp.get())); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 571 | left = 0; |
| 572 | top = 0; |
| 573 | didTempDraw = true; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 574 | } |
bsalomon@google.com | 0342a85 | 2012-08-20 19:22:38 +0000 | [diff] [blame] | 575 | } |
bsalomon@google.com | c436499 | 2011-11-07 15:54:49 +0000 | [diff] [blame] | 576 | } |
joshualitt | 5c55fef | 2014-10-31 14:04:35 -0700 | [diff] [blame] | 577 | |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 578 | if (GrGpu::kRequireDraw_DrawPreference == drawPreference && !didTempDraw) { |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 579 | return false; |
| 580 | } |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 581 | GrPixelConfig configToRead = dstConfig; |
| 582 | if (didTempDraw) { |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 583 | this->flushSurfaceWrites(surfaceToRead); |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 584 | // We swapped R and B while doing the temp draw. Swap back on the read. |
| 585 | if (tempDrawInfo.fSwapRAndB) { |
| 586 | configToRead = GrPixelConfigSwapRAndB(dstConfig); |
| 587 | } |
| 588 | } |
bsalomon | 6cb3cbe | 2015-07-30 07:34:27 -0700 | [diff] [blame] | 589 | if (!fGpu->readPixels(surfaceToRead, left, top, width, height, configToRead, buffer, |
| 590 | rowBytes)) { |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 591 | return false; |
| 592 | } |
| 593 | |
| 594 | // Perform umpremul conversion if we weren't able to perform it as a draw. |
| 595 | if (unpremul) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 596 | SkDstPixelInfo dstPI; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 597 | if (!GrPixelConfig2ColorAndProfileType(dstConfig, &dstPI.fColorType, nullptr)) { |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 598 | return false; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 599 | } |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 600 | dstPI.fAlphaType = kUnpremul_SkAlphaType; |
| 601 | dstPI.fPixels = buffer; |
| 602 | dstPI.fRowBytes = rowBytes; |
| 603 | |
| 604 | SkSrcPixelInfo srcPI; |
bsalomon | 3982602 | 2015-07-23 08:07:21 -0700 | [diff] [blame] | 605 | srcPI.fColorType = dstPI.fColorType; |
reed@google.com | 7111d46 | 2014-03-25 16:20:24 +0000 | [diff] [blame] | 606 | srcPI.fAlphaType = kPremul_SkAlphaType; |
| 607 | srcPI.fPixels = buffer; |
| 608 | srcPI.fRowBytes = rowBytes; |
| 609 | |
| 610 | return srcPI.convertPixelsTo(&dstPI, width, height); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 611 | } |
| 612 | return true; |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 613 | } |
| 614 | |
bsalomon | c49e868 | 2015-06-30 11:37:35 -0700 | [diff] [blame] | 615 | void GrContext::prepareSurfaceForExternalIO(GrSurface* surface) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 616 | RETURN_IF_ABANDONED |
bsalomon | 87a94eb | 2014-11-03 14:28:32 -0800 | [diff] [blame] | 617 | SkASSERT(surface); |
| 618 | ASSERT_OWNED_RESOURCE(surface); |
| 619 | if (surface->surfacePriv().hasPendingIO()) { |
| 620 | this->flush(); |
| 621 | } |
| 622 | GrRenderTarget* rt = surface->asRenderTarget(); |
| 623 | if (fGpu && rt) { |
| 624 | fGpu->resolveRenderTarget(rt); |
bsalomon | 41ebbdd | 2014-08-04 08:31:39 -0700 | [diff] [blame] | 625 | } |
bsalomon@google.com | 75f9f25 | 2012-01-31 13:35:56 +0000 | [diff] [blame] | 626 | } |
| 627 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 628 | void GrContext::copySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect, |
| 629 | const SkIPoint& dstPoint, uint32_t pixelOpsFlags) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 630 | RETURN_IF_ABANDONED |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 631 | if (!src || !dst) { |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 632 | return; |
| 633 | } |
bsalomon | e3d4bf2 | 2014-09-23 09:15:03 -0700 | [diff] [blame] | 634 | ASSERT_OWNED_RESOURCE(src); |
junov | 2bb5210 | 2014-09-29 10:18:59 -0700 | [diff] [blame] | 635 | ASSERT_OWNED_RESOURCE(dst); |
Brian Salomon | 34a9895 | 2014-09-24 11:41:24 -0400 | [diff] [blame] | 636 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 637 | // Since we're going to the draw target and not GPU, no need to check kNoFlush |
| 638 | // here. |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 639 | if (!dst->asRenderTarget()) { |
junov | 96c118e | 2014-09-26 13:09:47 -0700 | [diff] [blame] | 640 | return; |
| 641 | } |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 642 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 643 | SkAutoTUnref<GrDrawContext> drawContext(this->drawContext(dst->asRenderTarget())); |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 644 | if (!drawContext) { |
| 645 | return; |
| 646 | } |
| 647 | |
robertphillips | 2e1e51f | 2015-10-15 08:01:48 -0700 | [diff] [blame] | 648 | drawContext->copySurface(src, srcRect, dstPoint); |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 649 | |
| 650 | if (kFlushWrites_PixelOp & pixelOpsFlags) { |
| 651 | this->flush(); |
| 652 | } |
senorblanco@chromium.org | ef843cd | 2011-12-02 19:11:17 +0000 | [diff] [blame] | 653 | } |
| 654 | |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 655 | void GrContext::flushSurfaceWrites(GrSurface* surface) { |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 656 | RETURN_IF_ABANDONED |
bsalomon | f80bfed | 2014-10-07 05:56:02 -0700 | [diff] [blame] | 657 | if (surface->surfacePriv().hasPendingWrite()) { |
| 658 | this->flush(); |
| 659 | } |
| 660 | } |
| 661 | |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 662 | /* |
| 663 | * This method finds a path renderer that can draw the specified path on |
| 664 | * the provided target. |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 665 | * Due to its expense, the software path renderer has split out so it can |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 666 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 667 | */ |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 668 | GrPathRenderer* GrContext::getPathRenderer(const GrDrawTarget* target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 669 | const GrPipelineBuilder* pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 670 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 671 | const SkPath& path, |
kkinnunen | 1899651 | 2015-04-26 23:18:49 -0700 | [diff] [blame] | 672 | const GrStrokeInfo& stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 673 | bool allowSW, |
| 674 | GrPathRendererChain::DrawType drawType, |
| 675 | GrPathRendererChain::StencilSupport* stencilSupport) { |
| 676 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 677 | if (!fPathRendererChain) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 678 | fPathRendererChain = new GrPathRendererChain(this); |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 679 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 680 | |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 681 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(target, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 682 | pipelineBuilder, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 683 | viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 684 | path, |
sugoi@google.com | 12b4e27 | 2012-12-06 20:13:11 +0000 | [diff] [blame] | 685 | stroke, |
bsalomon@google.com | 45a15f5 | 2012-12-10 19:10:17 +0000 | [diff] [blame] | 686 | drawType, |
| 687 | stencilSupport); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 688 | |
robertphillips | ea46150 | 2015-05-26 11:38:03 -0700 | [diff] [blame] | 689 | if (!pr && allowSW) { |
| 690 | if (!fSoftwarePathRenderer) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 691 | fSoftwarePathRenderer = new GrSoftwarePathRenderer(this); |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 692 | } |
robertphillips@google.com | 72176b2 | 2012-05-23 13:19:12 +0000 | [diff] [blame] | 693 | pr = fSoftwarePathRenderer; |
| 694 | } |
| 695 | |
| 696 | return pr; |
bsalomon@google.com | 3008519 | 2011-08-19 15:42:31 +0000 | [diff] [blame] | 697 | } |
| 698 | |
bsalomon@google.com | 27847de | 2011-02-22 20:59:41 +0000 | [diff] [blame] | 699 | //////////////////////////////////////////////////////////////////////////////// |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 700 | int GrContext::getRecommendedSampleCount(GrPixelConfig config, |
| 701 | SkScalar dpi) const { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 702 | if (!this->caps()->isConfigRenderable(config, true)) { |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | int chosenSampleCount = 0; |
jvanverth | e9c0fc6 | 2015-04-29 11:18:05 -0700 | [diff] [blame] | 706 | if (fGpu->caps()->shaderCaps()->pathRenderingSupport()) { |
commit-bot@chromium.org | b471a32 | 2014-03-10 07:40:03 +0000 | [diff] [blame] | 707 | if (dpi >= 250.0f) { |
| 708 | chosenSampleCount = 4; |
| 709 | } else { |
| 710 | chosenSampleCount = 16; |
| 711 | } |
| 712 | } |
| 713 | return chosenSampleCount <= fGpu->caps()->maxSampleCount() ? |
| 714 | chosenSampleCount : 0; |
| 715 | } |
| 716 | |
robertphillips | 77a2e52 | 2015-10-17 07:43:27 -0700 | [diff] [blame] | 717 | |
| 718 | GrDrawContext* GrContext::drawContext(GrRenderTarget* rt, const SkSurfaceProps* surfaceProps) { |
| 719 | return fDrawingManager->drawContext(rt, surfaceProps); |
| 720 | } |
| 721 | |
| 722 | bool GrContext::abandoned() const { |
| 723 | return fDrawingManager->abandoned(); |
| 724 | } |
| 725 | |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 726 | namespace { |
| 727 | void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) { |
| 728 | GrConfigConversionEffect::PMConversion pmToUPM; |
| 729 | GrConfigConversionEffect::PMConversion upmToPM; |
| 730 | GrConfigConversionEffect::TestForPreservingPMConversions(ctx, &pmToUPM, &upmToPM); |
| 731 | *pmToUPMValue = pmToUPM; |
| 732 | *upmToPMValue = upmToPM; |
| 733 | } |
| 734 | } |
| 735 | |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 736 | void GrContext::testPMConversionsIfNecessary(uint32_t flags) { |
| 737 | if (SkToBool(kUnpremul_PixelOpsFlag & flags)) { |
| 738 | SkAutoMutexAcquire ama(fTestPMConversionsMutex); |
| 739 | if (!fDidTestPMConversions) { |
| 740 | test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion); |
| 741 | fDidTestPMConversions = true; |
| 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 746 | const GrFragmentProcessor* GrContext::createPMToUPMEffect(GrTexture* texture, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 747 | bool swapRAndB, |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 748 | const SkMatrix& matrix) const { |
| 749 | // We should have already called this->testPMConversionsIfNecessary(). |
| 750 | SkASSERT(fDidTestPMConversions); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 751 | GrConfigConversionEffect::PMConversion pmToUPM = |
| 752 | static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion); |
| 753 | if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 754 | return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 755 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 756 | return nullptr; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 757 | } |
| 758 | } |
| 759 | |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 760 | const GrFragmentProcessor* GrContext::createUPMToPMEffect(GrTexture* texture, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 761 | bool swapRAndB, |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 762 | const SkMatrix& matrix) const { |
| 763 | // We should have already called this->testPMConversionsIfNecessary(). |
| 764 | SkASSERT(fDidTestPMConversions); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 765 | GrConfigConversionEffect::PMConversion upmToPM = |
| 766 | static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion); |
| 767 | if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) { |
bsalomon | 4a33952 | 2015-10-06 08:40:50 -0700 | [diff] [blame] | 768 | return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, matrix); |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 769 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 770 | return nullptr; |
bsalomon@google.com | a04e8e8 | 2012-08-27 12:53:13 +0000 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 774 | bool GrContext::didFailPMUPMConversionTest() const { |
bsalomon | 6c6f658 | 2015-09-10 08:12:46 -0700 | [diff] [blame] | 775 | // We should have already called this->testPMConversionsIfNecessary(). |
| 776 | SkASSERT(fDidTestPMConversions); |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 777 | // 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] | 778 | return GrConfigConversionEffect::kNone_PMConversion == fPMToUPMConversion; |
bsalomon | 636e802 | 2015-07-29 06:08:46 -0700 | [diff] [blame] | 779 | } |
| 780 | |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 781 | ////////////////////////////////////////////////////////////////////////////// |
| 782 | |
| 783 | void GrContext::getResourceCacheLimits(int* maxTextures, size_t* maxTextureBytes) const { |
| 784 | if (maxTextures) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 785 | *maxTextures = fResourceCache->getMaxResourceCount(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 786 | } |
| 787 | if (maxTextureBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 788 | *maxTextureBytes = fResourceCache->getMaxResourceBytes(); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 789 | } |
| 790 | } |
| 791 | |
| 792 | void GrContext::setResourceCacheLimits(int maxTextures, size_t maxTextureBytes) { |
bsalomon | 0ea80f4 | 2015-02-11 10:49:59 -0800 | [diff] [blame] | 793 | fResourceCache->setLimits(maxTextures, maxTextureBytes); |
bsalomon | 37f9a26 | 2015-02-02 13:00:10 -0800 | [diff] [blame] | 794 | } |
| 795 | |
ericrk | 0a5fa48 | 2015-09-15 14:16:10 -0700 | [diff] [blame] | 796 | ////////////////////////////////////////////////////////////////////////////// |
| 797 | |
| 798 | void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { |
| 799 | fResourceCache->dumpMemoryStatistics(traceMemoryDump); |
| 800 | } |