blob: 8d7f945f503b3c4ac56fa7d8d99e0a45b98e8470 [file] [log] [blame]
bsalomon@google.com27847de2011-02-22 20:59:41 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2011 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.
bsalomon@google.com27847de2011-02-22 20:59:41 +00006 */
7
bsalomon@google.com1fadb202011-12-12 16:10:08 +00008#include "GrContext.h"
Brian Salomon5f33a8c2018-02-26 14:32:39 -05009#include "GrBackendSemaphore.h"
robertphillips77a2e522015-10-17 07:43:27 -070010#include "GrDrawingManager.h"
Robert Phillips646e4292017-06-13 12:44:56 -040011#include "GrGpu.h"
Robert Phillipsc994a932018-06-19 13:09:54 -040012#include "GrMemoryPool.h"
Robert Phillipsdbaf3172019-02-06 15:12:53 -050013#include "GrPathRendererChain.h"
Robert Phillips1afd4cd2018-01-08 13:40:32 -050014#include "GrProxyProvider.h"
Brian Salomonc65aec92017-03-09 09:03:58 -050015#include "GrRenderTargetProxy.h"
bsalomon0ea80f42015-02-11 10:49:59 -080016#include "GrResourceCache.h"
bsalomond309e7a2015-04-30 14:18:54 -070017#include "GrResourceProvider.h"
Greg Danield85f97d2017-03-07 13:37:21 -050018#include "GrSemaphore.h"
robertphillips@google.com72176b22012-05-23 13:19:12 +000019#include "GrSoftwarePathRenderer.h"
Brian Salomondcbb9d92017-07-19 10:53:20 -040020#include "GrTracing.h"
Robert Phillipsd5f9cdd2018-01-31 09:29:48 -050021#include "SkDeferredDisplayList.h"
Brian Osman3b655982017-03-07 16:58:08 -050022#include "SkGr.h"
Mike Reed7fcfb622018-02-09 13:26:46 -050023#include "SkImageInfoPriv.h"
Brian Osman51279982017-08-23 10:12:00 -040024#include "SkMakeUnique.h"
Robert Phillips6b6fcc72018-03-30 13:57:00 -040025#include "SkSurface_Gpu.h"
Brian Osman51279982017-08-23 10:12:00 -040026#include "SkTaskGroup.h"
Khushal71652e22018-10-29 13:05:36 -070027#include "SkTraceMemoryDump.h"
joshualitt5478d422014-11-14 16:00:38 -080028#include "effects/GrConfigConversionEffect.h"
Ethan Nicholas00543112018-07-31 09:44:36 -040029#include "effects/GrSkSLFP.h"
Chris Dalton6c3879d2018-11-01 11:13:19 -060030#include "ccpr/GrCoverageCountingPathRenderer.h"
Brian Salomon5f33a8c2018-02-26 14:32:39 -050031#include "text/GrTextBlobCache.h"
Robert Phillipsdbaf3172019-02-06 15:12:53 -050032#include "text/GrTextContext.h"
Mike Klein0ec1c572018-12-04 11:52:51 -050033#include <atomic>
34#include <unordered_map>
Greg Danielb76a72a2017-07-13 15:07:54 -040035
Robert Phillipse78b7252017-04-06 07:59:41 -040036#define ASSERT_OWNED_PROXY(P) \
Brian Salomonfd98c2c2018-07-31 17:25:29 -040037 SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this)
Robert Phillips7ee385e2017-03-30 08:02:11 -040038
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000039#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
joshualitt1de610a2016-01-06 08:26:09 -080040#define ASSERT_SINGLE_OWNER \
Robert Phillipsa41c6852019-02-07 10:44:10 -050041 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
robertphillips7761d612016-05-16 09:14:53 -070042#define RETURN_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return; }
43#define RETURN_FALSE_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return false; }
44#define RETURN_NULL_IF_ABANDONED if (fDrawingManager->wasAbandoned()) { return nullptr; }
bsalomon@google.combc4b6542011-11-19 13:56:11 +000045
robertphillipsea461502015-05-26 11:38:03 -070046////////////////////////////////////////////////////////////////////////////////
47
Robert Phillipsa41c6852019-02-07 10:44:10 -050048GrContext::GrContext(GrBackendApi backend, const GrContextOptions& options, int32_t contextID)
49 : INHERITED(backend, options, contextID) {
halcanary96fcdcc2015-08-27 07:41:13 -070050 fResourceCache = nullptr;
51 fResourceProvider = nullptr;
Robert Phillipsc4039ea2018-03-01 11:36:45 -050052 fGlyphCache = nullptr;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000053}
54
Robert Phillipsbb606772019-02-04 17:50:57 -050055bool GrContext::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
Greg Danielb76a72a2017-07-13 15:07:54 -040056 ASSERT_SINGLE_OWNER
Robert Phillipsfde6fa02018-03-02 08:53:14 -050057 SkASSERT(fThreadSafeProxy); // needs to have been initialized by derived classes
Robert Phillipsa41c6852019-02-07 10:44:10 -050058 SkASSERT(this->proxyProvider());
Robert Phillips88260b52018-01-19 12:56:09 -050059
Robert Phillipsbb606772019-02-04 17:50:57 -050060 if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
61 return false;
62 }
63
64 SkASSERT(this->caps());
65
Robert Phillips88260b52018-01-19 12:56:09 -050066 if (fGpu) {
Robert Phillipsa41c6852019-02-07 10:44:10 -050067 fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID());
68 fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner(),
Robert Phillipsc1541ae2019-02-04 12:05:37 -050069 this->options().fExplicitlyAllocateGPUResources);
Robert Phillips88260b52018-01-19 12:56:09 -050070 }
71
Robert Phillips88260b52018-01-19 12:56:09 -050072 if (fResourceCache) {
Robert Phillipsa41c6852019-02-07 10:44:10 -050073 fResourceCache->setProxyProvider(this->proxyProvider());
Robert Phillips88260b52018-01-19 12:56:09 -050074 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -050075
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000076 fDidTestPMConversions = false;
77
bsalomon6b2552f2016-09-15 13:50:26 -070078 GrPathRendererChain::Options prcOptions;
Robert Phillipsc1541ae2019-02-04 12:05:37 -050079 prcOptions.fAllowPathMaskCaching = this->options().fAllowPathMaskCaching;
Brian Osman195c05b2017-08-30 15:14:04 -040080#if GR_TEST_UTILS
Robert Phillipsc1541ae2019-02-04 12:05:37 -050081 prcOptions.fGpuPathRenderers = this->options().fGpuPathRenderers;
Brian Osman195c05b2017-08-30 15:14:04 -040082#endif
Robert Phillipsc1541ae2019-02-04 12:05:37 -050083 if (this->options().fDisableCoverageCountingPaths) {
Chris Daltonef125092018-06-26 18:16:47 -060084 prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kCoverageCounting;
85 }
Robert Phillipsc1541ae2019-02-04 12:05:37 -050086 if (this->options().fDisableDistanceFieldPaths) {
Brian Osman195c05b2017-08-30 15:14:04 -040087 prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
Brian Osmanb350ae22017-08-29 16:15:39 -040088 }
Brian Salomonaf597482017-11-07 16:23:34 -050089
Robert Phillipsd5f9cdd2018-01-31 09:29:48 -050090 if (!fResourceCache) {
91 // DDL TODO: remove this crippling of the path renderer chain
92 // Disable the small path renderer bc of the proxies in the atlas. They need to be
93 // unified when the opLists are added back to the destination drawing manager.
94 prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
Robert Phillips5ffcb4d2018-07-03 16:39:40 -040095 prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kStencilAndCover;
Robert Phillipsd5f9cdd2018-01-31 09:29:48 -050096 }
97
Herb Derby26cbe512018-05-24 14:39:01 -040098 GrTextContext::Options textContextOptions;
Robert Phillipsc1541ae2019-02-04 12:05:37 -050099 textContextOptions.fMaxDistanceFieldFontSize = this->options().fGlyphsAsPathsFontSize;
100 textContextOptions.fMinDistanceFieldFontSize = this->options().fMinDistanceFieldFontSize;
Herb Derby26cbe512018-05-24 14:39:01 -0400101 textContextOptions.fDistanceFieldVerticesAlwaysHaveW = false;
Brian Salomonb5086962017-12-13 10:59:33 -0500102#if SK_SUPPORT_ATLAS_TEXT
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500103 if (GrContextOptions::Enable::kYes == this->options().fDistanceFieldGlyphVerticesAlwaysHaveW) {
Herb Derby26cbe512018-05-24 14:39:01 -0400104 textContextOptions.fDistanceFieldVerticesAlwaysHaveW = true;
Brian Salomonb5086962017-12-13 10:59:33 -0500105 }
106#endif
Brian Salomonaf597482017-11-07 16:23:34 -0500107
Robert Phillips64ecdce2018-04-02 10:26:39 -0400108 bool explicitlyAllocatingResources = fResourceProvider
109 ? fResourceProvider->explicitlyAllocateGPUResources()
110 : false;
Herb Derby26cbe512018-05-24 14:39:01 -0400111 fDrawingManager.reset(new GrDrawingManager(this, prcOptions, textContextOptions,
Robert Phillipsa41c6852019-02-07 10:44:10 -0500112 this->singleOwner(), explicitlyAllocatingResources,
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500113 this->options().fSortRenderTargets,
114 this->options().fReduceOpListSplitting));
joshualitt7c3a2f82015-03-31 13:32:05 -0700115
Robert Phillipsbb606772019-02-04 17:50:57 -0500116 fGlyphCache = new GrStrikeCache(this->caps(), this->options().fGlyphCacheTextureMaximumBytes);
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500117
Robert Phillipsfd0d9702019-02-01 10:19:42 -0500118 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this, this->contextID()));
Brian Salomon91a3e522017-06-23 10:58:19 -0400119
Robert Phillipsfde6fa02018-03-02 08:53:14 -0500120 // DDL TODO: we need to think through how the task group & persistent cache
121 // get passed on to/shared between all the DDLRecorders created with this context.
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500122 if (this->options().fExecutor) {
123 fTaskGroup = skstd::make_unique<SkTaskGroup>(*this->options().fExecutor);
Brian Osman51279982017-08-23 10:12:00 -0400124 }
125
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500126 fPersistentCache = this->options().fPersistentCache;
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400127
Brian Salomon91a3e522017-06-23 10:58:19 -0400128 return true;
bsalomon@google.comc0af3172012-06-15 14:10:09 +0000129}
130
bsalomon@google.com27847de2011-02-22 20:59:41 +0000131GrContext::~GrContext() {
joshualitt1de610a2016-01-06 08:26:09 -0800132 ASSERT_SINGLE_OWNER
133
Robert Phillips2e6feed2018-01-22 15:27:20 -0500134 if (fDrawingManager) {
135 fDrawingManager->cleanup();
136 }
halcanary385fe4d2015-08-26 13:07:48 -0700137 delete fResourceProvider;
138 delete fResourceCache;
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500139 delete fGlyphCache;
bsalomon@google.com27847de2011-02-22 20:59:41 +0000140}
141
Robert Phillips4217ea72019-01-30 13:08:28 -0500142sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
143 return fThreadSafeProxy;
144}
145
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400146//////////////////////////////////////////////////////////////////////////////
147
bsalomon2354f842014-07-28 13:48:36 -0700148void GrContext::abandonContext() {
joshualitt1de610a2016-01-06 08:26:09 -0800149 ASSERT_SINGLE_OWNER
150
Robert Phillipsa41c6852019-02-07 10:44:10 -0500151 this->proxyProvider()->abandon();
bsalomond309e7a2015-04-30 14:18:54 -0700152 fResourceProvider->abandon();
robertphillips0dfa62c2015-11-16 06:23:31 -0800153
154 // Need to abandon the drawing manager first so all the render targets
155 // will be released/forgotten before they too are abandoned.
156 fDrawingManager->abandon();
157
bsalomon@google.com205d4602011-04-25 12:43:45 +0000158 // abandon first to so destructors
159 // don't try to free the resources in the API.
bsalomon0ea80f42015-02-11 10:49:59 -0800160 fResourceCache->abandonAll();
bsalomonc8dc1f72014-08-21 13:02:13 -0700161
bsalomon6e2aad42016-04-01 11:54:31 -0700162 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
163
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500164 fGlyphCache->freeAll();
bsalomon6e2aad42016-04-01 11:54:31 -0700165 fTextBlobCache->freeAll();
166}
167
Khushalc421ca12018-06-26 14:38:34 -0700168bool GrContext::abandoned() const {
169 ASSERT_SINGLE_OWNER
Brian Salomon9bc76d92019-01-24 12:18:33 -0500170 // If called from ~GrContext(), the drawing manager may already be gone.
171 return !fDrawingManager || fDrawingManager->wasAbandoned();
Khushalc421ca12018-06-26 14:38:34 -0700172}
173
bsalomon6e2aad42016-04-01 11:54:31 -0700174void GrContext::releaseResourcesAndAbandonContext() {
175 ASSERT_SINGLE_OWNER
176
Brian Salomon614c1a82018-12-19 15:42:06 -0500177 if (this->abandoned()) {
178 return;
179 }
Robert Phillipsa41c6852019-02-07 10:44:10 -0500180 this->proxyProvider()->abandon();
bsalomon6e2aad42016-04-01 11:54:31 -0700181 fResourceProvider->abandon();
182
183 // Need to abandon the drawing manager first so all the render targets
184 // will be released/forgotten before they too are abandoned.
185 fDrawingManager->abandon();
186
187 // Release all resources in the backend 3D API.
188 fResourceCache->releaseAll();
189
190 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
bsalomon@google.com205d4602011-04-25 12:43:45 +0000191
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500192 fGlyphCache->freeAll();
joshualitt26ffc002015-04-16 11:24:04 -0700193 fTextBlobCache->freeAll();
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000194}
195
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000196void GrContext::resetContext(uint32_t state) {
joshualitt1de610a2016-01-06 08:26:09 -0800197 ASSERT_SINGLE_OWNER
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000198 fGpu->markContextDirty(state);
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000199}
200
201void GrContext::freeGpuResources() {
joshualitt1de610a2016-01-06 08:26:09 -0800202 ASSERT_SINGLE_OWNER
203
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500204 fGlyphCache->freeAll();
robertphillips68737822015-10-29 12:12:21 -0700205
206 fDrawingManager->freeGpuResources();
bsalomon3033b9f2015-04-13 11:09:56 -0700207
208 fResourceCache->purgeAllUnlocked();
bsalomon@google.com27847de2011-02-22 20:59:41 +0000209}
210
Robert Phillips6eba0632018-03-28 12:25:42 -0400211void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) {
212 ASSERT_SINGLE_OWNER
213 fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
214 fResourceCache->purgeAsNeeded();
215 fTextBlobCache->purgeStaleBlobs();
216}
217
Jim Van Verth76d917c2017-12-13 09:26:37 -0500218void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
Brian Salomon5e150852017-03-22 14:53:13 -0400219 ASSERT_SINGLE_OWNER
Chris Dalton6c3879d2018-11-01 11:13:19 -0600220
221 auto purgeTime = GrStdSteadyClock::now() - msNotUsed;
222
Jim Van Verth76d917c2017-12-13 09:26:37 -0500223 fResourceCache->purgeAsNeeded();
Chris Dalton6c3879d2018-11-01 11:13:19 -0600224 fResourceCache->purgeResourcesNotUsedSince(purgeTime);
225
226 if (auto ccpr = fDrawingManager->getCoverageCountingPathRenderer()) {
Robert Phillipsa41c6852019-02-07 10:44:10 -0500227 ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime);
Chris Dalton6c3879d2018-11-01 11:13:19 -0600228 }
Jim Van Verth76d917c2017-12-13 09:26:37 -0500229
230 fTextBlobCache->purgeStaleBlobs();
Brian Salomon5e150852017-03-22 14:53:13 -0400231}
232
Derek Sollenberger5480a182017-05-25 16:43:59 -0400233void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
234 ASSERT_SINGLE_OWNER
235 fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
236}
237
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000238void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800239 ASSERT_SINGLE_OWNER
240
bsalomon71cb0c22014-11-14 12:10:14 -0800241 if (resourceCount) {
bsalomon0ea80f42015-02-11 10:49:59 -0800242 *resourceCount = fResourceCache->getBudgetedResourceCount();
bsalomon71cb0c22014-11-14 12:10:14 -0800243 }
244 if (resourceBytes) {
bsalomon0ea80f42015-02-11 10:49:59 -0800245 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
bsalomon71cb0c22014-11-14 12:10:14 -0800246 }
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000247}
248
Derek Sollenbergeree479142017-05-24 11:41:33 -0400249size_t GrContext::getResourceCachePurgeableBytes() const {
250 ASSERT_SINGLE_OWNER
251 return fResourceCache->getPurgeableBytes();
252}
253
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000254////////////////////////////////////////////////////////////////////////////////
255
Robert Phillipsbb606772019-02-04 17:50:57 -0500256int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400257
Robert Phillipsbb606772019-02-04 17:50:57 -0500258int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400259
Brian Salomonbdecacf2018-02-02 20:32:49 -0500260bool GrContext::colorTypeSupportedAsImage(SkColorType colorType) const {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400261 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Robert Phillipsbb606772019-02-04 17:50:57 -0500262 return this->caps()->isConfigTexturable(config);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500263}
264
265int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400266 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Robert Phillipsbb606772019-02-04 17:50:57 -0500267 return this->caps()->maxRenderTargetSampleCount(config);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500268}
269
270////////////////////////////////////////////////////////////////////////////////
271
joshualitt0db6dfa2015-04-10 07:01:30 -0700272void GrContext::TextBlobCacheOverBudgetCB(void* data) {
273 SkASSERT(data);
Brian Osman11052242016-10-27 14:47:55 -0400274 // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on
275 // GrRenderTargetContext to perform a necessary flush. The solution is to move drawText calls
276 // to below the GrContext level, but this is not trivial because they call drawPath on
277 // SkGpuDevice.
joshualitt0db6dfa2015-04-10 07:01:30 -0700278 GrContext* context = reinterpret_cast<GrContext*>(data);
279 context->flush();
280}
281
bsalomon@google.com27847de2011-02-22 20:59:41 +0000282////////////////////////////////////////////////////////////////////////////////
283
bsalomonb77a9072016-09-07 10:02:04 -0700284void GrContext::flush() {
joshualitt1de610a2016-01-06 08:26:09 -0800285 ASSERT_SINGLE_OWNER
robertphillipsea461502015-05-26 11:38:03 -0700286 RETURN_IF_ABANDONED
Robert Phillips7ee385e2017-03-30 08:02:11 -0400287
288 fDrawingManager->flush(nullptr);
289}
290
Greg Daniel51316782017-08-02 15:10:09 +0000291GrSemaphoresSubmitted GrContext::flushAndSignalSemaphores(int numSemaphores,
292 GrBackendSemaphore signalSemaphores[]) {
293 ASSERT_SINGLE_OWNER
294 if (fDrawingManager->wasAbandoned()) { return GrSemaphoresSubmitted::kNo; }
295
296 return fDrawingManager->flush(nullptr, numSemaphores, signalSemaphores);
297}
298
Greg Daniela870b462019-01-08 15:49:46 -0500299////////////////////////////////////////////////////////////////////////////////
300
301void GrContext::storeVkPipelineCacheData() {
302 if (fGpu) {
303 fGpu->storeVkPipelineCacheData();
304 }
305}
306
307////////////////////////////////////////////////////////////////////////////////
308
Brian Salomonaff329b2017-08-11 09:40:37 -0400309std::unique_ptr<GrFragmentProcessor> GrContext::createPMToUPMEffect(
Brian Osman5ea96bf2018-10-02 14:58:05 -0400310 std::unique_ptr<GrFragmentProcessor> fp) {
Robert Phillips757914d2017-01-25 15:48:30 -0500311 ASSERT_SINGLE_OWNER
Brian Osman5ea96bf2018-10-02 14:58:05 -0400312 // We should have already called this->validPMUPMConversionExists() in this case
313 SkASSERT(fDidTestPMConversions);
314 // ...and it should have succeeded
315 SkASSERT(this->validPMUPMConversionExists());
Brian Osman409e74f2017-04-17 11:48:28 -0400316
Brian Osman5ea96bf2018-10-02 14:58:05 -0400317 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul);
Robert Phillips757914d2017-01-25 15:48:30 -0500318}
319
Brian Salomonaff329b2017-08-11 09:40:37 -0400320std::unique_ptr<GrFragmentProcessor> GrContext::createUPMToPMEffect(
Brian Osman5ea96bf2018-10-02 14:58:05 -0400321 std::unique_ptr<GrFragmentProcessor> fp) {
joshualitt1de610a2016-01-06 08:26:09 -0800322 ASSERT_SINGLE_OWNER
Brian Osman5ea96bf2018-10-02 14:58:05 -0400323 // We should have already called this->validPMUPMConversionExists() in this case
324 SkASSERT(fDidTestPMConversions);
325 // ...and it should have succeeded
326 SkASSERT(this->validPMUPMConversionExists());
Brian Osman409e74f2017-04-17 11:48:28 -0400327
Brian Osman5ea96bf2018-10-02 14:58:05 -0400328 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000329}
330
Brian Osman409e74f2017-04-17 11:48:28 -0400331bool GrContext::validPMUPMConversionExists() {
joshualitt1de610a2016-01-06 08:26:09 -0800332 ASSERT_SINGLE_OWNER
Brian Osman409e74f2017-04-17 11:48:28 -0400333 if (!fDidTestPMConversions) {
Brian Osman28804f32017-04-20 10:24:36 -0400334 fPMUPMConversionsRoundTrip = GrConfigConversionEffect::TestForPreservingPMConversions(this);
Brian Osman409e74f2017-04-17 11:48:28 -0400335 fDidTestPMConversions = true;
336 }
337
bsalomon636e8022015-07-29 06:08:46 -0700338 // The PM<->UPM tests fail or succeed together so we only need to check one.
Brian Osman28804f32017-04-20 10:24:36 -0400339 return fPMUPMConversionsRoundTrip;
bsalomon636e8022015-07-29 06:08:46 -0700340}
341
Khushal3e7548c2018-05-23 15:45:01 -0700342bool GrContext::supportsDistanceFieldText() const {
Robert Phillipsbb606772019-02-04 17:50:57 -0500343 return this->caps()->shaderCaps()->supportsDistanceFieldText();
Khushal3e7548c2018-05-23 15:45:01 -0700344}
345
bsalomon37f9a262015-02-02 13:00:10 -0800346//////////////////////////////////////////////////////////////////////////////
347
Robert Phillipsfc711a22018-02-13 17:03:00 -0500348// DDL TODO: remove 'maxResources'
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500349void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800350 ASSERT_SINGLE_OWNER
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500351 if (maxResources) {
352 *maxResources = fResourceCache->getMaxResourceCount();
bsalomon37f9a262015-02-02 13:00:10 -0800353 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500354 if (maxResourceBytes) {
355 *maxResourceBytes = fResourceCache->getMaxResourceBytes();
bsalomon37f9a262015-02-02 13:00:10 -0800356 }
357}
358
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500359void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) {
joshualitt1de610a2016-01-06 08:26:09 -0800360 ASSERT_SINGLE_OWNER
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500361 fResourceCache->setLimits(maxResources, maxResourceBytes);
bsalomon37f9a262015-02-02 13:00:10 -0800362}
363
ericrk0a5fa482015-09-15 14:16:10 -0700364//////////////////////////////////////////////////////////////////////////////
ericrk0a5fa482015-09-15 14:16:10 -0700365void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
joshualitt1de610a2016-01-06 08:26:09 -0800366 ASSERT_SINGLE_OWNER
ericrk0a5fa482015-09-15 14:16:10 -0700367 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
Khushal71652e22018-10-29 13:05:36 -0700368 traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
369 fTextBlobCache->usedBytes());
ericrk0a5fa482015-09-15 14:16:10 -0700370}
Brian Osman71a18892017-08-10 10:23:25 -0400371