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