Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/GrRecordingContext.h" |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrContext.h" |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 11 | #include "src/core/SkArenaAlloc.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 12 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "src/gpu/GrCaps.h" |
| 14 | #include "src/gpu/GrDrawingManager.h" |
| 15 | #include "src/gpu/GrMemoryPool.h" |
| 16 | #include "src/gpu/GrProxyProvider.h" |
| 17 | #include "src/gpu/GrRecordingContextPriv.h" |
| 18 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrSkSLFPFactoryCache.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrTextureContext.h" |
| 21 | #include "src/gpu/SkGr.h" |
Robert Phillips | 7f11fb5 | 2019-12-03 13:35:19 -0500 | [diff] [blame] | 22 | #include "src/gpu/effects/GrSkSLFP.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 23 | #include "src/gpu/text/GrTextBlobCache.h" |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 24 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 25 | #define ASSERT_SINGLE_OWNER_PRIV \ |
| 26 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());) |
| 27 | |
Robert Phillips | c1541ae | 2019-02-04 12:05:37 -0500 | [diff] [blame] | 28 | GrRecordingContext::GrRecordingContext(GrBackendApi backend, |
| 29 | const GrContextOptions& options, |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 30 | uint32_t contextID) |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 31 | : INHERITED(backend, options, contextID) |
| 32 | , fAuditTrail(new GrAuditTrail()) { |
Robert Phillips | 4217ea7 | 2019-01-30 13:08:28 -0500 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | GrRecordingContext::~GrRecordingContext() { } |
| 36 | |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 37 | /** |
| 38 | * TODO: move textblob draw calls below context (see comment below) |
| 39 | */ |
| 40 | static void textblobcache_overbudget_CB(void* data) { |
| 41 | SkASSERT(data); |
| 42 | GrRecordingContext* context = reinterpret_cast<GrRecordingContext*>(data); |
| 43 | |
| 44 | GrContext* direct = context->priv().asDirectContext(); |
| 45 | if (!direct) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on |
| 50 | // GrRenderTargetContext to perform a necessary flush. The solution is to move drawText calls |
| 51 | // to below the GrContext level, but this is not trivial because they call drawPath on |
| 52 | // SkGpuDevice. |
| 53 | direct->flush(); |
| 54 | } |
| 55 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 56 | bool GrRecordingContext::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> cache) { |
| 57 | |
| 58 | if (!INHERITED::init(std::move(caps), std::move(cache))) { |
| 59 | return false; |
| 60 | } |
| 61 | |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 62 | fStrikeCache.reset(new GrStrikeCache(this->caps(), |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 63 | this->options().fGlyphCacheTextureMaximumBytes)); |
| 64 | |
| 65 | fTextBlobCache.reset(new GrTextBlobCache(textblobcache_overbudget_CB, this, |
| 66 | this->contextID())); |
| 67 | |
Robert Phillips | 56181ba | 2019-03-08 12:00:45 -0500 | [diff] [blame] | 68 | return true; |
| 69 | } |
| 70 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 71 | void GrRecordingContext::setupDrawingManager(bool sortOpsTasks, bool reduceOpsTaskSplitting) { |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 72 | GrPathRendererChain::Options prcOptions; |
| 73 | prcOptions.fAllowPathMaskCaching = this->options().fAllowPathMaskCaching; |
| 74 | #if GR_TEST_UTILS |
| 75 | prcOptions.fGpuPathRenderers = this->options().fGpuPathRenderers; |
| 76 | #endif |
Chris Dalton | f774818 | 2019-03-18 16:22:30 +0000 | [diff] [blame] | 77 | // FIXME: Once this is removed from Chrome and Android, rename to fEnable"". |
| 78 | if (!this->options().fDisableCoverageCountingPaths) { |
| 79 | prcOptions.fGpuPathRenderers |= GpuPathRenderers::kCoverageCounting; |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 80 | } |
| 81 | if (this->options().fDisableDistanceFieldPaths) { |
| 82 | prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall; |
| 83 | } |
| 84 | |
| 85 | if (!this->proxyProvider()->renderingDirectly()) { |
| 86 | // DDL TODO: remove this crippling of the path renderer chain |
| 87 | // Disable the small path renderer bc of the proxies in the atlas. They need to be |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 88 | // unified when the opsTasks are added back to the destination drawing manager. |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 89 | prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall; |
| 90 | } |
| 91 | |
| 92 | GrTextContext::Options textContextOptions; |
| 93 | textContextOptions.fMaxDistanceFieldFontSize = this->options().fGlyphsAsPathsFontSize; |
| 94 | textContextOptions.fMinDistanceFieldFontSize = this->options().fMinDistanceFieldFontSize; |
| 95 | textContextOptions.fDistanceFieldVerticesAlwaysHaveW = false; |
| 96 | #if SK_SUPPORT_ATLAS_TEXT |
| 97 | if (GrContextOptions::Enable::kYes == this->options().fDistanceFieldGlyphVerticesAlwaysHaveW) { |
| 98 | textContextOptions.fDistanceFieldVerticesAlwaysHaveW = true; |
| 99 | } |
| 100 | #endif |
| 101 | |
| 102 | fDrawingManager.reset(new GrDrawingManager(this, |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 103 | prcOptions, |
| 104 | textContextOptions, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 105 | sortOpsTasks, |
| 106 | reduceOpsTaskSplitting)); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 107 | } |
| 108 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 109 | void GrRecordingContext::abandonContext() { |
| 110 | INHERITED::abandonContext(); |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 111 | |
Herb Derby | a00da61 | 2019-03-04 17:10:01 -0500 | [diff] [blame] | 112 | fStrikeCache->freeAll(); |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 113 | fTextBlobCache->freeAll(); |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 114 | } |
| 115 | |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 116 | GrDrawingManager* GrRecordingContext::drawingManager() { |
| 117 | return fDrawingManager.get(); |
| 118 | } |
| 119 | |
Michael Ludwig | cb10e4d | 2019-12-12 13:59:20 -0500 | [diff] [blame^] | 120 | GrOpMemoryPool* GrRecordingContext::opMemoryPool() { |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 121 | if (!fOpMemoryPool) { |
| 122 | // DDL TODO: should the size of the memory pool be decreased in DDL mode? CPU-side memory |
| 123 | // consumed in DDL mode vs. normal mode for a single skp might be a good metric of wasted |
| 124 | // memory. |
Michael Ludwig | cb10e4d | 2019-12-12 13:59:20 -0500 | [diff] [blame^] | 125 | fOpMemoryPool = std::make_unique<GrOpMemoryPool>(16384, 16384); |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 126 | } |
| 127 | |
Michael Ludwig | cb10e4d | 2019-12-12 13:59:20 -0500 | [diff] [blame^] | 128 | return fOpMemoryPool.get(); |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 129 | } |
| 130 | |
Michael Ludwig | cb10e4d | 2019-12-12 13:59:20 -0500 | [diff] [blame^] | 131 | std::unique_ptr<GrOpMemoryPool> GrRecordingContext::detachOpMemoryPool() { |
| 132 | return std::move(fOpMemoryPool); |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 133 | } |
| 134 | |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 135 | // Stored in this arena: |
| 136 | // GrTextureOp's DynamicStateArrays and FixedDynamicState |
Robert Phillips | d4fb7c7 | 2019-11-15 17:28:37 -0500 | [diff] [blame] | 137 | // some GrGeometryProcessors, GrPipelines and GrProgramInfos |
| 138 | SkArenaAlloc* GrRecordingContext::recordTimeAllocator() { |
| 139 | if (!fRecordTimeAllocator) { |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 140 | // TODO: empirically determine a better number for SkArenaAlloc's firstHeapAllocation param |
Michael Ludwig | cb10e4d | 2019-12-12 13:59:20 -0500 | [diff] [blame^] | 141 | fRecordTimeAllocator = std::make_unique<SkArenaAlloc>(sizeof(GrPipeline) * 100); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 142 | } |
| 143 | |
Robert Phillips | d4fb7c7 | 2019-11-15 17:28:37 -0500 | [diff] [blame] | 144 | return fRecordTimeAllocator.get(); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 145 | } |
| 146 | |
Robert Phillips | d4fb7c7 | 2019-11-15 17:28:37 -0500 | [diff] [blame] | 147 | std::unique_ptr<SkArenaAlloc> GrRecordingContext::detachRecordTimeAllocator() { |
| 148 | return std::move(fRecordTimeAllocator); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 149 | } |
| 150 | |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 151 | GrTextBlobCache* GrRecordingContext::getTextBlobCache() { |
| 152 | return fTextBlobCache.get(); |
| 153 | } |
| 154 | |
| 155 | const GrTextBlobCache* GrRecordingContext::getTextBlobCache() const { |
| 156 | return fTextBlobCache.get(); |
| 157 | } |
| 158 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 159 | void GrRecordingContext::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 160 | this->drawingManager()->addOnFlushCallbackObject(onFlushCBObject); |
| 161 | } |
| 162 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 163 | std::unique_ptr<GrSurfaceContext> GrRecordingContext::makeWrappedSurfaceContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 164 | sk_sp<GrSurfaceProxy> proxy, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 165 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 166 | SkAlphaType alphaType, |
| 167 | sk_sp<SkColorSpace> colorSpace, |
| 168 | const SkSurfaceProps* props) { |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 169 | ASSERT_SINGLE_OWNER_PRIV |
| 170 | |
Brian Salomon | 9d8cac8 | 2019-07-16 15:59:31 -0400 | [diff] [blame] | 171 | SkASSERT(proxy); |
| 172 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 173 | if (proxy->asRenderTargetProxy()) { |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 174 | SkASSERT(kPremul_SkAlphaType == alphaType || kOpaque_SkAlphaType == alphaType); |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 175 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType, |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 176 | std::move(colorSpace), props); |
| 177 | } else { |
| 178 | SkASSERT(proxy->asTextureProxy()); |
| 179 | SkASSERT(!props); |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 180 | return this->drawingManager()->makeTextureContext(std::move(proxy), colorType, alphaType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 181 | std::move(colorSpace)); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 185 | std::unique_ptr<GrTextureContext> GrRecordingContext::makeDeferredTextureContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 186 | SkBackingFit fit, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 187 | int width, |
| 188 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 189 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 190 | SkAlphaType alphaType, |
| 191 | sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 192 | GrMipMapped mipMapped, |
| 193 | GrSurfaceOrigin origin, |
| 194 | SkBudgeted budgeted, |
| 195 | GrProtected isProtected) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 196 | auto format = this->caps()->getDefaultBackendFormat(colorType, GrRenderable::kNo); |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 197 | if (!format.isValid()) { |
| 198 | return nullptr; |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 199 | } |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 200 | auto config = this->caps()->getConfigFromBackendFormat(format, colorType); |
| 201 | if (config == kUnknown_GrPixelConfig) { |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 202 | return nullptr; |
| 203 | } |
| 204 | |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 205 | GrSurfaceDesc desc; |
| 206 | desc.fWidth = width; |
| 207 | desc.fHeight = height; |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 208 | desc.fConfig = config; |
| 209 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 210 | sk_sp<GrTextureProxy> texture = this->proxyProvider()->createProxy( |
| 211 | format, desc, GrRenderable::kNo, 1, origin, mipMapped, fit, budgeted, isProtected); |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 212 | if (!texture) { |
| 213 | return nullptr; |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 214 | } |
| 215 | |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 216 | auto drawingManager = this->drawingManager(); |
| 217 | |
| 218 | return drawingManager->makeTextureContext(std::move(texture), colorType, alphaType, |
| 219 | std::move(colorSpace)); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 220 | } |
| 221 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 222 | std::unique_ptr<GrRenderTargetContext> GrRecordingContext::makeDeferredRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 223 | SkBackingFit fit, |
| 224 | int width, |
| 225 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 226 | GrColorType colorType, |
| 227 | sk_sp<SkColorSpace> colorSpace, |
| 228 | int sampleCnt, |
| 229 | GrMipMapped mipMapped, |
| 230 | GrSurfaceOrigin origin, |
| 231 | const SkSurfaceProps* surfaceProps, |
| 232 | SkBudgeted budgeted, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 233 | GrProtected isProtected) { |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 234 | SkASSERT(sampleCnt > 0); |
| 235 | if (this->abandoned()) { |
| 236 | return nullptr; |
| 237 | } |
| 238 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 239 | auto format = this->caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes); |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 240 | if (!format.isValid()) { |
| 241 | return nullptr; |
| 242 | } |
| 243 | auto config = this->caps()->getConfigFromBackendFormat(format, colorType); |
| 244 | if (config == kUnknown_GrPixelConfig) { |
| 245 | return nullptr; |
| 246 | } |
| 247 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 248 | GrSurfaceDesc desc; |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 249 | desc.fWidth = width; |
| 250 | desc.fHeight = height; |
| 251 | desc.fConfig = config; |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 252 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 253 | sk_sp<GrTextureProxy> rtp = |
| 254 | this->proxyProvider()->createProxy(format, desc, GrRenderable::kYes, sampleCnt, origin, |
| 255 | mipMapped, fit, budgeted, isProtected); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 256 | if (!rtp) { |
| 257 | return nullptr; |
| 258 | } |
| 259 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 260 | auto drawingManager = this->drawingManager(); |
| 261 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 262 | auto renderTargetContext = drawingManager->makeRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 263 | std::move(rtp), colorType, std::move(colorSpace), surfaceProps); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 264 | if (!renderTargetContext) { |
| 265 | return nullptr; |
| 266 | } |
| 267 | |
| 268 | renderTargetContext->discard(); |
| 269 | |
| 270 | return renderTargetContext; |
| 271 | } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 272 | |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 273 | static inline GrColorType color_type_fallback(GrColorType ct) { |
| 274 | switch (ct) { |
| 275 | // kRGBA_8888 is our default fallback for many color types that may not have renderable |
| 276 | // backend formats. |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 277 | case GrColorType::kAlpha_8: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 278 | case GrColorType::kBGR_565: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 279 | case GrColorType::kABGR_4444: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 280 | case GrColorType::kBGRA_8888: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 281 | case GrColorType::kRGBA_1010102: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 282 | case GrColorType::kRGBA_F16: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 283 | case GrColorType::kRGBA_F16_Clamped: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 284 | return GrColorType::kRGBA_8888; |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 285 | case GrColorType::kAlpha_F16: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 286 | return GrColorType::kRGBA_F16; |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 287 | case GrColorType::kGray_8: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 288 | return GrColorType::kRGB_888x; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 289 | default: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 290 | return GrColorType::kUnknown; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 294 | std::unique_ptr<GrRenderTargetContext> |
| 295 | GrRecordingContext::makeDeferredRenderTargetContextWithFallback(SkBackingFit fit, |
| 296 | int width, |
| 297 | int height, |
| 298 | GrColorType colorType, |
| 299 | sk_sp<SkColorSpace> colorSpace, |
| 300 | int sampleCnt, |
| 301 | GrMipMapped mipMapped, |
| 302 | GrSurfaceOrigin origin, |
| 303 | const SkSurfaceProps* surfaceProps, |
| 304 | SkBudgeted budgeted, |
| 305 | GrProtected isProtected) { |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 306 | SkASSERT(sampleCnt > 0); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 307 | std::unique_ptr<GrRenderTargetContext> rtc; |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 308 | do { |
| 309 | rtc = this->makeDeferredRenderTargetContext(fit, width, height, colorType, colorSpace, |
| 310 | sampleCnt, mipMapped, origin, surfaceProps, |
| 311 | budgeted, isProtected); |
| 312 | colorType = color_type_fallback(colorType); |
| 313 | } while (!rtc && colorType != GrColorType::kUnknown); |
| 314 | return rtc; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 315 | } |
| 316 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 317 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 318 | sk_sp<const GrCaps> GrRecordingContextPriv::refCaps() const { |
| 319 | return fContext->refCaps(); |
| 320 | } |
| 321 | |
Michael Ludwig | cb10e4d | 2019-12-12 13:59:20 -0500 | [diff] [blame^] | 322 | std::unique_ptr<GrOpMemoryPool> GrRecordingContextPriv::detachOpMemoryPool() { |
| 323 | return fContext->detachOpMemoryPool(); |
| 324 | } |
| 325 | |
Robert Phillips | d4fb7c7 | 2019-11-15 17:28:37 -0500 | [diff] [blame] | 326 | std::unique_ptr<SkArenaAlloc> GrRecordingContextPriv::detachRecordTimeAllocator() { |
| 327 | return fContext->detachRecordTimeAllocator(); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 330 | sk_sp<GrSkSLFPFactoryCache> GrRecordingContextPriv::fpFactoryCache() { |
| 331 | return fContext->fpFactoryCache(); |
| 332 | } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 333 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 334 | void GrRecordingContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 335 | fContext->addOnFlushCallbackObject(onFlushCBObject); |
| 336 | } |
| 337 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 338 | std::unique_ptr<GrSurfaceContext> GrRecordingContextPriv::makeWrappedSurfaceContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 339 | sk_sp<GrSurfaceProxy> proxy, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 340 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 341 | SkAlphaType alphaType, |
| 342 | sk_sp<SkColorSpace> colorSpace, |
| 343 | const SkSurfaceProps* props) { |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 344 | return fContext->makeWrappedSurfaceContext(std::move(proxy), colorType, alphaType, |
| 345 | std::move(colorSpace), props); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 346 | } |
| 347 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 348 | std::unique_ptr<GrTextureContext> GrRecordingContextPriv::makeDeferredTextureContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 349 | SkBackingFit fit, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 350 | int width, |
| 351 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 352 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 353 | SkAlphaType alphaType, |
| 354 | sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 355 | GrMipMapped mipMapped, |
| 356 | GrSurfaceOrigin origin, |
| 357 | SkBudgeted budgeted, |
| 358 | GrProtected isProtected) { |
| 359 | return fContext->makeDeferredTextureContext(fit, width, height, colorType, alphaType, |
| 360 | std::move(colorSpace), mipMapped, origin, budgeted, |
| 361 | isProtected); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 362 | } |
| 363 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 364 | std::unique_ptr<GrRenderTargetContext> GrRecordingContextPriv::makeDeferredRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 365 | SkBackingFit fit, |
| 366 | int width, |
| 367 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 368 | GrColorType colorType, |
| 369 | sk_sp<SkColorSpace> colorSpace, |
| 370 | int sampleCnt, |
| 371 | GrMipMapped mipMapped, |
| 372 | GrSurfaceOrigin origin, |
| 373 | const SkSurfaceProps* surfaceProps, |
| 374 | SkBudgeted budgeted, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 375 | GrProtected isProtected) { |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 376 | return fContext->makeDeferredRenderTargetContext(fit, width, height, colorType, |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 377 | std::move(colorSpace), sampleCnt, mipMapped, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 378 | origin, surfaceProps, budgeted, isProtected); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 379 | } |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 380 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 381 | std::unique_ptr<GrRenderTargetContext> |
| 382 | GrRecordingContextPriv::makeDeferredRenderTargetContextWithFallback( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 383 | SkBackingFit fit, |
| 384 | int width, |
| 385 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 386 | GrColorType colorType, |
| 387 | sk_sp<SkColorSpace> colorSpace, |
| 388 | int sampleCnt, |
| 389 | GrMipMapped mipMapped, |
| 390 | GrSurfaceOrigin origin, |
| 391 | const SkSurfaceProps* surfaceProps, |
| 392 | SkBudgeted budgeted, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 393 | GrProtected isProtected) { |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 394 | return fContext->makeDeferredRenderTargetContextWithFallback(fit, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 395 | width, |
| 396 | height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 397 | colorType, |
| 398 | std::move(colorSpace), |
| 399 | sampleCnt, |
| 400 | mipMapped, |
| 401 | origin, |
| 402 | surfaceProps, |
| 403 | budgeted, |
| 404 | isProtected); |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 405 | } |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 406 | |
| 407 | GrContext* GrRecordingContextPriv::backdoor() { |
| 408 | return (GrContext*) fContext; |
| 409 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 410 | |