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