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