blob: d6bc93c2c8ec15634bb33357e50c7f28da313676 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkTraceMemoryDump.h"
9#include "include/gpu/GrBackendSemaphore.h"
10#include "include/gpu/GrContext.h"
11#include "include/private/GrRenderTargetProxy.h"
12#include "include/private/SkDeferredDisplayList.h"
13#include "include/private/SkImageInfoPriv.h"
14#include "src/core/SkMakeUnique.h"
15#include "src/core/SkTaskGroup.h"
16#include "src/gpu/GrDrawingManager.h"
17#include "src/gpu/GrGpu.h"
18#include "src/gpu/GrMemoryPool.h"
19#include "src/gpu/GrPathRendererChain.h"
20#include "src/gpu/GrProxyProvider.h"
21#include "src/gpu/GrResourceCache.h"
22#include "src/gpu/GrResourceProvider.h"
23#include "src/gpu/GrSemaphore.h"
Brian Osman5e7fbfd2019-05-03 13:13:35 -040024#include "src/gpu/GrShaderUtils.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "src/gpu/GrSoftwarePathRenderer.h"
26#include "src/gpu/GrTracing.h"
27#include "src/gpu/SkGr.h"
28#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
29#include "src/gpu/effects/GrSkSLFP.h"
30#include "src/gpu/effects/generated/GrConfigConversionEffect.h"
31#include "src/gpu/text/GrTextBlobCache.h"
32#include "src/gpu/text/GrTextContext.h"
33#include "src/image/SkSurface_Gpu.h"
Mike Klein0ec1c572018-12-04 11:52:51 -050034#include <atomic>
35#include <unordered_map>
Greg Danielb76a72a2017-07-13 15:07:54 -040036
Robert Phillipse78b7252017-04-06 07:59:41 -040037#define ASSERT_OWNED_PROXY(P) \
Brian Salomonfd98c2c2018-07-31 17:25:29 -040038 SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this)
Robert Phillips7ee385e2017-03-30 08:02:11 -040039
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000040#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
joshualitt1de610a2016-01-06 08:26:09 -080041#define ASSERT_SINGLE_OWNER \
Robert Phillipsa41c6852019-02-07 10:44:10 -050042 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
Robert Phillipsa9162df2019-02-11 14:12:03 -050043#define RETURN_IF_ABANDONED if (this->abandoned()) { return; }
44#define RETURN_FALSE_IF_ABANDONED if (this->abandoned()) { return false; }
45#define RETURN_NULL_IF_ABANDONED if (this->abandoned()) { return nullptr; }
bsalomon@google.combc4b6542011-11-19 13:56:11 +000046
robertphillipsea461502015-05-26 11:38:03 -070047////////////////////////////////////////////////////////////////////////////////
48
Robert Phillipsa41c6852019-02-07 10:44:10 -050049GrContext::GrContext(GrBackendApi backend, const GrContextOptions& options, int32_t contextID)
50 : INHERITED(backend, options, contextID) {
halcanary96fcdcc2015-08-27 07:41:13 -070051 fResourceCache = nullptr;
52 fResourceProvider = 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;
Robert Phillips292a6b22019-02-14 14:49:02 -050063}
64
Robert Phillipsbb606772019-02-04 17:50:57 -050065bool GrContext::init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) {
Greg Danielb76a72a2017-07-13 15:07:54 -040066 ASSERT_SINGLE_OWNER
Robert Phillipsfde6fa02018-03-02 08:53:14 -050067 SkASSERT(fThreadSafeProxy); // needs to have been initialized by derived classes
Robert Phillipsa41c6852019-02-07 10:44:10 -050068 SkASSERT(this->proxyProvider());
Robert Phillips88260b52018-01-19 12:56:09 -050069
Robert Phillipsbb606772019-02-04 17:50:57 -050070 if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
71 return false;
72 }
73
74 SkASSERT(this->caps());
Herb Derbya00da612019-03-04 17:10:01 -050075 SkASSERT(this->getGrStrikeCache());
Robert Phillips2184fb72019-02-21 16:11:41 -050076 SkASSERT(this->getTextBlobCache());
Robert Phillipsbb606772019-02-04 17:50:57 -050077
Robert Phillips88260b52018-01-19 12:56:09 -050078 if (fGpu) {
Robert Phillipsa41c6852019-02-07 10:44:10 -050079 fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID());
Robert Phillips12c46292019-04-23 07:36:17 -040080 fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner());
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
Robert Phillipsfde6fa02018-03-02 08:53:14 -050089 // DDL TODO: we need to think through how the task group & persistent cache
90 // get passed on to/shared between all the DDLRecorders created with this context.
Robert Phillipsc1541ae2019-02-04 12:05:37 -050091 if (this->options().fExecutor) {
92 fTaskGroup = skstd::make_unique<SkTaskGroup>(*this->options().fExecutor);
Brian Osman51279982017-08-23 10:12:00 -040093 }
94
Robert Phillipsc1541ae2019-02-04 12:05:37 -050095 fPersistentCache = this->options().fPersistentCache;
Brian Osman5e7fbfd2019-05-03 13:13:35 -040096 fShaderErrorHandler = this->options().fShaderErrorHandler;
97 if (!fShaderErrorHandler) {
98 fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
99 }
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400100
Brian Salomon91a3e522017-06-23 10:58:19 -0400101 return true;
bsalomon@google.comc0af3172012-06-15 14:10:09 +0000102}
103
Robert Phillips4217ea72019-01-30 13:08:28 -0500104sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
105 return fThreadSafeProxy;
106}
107
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400108//////////////////////////////////////////////////////////////////////////////
109
bsalomon2354f842014-07-28 13:48:36 -0700110void GrContext::abandonContext() {
Robert Phillipsa9162df2019-02-11 14:12:03 -0500111 if (this->abandoned()) {
112 return;
113 }
joshualitt1de610a2016-01-06 08:26:09 -0800114
Robert Phillipsa9162df2019-02-11 14:12:03 -0500115 INHERITED::abandonContext();
116
bsalomond309e7a2015-04-30 14:18:54 -0700117 fResourceProvider->abandon();
robertphillips0dfa62c2015-11-16 06:23:31 -0800118
Robert Phillipsa9162df2019-02-11 14:12:03 -0500119 // Need to cleanup the drawing manager first so all the render targets
robertphillips0dfa62c2015-11-16 06:23:31 -0800120 // will be released/forgotten before they too are abandoned.
Robert Phillips6a6de562019-02-15 15:19:15 -0500121 this->drawingManager()->cleanup();
robertphillips0dfa62c2015-11-16 06:23:31 -0800122
bsalomon@google.com205d4602011-04-25 12:43:45 +0000123 // abandon first to so destructors
124 // don't try to free the resources in the API.
bsalomon0ea80f42015-02-11 10:49:59 -0800125 fResourceCache->abandonAll();
bsalomonc8dc1f72014-08-21 13:02:13 -0700126
bsalomon6e2aad42016-04-01 11:54:31 -0700127 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
Khushalc421ca12018-06-26 14:38:34 -0700128}
129
bsalomon6e2aad42016-04-01 11:54:31 -0700130void GrContext::releaseResourcesAndAbandonContext() {
Brian Salomon614c1a82018-12-19 15:42:06 -0500131 if (this->abandoned()) {
132 return;
133 }
Robert Phillipsa9162df2019-02-11 14:12:03 -0500134
135 INHERITED::abandonContext();
136
bsalomon6e2aad42016-04-01 11:54:31 -0700137 fResourceProvider->abandon();
138
Robert Phillipsa9162df2019-02-11 14:12:03 -0500139 // Need to cleanup the drawing manager first so all the render targets
bsalomon6e2aad42016-04-01 11:54:31 -0700140 // will be released/forgotten before they too are abandoned.
Robert Phillips6a6de562019-02-15 15:19:15 -0500141 this->drawingManager()->cleanup();
bsalomon6e2aad42016-04-01 11:54:31 -0700142
143 // Release all resources in the backend 3D API.
144 fResourceCache->releaseAll();
145
146 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000147}
148
Brian Salomon1f05d452019-02-08 12:33:08 -0500149void GrContext::resetGLTextureBindings() {
150 if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) {
151 return;
152 }
153 fGpu->resetTextureBindings();
154}
155
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000156void GrContext::resetContext(uint32_t state) {
joshualitt1de610a2016-01-06 08:26:09 -0800157 ASSERT_SINGLE_OWNER
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000158 fGpu->markContextDirty(state);
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000159}
160
161void GrContext::freeGpuResources() {
joshualitt1de610a2016-01-06 08:26:09 -0800162 ASSERT_SINGLE_OWNER
163
Robert Phillips2184fb72019-02-21 16:11:41 -0500164 // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
165 // Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
Herb Derbya00da612019-03-04 17:10:01 -0500166 this->getGrStrikeCache()->freeAll();
robertphillips68737822015-10-29 12:12:21 -0700167
Robert Phillips6a6de562019-02-15 15:19:15 -0500168 this->drawingManager()->freeGpuResources();
bsalomon3033b9f2015-04-13 11:09:56 -0700169
170 fResourceCache->purgeAllUnlocked();
bsalomon@google.com27847de2011-02-22 20:59:41 +0000171}
172
Robert Phillips6eba0632018-03-28 12:25:42 -0400173void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) {
174 ASSERT_SINGLE_OWNER
175 fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
176 fResourceCache->purgeAsNeeded();
Robert Phillips2184fb72019-02-21 16:11:41 -0500177
178 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
179 // place to purge stale blobs
180 this->getTextBlobCache()->purgeStaleBlobs();
Robert Phillips6eba0632018-03-28 12:25:42 -0400181}
182
Jim Van Verth76d917c2017-12-13 09:26:37 -0500183void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
Brian Salomon5e150852017-03-22 14:53:13 -0400184 ASSERT_SINGLE_OWNER
Chris Dalton6c3879d2018-11-01 11:13:19 -0600185
186 auto purgeTime = GrStdSteadyClock::now() - msNotUsed;
187
Jim Van Verth76d917c2017-12-13 09:26:37 -0500188 fResourceCache->purgeAsNeeded();
Chris Dalton6c3879d2018-11-01 11:13:19 -0600189 fResourceCache->purgeResourcesNotUsedSince(purgeTime);
190
Robert Phillips6a6de562019-02-15 15:19:15 -0500191 if (auto ccpr = this->drawingManager()->getCoverageCountingPathRenderer()) {
Robert Phillipsa41c6852019-02-07 10:44:10 -0500192 ccpr->purgeCacheEntriesOlderThan(this->proxyProvider(), purgeTime);
Chris Dalton6c3879d2018-11-01 11:13:19 -0600193 }
Jim Van Verth76d917c2017-12-13 09:26:37 -0500194
Robert Phillips2184fb72019-02-21 16:11:41 -0500195 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
196 // place to purge stale blobs
197 this->getTextBlobCache()->purgeStaleBlobs();
Brian Salomon5e150852017-03-22 14:53:13 -0400198}
199
Derek Sollenberger5480a182017-05-25 16:43:59 -0400200void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
201 ASSERT_SINGLE_OWNER
202 fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
203}
204
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000205void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800206 ASSERT_SINGLE_OWNER
207
bsalomon71cb0c22014-11-14 12:10:14 -0800208 if (resourceCount) {
bsalomon0ea80f42015-02-11 10:49:59 -0800209 *resourceCount = fResourceCache->getBudgetedResourceCount();
bsalomon71cb0c22014-11-14 12:10:14 -0800210 }
211 if (resourceBytes) {
bsalomon0ea80f42015-02-11 10:49:59 -0800212 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
bsalomon71cb0c22014-11-14 12:10:14 -0800213 }
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000214}
215
Derek Sollenbergeree479142017-05-24 11:41:33 -0400216size_t GrContext::getResourceCachePurgeableBytes() const {
217 ASSERT_SINGLE_OWNER
218 return fResourceCache->getPurgeableBytes();
219}
220
Adrienne Walker0f827972019-03-26 13:46:14 -0700221size_t GrContext::ComputeTextureSize(SkColorType type, int width, int height, GrMipMapped mipMapped,
222 bool useNextPow2) {
223 int colorSamplesPerPixel = 1;
224 return GrSurface::ComputeSize(SkColorType2GrPixelConfig(type), width, height,
225 colorSamplesPerPixel, mipMapped, useNextPow2);
226}
227
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000228////////////////////////////////////////////////////////////////////////////////
229
Robert Phillipsbb606772019-02-04 17:50:57 -0500230int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400231
Robert Phillipsbb606772019-02-04 17:50:57 -0500232int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400233
Brian Salomonbdecacf2018-02-02 20:32:49 -0500234bool GrContext::colorTypeSupportedAsImage(SkColorType colorType) const {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400235 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Robert Phillipsbb606772019-02-04 17:50:57 -0500236 return this->caps()->isConfigTexturable(config);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500237}
238
239int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const {
Brian Osman2b23c4b2018-06-01 12:25:08 -0400240 GrPixelConfig config = SkColorType2GrPixelConfig(colorType);
Robert Phillipsbb606772019-02-04 17:50:57 -0500241 return this->caps()->maxRenderTargetSampleCount(config);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500242}
243
244////////////////////////////////////////////////////////////////////////////////
245
Greg Daniel06be0792019-04-22 15:53:23 -0400246bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[]) {
Brian Salomon9ff5acb2019-05-08 09:04:47 -0400247 if (!fGpu || fGpu->caps()->semaphoreSupport()) {
Greg Daniel06be0792019-04-22 15:53:23 -0400248 return false;
249 }
250 for (int i = 0; i < numSemaphores; ++i) {
251 sk_sp<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore(
252 waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait,
253 kAdopt_GrWrapOwnership);
254 fGpu->waitSemaphore(std::move(sema));
255 }
256 return true;
257}
258
259////////////////////////////////////////////////////////////////////////////////
260
Greg Daniel797efca2019-05-09 14:04:20 -0400261GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info,
262 const GrPrepareForExternalIORequests& externalRequests) {
Greg Daniel51316782017-08-02 15:10:09 +0000263 ASSERT_SINGLE_OWNER
Robert Phillipsa9162df2019-02-11 14:12:03 -0500264 if (this->abandoned()) {
265 return GrSemaphoresSubmitted::kNo;
266 }
Greg Daniel51316782017-08-02 15:10:09 +0000267
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400268 return this->drawingManager()->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
Greg Daniel797efca2019-05-09 14:04:20 -0400269 info, externalRequests);
Greg Daniel51316782017-08-02 15:10:09 +0000270}
271
Greg Daniela870b462019-01-08 15:49:46 -0500272////////////////////////////////////////////////////////////////////////////////
273
Brian Salomonb0d8b762019-05-06 16:58:22 -0400274void GrContext::checkAsyncWorkCompletion() {
275 if (fGpu) {
276 fGpu->checkFinishProcs();
277 }
278}
279
280////////////////////////////////////////////////////////////////////////////////
281
Greg Daniela870b462019-01-08 15:49:46 -0500282void GrContext::storeVkPipelineCacheData() {
283 if (fGpu) {
284 fGpu->storeVkPipelineCacheData();
285 }
286}
287
288////////////////////////////////////////////////////////////////////////////////
289
Brian Salomonaff329b2017-08-11 09:40:37 -0400290std::unique_ptr<GrFragmentProcessor> GrContext::createPMToUPMEffect(
Brian Osman5ea96bf2018-10-02 14:58:05 -0400291 std::unique_ptr<GrFragmentProcessor> fp) {
Robert Phillips757914d2017-01-25 15:48:30 -0500292 ASSERT_SINGLE_OWNER
Brian Osman5ea96bf2018-10-02 14:58:05 -0400293 // We should have already called this->validPMUPMConversionExists() in this case
294 SkASSERT(fDidTestPMConversions);
295 // ...and it should have succeeded
296 SkASSERT(this->validPMUPMConversionExists());
Brian Osman409e74f2017-04-17 11:48:28 -0400297
Brian Osman5ea96bf2018-10-02 14:58:05 -0400298 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul);
Robert Phillips757914d2017-01-25 15:48:30 -0500299}
300
Brian Salomonaff329b2017-08-11 09:40:37 -0400301std::unique_ptr<GrFragmentProcessor> GrContext::createUPMToPMEffect(
Brian Osman5ea96bf2018-10-02 14:58:05 -0400302 std::unique_ptr<GrFragmentProcessor> fp) {
joshualitt1de610a2016-01-06 08:26:09 -0800303 ASSERT_SINGLE_OWNER
Brian Osman5ea96bf2018-10-02 14:58:05 -0400304 // We should have already called this->validPMUPMConversionExists() in this case
305 SkASSERT(fDidTestPMConversions);
306 // ...and it should have succeeded
307 SkASSERT(this->validPMUPMConversionExists());
Brian Osman409e74f2017-04-17 11:48:28 -0400308
Brian Osman5ea96bf2018-10-02 14:58:05 -0400309 return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
bsalomon@google.coma04e8e82012-08-27 12:53:13 +0000310}
311
Brian Osman409e74f2017-04-17 11:48:28 -0400312bool GrContext::validPMUPMConversionExists() {
joshualitt1de610a2016-01-06 08:26:09 -0800313 ASSERT_SINGLE_OWNER
Brian Osman409e74f2017-04-17 11:48:28 -0400314 if (!fDidTestPMConversions) {
Brian Osman28804f32017-04-20 10:24:36 -0400315 fPMUPMConversionsRoundTrip = GrConfigConversionEffect::TestForPreservingPMConversions(this);
Brian Osman409e74f2017-04-17 11:48:28 -0400316 fDidTestPMConversions = true;
317 }
318
bsalomon636e8022015-07-29 06:08:46 -0700319 // The PM<->UPM tests fail or succeed together so we only need to check one.
Brian Osman28804f32017-04-20 10:24:36 -0400320 return fPMUPMConversionsRoundTrip;
bsalomon636e8022015-07-29 06:08:46 -0700321}
322
Khushal3e7548c2018-05-23 15:45:01 -0700323bool GrContext::supportsDistanceFieldText() const {
Robert Phillipsbb606772019-02-04 17:50:57 -0500324 return this->caps()->shaderCaps()->supportsDistanceFieldText();
Khushal3e7548c2018-05-23 15:45:01 -0700325}
326
bsalomon37f9a262015-02-02 13:00:10 -0800327//////////////////////////////////////////////////////////////////////////////
328
Robert Phillipsfc711a22018-02-13 17:03:00 -0500329// DDL TODO: remove 'maxResources'
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500330void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800331 ASSERT_SINGLE_OWNER
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500332 if (maxResources) {
333 *maxResources = fResourceCache->getMaxResourceCount();
bsalomon37f9a262015-02-02 13:00:10 -0800334 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500335 if (maxResourceBytes) {
336 *maxResourceBytes = fResourceCache->getMaxResourceBytes();
bsalomon37f9a262015-02-02 13:00:10 -0800337 }
338}
339
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500340void GrContext::setResourceCacheLimits(int maxResources, size_t maxResourceBytes) {
joshualitt1de610a2016-01-06 08:26:09 -0800341 ASSERT_SINGLE_OWNER
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500342 fResourceCache->setLimits(maxResources, maxResourceBytes);
bsalomon37f9a262015-02-02 13:00:10 -0800343}
344
ericrk0a5fa482015-09-15 14:16:10 -0700345//////////////////////////////////////////////////////////////////////////////
ericrk0a5fa482015-09-15 14:16:10 -0700346void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
joshualitt1de610a2016-01-06 08:26:09 -0800347 ASSERT_SINGLE_OWNER
ericrk0a5fa482015-09-15 14:16:10 -0700348 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
Khushal71652e22018-10-29 13:05:36 -0700349 traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
Robert Phillips2184fb72019-02-21 16:11:41 -0500350 this->getTextBlobCache()->usedBytes());
ericrk0a5fa482015-09-15 14:16:10 -0700351}
Brian Osman71a18892017-08-10 10:23:25 -0400352
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400353//////////////////////////////////////////////////////////////////////////////
354GrBackendTexture GrContext::createBackendTexture(int width, int height,
355 GrBackendFormat backendFormat,
356 GrMipMapped mipMapped,
357 GrRenderable renderable) {
358 if (!this->asDirectContext()) {
359 return GrBackendTexture();
360 }
361
362 if (this->abandoned()) {
363 return GrBackendTexture();
364 }
365
366 if (!backendFormat.isValid()) {
367 return GrBackendTexture();
368 }
369
Robert Phillipsf0313ee2019-05-21 13:51:11 -0400370 return fGpu->createBackendTexture(width, height, backendFormat,
371 mipMapped, renderable,
372 nullptr, 0);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400373}
374
375GrBackendTexture GrContext::createBackendTexture(int width, int height,
376 SkColorType colorType,
377 GrMipMapped mipMapped,
378 GrRenderable renderable) {
379 if (!this->asDirectContext()) {
380 return GrBackendTexture();
381 }
382
383 if (this->abandoned()) {
384 return GrBackendTexture();
385 }
386
387 GrBackendFormat format = this->caps()->getBackendFormatFromColorType(colorType);
388 if (!format.isValid()) {
389 return GrBackendTexture();
390 }
391
392 return this->createBackendTexture(width, height, format, mipMapped, renderable);
393}
394
395void GrContext::deleteBackendTexture(GrBackendTexture backendTex) {
396 if (this->abandoned() || !backendTex.isValid()) {
397 return;
398 }
399
Robert Phillipsf0313ee2019-05-21 13:51:11 -0400400 fGpu->deleteBackendTexture(backendTex);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400401}
402