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 |
| 140 | SkArenaAlloc* GrRecordingContext::opPODAllocator() { |
| 141 | if (!fOpPODAllocator) { |
| 142 | // TODO: empirically determine a better number for SkArenaAlloc's firstHeapAllocation param |
| 143 | fOpPODAllocator = std::unique_ptr<SkArenaAlloc>(new SkArenaAlloc(sizeof(GrPipeline) * 100)); |
| 144 | } |
| 145 | |
| 146 | SkASSERT(fOpPODAllocator); |
| 147 | return fOpPODAllocator.get(); |
| 148 | } |
| 149 | |
| 150 | std::unique_ptr<SkArenaAlloc> GrRecordingContext::detachOpPOD() { |
| 151 | return std::move(fOpPODAllocator); |
| 152 | } |
| 153 | |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 154 | GrTextBlobCache* GrRecordingContext::getTextBlobCache() { |
| 155 | return fTextBlobCache.get(); |
| 156 | } |
| 157 | |
| 158 | const GrTextBlobCache* GrRecordingContext::getTextBlobCache() const { |
| 159 | return fTextBlobCache.get(); |
| 160 | } |
| 161 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 162 | void GrRecordingContext::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 163 | this->drawingManager()->addOnFlushCallbackObject(onFlushCBObject); |
| 164 | } |
| 165 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 166 | std::unique_ptr<GrSurfaceContext> GrRecordingContext::makeWrappedSurfaceContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 167 | sk_sp<GrSurfaceProxy> proxy, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 168 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 169 | SkAlphaType alphaType, |
| 170 | sk_sp<SkColorSpace> colorSpace, |
| 171 | const SkSurfaceProps* props) { |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 172 | ASSERT_SINGLE_OWNER_PRIV |
| 173 | |
Brian Salomon | 9d8cac8 | 2019-07-16 15:59:31 -0400 | [diff] [blame] | 174 | SkASSERT(proxy); |
| 175 | |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 176 | if (proxy->asRenderTargetProxy()) { |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 177 | SkASSERT(kPremul_SkAlphaType == alphaType || kOpaque_SkAlphaType == alphaType); |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 178 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType, |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 179 | std::move(colorSpace), props); |
| 180 | } else { |
| 181 | SkASSERT(proxy->asTextureProxy()); |
| 182 | SkASSERT(!props); |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 183 | return this->drawingManager()->makeTextureContext(std::move(proxy), colorType, alphaType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 184 | std::move(colorSpace)); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 188 | std::unique_ptr<GrTextureContext> GrRecordingContext::makeDeferredTextureContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 189 | SkBackingFit fit, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 190 | int width, |
| 191 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 192 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 193 | SkAlphaType alphaType, |
| 194 | sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 195 | GrMipMapped mipMapped, |
| 196 | GrSurfaceOrigin origin, |
| 197 | SkBudgeted budgeted, |
| 198 | GrProtected isProtected) { |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 199 | auto format = this->caps()->getDefaultBackendFormat(colorType, GrRenderable::kNo); |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 200 | if (!format.isValid()) { |
| 201 | return nullptr; |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 202 | } |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 203 | auto config = this->caps()->getConfigFromBackendFormat(format, colorType); |
| 204 | if (config == kUnknown_GrPixelConfig) { |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 205 | return nullptr; |
| 206 | } |
| 207 | |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 208 | GrSurfaceDesc desc; |
| 209 | desc.fWidth = width; |
| 210 | desc.fHeight = height; |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 211 | desc.fConfig = config; |
| 212 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 213 | sk_sp<GrTextureProxy> texture = this->proxyProvider()->createProxy( |
| 214 | format, desc, GrRenderable::kNo, 1, origin, mipMapped, fit, budgeted, isProtected); |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 215 | if (!texture) { |
| 216 | return nullptr; |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 217 | } |
| 218 | |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 219 | auto drawingManager = this->drawingManager(); |
| 220 | |
| 221 | return drawingManager->makeTextureContext(std::move(texture), colorType, alphaType, |
| 222 | std::move(colorSpace)); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 223 | } |
| 224 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 225 | std::unique_ptr<GrRenderTargetContext> GrRecordingContext::makeDeferredRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 226 | SkBackingFit fit, |
| 227 | int width, |
| 228 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 229 | GrColorType colorType, |
| 230 | sk_sp<SkColorSpace> colorSpace, |
| 231 | int sampleCnt, |
| 232 | GrMipMapped mipMapped, |
| 233 | GrSurfaceOrigin origin, |
| 234 | const SkSurfaceProps* surfaceProps, |
| 235 | SkBudgeted budgeted, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 236 | GrProtected isProtected) { |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 237 | SkASSERT(sampleCnt > 0); |
| 238 | if (this->abandoned()) { |
| 239 | return nullptr; |
| 240 | } |
| 241 | |
Robert Phillips | 0a15cc6 | 2019-07-30 12:49:10 -0400 | [diff] [blame] | 242 | auto format = this->caps()->getDefaultBackendFormat(colorType, GrRenderable::kYes); |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 243 | if (!format.isValid()) { |
| 244 | return nullptr; |
| 245 | } |
| 246 | auto config = this->caps()->getConfigFromBackendFormat(format, colorType); |
| 247 | if (config == kUnknown_GrPixelConfig) { |
| 248 | return nullptr; |
| 249 | } |
| 250 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 251 | GrSurfaceDesc desc; |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 252 | desc.fWidth = width; |
| 253 | desc.fHeight = height; |
| 254 | desc.fConfig = config; |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 255 | |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 256 | sk_sp<GrTextureProxy> rtp = |
| 257 | this->proxyProvider()->createProxy(format, desc, GrRenderable::kYes, sampleCnt, origin, |
| 258 | mipMapped, fit, budgeted, isProtected); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 259 | if (!rtp) { |
| 260 | return nullptr; |
| 261 | } |
| 262 | |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 263 | auto drawingManager = this->drawingManager(); |
| 264 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 265 | auto renderTargetContext = drawingManager->makeRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 266 | std::move(rtp), colorType, std::move(colorSpace), surfaceProps); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 267 | if (!renderTargetContext) { |
| 268 | return nullptr; |
| 269 | } |
| 270 | |
| 271 | renderTargetContext->discard(); |
| 272 | |
| 273 | return renderTargetContext; |
| 274 | } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 275 | |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 276 | static inline GrColorType color_type_fallback(GrColorType ct) { |
| 277 | switch (ct) { |
| 278 | // kRGBA_8888 is our default fallback for many color types that may not have renderable |
| 279 | // backend formats. |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 280 | case GrColorType::kAlpha_8: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 281 | case GrColorType::kBGR_565: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 282 | case GrColorType::kABGR_4444: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 283 | case GrColorType::kBGRA_8888: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 284 | case GrColorType::kRGBA_1010102: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 285 | case GrColorType::kRGBA_F16: |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 286 | case GrColorType::kRGBA_F16_Clamped: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 287 | return GrColorType::kRGBA_8888; |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 288 | case GrColorType::kAlpha_F16: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 289 | return GrColorType::kRGBA_F16; |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 290 | case GrColorType::kGray_8: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 291 | return GrColorType::kRGB_888x; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 292 | default: |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 293 | return GrColorType::kUnknown; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 297 | std::unique_ptr<GrRenderTargetContext> |
| 298 | GrRecordingContext::makeDeferredRenderTargetContextWithFallback(SkBackingFit fit, |
| 299 | int width, |
| 300 | int height, |
| 301 | GrColorType colorType, |
| 302 | sk_sp<SkColorSpace> colorSpace, |
| 303 | int sampleCnt, |
| 304 | GrMipMapped mipMapped, |
| 305 | GrSurfaceOrigin origin, |
| 306 | const SkSurfaceProps* surfaceProps, |
| 307 | SkBudgeted budgeted, |
| 308 | GrProtected isProtected) { |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 309 | SkASSERT(sampleCnt > 0); |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 310 | std::unique_ptr<GrRenderTargetContext> rtc; |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 311 | do { |
| 312 | rtc = this->makeDeferredRenderTargetContext(fit, width, height, colorType, colorSpace, |
| 313 | sampleCnt, mipMapped, origin, surfaceProps, |
| 314 | budgeted, isProtected); |
| 315 | colorType = color_type_fallback(colorType); |
| 316 | } while (!rtc && colorType != GrColorType::kUnknown); |
| 317 | return rtc; |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 320 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 321 | sk_sp<const GrCaps> GrRecordingContextPriv::refCaps() const { |
| 322 | return fContext->refCaps(); |
| 323 | } |
| 324 | |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame^] | 325 | std::unique_ptr<SkArenaAlloc> GrRecordingContextPriv::detachOpPOD() { |
| 326 | return fContext->detachOpPOD(); |
| 327 | } |
| 328 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 329 | sk_sp<GrSkSLFPFactoryCache> GrRecordingContextPriv::fpFactoryCache() { |
| 330 | return fContext->fpFactoryCache(); |
| 331 | } |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 332 | |
| 333 | sk_sp<GrOpMemoryPool> GrRecordingContextPriv::refOpMemoryPool() { |
| 334 | return fContext->refOpMemoryPool(); |
| 335 | } |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 336 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 337 | void GrRecordingContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 338 | fContext->addOnFlushCallbackObject(onFlushCBObject); |
| 339 | } |
| 340 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 341 | std::unique_ptr<GrSurfaceContext> GrRecordingContextPriv::makeWrappedSurfaceContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 342 | sk_sp<GrSurfaceProxy> proxy, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 343 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 344 | SkAlphaType alphaType, |
| 345 | sk_sp<SkColorSpace> colorSpace, |
| 346 | const SkSurfaceProps* props) { |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 347 | return fContext->makeWrappedSurfaceContext(std::move(proxy), colorType, alphaType, |
| 348 | std::move(colorSpace), props); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 349 | } |
| 350 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 351 | std::unique_ptr<GrTextureContext> GrRecordingContextPriv::makeDeferredTextureContext( |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 352 | SkBackingFit fit, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 353 | int width, |
| 354 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 355 | GrColorType colorType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 356 | SkAlphaType alphaType, |
| 357 | sk_sp<SkColorSpace> colorSpace, |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 358 | GrMipMapped mipMapped, |
| 359 | GrSurfaceOrigin origin, |
| 360 | SkBudgeted budgeted, |
| 361 | GrProtected isProtected) { |
| 362 | return fContext->makeDeferredTextureContext(fit, width, height, colorType, alphaType, |
| 363 | std::move(colorSpace), mipMapped, origin, budgeted, |
| 364 | isProtected); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 365 | } |
| 366 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 367 | std::unique_ptr<GrRenderTargetContext> GrRecordingContextPriv::makeDeferredRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 368 | SkBackingFit fit, |
| 369 | int width, |
| 370 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 371 | GrColorType colorType, |
| 372 | sk_sp<SkColorSpace> colorSpace, |
| 373 | int sampleCnt, |
| 374 | GrMipMapped mipMapped, |
| 375 | GrSurfaceOrigin origin, |
| 376 | const SkSurfaceProps* surfaceProps, |
| 377 | SkBudgeted budgeted, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 378 | GrProtected isProtected) { |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 379 | return fContext->makeDeferredRenderTargetContext(fit, width, height, colorType, |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 380 | std::move(colorSpace), sampleCnt, mipMapped, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 381 | origin, surfaceProps, budgeted, isProtected); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 382 | } |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 383 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 384 | std::unique_ptr<GrRenderTargetContext> |
| 385 | GrRecordingContextPriv::makeDeferredRenderTargetContextWithFallback( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 386 | SkBackingFit fit, |
| 387 | int width, |
| 388 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 389 | GrColorType colorType, |
| 390 | sk_sp<SkColorSpace> colorSpace, |
| 391 | int sampleCnt, |
| 392 | GrMipMapped mipMapped, |
| 393 | GrSurfaceOrigin origin, |
| 394 | const SkSurfaceProps* surfaceProps, |
| 395 | SkBudgeted budgeted, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 396 | GrProtected isProtected) { |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 397 | return fContext->makeDeferredRenderTargetContextWithFallback(fit, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 398 | width, |
| 399 | height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 400 | colorType, |
| 401 | std::move(colorSpace), |
| 402 | sampleCnt, |
| 403 | mipMapped, |
| 404 | origin, |
| 405 | surfaceProps, |
| 406 | budgeted, |
| 407 | isProtected); |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 408 | } |
Robert Phillips | 9338c60 | 2019-02-19 12:52:29 -0500 | [diff] [blame] | 409 | |
| 410 | GrContext* GrRecordingContextPriv::backdoor() { |
| 411 | return (GrContext*) fContext; |
| 412 | } |
Greg Daniel | 7bfc913 | 2019-08-14 14:23:53 -0400 | [diff] [blame] | 413 | |