blob: 1ccbc6ba76f1353b7259f73a3e0914c0495d32c7 [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());)
Robert Phillipsa9162df2019-02-11 14:12:03 -050042#define RETURN_IF_ABANDONED if (this->abandoned()) { return; }
43#define RETURN_FALSE_IF_ABANDONED if (this->abandoned()) { return false; }
44#define RETURN_NULL_IF_ABANDONED if (this->abandoned()) { 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 Phillips292a6b22019-02-14 14:49:02 -050055GrContext::~GrContext() {
56 ASSERT_SINGLE_OWNER
57
Robert Phillips6a6de562019-02-15 15:19:15 -050058 if (this->drawingManager()) {
59 this->drawingManager()->cleanup();
Robert Phillips292a6b22019-02-14 14:49:02 -050060 }
61 delete fResourceProvider;
62 delete fResourceCache;
63 delete fGlyphCache;
64}
65
Robert Phillipsbb606772019-02-04 17:50:57 -050066bool GrContext::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
Greg Danielb76a72a2017-07-13 15:07:54 -040067 ASSERT_SINGLE_OWNER
Robert Phillipsfde6fa02018-03-02 08:53:14 -050068 SkASSERT(fThreadSafeProxy); // needs to have been initialized by derived classes
Robert Phillipsa41c6852019-02-07 10:44:10 -050069 SkASSERT(this->proxyProvider());
Robert Phillips88260b52018-01-19 12:56:09 -050070
Robert Phillipsbb606772019-02-04 17:50:57 -050071 if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
72 return false;
73 }
74
75 SkASSERT(this->caps());
76
Robert Phillips88260b52018-01-19 12:56:09 -050077 if (fGpu) {
Robert Phillipsa41c6852019-02-07 10:44:10 -050078 fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID());
79 fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner(),
Robert Phillips292a6b22019-02-14 14:49:02 -050080 this->explicitlyAllocateGPUResources());
Robert Phillips88260b52018-01-19 12:56:09 -050081 }
82
Robert Phillips88260b52018-01-19 12:56:09 -050083 if (fResourceCache) {
Robert Phillipsa41c6852019-02-07 10:44:10 -050084 fResourceCache->setProxyProvider(this->proxyProvider());
Robert Phillips88260b52018-01-19 12:56:09 -050085 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -050086
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000087 fDidTestPMConversions = false;
88
bsalomon6b2552f2016-09-15 13:50:26 -070089 GrPathRendererChain::Options prcOptions;
Robert Phillipsc1541ae2019-02-04 12:05:37 -050090 prcOptions.fAllowPathMaskCaching = this->options().fAllowPathMaskCaching;
Brian Osman195c05b2017-08-30 15:14:04 -040091#if GR_TEST_UTILS
Robert Phillipsc1541ae2019-02-04 12:05:37 -050092 prcOptions.fGpuPathRenderers = this->options().fGpuPathRenderers;
Brian Osman195c05b2017-08-30 15:14:04 -040093#endif
Robert Phillipsc1541ae2019-02-04 12:05:37 -050094 if (this->options().fDisableCoverageCountingPaths) {
Chris Daltonef125092018-06-26 18:16:47 -060095 prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kCoverageCounting;
96 }
Robert Phillipsc1541ae2019-02-04 12:05:37 -050097 if (this->options().fDisableDistanceFieldPaths) {
Brian Osman195c05b2017-08-30 15:14:04 -040098 prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
Brian Osmanb350ae22017-08-29 16:15:39 -040099 }
Brian Salomonaf597482017-11-07 16:23:34 -0500100
Robert Phillipsd5f9cdd2018-01-31 09:29:48 -0500101 if (!fResourceCache) {
102 // DDL TODO: remove this crippling of the path renderer chain
103 // Disable the small path renderer bc of the proxies in the atlas. They need to be
104 // unified when the opLists are added back to the destination drawing manager.
105 prcOptions.fGpuPathRenderers &= ~GpuPathRenderers::kSmall;
106 }
107
Herb Derby26cbe512018-05-24 14:39:01 -0400108 GrTextContext::Options textContextOptions;
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500109 textContextOptions.fMaxDistanceFieldFontSize = this->options().fGlyphsAsPathsFontSize;
110 textContextOptions.fMinDistanceFieldFontSize = this->options().fMinDistanceFieldFontSize;
Herb Derby26cbe512018-05-24 14:39:01 -0400111 textContextOptions.fDistanceFieldVerticesAlwaysHaveW = false;
Brian Salomonb5086962017-12-13 10:59:33 -0500112#if SK_SUPPORT_ATLAS_TEXT
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500113 if (GrContextOptions::Enable::kYes == this->options().fDistanceFieldGlyphVerticesAlwaysHaveW) {
Herb Derby26cbe512018-05-24 14:39:01 -0400114 textContextOptions.fDistanceFieldVerticesAlwaysHaveW = true;
Brian Salomonb5086962017-12-13 10:59:33 -0500115 }
116#endif
Brian Salomonaf597482017-11-07 16:23:34 -0500117
Herb Derby26cbe512018-05-24 14:39:01 -0400118 fDrawingManager.reset(new GrDrawingManager(this, prcOptions, textContextOptions,
Robert Phillips7e90be92019-02-15 12:22:59 -0500119 this->singleOwner(),
120 this->explicitlyAllocateGPUResources(),
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500121 this->options().fSortRenderTargets,
122 this->options().fReduceOpListSplitting));
joshualitt7c3a2f82015-03-31 13:32:05 -0700123
Robert Phillipsbb606772019-02-04 17:50:57 -0500124 fGlyphCache = new GrStrikeCache(this->caps(), this->options().fGlyphCacheTextureMaximumBytes);
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500125
Robert Phillipsfd0d9702019-02-01 10:19:42 -0500126 fTextBlobCache.reset(new GrTextBlobCache(TextBlobCacheOverBudgetCB, this, this->contextID()));
Brian Salomon91a3e522017-06-23 10:58:19 -0400127
Robert Phillipsfde6fa02018-03-02 08:53:14 -0500128 // DDL TODO: we need to think through how the task group & persistent cache
129 // get passed on to/shared between all the DDLRecorders created with this context.
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500130 if (this->options().fExecutor) {
131 fTaskGroup = skstd::make_unique<SkTaskGroup>(*this->options().fExecutor);
Brian Osman51279982017-08-23 10:12:00 -0400132 }
133
Robert Phillipsc1541ae2019-02-04 12:05:37 -0500134 fPersistentCache = this->options().fPersistentCache;
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400135
Brian Salomon91a3e522017-06-23 10:58:19 -0400136 return true;
bsalomon@google.comc0af3172012-06-15 14:10:09 +0000137}
138
Robert Phillips4217ea72019-01-30 13:08:28 -0500139sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
140 return fThreadSafeProxy;
141}
142
Robert Phillipsb97da532019-02-12 15:24:12 -0500143GrDrawingManager* GrContext::drawingManager() {
144 return fDrawingManager.get();
145}
146
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400147//////////////////////////////////////////////////////////////////////////////
148
bsalomon2354f842014-07-28 13:48:36 -0700149void GrContext::abandonContext() {
Robert Phillipsa9162df2019-02-11 14:12:03 -0500150 if (this->abandoned()) {
151 return;
152 }
joshualitt1de610a2016-01-06 08:26:09 -0800153
Robert Phillipsa9162df2019-02-11 14:12:03 -0500154 INHERITED::abandonContext();
155
bsalomond309e7a2015-04-30 14:18:54 -0700156 fResourceProvider->abandon();
robertphillips0dfa62c2015-11-16 06:23:31 -0800157
Robert Phillipsa9162df2019-02-11 14:12:03 -0500158 // Need to cleanup the drawing manager first so all the render targets
robertphillips0dfa62c2015-11-16 06:23:31 -0800159 // will be released/forgotten before they too are abandoned.
Robert Phillips6a6de562019-02-15 15:19:15 -0500160 this->drawingManager()->cleanup();
robertphillips0dfa62c2015-11-16 06:23:31 -0800161
bsalomon@google.com205d4602011-04-25 12:43:45 +0000162 // abandon first to so destructors
163 // don't try to free the resources in the API.
bsalomon0ea80f42015-02-11 10:49:59 -0800164 fResourceCache->abandonAll();
bsalomonc8dc1f72014-08-21 13:02:13 -0700165
bsalomon6e2aad42016-04-01 11:54:31 -0700166 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
167
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500168 fGlyphCache->freeAll();
bsalomon6e2aad42016-04-01 11:54:31 -0700169 fTextBlobCache->freeAll();
Khushalc421ca12018-06-26 14:38:34 -0700170}
171
bsalomon6e2aad42016-04-01 11:54:31 -0700172void GrContext::releaseResourcesAndAbandonContext() {
Brian Salomon614c1a82018-12-19 15:42:06 -0500173 if (this->abandoned()) {
174 return;
175 }
Robert Phillipsa9162df2019-02-11 14:12:03 -0500176
177 INHERITED::abandonContext();
178
bsalomon6e2aad42016-04-01 11:54:31 -0700179 fResourceProvider->abandon();
180
Robert Phillipsa9162df2019-02-11 14:12:03 -0500181 // Need to cleanup the drawing manager first so all the render targets
bsalomon6e2aad42016-04-01 11:54:31 -0700182 // will be released/forgotten before they too are abandoned.
Robert Phillips6a6de562019-02-15 15:19:15 -0500183 this->drawingManager()->cleanup();
bsalomon6e2aad42016-04-01 11:54:31 -0700184
185 // Release all resources in the backend 3D API.
186 fResourceCache->releaseAll();
187
188 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
bsalomon@google.com205d4602011-04-25 12:43:45 +0000189
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500190 fGlyphCache->freeAll();
joshualitt26ffc002015-04-16 11:24:04 -0700191 fTextBlobCache->freeAll();
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000192}
193
Brian Salomon1f05d452019-02-08 12:33:08 -0500194void GrContext::resetGLTextureBindings() {
195 if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) {
196 return;
197 }
198 fGpu->resetTextureBindings();
199}
200
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000201void GrContext::resetContext(uint32_t state) {
joshualitt1de610a2016-01-06 08:26:09 -0800202 ASSERT_SINGLE_OWNER
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000203 fGpu->markContextDirty(state);
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000204}
205
206void GrContext::freeGpuResources() {
joshualitt1de610a2016-01-06 08:26:09 -0800207 ASSERT_SINGLE_OWNER
208
Robert Phillipsc4039ea2018-03-01 11:36:45 -0500209 fGlyphCache->freeAll();
robertphillips68737822015-10-29 12:12:21 -0700210
Robert Phillips6a6de562019-02-15 15:19:15 -0500211 this->drawingManager()->freeGpuResources();
bsalomon3033b9f2015-04-13 11:09:56 -0700212
213 fResourceCache->purgeAllUnlocked();
bsalomon@google.com27847de2011-02-22 20:59:41 +0000214}
215
Robert Phillips6eba0632018-03-28 12:25:42 -0400216void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) {
217 ASSERT_SINGLE_OWNER
218 fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
219 fResourceCache->purgeAsNeeded();
220 fTextBlobCache->purgeStaleBlobs();
221}
222
Jim Van Verth76d917c2017-12-13 09:26:37 -0500223void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
Brian Salomon5e150852017-03-22 14:53:13 -0400224 ASSERT_SINGLE_OWNER
Chris Dalton6c3879d2018-11-01 11:13:19 -0600225
226 auto purgeTime = GrStdSteadyClock::now() - msNotUsed;
227
Jim Van Verth76d917c2017-12-13 09:26:37 -0500228 fResourceCache->purgeAsNeeded();
Chris Dalton6c3879d2018-11-01 11:13:19 -0600229 fResourceCache->purgeResourcesNotUsedSince(purgeTime);
230
Robert Phillips6a6de562019-02-15 15:19:15 -0500231 if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) {
Robert Phillipsa41c6852019-02-07 10:44:10 -0500232 ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime);
Chris Dalton6c3879d2018-11-01 11:13:19 -0600233 }
Jim Van Verth76d917c2017-12-13 09:26:37 -0500234
235 fTextBlobCache->purgeStaleBlobs();
Brian Salomon5e150852017-03-22 14:53:13 -0400236}
237
Derek Sollenberger5480a182017-05-25 16:43:59 -0400238void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
239 ASSERT_SINGLE_OWNER
240 fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
241}
242
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000243void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800244 ASSERT_SINGLE_OWNER
245
bsalomon71cb0c22014-11-14 12:10:14 -0800246 if (resourceCount) {
bsalomon0ea80f42015-02-11 10:49:59 -0800247 *resourceCount = fResourceCache->getBudgetedResourceCount();
bsalomon71cb0c22014-11-14 12:10:14 -0800248 }
249 if (resourceBytes) {
bsalomon0ea80f42015-02-11 10:49:59 -0800250 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
bsalomon71cb0c22014-11-14 12:10:14 -0800251 }
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000252}
253
Derek Sollenbergeree479142017-05-24 11:41:33 -0400254size_t GrContext::getResourceCachePurgeableBytes() const {
255 ASSERT_SINGLE_OWNER
256 return fResourceCache->getPurgeableBytes();
257}
258
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000259////////////////////////////////////////////////////////////////////////////////
260
Robert Phillipsbb606772019-02-04 17:50:57 -0500261int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400262
Robert Phillipsbb606772019-02-04 17:50:57 -0500263int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400264
Brian Salomonbdecacf2018-02-02 20:32:49 -0500265bool GrContext::colorTypeSupportedAsImage(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()->isConfigTexturable(config);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500268}
269
270int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400271 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Robert Phillipsbb606772019-02-04 17:50:57 -0500272 return this->caps()->maxRenderTargetSampleCount(config);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500273}
274
275////////////////////////////////////////////////////////////////////////////////
276
joshualitt0db6dfa2015-04-10 07:01:30 -0700277void GrContext::TextBlobCacheOverBudgetCB(void* data) {
278 SkASSERT(data);
Brian Osman11052242016-10-27 14:47:55 -0400279 // TextBlobs are drawn at the SkGpuDevice level, therefore they cannot rely on
280 // GrRenderTargetContext to perform a necessary flush. The solution is to move drawText calls
281 // to below the GrContext level, but this is not trivial because they call drawPath on
282 // SkGpuDevice.
joshualitt0db6dfa2015-04-10 07:01:30 -0700283 GrContext* context = reinterpret_cast<GrContext*>(data);
284 context->flush();
285}
286
bsalomon@google.com27847de2011-02-22 20:59:41 +0000287////////////////////////////////////////////////////////////////////////////////
288
bsalomonb77a9072016-09-07 10:02:04 -0700289void GrContext::flush() {
joshualitt1de610a2016-01-06 08:26:09 -0800290 ASSERT_SINGLE_OWNER
robertphillipsea461502015-05-26 11:38:03 -0700291 RETURN_IF_ABANDONED
Robert Phillips7ee385e2017-03-30 08:02:11 -0400292
Robert Phillips6a6de562019-02-15 15:19:15 -0500293 this->drawingManager()->flush(nullptr);
Robert Phillips7ee385e2017-03-30 08:02:11 -0400294}
295
Greg Daniel51316782017-08-02 15:10:09 +0000296GrSemaphoresSubmitted GrContext::flushAndSignalSemaphores(int numSemaphores,
297 GrBackendSemaphore signalSemaphores[]) {
298 ASSERT_SINGLE_OWNER
Robert Phillipsa9162df2019-02-11 14:12:03 -0500299 if (this->abandoned()) {
300 return GrSemaphoresSubmitted::kNo;
301 }
Greg Daniel51316782017-08-02 15:10:09 +0000302
Robert Phillips6a6de562019-02-15 15:19:15 -0500303 return this->drawingManager()->flush(nullptr, numSemaphores, signalSemaphores);
Greg Daniel51316782017-08-02 15:10:09 +0000304}
305
Greg Daniela870b462019-01-08 15:49:46 -0500306////////////////////////////////////////////////////////////////////////////////
307
308void GrContext::storeVkPipelineCacheData() {
309 if (fGpu) {
310 fGpu->storeVkPipelineCacheData();
311 }
312}
313
314////////////////////////////////////////////////////////////////////////////////
315
Brian Salomonaff329b2017-08-11 09:40:37 -0400316std::unique_ptr<GrFragmentProcessor> GrContext::createPMToUPMEffect(
Brian Osman5ea96bf2018-10-02 14:58:05 -0400317 std::unique_ptr<GrFragmentProcessor> fp) {
Robert Phillips757914d2017-01-25 15:48:30 -0500318 ASSERT_SINGLE_OWNER
Brian Osman5ea96bf2018-10-02 14:58:05 -0400319 // We should have already called this->validPMUPMConversionExists() in this case
320 SkASSERT(fDidTestPMConversions);
321 // ...and it should have succeeded
322 SkASSERT(this->validPMUPMConversionExists());
Brian Osman409e74f2017-04-17 11:48:28 -0400323
Brian Osman5ea96bf2018-10-02 14:58:05 -0400324 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul);
Robert Phillips757914d2017-01-25 15:48:30 -0500325}
326
Brian Salomonaff329b2017-08-11 09:40:37 -0400327std::unique_ptr<GrFragmentProcessor> GrContext::createUPMToPMEffect(
Brian Osman5ea96bf2018-10-02 14:58:05 -0400328 std::unique_ptr<GrFragmentProcessor> fp) {
joshualitt1de610a2016-01-06 08:26:09 -0800329 ASSERT_SINGLE_OWNER
Brian Osman5ea96bf2018-10-02 14:58:05 -0400330 // We should have already called this->validPMUPMConversionExists() in this case
331 SkASSERT(fDidTestPMConversions);
332 // ...and it should have succeeded
333 SkASSERT(this->validPMUPMConversionExists());
Brian Osman409e74f2017-04-17 11:48:28 -0400334
Brian Osman5ea96bf2018-10-02 14:58:05 -0400335 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000336}
337
Brian Osman409e74f2017-04-17 11:48:28 -0400338bool GrContext::validPMUPMConversionExists() {
joshualitt1de610a2016-01-06 08:26:09 -0800339 ASSERT_SINGLE_OWNER
Brian Osman409e74f2017-04-17 11:48:28 -0400340 if (!fDidTestPMConversions) {
Brian Osman28804f32017-04-20 10:24:36 -0400341 fPMUPMConversionsRoundTrip = GrConfigConversionEffect::TestForPreservingPMConversions(this);
Brian Osman409e74f2017-04-17 11:48:28 -0400342 fDidTestPMConversions = true;
343 }
344
bsalomon636e8022015-07-29 06:08:46 -0700345 // The PM<->UPM tests fail or succeed together so we only need to check one.
Brian Osman28804f32017-04-20 10:24:36 -0400346 return fPMUPMConversionsRoundTrip;
bsalomon636e8022015-07-29 06:08:46 -0700347}
348
Khushal3e7548c2018-05-23 15:45:01 -0700349bool GrContext::supportsDistanceFieldText() const {
Robert Phillipsbb606772019-02-04 17:50:57 -0500350 return this->caps()->shaderCaps()->supportsDistanceFieldText();
Khushal3e7548c2018-05-23 15:45:01 -0700351}
352
bsalomon37f9a262015-02-02 13:00:10 -0800353//////////////////////////////////////////////////////////////////////////////
354
Robert Phillipsfc711a22018-02-13 17:03:00 -0500355// DDL TODO: remove 'maxResources'
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500356void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800357 ASSERT_SINGLE_OWNER
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500358 if (maxResources) {
359 *maxResources = fResourceCache->getMaxResourceCount();
bsalomon37f9a262015-02-02 13:00:10 -0800360 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500361 if (maxResourceBytes) {
362 *maxResourceBytes = fResourceCache->getMaxResourceBytes();
bsalomon37f9a262015-02-02 13:00:10 -0800363 }
364}
365
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500366void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) {
joshualitt1de610a2016-01-06 08:26:09 -0800367 ASSERT_SINGLE_OWNER
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500368 fResourceCache->setLimits(maxResources, maxResourceBytes);
bsalomon37f9a262015-02-02 13:00:10 -0800369}
370
ericrk0a5fa482015-09-15 14:16:10 -0700371//////////////////////////////////////////////////////////////////////////////
ericrk0a5fa482015-09-15 14:16:10 -0700372void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
joshualitt1de610a2016-01-06 08:26:09 -0800373 ASSERT_SINGLE_OWNER
ericrk0a5fa482015-09-15 14:16:10 -0700374 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
Khushal71652e22018-10-29 13:05:36 -0700375 traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
376 fTextBlobCache->usedBytes());
ericrk0a5fa482015-09-15 14:16:10 -0700377}
Brian Osman71a18892017-08-10 10:23:25 -0400378