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" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 11 | #include "src/gpu/GrAuditTrail.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "src/gpu/GrContextThreadSafeProxyPriv.h" |
| 13 | #include "src/gpu/GrDrawingManager.h" |
| 14 | #include "src/gpu/GrGpu.h" |
| 15 | #include "src/gpu/GrMemoryPool.h" |
| 16 | #include "src/gpu/GrRenderTargetContext.h" |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 17 | #include "src/gpu/GrSurfaceContext.h" |
Greg Daniel | 46cfbc6 | 2019-06-07 11:43:30 -0400 | [diff] [blame] | 18 | #include "src/gpu/GrSurfaceContextPriv.h" |
Mike Klein | 4b432fa | 2019-06-06 11:44:05 -0500 | [diff] [blame] | 19 | #include "src/gpu/GrSurfacePriv.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 20 | #include "src/gpu/GrTexture.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/gpu/SkGr.h" |
Robert Phillips | 7f11fb5 | 2019-12-03 13:35:19 -0500 | [diff] [blame] | 22 | #include "src/gpu/effects/GrSkSLFP.h" |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 23 | #include "src/gpu/effects/generated/GrConfigConversionEffect.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 24 | #include "src/gpu/text/GrAtlasManager.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 25 | #include "src/gpu/text/GrTextBlobCache.h" |
| 26 | #include "src/image/SkImage_Base.h" |
| 27 | #include "src/image/SkImage_Gpu.h" |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 28 | |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 29 | #define ASSERT_OWNED_PROXY(P) \ |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 30 | SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == fContext) |
Adlai Holler | 33dbd65 | 2020-06-01 12:35:42 -0400 | [diff] [blame] | 31 | #define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(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 | c5058a6 | 2019-02-15 12:52:59 -0500 | [diff] [blame] | 39 | void GrContextPriv::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 40 | fContext->addOnFlushCallbackObject(onFlushCBObject); |
| 41 | } |
| 42 | |
Greg Daniel | 55f040b | 2020-02-13 15:38:32 +0000 | [diff] [blame] | 43 | GrSemaphoresSubmitted GrContextPriv::flushSurfaces(GrSurfaceProxy* proxies[], int numProxies, |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 44 | const GrFlushInfo& info) { |
| 45 | ASSERT_SINGLE_OWNER |
| 46 | RETURN_VALUE_IF_ABANDONED(GrSemaphoresSubmitted::kNo) |
| 47 | GR_CREATE_TRACE_MARKER_CONTEXT("GrContextPriv", "flushSurfaces", fContext); |
| 48 | SkASSERT(numProxies >= 0); |
| 49 | SkASSERT(!numProxies || proxies); |
| 50 | for (int i = 0; i < numProxies; ++i) { |
| 51 | SkASSERT(proxies[i]); |
| 52 | ASSERT_OWNED_PROXY(proxies[i]); |
| 53 | } |
| 54 | return fContext->drawingManager()->flushSurfaces( |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 55 | proxies, numProxies, SkSurface::BackendSurfaceAccess::kNoAccess, info, nullptr); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 56 | } |
| 57 | |
Greg Daniel | 55f040b | 2020-02-13 15:38:32 +0000 | [diff] [blame] | 58 | void GrContextPriv::flushSurface(GrSurfaceProxy* proxy) { |
| 59 | this->flushSurfaces(proxy ? &proxy : nullptr, proxy ? 1 : 0, {}); |
Brian Salomon | 693bc2b | 2019-05-09 13:48:00 +0000 | [diff] [blame] | 60 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 61 | |
Adlai Holler | 7580ad4 | 2020-06-24 13:45:25 -0400 | [diff] [blame] | 62 | void GrContextPriv::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList> ddl, |
| 63 | GrRenderTargetProxy* newDest) { |
| 64 | fContext->drawingManager()->copyRenderTasksFromDDL(std::move(ddl), newDest); |
| 65 | } |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 66 | |
Robert Phillips | 43e7e4f | 2020-05-06 13:34:45 -0400 | [diff] [blame] | 67 | bool GrContextPriv::compile(const GrProgramDesc& desc, const GrProgramInfo& info) { |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 68 | GrGpu* gpu = this->getGpu(); |
| 69 | if (!gpu) { |
Robert Phillips | 43e7e4f | 2020-05-06 13:34:45 -0400 | [diff] [blame] | 70 | return false; |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 71 | } |
| 72 | |
Robert Phillips | 43e7e4f | 2020-05-06 13:34:45 -0400 | [diff] [blame] | 73 | return gpu->compile(desc, info); |
Robert Phillips | 7b0ed55 | 2020-02-20 12:45:19 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 77 | ////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 78 | #if GR_TEST_UTILS |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 79 | |
| 80 | void GrContextPriv::dumpCacheStats(SkString* out) const { |
| 81 | #if GR_CACHE_STATS |
| 82 | fContext->fResourceCache->dumpStats(out); |
| 83 | #endif |
| 84 | } |
| 85 | |
| 86 | void GrContextPriv::dumpCacheStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 87 | SkTArray<double>* values) const { |
| 88 | #if GR_CACHE_STATS |
| 89 | fContext->fResourceCache->dumpStatsKeyValuePairs(keys, values); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | void GrContextPriv::printCacheStats() const { |
| 94 | SkString out; |
| 95 | this->dumpCacheStats(&out); |
| 96 | SkDebugf("%s", out.c_str()); |
| 97 | } |
| 98 | |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 99 | ///////////////////////////////////////////////// |
| 100 | void GrContextPriv::resetGpuStats() const { |
| 101 | #if GR_GPU_STATS |
| 102 | fContext->fGpu->stats()->reset(); |
| 103 | #endif |
| 104 | } |
| 105 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 106 | void GrContextPriv::dumpGpuStats(SkString* out) const { |
| 107 | #if GR_GPU_STATS |
| 108 | return fContext->fGpu->stats()->dump(out); |
| 109 | #endif |
| 110 | } |
| 111 | |
| 112 | void GrContextPriv::dumpGpuStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 113 | SkTArray<double>* values) const { |
| 114 | #if GR_GPU_STATS |
| 115 | return fContext->fGpu->stats()->dumpKeyValuePairs(keys, values); |
| 116 | #endif |
| 117 | } |
| 118 | |
| 119 | void GrContextPriv::printGpuStats() const { |
| 120 | SkString out; |
| 121 | this->dumpGpuStats(&out); |
| 122 | SkDebugf("%s", out.c_str()); |
| 123 | } |
| 124 | |
Robert Phillips | 273f107 | 2020-05-05 13:03:07 -0400 | [diff] [blame] | 125 | ///////////////////////////////////////////////// |
| 126 | void GrContextPriv::resetContextStats() const { |
| 127 | #if GR_GPU_STATS |
| 128 | fContext->stats()->reset(); |
| 129 | #endif |
| 130 | } |
| 131 | |
| 132 | void GrContextPriv::dumpContextStats(SkString* out) const { |
| 133 | #if GR_GPU_STATS |
| 134 | return fContext->stats()->dump(out); |
| 135 | #endif |
| 136 | } |
| 137 | |
| 138 | void GrContextPriv::dumpContextStatsKeyValuePairs(SkTArray<SkString>* keys, |
| 139 | SkTArray<double>* values) const { |
| 140 | #if GR_GPU_STATS |
| 141 | return fContext->stats()->dumpKeyValuePairs(keys, values); |
| 142 | #endif |
| 143 | } |
| 144 | |
| 145 | void GrContextPriv::printContextStats() const { |
| 146 | SkString out; |
| 147 | this->dumpContextStats(&out); |
| 148 | SkDebugf("%s", out.c_str()); |
| 149 | } |
| 150 | |
| 151 | ///////////////////////////////////////////////// |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 152 | sk_sp<SkImage> GrContextPriv::testingOnly_getFontAtlasImage(GrMaskFormat format, unsigned int index) { |
| 153 | auto atlasManager = this->getAtlasManager(); |
| 154 | if (!atlasManager) { |
| 155 | return nullptr; |
| 156 | } |
| 157 | |
| 158 | unsigned int numActiveProxies; |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 159 | const GrSurfaceProxyView* views = atlasManager->getViews(format, &numActiveProxies); |
| 160 | if (index >= numActiveProxies || !views || !views[index].proxy()) { |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 161 | return nullptr; |
| 162 | } |
| 163 | |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 164 | SkColorType colorType = GrColorTypeToSkColorType(GrMaskFormatToColorType(format)); |
Greg Daniel | 9715b6c | 2019-12-10 15:03:10 -0500 | [diff] [blame] | 165 | SkASSERT(views[index].proxy()->priv().isExact()); |
Brian Salomon | 729fc0c | 2019-09-30 16:33:11 +0000 | [diff] [blame] | 166 | sk_sp<SkImage> image(new SkImage_Gpu(sk_ref_sp(fContext), kNeedNewImageUniqueID, |
Greg Daniel | 7c165a4 | 2020-01-22 12:22:36 -0500 | [diff] [blame] | 167 | views[index], colorType, kPremul_SkAlphaType, nullptr)); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 168 | return image; |
| 169 | } |
| 170 | |
| 171 | void GrContextPriv::testingOnly_purgeAllUnlockedResources() { |
| 172 | fContext->fResourceCache->purgeAllUnlocked(); |
| 173 | } |
| 174 | |
| 175 | void GrContextPriv::testingOnly_flushAndRemoveOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 176 | fContext->flushAndSubmit(); |
Robert Phillips | 292a6b2 | 2019-02-14 14:49:02 -0500 | [diff] [blame] | 177 | fContext->drawingManager()->testingOnly_removeOnFlushCallbackObject(cb); |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 178 | } |
| 179 | #endif |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 180 | |
| 181 | bool GrContextPriv::validPMUPMConversionExists() { |
| 182 | ASSERT_SINGLE_OWNER |
Robert Phillips | 07531a0 | 2020-07-15 15:11:09 -0400 | [diff] [blame] | 183 | |
Greg Daniel | 6eb8c24 | 2019-06-05 10:22:24 -0400 | [diff] [blame] | 184 | if (!fContext->fDidTestPMConversions) { |
| 185 | fContext->fPMUPMConversionsRoundTrip = |
| 186 | GrConfigConversionEffect::TestForPreservingPMConversions(fContext); |
| 187 | fContext->fDidTestPMConversions = true; |
| 188 | } |
| 189 | |
| 190 | // The PM<->UPM tests fail or succeed together so we only need to check one. |
| 191 | return fContext->fPMUPMConversionsRoundTrip; |
| 192 | } |
| 193 | |
| 194 | std::unique_ptr<GrFragmentProcessor> GrContextPriv::createPMToUPMEffect( |
| 195 | std::unique_ptr<GrFragmentProcessor> fp) { |
| 196 | ASSERT_SINGLE_OWNER |
| 197 | // We should have already called this->priv().validPMUPMConversionExists() in this case |
| 198 | SkASSERT(fContext->fDidTestPMConversions); |
| 199 | // ...and it should have succeeded |
| 200 | SkASSERT(this->validPMUPMConversionExists()); |
| 201 | |
| 202 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul); |
| 203 | } |
| 204 | |
| 205 | std::unique_ptr<GrFragmentProcessor> GrContextPriv::createUPMToPMEffect( |
| 206 | std::unique_ptr<GrFragmentProcessor> fp) { |
| 207 | ASSERT_SINGLE_OWNER |
| 208 | // We should have already called this->priv().validPMUPMConversionExists() in this case |
| 209 | SkASSERT(fContext->fDidTestPMConversions); |
| 210 | // ...and it should have succeeded |
| 211 | SkASSERT(this->validPMUPMConversionExists()); |
| 212 | |
| 213 | return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul); |
| 214 | } |