Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -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 "src/gpu/GrContextPriv.h" |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "include/gpu/GrContextThreadSafeProxy.h" |
| 11 | #include "include/gpu/GrTexture.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/GrContextThreadSafeProxyPriv.h" |
| 14 | #include "src/gpu/GrDrawingManager.h" |
| 15 | #include "src/gpu/GrGpu.h" |
| 16 | #include "src/gpu/GrMemoryPool.h" |
| 17 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrSkSLFPFactoryCache.h" |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrSurfaceContextPriv.h" |
Mike Klein | 4b432fa | 2019-06-06 11:44:05 -0500 | [diff] [blame] | 20 | #include "src/gpu/GrSurfacePriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/GrTextureContext.h" |
| 22 | #include "src/gpu/SkGr.h" |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 23 | #include "src/gpu/effects/generated/GrConfigConversionEffect.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/text/GrTextBlobCache.h" |
| 25 | #include "src/image/SkImage_Base.h" |
| 26 | #include "src/image/SkImage_Gpu.h" |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 27 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 28 | #define ASSERT_OWNED_PROXY(P) \ |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 29 | SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == fContext) |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 30 | #define ASSERT_SINGLE_OWNER \ |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 31 | SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(fContext->singleOwner());) |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 32 | #define RETURN_VALUE_IF_ABANDONED(value) if (fContext->abandoned()) { return (value); } |
| 33 | #define RETURN_IF_ABANDONED RETURN_VALUE_IF_ABANDONED(void) |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 34 | |
Robert Phillips | a41c685 | 2019-02-07 10:44:10 -0500 | [diff] [blame] | 35 | sk_sp<const GrCaps> GrContextPriv::refCaps() const { |
| 36 | return fContext->refCaps(); |
| 37 | } |
| 38 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 39 | sk_sp<GrSkSLFPFactoryCache> GrContextPriv::fpFactoryCache() { |
| 40 | return fContext->fpFactoryCache(); |
| 41 | } |
| 42 | |
| 43 | sk_sp<GrOpMemoryPool> GrContextPriv::refOpMemoryPool() { |
Robert Phillips | d684148 | 2019-02-08 10:29:20 -0500 | [diff] [blame] | 44 | return fContext->refOpMemoryPool(); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 45 | } |
| 46 | |
Robert Phillips | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 47 | void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 48 | fContext->addOnFlushCallbackObject(onFlushCBObject); |
| 49 | } |
| 50 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 51 | std::unique_ptr<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext( |
| 52 | sk_sp<GrSurfaceProxy> proxy, |
| 53 | GrColorType colorType, |
| 54 | SkAlphaType alphaType, |
| 55 | sk_sp<SkColorSpace> colorSpace, |
| 56 | const SkSurfaceProps* props) { |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 57 | return fContext->makeWrappedSurfaceContext(std::move(proxy), colorType, alphaType, |
| 58 | std::move(colorSpace), props); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 59 | } |
| 60 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 61 | std::unique_ptr<GrTextureContext> GrContextPriv::makeDeferredTextureContext( |
| 62 | SkBackingFit fit, |
| 63 | int width, |
| 64 | int height, |
| 65 | GrColorType colorType, |
| 66 | SkAlphaType alphaType, |
| 67 | sk_sp<SkColorSpace> colorSpace, |
| 68 | GrMipMapped mipMapped, |
| 69 | GrSurfaceOrigin origin, |
| 70 | SkBudgeted budgeted, |
| 71 | GrProtected isProtected) { |
Brian Salomon | 947efe2 | 2019-07-16 15:36:11 -0400 | [diff] [blame] | 72 | return fContext->makeDeferredTextureContext(fit, width, height, colorType, alphaType, |
| 73 | std::move(colorSpace), mipMapped, origin, budgeted, |
| 74 | isProtected); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 77 | std::unique_ptr<GrRenderTargetContext> GrContextPriv::makeDeferredRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 78 | SkBackingFit fit, |
| 79 | int width, |
| 80 | int height, |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 81 | GrColorType colorType, |
| 82 | sk_sp<SkColorSpace> colorSpace, |
| 83 | int sampleCnt, |
| 84 | GrMipMapped mipMapped, |
| 85 | GrSurfaceOrigin origin, |
| 86 | const SkSurfaceProps* surfaceProps, |
| 87 | SkBudgeted budgeted, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 88 | GrProtected isProtected) { |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 89 | return fContext->makeDeferredRenderTargetContext(fit, width, height, colorType, |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 90 | std::move(colorSpace), sampleCnt, mipMapped, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 91 | origin, surfaceProps, budgeted, isProtected); |
Robert Phillips | b97da53 | 2019-02-12 15:24:12 -0500 | [diff] [blame] | 92 | } |
| 93 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 94 | std::unique_ptr<GrRenderTargetContext> GrContextPriv::makeDeferredRenderTargetContextWithFallback( |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 95 | SkBackingFit fit, int width, int height, GrColorType colorType, |
| 96 | sk_sp<SkColorSpace> colorSpace, int sampleCnt, GrMipMapped mipMapped, |
| 97 | GrSurfaceOrigin origin, const SkSurfaceProps* surfaceProps, SkBudgeted budgeted) { |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 98 | return fContext->makeDeferredRenderTargetContextWithFallback( |
Brian Salomon | 27ae52c | 2019-07-03 11:27:44 -0400 | [diff] [blame] | 99 | fit, width, height, colorType, std::move(colorSpace), sampleCnt, mipMapped, origin, |
| 100 | surfaceProps, budgeted); |
Robert Phillips | 6f0e02f | 2019-02-13 11:02:28 -0500 | [diff] [blame] | 101 | } |
| 102 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 103 | std::unique_ptr<GrTextureContext> GrContextPriv::makeBackendTextureContext( |
| 104 | const GrBackendTexture& tex, |
| 105 | GrSurfaceOrigin origin, |
| 106 | GrColorType colorType, |
| 107 | SkAlphaType alphaType, |
| 108 | sk_sp<SkColorSpace> colorSpace) { |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 109 | ASSERT_SINGLE_OWNER |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 110 | |
| 111 | sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendTexture( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 112 | tex, colorType, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 113 | if (!proxy) { |
| 114 | return nullptr; |
| 115 | } |
| 116 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 117 | return this->drawingManager()->makeTextureContext(std::move(proxy), colorType, alphaType, |
Brian Salomon | e7499c7 | 2019-06-24 12:12:36 -0400 | [diff] [blame] | 118 | std::move(colorSpace)); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 119 | } |
| 120 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 121 | std::unique_ptr<GrRenderTargetContext> GrContextPriv::makeBackendTextureRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 122 | const GrBackendTexture& tex, |
| 123 | GrSurfaceOrigin origin, |
| 124 | int sampleCnt, |
| 125 | GrColorType colorType, |
| 126 | sk_sp<SkColorSpace> colorSpace, |
| 127 | const SkSurfaceProps* props, |
| 128 | ReleaseProc releaseProc, |
| 129 | ReleaseContext releaseCtx) { |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 130 | ASSERT_SINGLE_OWNER |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 131 | SkASSERT(sampleCnt > 0); |
| 132 | |
| 133 | sk_sp<GrTextureProxy> proxy(this->proxyProvider()->wrapRenderableBackendTexture( |
Robert Phillips | 0902c98 | 2019-07-16 07:47:56 -0400 | [diff] [blame] | 134 | tex, origin, sampleCnt, colorType, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, |
| 135 | releaseProc, releaseCtx)); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 136 | if (!proxy) { |
| 137 | return nullptr; |
| 138 | } |
| 139 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 140 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType, |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 141 | std::move(colorSpace), props); |
| 142 | } |
| 143 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 144 | std::unique_ptr<GrRenderTargetContext> GrContextPriv::makeBackendRenderTargetRenderTargetContext( |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 145 | const GrBackendRenderTarget& backendRT, |
| 146 | GrSurfaceOrigin origin, |
| 147 | GrColorType colorType, |
| 148 | sk_sp<SkColorSpace> colorSpace, |
| 149 | const SkSurfaceProps* surfaceProps, |
| 150 | ReleaseProc releaseProc, |
| 151 | ReleaseContext releaseCtx) { |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 152 | ASSERT_SINGLE_OWNER |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 153 | |
| 154 | sk_sp<GrSurfaceProxy> proxy = this->proxyProvider()->wrapBackendRenderTarget( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 155 | backendRT, colorType, origin, releaseProc, releaseCtx); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 156 | if (!proxy) { |
| 157 | return nullptr; |
| 158 | } |
| 159 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 160 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType, |
| 161 | std::move(colorSpace), surfaceProps); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 162 | } |
| 163 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 164 | std::unique_ptr<GrRenderTargetContext> |
| 165 | GrContextPriv::makeBackendTextureAsRenderTargetRenderTargetContext(const GrBackendTexture& tex, |
| 166 | GrSurfaceOrigin origin, |
| 167 | int sampleCnt, |
| 168 | GrColorType colorType, |
| 169 | sk_sp<SkColorSpace> colorSpace, |
| 170 | const SkSurfaceProps* props) { |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 171 | ASSERT_SINGLE_OWNER |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 172 | SkASSERT(sampleCnt > 0); |
| 173 | sk_sp<GrSurfaceProxy> proxy( |
Robert Phillips | c80b0e9 | 2019-07-23 10:27:09 -0400 | [diff] [blame] | 174 | this->proxyProvider()->wrapBackendTextureAsRenderTarget(tex, colorType, |
| 175 | origin, sampleCnt)); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 176 | if (!proxy) { |
| 177 | return nullptr; |
| 178 | } |
| 179 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 180 | return this->drawingManager()->makeRenderTargetContext(std::move(proxy), colorType, |
| 181 | std::move(colorSpace), props); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 182 | } |
| 183 | |
Brian Salomon | bf6b979 | 2019-08-21 09:38:10 -0400 | [diff] [blame] | 184 | std::unique_ptr<GrRenderTargetContext> GrContextPriv::makeVulkanSecondaryCBRenderTargetContext( |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 185 | const SkImageInfo& imageInfo, const GrVkDrawableInfo& vkInfo, const SkSurfaceProps* props) { |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 186 | ASSERT_SINGLE_OWNER |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 187 | sk_sp<GrSurfaceProxy> proxy( |
| 188 | this->proxyProvider()->wrapVulkanSecondaryCBAsRenderTarget(imageInfo, vkInfo)); |
| 189 | if (!proxy) { |
| 190 | return nullptr; |
| 191 | } |
| 192 | |
Brian Salomon | d628747 | 2019-06-24 15:50:07 -0400 | [diff] [blame] | 193 | return this->drawingManager()->makeRenderTargetContext( |
| 194 | std::move(proxy), |
| 195 | SkColorTypeToGrColorType(imageInfo.colorType()), |
| 196 | imageInfo.refColorSpace(), |
| 197 | props); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 198 | } |
| 199 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 200 | GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies, |
| 201 | const GrFlushInfo& info) { |
| 202 | ASSERT_SINGLE_OWNER |
| 203 | RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo) |
| 204 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "flushSurfaces", fContext); |
| 205 | SkASSERT(numProxies >= 0); |
| 206 | SkASSERT(!numProxies || proxies); |
| 207 | for (int i = 0; i < numProxies; ++i) { |
| 208 | SkASSERT(proxies[i]); |
| 209 | ASSERT_OWNED_PROXY(proxies[i]); |
| 210 | } |
| 211 | return fContext->drawingManager()->flushSurfaces( |
| 212 | proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 213 | } |
| 214 | |
Brian Salomon | 693bc2b | 2019-05-09 13:48:00 +0000 | [diff] [blame] | 215 | void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) { |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 216 | this->flushSurfaces(proxy ? &proxy : nullptr, proxy ? 1 : 0, {}); |
Brian Salomon | 693bc2b | 2019-05-09 13:48:00 +0000 | [diff] [blame] | 217 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 218 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 219 | void GrContextPriv::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) { |
| 220 | fContext->drawingManager()->moveRenderTasksToDDL(ddl); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 221 | } |
| 222 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 223 | void GrContextPriv::copyRenderTasksFromDDL(const SkDeferredDisplayList* ddl, |
| 224 | GrRenderTargetProxy* newDest) { |
| 225 | fContext->drawingManager()->copyRenderTasksFromDDL(ddl, newDest); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 226 | } |
| 227 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 228 | ////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 229 | |
| 230 | #if GR_TEST_UTILS |
| 231 | void GrContextPriv::resetGpuStats() const { |
| 232 | #if GR_GPU_STATS |
| 233 | fContext->fGpu->stats()->reset(); |
| 234 | #endif |
| 235 | } |
| 236 | |
| 237 | void GrContextPriv::dumpCacheStats(SkString* out) const { |
| 238 | #if GR_CACHE_STATS |
| 239 | fContext->fResourceCache->dumpStats(out); |
| 240 | #endif |
| 241 | } |
| 242 | |
| 243 | void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 244 | SkTArray<double>* values) const { |
| 245 | #if GR_CACHE_STATS |
| 246 | fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values); |
| 247 | #endif |
| 248 | } |
| 249 | |
| 250 | void GrContextPriv::printCacheStats() const { |
| 251 | SkString out; |
| 252 | this->dumpCacheStats(&out); |
| 253 | SkDebugf("%s", out.c_str()); |
| 254 | } |
| 255 | |
| 256 | void GrContextPriv::dumpGpuStats(SkString* out) const { |
| 257 | #if GR_GPU_STATS |
| 258 | return fContext->fGpu->stats()->dump(out); |
| 259 | #endif |
| 260 | } |
| 261 | |
| 262 | void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 263 | SkTArray<double>* values) const { |
| 264 | #if GR_GPU_STATS |
| 265 | return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values); |
| 266 | #endif |
| 267 | } |
| 268 | |
| 269 | void GrContextPriv::printGpuStats() const { |
| 270 | SkString out; |
| 271 | this->dumpGpuStats(&out); |
| 272 | SkDebugf("%s", out.c_str()); |
| 273 | } |
| 274 | |
| 275 | void GrContextPriv::testingOnly_setTextBlobCacheLimit(size_t bytes) { |
Robert Phillips | 2184fb7 | 2019-02-21 16:11:41 -0500 | [diff] [blame] | 276 | fContext->priv().getTextBlobCache()->setBudget(bytes); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | sk_sp<SkImage> GrContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index) { |
| 280 | auto atlasManager = this->getAtlasManager(); |
| 281 | if (!atlasManager) { |
| 282 | return nullptr; |
| 283 | } |
| 284 | |
| 285 | unsigned int numActiveProxies; |
| 286 | const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(format, &numActiveProxies); |
| 287 | if (index >= numActiveProxies || !proxies || !proxies[index]) { |
| 288 | return nullptr; |
| 289 | } |
| 290 | |
| 291 | SkASSERT(proxies[index]->priv().isExact()); |
| 292 | sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID, |
| 293 | kPremul_SkAlphaType, proxies[index], nullptr)); |
| 294 | return image; |
| 295 | } |
| 296 | |
| 297 | void GrContextPriv::testingOnly_purgeAllUnlockedResources() { |
| 298 | fContext->fResourceCache->purgeAllUnlocked(); |
| 299 | } |
| 300 | |
| 301 | void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 302 | fContext->flush(); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 303 | fContext->drawingManager()->testingOnly_removeOnFlushCallbackObject(cb); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 304 | } |
| 305 | #endif |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 306 | |
| 307 | bool GrContextPriv::validPMUPMConversionExists() { |
| 308 | ASSERT_SINGLE_OWNER |
| 309 | if (!fContext->fDidTestPMConversions) { |
| 310 | fContext->fPMUPMConversionsRoundTrip = |
| 311 | GrConfigConversionEffect::TestForPreservingPMConversions(fContext); |
| 312 | fContext->fDidTestPMConversions = true; |
| 313 | } |
| 314 | |
| 315 | // The PM<->UPM tests fail or succeed together so we only need to check one. |
| 316 | return fContext->fPMUPMConversionsRoundTrip; |
| 317 | } |
| 318 | |
| 319 | std::unique_ptr<GrFragmentProcessor> GrContextPriv::createPMToUPMEffect( |
| 320 | std::unique_ptr<GrFragmentProcessor> fp) { |
| 321 | ASSERT_SINGLE_OWNER |
| 322 | // We should have already called this->priv().validPMUPMConversionExists() in this case |
| 323 | SkASSERT(fContext->fDidTestPMConversions); |
| 324 | // ...and it should have succeeded |
| 325 | SkASSERT(this->validPMUPMConversionExists()); |
| 326 | |
| 327 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul); |
| 328 | } |
| 329 | |
| 330 | std::unique_ptr<GrFragmentProcessor> GrContextPriv::createUPMToPMEffect( |
| 331 | std::unique_ptr<GrFragmentProcessor> fp) { |
| 332 | ASSERT_SINGLE_OWNER |
| 333 | // We should have already called this->priv().validPMUPMConversionExists() in this case |
| 334 | SkASSERT(fContext->fDidTestPMConversions); |
| 335 | // ...and it should have succeeded |
| 336 | SkASSERT(this->validPMUPMConversionExists()); |
| 337 | |
| 338 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul); |
| 339 | } |
Robert Phillips | cb1adb4 | 2019-06-10 15:09:34 -0400 | [diff] [blame] | 340 | |
| 341 | ////////////////////////////////////////////////////////////////////////////// |
| 342 | |
| 343 | #include "src/core/SkMipMap.h" |
| 344 | |
| 345 | GrBackendTexture GrContextPriv::createBackendTexture(const SkPixmap srcData[], int numLevels, |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 346 | GrRenderable renderable, |
| 347 | GrProtected isProtected) { |
Robert Phillips | cb1adb4 | 2019-06-10 15:09:34 -0400 | [diff] [blame] | 348 | if (!fContext->asDirectContext()) { |
| 349 | return {}; |
| 350 | } |
| 351 | |
| 352 | if (this->abandoned()) { |
| 353 | return {}; |
| 354 | } |
| 355 | |
| 356 | if (!srcData || !numLevels) { |
| 357 | return {}; |
| 358 | } |
| 359 | |
| 360 | int baseWidth = srcData[0].width(); |
| 361 | int baseHeight = srcData[0].height(); |
| 362 | SkColorType colorType = srcData[0].colorType(); |
| 363 | |
| 364 | if (numLevels > 1) { |
| 365 | if (numLevels != SkMipMap::ComputeLevelCount(baseWidth, baseHeight) + 1) { |
| 366 | return {}; |
| 367 | } |
| 368 | |
| 369 | int currentWidth = baseWidth; |
| 370 | int currentHeight = baseHeight; |
| 371 | for (int i = 1; i < numLevels; ++i) { |
| 372 | currentWidth = SkTMax(1, currentWidth / 2); |
| 373 | currentHeight = SkTMax(1, currentHeight / 2); |
| 374 | |
| 375 | if (srcData[i].colorType() != colorType) { |
| 376 | return {}; |
| 377 | } |
| 378 | |
| 379 | if (srcData[i].width() != currentWidth || srcData[i].height() != currentHeight) { |
| 380 | return {}; |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
Robert Phillips | d5e80ca | 2019-07-29 14:11:35 -0400 | [diff] [blame] | 385 | GrBackendFormat backendFormat = fContext->defaultBackendFormat(colorType, renderable); |
Robert Phillips | cb1adb4 | 2019-06-10 15:09:34 -0400 | [diff] [blame] | 386 | if (!backendFormat.isValid()) { |
| 387 | return {}; |
| 388 | } |
| 389 | |
| 390 | GrGpu* gpu = fContext->fGpu.get(); |
| 391 | |
| 392 | // TODO: propagate the array of pixmaps interface to GrGpu |
| 393 | return gpu->createBackendTexture(baseWidth, baseHeight, backendFormat, |
| 394 | GrMipMapped::kNo, // TODO: use real mipmap setting here |
| 395 | renderable, srcData[0].addr(), srcData[0].rowBytes(), |
Robert Phillips | da2e67a | 2019-07-01 15:04:06 -0400 | [diff] [blame] | 396 | nullptr, isProtected); |
Robert Phillips | cb1adb4 | 2019-06-10 15:09:34 -0400 | [diff] [blame] | 397 | } |