blob: 12748787f6d7b178a6ce3824dab1645316ec17f6 [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
Brian Salomon9241a6d2019-10-03 13:26:54 -04008#include "include/gpu/GrContext.h"
9
Robert Phillips4d5594d2020-02-21 14:24:40 -050010#include "include/core/SkDeferredDisplayList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkTraceMemoryDump.h"
12#include "include/gpu/GrBackendSemaphore.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/private/SkImageInfoPriv.h"
Brian Salomon85c3d682019-11-04 15:04:54 -050014#include "src/core/SkMipMap.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050015#include "src/core/SkTaskGroup.h"
Brian Salomon9241a6d2019-10-03 13:26:54 -040016#include "src/gpu/GrClientMappedBufferManager.h"
Greg Daniel7fd7a8a2019-10-10 16:10:31 -040017#include "src/gpu/GrContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050018#include "src/gpu/GrDrawingManager.h"
19#include "src/gpu/GrGpu.h"
20#include "src/gpu/GrMemoryPool.h"
21#include "src/gpu/GrPathRendererChain.h"
22#include "src/gpu/GrProxyProvider.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040023#include "src/gpu/GrRenderTargetProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050024#include "src/gpu/GrResourceCache.h"
25#include "src/gpu/GrResourceProvider.h"
26#include "src/gpu/GrSemaphore.h"
Brian Osman5e7fbfd2019-05-03 13:13:35 -040027#include "src/gpu/GrShaderUtils.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050028#include "src/gpu/GrSoftwarePathRenderer.h"
29#include "src/gpu/GrTracing.h"
30#include "src/gpu/SkGr.h"
31#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
32#include "src/gpu/effects/GrSkSLFP.h"
Robert Phillips41bd97d2020-04-07 14:19:37 -040033#include "src/gpu/text/GrStrikeCache.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050034#include "src/gpu/text/GrTextBlobCache.h"
35#include "src/gpu/text/GrTextContext.h"
Greg Daniel7fd7a8a2019-10-10 16:10:31 -040036#include "src/image/SkImage_GpuBase.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050037#include "src/image/SkSurface_Gpu.h"
Mike Klein0ec1c572018-12-04 11:52:51 -050038#include <atomic>
Greg Danielb76a72a2017-07-13 15:07:54 -040039
Robert Phillipse78b7252017-04-06 07:59:41 -040040#define ASSERT_OWNED_PROXY(P) \
Brian Salomonfd98c2c2018-07-31 17:25:29 -040041 SkASSERT(!(P) || !((P)->peekTexture()) || (P)->peekTexture()->getContext() == this)
Robert Phillips7ee385e2017-03-30 08:02:11 -040042
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000043#define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this)
joshualitt1de610a2016-01-06 08:26:09 -080044#define ASSERT_SINGLE_OWNER \
Robert Phillipsa41c6852019-02-07 10:44:10 -050045 SkDEBUGCODE(GrSingleOwner::AutoEnforce debug_SingleOwner(this->singleOwner());)
Robert Phillipsa9162df2019-02-11 14:12:03 -050046#define RETURN_IF_ABANDONED if (this->abandoned()) { return; }
47#define RETURN_FALSE_IF_ABANDONED if (this->abandoned()) { return false; }
48#define RETURN_NULL_IF_ABANDONED if (this->abandoned()) { return nullptr; }
bsalomon@google.combc4b6542011-11-19 13:56:11 +000049
robertphillipsea461502015-05-26 11:38:03 -070050////////////////////////////////////////////////////////////////////////////////
51
Robert Phillipsa41c6852019-02-07 10:44:10 -050052GrContext::GrContext(GrBackendApi backend, const GrContextOptions& options, int32_t contextID)
53 : INHERITED(backend, options, contextID) {
halcanary96fcdcc2015-08-27 07:41:13 -070054 fResourceCache = nullptr;
55 fResourceProvider = nullptr;
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000056}
57
Robert Phillips292a6b22019-02-14 14:49:02 -050058GrContext::~GrContext() {
59 ASSERT_SINGLE_OWNER
60
Robert Phillips6a6de562019-02-15 15:19:15 -050061 if (this->drawingManager()) {
62 this->drawingManager()->cleanup();
Robert Phillips292a6b22019-02-14 14:49:02 -050063 }
64 delete fResourceProvider;
65 delete fResourceCache;
Robert Phillips292a6b22019-02-14 14:49:02 -050066}
67
Brian Osman7b1678a2019-12-16 09:17:25 -050068bool GrContext::init(sk_sp<const GrCaps> caps) {
Greg Danielb76a72a2017-07-13 15:07:54 -040069 ASSERT_SINGLE_OWNER
Robert Phillipsa41c6852019-02-07 10:44:10 -050070 SkASSERT(this->proxyProvider());
Robert Phillips88260b52018-01-19 12:56:09 -050071
Brian Osman7b1678a2019-12-16 09:17:25 -050072 if (!INHERITED::init(std::move(caps))) {
Robert Phillipsbb606772019-02-04 17:50:57 -050073 return false;
74 }
75
76 SkASSERT(this->caps());
Robert Phillips2184fb72019-02-21 16:11:41 -050077 SkASSERT(this->getTextBlobCache());
Robert Phillipsbb606772019-02-04 17:50:57 -050078
Robert Phillips88260b52018-01-19 12:56:09 -050079 if (fGpu) {
Robert Phillips4d932d12020-04-09 08:58:52 -040080 fStrikeCache.reset(new GrStrikeCache{});
Robert Phillipsa41c6852019-02-07 10:44:10 -050081 fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID());
Robert Phillips12c46292019-04-23 07:36:17 -040082 fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner());
Mike Kleinf46d5ca2019-12-11 10:45:01 -050083 fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
Robert Phillips88260b52018-01-19 12:56:09 -050084 }
85
Robert Phillips88260b52018-01-19 12:56:09 -050086 if (fResourceCache) {
Robert Phillipsa41c6852019-02-07 10:44:10 -050087 fResourceCache->setProxyProvider(this->proxyProvider());
Robert Phillips88260b52018-01-19 12:56:09 -050088 }
Robert Phillips1afd4cd2018-01-08 13:40:32 -050089
bsalomon@google.com6e4e6502013-02-25 20:12:45 +000090 fDidTestPMConversions = false;
91
Robert Phillipsfde6fa02018-03-02 08:53:14 -050092 // DDL TODO: we need to think through how the task group & persistent cache
93 // get passed on to/shared between all the DDLRecorders created with this context.
Robert Phillipsc1541ae2019-02-04 12:05:37 -050094 if (this->options().fExecutor) {
Mike Kleinf46d5ca2019-12-11 10:45:01 -050095 fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
Brian Osman51279982017-08-23 10:12:00 -040096 }
97
Robert Phillipsc1541ae2019-02-04 12:05:37 -050098 fPersistentCache = this->options().fPersistentCache;
Brian Osman5e7fbfd2019-05-03 13:13:35 -040099 fShaderErrorHandler = this->options().fShaderErrorHandler;
100 if (!fShaderErrorHandler) {
101 fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
102 }
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400103
Brian Salomon91a3e522017-06-23 10:58:19 -0400104 return true;
bsalomon@google.comc0af3172012-06-15 14:10:09 +0000105}
106
Robert Phillips4217ea72019-01-30 13:08:28 -0500107sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
108 return fThreadSafeProxy;
109}
110
Brian Salomonc7fe0f72018-05-11 10:14:21 -0400111//////////////////////////////////////////////////////////////////////////////
112
bsalomon2354f842014-07-28 13:48:36 -0700113void GrContext::abandonContext() {
Greg Daniel6e35a002020-04-01 13:29:59 -0400114 if (INHERITED::abandoned()) {
Robert Phillipsa9162df2019-02-11 14:12:03 -0500115 return;
116 }
joshualitt1de610a2016-01-06 08:26:09 -0800117
Robert Phillipsa9162df2019-02-11 14:12:03 -0500118 INHERITED::abandonContext();
119
Robert Phillips4d932d12020-04-09 08:58:52 -0400120 fStrikeCache->freeAll();
121
Brian Salomon9241a6d2019-10-03 13:26:54 -0400122 fMappedBufferManager->abandon();
123
bsalomond309e7a2015-04-30 14:18:54 -0700124 fResourceProvider->abandon();
robertphillips0dfa62c2015-11-16 06:23:31 -0800125
Robert Phillipsa9162df2019-02-11 14:12:03 -0500126 // Need to cleanup the drawing manager first so all the render targets
robertphillips0dfa62c2015-11-16 06:23:31 -0800127 // will be released/forgotten before they too are abandoned.
Robert Phillips6a6de562019-02-15 15:19:15 -0500128 this->drawingManager()->cleanup();
robertphillips0dfa62c2015-11-16 06:23:31 -0800129
bsalomon@google.com205d4602011-04-25 12:43:45 +0000130 // abandon first to so destructors
131 // don't try to free the resources in the API.
bsalomon0ea80f42015-02-11 10:49:59 -0800132 fResourceCache->abandonAll();
bsalomonc8dc1f72014-08-21 13:02:13 -0700133
bsalomon6e2aad42016-04-01 11:54:31 -0700134 fGpu->disconnect(GrGpu::DisconnectType::kAbandon);
Brian Salomon9241a6d2019-10-03 13:26:54 -0400135
136 fMappedBufferManager.reset();
Khushalc421ca12018-06-26 14:38:34 -0700137}
138
bsalomon6e2aad42016-04-01 11:54:31 -0700139void GrContext::releaseResourcesAndAbandonContext() {
Greg Daniel6e35a002020-04-01 13:29:59 -0400140 if (INHERITED::abandoned()) {
Brian Salomon614c1a82018-12-19 15:42:06 -0500141 return;
142 }
Robert Phillipsa9162df2019-02-11 14:12:03 -0500143
144 INHERITED::abandonContext();
145
Brian Salomon9241a6d2019-10-03 13:26:54 -0400146 fMappedBufferManager.reset();
147
bsalomon6e2aad42016-04-01 11:54:31 -0700148 fResourceProvider->abandon();
149
Robert Phillipsa9162df2019-02-11 14:12:03 -0500150 // Need to cleanup the drawing manager first so all the render targets
bsalomon6e2aad42016-04-01 11:54:31 -0700151 // will be released/forgotten before they too are abandoned.
Robert Phillips6a6de562019-02-15 15:19:15 -0500152 this->drawingManager()->cleanup();
bsalomon6e2aad42016-04-01 11:54:31 -0700153
154 // Release all resources in the backend 3D API.
155 fResourceCache->releaseAll();
156
157 fGpu->disconnect(GrGpu::DisconnectType::kCleanup);
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000158}
159
Greg Daniel6e35a002020-04-01 13:29:59 -0400160bool GrContext::abandoned() {
161 if (INHERITED::abandoned()) {
162 return true;
163 }
164
165 if (fGpu && fGpu->isDeviceLost()) {
166 this->abandonContext();
167 return true;
168 }
169 return false;
170}
171
Brian Salomon1f05d452019-02-08 12:33:08 -0500172void GrContext::resetGLTextureBindings() {
173 if (this->abandoned() || this->backend() != GrBackendApi::kOpenGL) {
174 return;
175 }
176 fGpu->resetTextureBindings();
177}
178
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000179void GrContext::resetContext(uint32_t state) {
joshualitt1de610a2016-01-06 08:26:09 -0800180 ASSERT_SINGLE_OWNER
bsalomon@google.com0a208a12013-06-28 18:57:35 +0000181 fGpu->markContextDirty(state);
bsalomon@google.com8fe72472011-03-30 21:26:44 +0000182}
183
184void GrContext::freeGpuResources() {
joshualitt1de610a2016-01-06 08:26:09 -0800185 ASSERT_SINGLE_OWNER
186
Robert Phillips2184fb72019-02-21 16:11:41 -0500187 // TODO: the glyph cache doesn't hold any GpuResources so this call should not be needed here.
188 // Some slack in the GrTextBlob's implementation requires it though. That could be fixed.
Robert Phillips4d932d12020-04-09 08:58:52 -0400189 fStrikeCache->freeAll();
robertphillips68737822015-10-29 12:12:21 -0700190
Robert Phillips6a6de562019-02-15 15:19:15 -0500191 this->drawingManager()->freeGpuResources();
bsalomon3033b9f2015-04-13 11:09:56 -0700192
193 fResourceCache->purgeAllUnlocked();
bsalomon@google.com27847de2011-02-22 20:59:41 +0000194}
195
Robert Phillips6eba0632018-03-28 12:25:42 -0400196void GrContext::purgeUnlockedResources(bool scratchResourcesOnly) {
197 ASSERT_SINGLE_OWNER
Robert Phillipsddc21482019-10-16 14:30:09 -0400198
199 if (this->abandoned()) {
200 return;
201 }
202
Robert Phillips6eba0632018-03-28 12:25:42 -0400203 fResourceCache->purgeUnlockedResources(scratchResourcesOnly);
204 fResourceCache->purgeAsNeeded();
Robert Phillips2184fb72019-02-21 16:11:41 -0500205
206 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
207 // place to purge stale blobs
208 this->getTextBlobCache()->purgeStaleBlobs();
Robert Phillips6eba0632018-03-28 12:25:42 -0400209}
210
Jim Van Verth76d917c2017-12-13 09:26:37 -0500211void GrContext::performDeferredCleanup(std::chrono::milliseconds msNotUsed) {
Yuqian Li40aa85f2019-07-02 13:45:00 -0700212 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
213
Brian Salomon5e150852017-03-22 14:53:13 -0400214 ASSERT_SINGLE_OWNER
Chris Dalton6c3879d2018-11-01 11:13:19 -0600215
Brian Salomon9241a6d2019-10-03 13:26:54 -0400216 if (this->abandoned()) {
217 return;
218 }
219
220 fMappedBufferManager->process();
Chris Dalton6c3879d2018-11-01 11:13:19 -0600221 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
Robert Phillips6a6de562019-02-15 15:19:15 -0500226 if (auto ccpr = this->drawingManager()->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
Robert Phillips2184fb72019-02-21 16:11:41 -0500230 // The textBlob Cache doesn't actually hold any GPU resource but this is a convenient
231 // place to purge stale blobs
232 this->getTextBlobCache()->purgeStaleBlobs();
Brian Salomon5e150852017-03-22 14:53:13 -0400233}
234
Derek Sollenberger5480a182017-05-25 16:43:59 -0400235void GrContext::purgeUnlockedResources(size_t bytesToPurge, bool preferScratchResources) {
236 ASSERT_SINGLE_OWNER
Robert Phillipsddc21482019-10-16 14:30:09 -0400237
238 if (this->abandoned()) {
239 return;
240 }
241
Derek Sollenberger5480a182017-05-25 16:43:59 -0400242 fResourceCache->purgeUnlockedResources(bytesToPurge, preferScratchResources);
243}
244
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000245void GrContext::getResourceCacheUsage(int* resourceCount, size_t* resourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800246 ASSERT_SINGLE_OWNER
247
bsalomon71cb0c22014-11-14 12:10:14 -0800248 if (resourceCount) {
bsalomon0ea80f42015-02-11 10:49:59 -0800249 *resourceCount = fResourceCache->getBudgetedResourceCount();
bsalomon71cb0c22014-11-14 12:10:14 -0800250 }
251 if (resourceBytes) {
bsalomon0ea80f42015-02-11 10:49:59 -0800252 *resourceBytes = fResourceCache->getBudgetedResourceBytes();
bsalomon71cb0c22014-11-14 12:10:14 -0800253 }
commit-bot@chromium.orgd8a57af2014-03-19 21:19:16 +0000254}
255
Derek Sollenbergeree479142017-05-24 11:41:33 -0400256size_t GrContext::getResourceCachePurgeableBytes() const {
257 ASSERT_SINGLE_OWNER
258 return fResourceCache->getPurgeableBytes();
259}
260
Greg Daniel8b666172019-10-09 12:38:22 -0400261size_t GrContext::ComputeImageSize(sk_sp<SkImage> image, GrMipMapped mipMapped, bool useNextPow2) {
262 if (!image->isTextureBacked()) {
263 return 0;
264 }
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400265 SkImage_GpuBase* gpuImage = static_cast<SkImage_GpuBase*>(as_IB(image.get()));
266 GrTextureProxy* proxy = gpuImage->peekProxy();
267 if (!proxy) {
268 return 0;
269 }
270
271 const GrCaps& caps = *gpuImage->context()->priv().caps();
Greg Daniel8b666172019-10-09 12:38:22 -0400272 int colorSamplesPerPixel = 1;
Brian Salomon9f2b86c2019-10-22 10:37:46 -0400273 return GrSurface::ComputeSize(caps, proxy->backendFormat(), image->dimensions(),
Greg Daniel7fd7a8a2019-10-10 16:10:31 -0400274 colorSamplesPerPixel, mipMapped, useNextPow2);
Greg Daniel8b666172019-10-09 12:38:22 -0400275}
276
bsalomon@google.comfea37b52011-04-25 15:51:06 +0000277////////////////////////////////////////////////////////////////////////////////
278
Robert Phillipsbb606772019-02-04 17:50:57 -0500279int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400280
Robert Phillipsbb606772019-02-04 17:50:57 -0500281int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); }
Brian Salomonf932a632018-04-05 12:46:09 -0400282
Brian Salomonbdecacf2018-02-02 20:32:49 -0500283bool GrContext::colorTypeSupportedAsImage(SkColorType colorType) const {
Greg Daniel7bfc9132019-08-14 14:23:53 -0400284 GrBackendFormat format =
285 this->caps()->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType),
286 GrRenderable::kNo);
287 return format.isValid();
Brian Salomonbdecacf2018-02-02 20:32:49 -0500288}
289
290int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const {
Greg Danieleadfac92019-08-02 09:03:53 -0400291 GrBackendFormat format =
292 this->caps()->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType),
293 GrRenderable::kYes);
294 return this->caps()->maxRenderTargetSampleCount(format);
Brian Salomonbdecacf2018-02-02 20:32:49 -0500295}
296
297////////////////////////////////////////////////////////////////////////////////
298
Greg Daniel06be0792019-04-22 15:53:23 -0400299bool GrContext::wait(int numSemaphores, const GrBackendSemaphore waitSemaphores[]) {
Brian Salomon9ff5acb2019-05-08 09:04:47 -0400300 if (!fGpu || fGpu->caps()->semaphoreSupport()) {
Greg Daniel06be0792019-04-22 15:53:23 -0400301 return false;
302 }
303 for (int i = 0; i < numSemaphores; ++i) {
Greg Daniel301015c2019-11-18 14:06:46 -0500304 std::unique_ptr<GrSemaphore> sema = fResourceProvider->wrapBackendSemaphore(
Greg Daniel06be0792019-04-22 15:53:23 -0400305 waitSemaphores[i], GrResourceProvider::SemaphoreWrapType::kWillWait,
306 kAdopt_GrWrapOwnership);
Greg Daniel301015c2019-11-18 14:06:46 -0500307 fGpu->waitSemaphore(sema.get());
Greg Daniel06be0792019-04-22 15:53:23 -0400308 }
309 return true;
310}
311
312////////////////////////////////////////////////////////////////////////////////
313
Greg Daniel797efca2019-05-09 14:04:20 -0400314GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info,
315 const GrPrepareForExternalIORequests& externalRequests) {
Greg Daniel51316782017-08-02 15:10:09 +0000316 ASSERT_SINGLE_OWNER
Robert Phillipsa9162df2019-02-11 14:12:03 -0500317 if (this->abandoned()) {
Greg Daniel55822f12020-05-26 11:26:45 -0400318 if (info.fFinishedProc) {
319 info.fFinishedProc(info.fFinishedContext);
320 }
321 if (info.fSubmittedProc) {
322 info.fSubmittedProc(info.fSubmittedContext, false);
323 }
Robert Phillipsa9162df2019-02-11 14:12:03 -0500324 return GrSemaphoresSubmitted::kNo;
325 }
Greg Daniel51316782017-08-02 15:10:09 +0000326
Greg Daniel04283f32020-05-20 13:16:00 -0400327 bool flushed = this->drawingManager()->flush(
328 nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, info, externalRequests);
Greg Danielfe159622020-04-10 17:43:51 +0000329
Greg Daniel04283f32020-05-20 13:16:00 -0400330 if (!flushed || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
Greg Danielfe159622020-04-10 17:43:51 +0000331 return GrSemaphoresSubmitted::kNo;
332 }
333 return GrSemaphoresSubmitted::kYes;
Greg Daniel51316782017-08-02 15:10:09 +0000334}
335
Greg Daniel04283f32020-05-20 13:16:00 -0400336bool GrContext::submit(bool syncCpu) {
337 ASSERT_SINGLE_OWNER
338 if (this->abandoned()) {
339 return false;
340 }
341
342 if (!fGpu) {
343 return false;
344 }
345
346 return fGpu->submitToGpu(syncCpu);
Greg Danielda50cb82020-05-13 14:07:40 -0400347}
348
Greg Daniela870b462019-01-08 15:49:46 -0500349////////////////////////////////////////////////////////////////////////////////
350
Brian Salomonb0d8b762019-05-06 16:58:22 -0400351void GrContext::checkAsyncWorkCompletion() {
352 if (fGpu) {
353 fGpu->checkFinishProcs();
354 }
355}
356
357////////////////////////////////////////////////////////////////////////////////
358
Greg Daniela870b462019-01-08 15:49:46 -0500359void GrContext::storeVkPipelineCacheData() {
360 if (fGpu) {
361 fGpu->storeVkPipelineCacheData();
362 }
363}
364
365////////////////////////////////////////////////////////////////////////////////
366
Khushal3e7548c2018-05-23 15:45:01 -0700367bool GrContext::supportsDistanceFieldText() const {
Robert Phillipsbb606772019-02-04 17:50:57 -0500368 return this->caps()->shaderCaps()->supportsDistanceFieldText();
Khushal3e7548c2018-05-23 15:45:01 -0700369}
370
bsalomon37f9a262015-02-02 13:00:10 -0800371//////////////////////////////////////////////////////////////////////////////
372
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500373void GrContext::getResourceCacheLimits(int* maxResources, size_t* maxResourceBytes) const {
joshualitt1de610a2016-01-06 08:26:09 -0800374 ASSERT_SINGLE_OWNER
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500375 if (maxResources) {
Robert Phillipscf39f372019-09-03 10:29:20 -0400376 *maxResources = -1;
bsalomon37f9a262015-02-02 13:00:10 -0800377 }
Robert Phillips8d1e67e2017-12-04 13:48:14 -0500378 if (maxResourceBytes) {
Robert Phillipscf39f372019-09-03 10:29:20 -0400379 *maxResourceBytes = this->getResourceCacheLimit();
bsalomon37f9a262015-02-02 13:00:10 -0800380 }
381}
382
Robert Phillipscf39f372019-09-03 10:29:20 -0400383size_t GrContext::getResourceCacheLimit() const {
joshualitt1de610a2016-01-06 08:26:09 -0800384 ASSERT_SINGLE_OWNER
Robert Phillipscf39f372019-09-03 10:29:20 -0400385 return fResourceCache->getMaxResourceBytes();
386}
387
388void GrContext::setResourceCacheLimits(int unused, size_t maxResourceBytes) {
389 ASSERT_SINGLE_OWNER
390 this->setResourceCacheLimit(maxResourceBytes);
391}
392
393void GrContext::setResourceCacheLimit(size_t maxResourceBytes) {
394 ASSERT_SINGLE_OWNER
395 fResourceCache->setLimit(maxResourceBytes);
bsalomon37f9a262015-02-02 13:00:10 -0800396}
397
ericrk0a5fa482015-09-15 14:16:10 -0700398//////////////////////////////////////////////////////////////////////////////
ericrk0a5fa482015-09-15 14:16:10 -0700399void GrContext::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const {
joshualitt1de610a2016-01-06 08:26:09 -0800400 ASSERT_SINGLE_OWNER
ericrk0a5fa482015-09-15 14:16:10 -0700401 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
Khushal71652e22018-10-29 13:05:36 -0700402 traceMemoryDump->dumpNumericValue("skia/gr_text_blob_cache", "size", "bytes",
Robert Phillips2184fb72019-02-21 16:11:41 -0500403 this->getTextBlobCache()->usedBytes());
ericrk0a5fa482015-09-15 14:16:10 -0700404}
Brian Osman71a18892017-08-10 10:23:25 -0400405
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400406//////////////////////////////////////////////////////////////////////////////
407GrBackendTexture GrContext::createBackendTexture(int width, int height,
Greg Danielf91aeb22019-06-18 09:58:02 -0400408 const GrBackendFormat& backendFormat,
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400409 GrMipMapped mipMapped,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400410 GrRenderable renderable,
411 GrProtected isProtected) {
Brian Salomonc42eb662019-06-24 17:13:00 -0400412 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400413 if (!this->asDirectContext()) {
414 return GrBackendTexture();
415 }
416
417 if (this->abandoned()) {
418 return GrBackendTexture();
419 }
420
Robert Phillips4277f012020-01-21 14:28:34 -0500421 return fGpu->createBackendTexture({width, height}, backendFormat, renderable,
Greg Daniel16032b32020-05-06 15:31:10 -0400422 mipMapped, isProtected);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400423}
424
425GrBackendTexture GrContext::createBackendTexture(int width, int height,
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400426 SkColorType skColorType,
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400427 GrMipMapped mipMapped,
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400428 GrRenderable renderable,
429 GrProtected isProtected) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400430 if (!this->asDirectContext()) {
431 return GrBackendTexture();
432 }
433
434 if (this->abandoned()) {
435 return GrBackendTexture();
436 }
437
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400438 const GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400439
Emircan Uysaler23ca4e72019-06-24 10:53:09 -0400440 return this->createBackendTexture(width, height, format, mipMapped, renderable, isProtected);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400441}
442
Robert Phillips02dc0302019-07-02 17:58:27 -0400443GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c) {
Robert Phillips02dc0302019-07-02 17:58:27 -0400444 if (!this->asDirectContext() || !c.isValid()) {
445 return GrBackendTexture();
446 }
447
448 if (this->abandoned()) {
449 return GrBackendTexture();
450 }
451
452 if (c.usesGLFBO0()) {
453 // If we are making the surface we will never use FBO0.
454 return GrBackendTexture();
455 }
456
457 if (c.vulkanSecondaryCBCompatible()) {
458 return {};
459 }
460
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400461 const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes);
Robert Phillips02dc0302019-07-02 17:58:27 -0400462 if (!format.isValid()) {
463 return GrBackendTexture();
464 }
465
Robert Phillips02dc0302019-07-02 17:58:27 -0400466 GrBackendTexture result = this->createBackendTexture(c.width(), c.height(), format,
467 GrMipMapped(c.isMipMapped()),
468 GrRenderable::kYes,
Robert Phillips3cd54322019-07-10 09:28:59 -0400469 c.isProtected());
Robert Phillips02dc0302019-07-02 17:58:27 -0400470 SkASSERT(c.isCompatible(result));
471 return result;
472}
473
474GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400475 const SkColor4f& color,
476 GrGpuFinishedProc finishedProc,
477 GrGpuFinishedContext finishedContext) {
Robert Phillips02dc0302019-07-02 17:58:27 -0400478 if (!this->asDirectContext() || !c.isValid()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400479 finishedProc(finishedContext);
480 return {};
Robert Phillips02dc0302019-07-02 17:58:27 -0400481 }
482
483 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400484 finishedProc(finishedContext);
485 return {};
Robert Phillips02dc0302019-07-02 17:58:27 -0400486 }
487
488 if (c.usesGLFBO0()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400489 finishedProc(finishedContext);
Robert Phillips02dc0302019-07-02 17:58:27 -0400490 // If we are making the surface we will never use FBO0.
Greg Danielc1ad77c2020-05-06 11:40:03 -0400491 return {};
Robert Phillips02dc0302019-07-02 17:58:27 -0400492 }
493
494 if (c.vulkanSecondaryCBCompatible()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400495 finishedProc(finishedContext);
Robert Phillips02dc0302019-07-02 17:58:27 -0400496 return {};
497 }
498
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400499 const GrBackendFormat format = this->defaultBackendFormat(c.colorType(), GrRenderable::kYes);
Robert Phillips02dc0302019-07-02 17:58:27 -0400500 if (!format.isValid()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400501 finishedProc(finishedContext);
502 return {};
Robert Phillips02dc0302019-07-02 17:58:27 -0400503 }
504
Robert Phillips02dc0302019-07-02 17:58:27 -0400505 GrBackendTexture result = this->createBackendTexture(c.width(), c.height(), format, color,
506 GrMipMapped(c.isMipMapped()),
507 GrRenderable::kYes,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400508 c.isProtected(), finishedProc,
509 finishedContext);
Robert Phillips02dc0302019-07-02 17:58:27 -0400510 SkASSERT(c.isCompatible(result));
511 return result;
512}
513
Greg Daniel16032b32020-05-06 15:31:10 -0400514static GrBackendTexture create_and_update_backend_texture(GrContext* context,
515 SkISize dimensions,
516 const GrBackendFormat& backendFormat,
517 GrMipMapped mipMapped,
518 GrRenderable renderable,
519 GrProtected isProtected,
520 GrGpuFinishedProc finishedProc,
521 GrGpuFinishedContext finishedContext,
522 const GrGpu::BackendTextureData* data) {
523 GrGpu* gpu = context->priv().getGpu();
524
525 GrBackendTexture beTex = gpu->createBackendTexture(dimensions, backendFormat, renderable,
526 mipMapped, isProtected);
527 if (!beTex.isValid()) {
528 return {};
529 }
530
531 if (!context->priv().getGpu()->updateBackendTexture(beTex, finishedProc, finishedContext,
532 data)) {
533 context->deleteBackendTexture(beTex);
534 return {};
535 }
536 return beTex;
537}
538
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400539GrBackendTexture GrContext::createBackendTexture(int width, int height,
Greg Danielf91aeb22019-06-18 09:58:02 -0400540 const GrBackendFormat& backendFormat,
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400541 const SkColor4f& color,
542 GrMipMapped mipMapped,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400543 GrRenderable renderable,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400544 GrProtected isProtected,
545 GrGpuFinishedProc finishedProc,
546 GrGpuFinishedContext finishedContext) {
Brian Salomonc42eb662019-06-24 17:13:00 -0400547 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400548 if (!this->asDirectContext()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400549 finishedProc(finishedContext);
550 return {};
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400551 }
552
553 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400554 finishedProc(finishedContext);
555 return {};
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400556 }
557
Brian Salomon85c3d682019-11-04 15:04:54 -0500558 GrGpu::BackendTextureData data(color);
Greg Daniel16032b32020-05-06 15:31:10 -0400559 return create_and_update_backend_texture(this, {width, height}, backendFormat, mipMapped,
560 renderable, isProtected, finishedProc, finishedContext,
561 &data);
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400562}
563
564GrBackendTexture GrContext::createBackendTexture(int width, int height,
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400565 SkColorType skColorType,
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400566 const SkColor4f& color,
567 GrMipMapped mipMapped,
Robert Phillipsda2e67a2019-07-01 15:04:06 -0400568 GrRenderable renderable,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400569 GrProtected isProtected,
570 GrGpuFinishedProc finishedProc,
571 GrGpuFinishedContext finishedContext) {
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400572 if (!this->asDirectContext()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400573 finishedProc(finishedContext);
574 return {};
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400575 }
576
577 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400578 finishedProc(finishedContext);
579 return {};
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400580 }
581
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400582 GrBackendFormat format = this->defaultBackendFormat(skColorType, renderable);
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400583 if (!format.isValid()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400584 finishedProc(finishedContext);
585 return {};
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400586 }
Robert Phillipsd5e80ca2019-07-29 14:11:35 -0400587
588 GrColorType grColorType = SkColorTypeToGrColorType(skColorType);
Brian Salomon982f5462020-03-30 12:52:33 -0400589 SkColor4f swizzledColor = this->caps()->getWriteSwizzle(format, grColorType).applyTo(color);
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400590
Brian Salomonb450f3b2019-07-09 09:36:51 -0400591 return this->createBackendTexture(width, height, format, swizzledColor, mipMapped, renderable,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400592 isProtected, finishedProc, finishedContext);
Robert Phillips4bdd36f2019-06-04 11:03:06 -0400593}
594
Robert Phillipsba5c7ad2020-01-24 11:03:33 -0500595GrBackendTexture GrContext::createBackendTexture(const SkPixmap srcData[], int numProvidedLevels,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400596 GrRenderable renderable, GrProtected isProtected,
597 GrGpuFinishedProc finishedProc,
598 GrGpuFinishedContext finishedContext) {
Robert Phillips66944402019-09-30 13:21:25 -0400599 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
600
601 if (!this->asDirectContext()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400602 finishedProc(finishedContext);
Robert Phillips66944402019-09-30 13:21:25 -0400603 return {};
604 }
605
606 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400607 finishedProc(finishedContext);
Robert Phillips66944402019-09-30 13:21:25 -0400608 return {};
609 }
610
Robert Phillipsba5c7ad2020-01-24 11:03:33 -0500611 if (!srcData || numProvidedLevels <= 0) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400612 finishedProc(finishedContext);
Robert Phillips66944402019-09-30 13:21:25 -0400613 return {};
614 }
615
616 int baseWidth = srcData[0].width();
617 int baseHeight = srcData[0].height();
618 SkColorType colorType = srcData[0].colorType();
619
Robert Phillipsba5c7ad2020-01-24 11:03:33 -0500620 GrMipMapped mipMapped = GrMipMapped::kNo;
621 int numExpectedLevels = 1;
622 if (numProvidedLevels > 1) {
623 numExpectedLevels = SkMipMap::ComputeLevelCount(baseWidth, baseHeight) + 1;
624 mipMapped = GrMipMapped::kYes;
625 }
626
627 if (numProvidedLevels != numExpectedLevels) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400628 finishedProc(finishedContext);
Robert Phillipsba5c7ad2020-01-24 11:03:33 -0500629 return {};
630 }
631
Robert Phillips66944402019-09-30 13:21:25 -0400632 GrBackendFormat backendFormat = this->defaultBackendFormat(colorType, renderable);
633
Brian Salomon85c3d682019-11-04 15:04:54 -0500634 GrGpu::BackendTextureData data(srcData);
Greg Daniel16032b32020-05-06 15:31:10 -0400635 return create_and_update_backend_texture(this, {baseWidth, baseHeight}, backendFormat,
636 mipMapped, renderable, isProtected, finishedProc,
637 finishedContext, &data);
Robert Phillips66944402019-09-30 13:21:25 -0400638}
639
Greg Danielb2365d82020-05-13 15:32:04 -0400640bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
641 const SkColor4f& color,
642 GrGpuFinishedProc finishedProc,
643 GrGpuFinishedContext finishedContext) {
644 if (!this->asDirectContext()) {
645 finishedProc(finishedContext);
646 return false;
647 }
648
649 if (this->abandoned()) {
650 finishedProc(finishedContext);
651 return false;
652 }
653
654 GrGpu::BackendTextureData data(color);
655 return fGpu->updateBackendTexture(backendTexture, finishedProc, finishedContext, &data);
656}
657
658bool GrContext::updateBackendTexture(const GrBackendTexture& backendTexture,
659 const SkPixmap srcData[],
660 int numLevels,
661 GrGpuFinishedProc finishedProc,
662 GrGpuFinishedContext finishedContext) {
663 if (!this->asDirectContext()) {
664 finishedProc(finishedContext);
665 return false;
666 }
667
668 if (this->abandoned()) {
669 finishedProc(finishedContext);
670 return false;
671 }
672
673 if (!srcData || numLevels <= 0) {
674 finishedProc(finishedContext);
675 return false;
676 }
677
678 int numExpectedLevels = 1;
679 if (backendTexture.hasMipMaps()) {
680 numExpectedLevels = SkMipMap::ComputeLevelCount(backendTexture.width(),
681 backendTexture.height()) + 1;
682 }
683 if (numLevels != numExpectedLevels) {
684 finishedProc(finishedContext);
685 return false;
686 }
687
688 GrGpu::BackendTextureData data(srcData);
689 return fGpu->updateBackendTexture(backendTexture, finishedProc, finishedContext, &data);
690}
691
Robert Phillipsb915c942019-12-17 14:44:37 -0500692//////////////////////////////////////////////////////////////////////////////
693
694GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height,
695 const GrBackendFormat& backendFormat,
696 const SkColor4f& color,
697 GrMipMapped mipMapped,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400698 GrProtected isProtected,
699 GrGpuFinishedProc finishedProc,
700 GrGpuFinishedContext finishedContext) {
Robert Phillipsb915c942019-12-17 14:44:37 -0500701 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
702 if (!this->asDirectContext()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400703 finishedProc(finishedContext);
704 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500705 }
706
707 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400708 finishedProc(finishedContext);
709 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500710 }
711
712 GrGpu::BackendTextureData data(color);
Robert Phillips4277f012020-01-21 14:28:34 -0500713 return fGpu->createCompressedBackendTexture({width, height}, backendFormat,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400714 mipMapped, isProtected, finishedProc,
715 finishedContext, &data);
Robert Phillipsb915c942019-12-17 14:44:37 -0500716}
717
718GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height,
719 SkImage::CompressionType compression,
720 const SkColor4f& color,
721 GrMipMapped mipMapped,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400722 GrProtected isProtected,
723 GrGpuFinishedProc finishedProc,
724 GrGpuFinishedContext finishedContext) {
Robert Phillipsb915c942019-12-17 14:44:37 -0500725 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
726 if (!this->asDirectContext()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400727 finishedProc(finishedContext);
728 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500729 }
730
731 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400732 finishedProc(finishedContext);
733 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500734 }
735
736 GrBackendFormat format = this->compressedBackendFormat(compression);
737 return this->createCompressedBackendTexture(width, height, format, color,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400738 mipMapped, isProtected, finishedProc,
739 finishedContext);
Robert Phillipsb915c942019-12-17 14:44:37 -0500740}
741
742GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height,
743 const GrBackendFormat& backendFormat,
744 const void* compressedData,
745 size_t dataSize,
746 GrMipMapped mipMapped,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400747 GrProtected isProtected,
748 GrGpuFinishedProc finishedProc,
749 GrGpuFinishedContext finishedContext) {
Robert Phillipsb915c942019-12-17 14:44:37 -0500750 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
751 if (!this->asDirectContext()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400752 finishedProc(finishedContext);
753 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500754 }
755
756 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400757 finishedProc(finishedContext);
758 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500759 }
760
761 GrGpu::BackendTextureData data(compressedData, dataSize);
Robert Phillips4277f012020-01-21 14:28:34 -0500762 return fGpu->createCompressedBackendTexture({width, height}, backendFormat,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400763 mipMapped, isProtected, finishedProc,
764 finishedContext, &data);
Robert Phillipsb915c942019-12-17 14:44:37 -0500765}
766
767GrBackendTexture GrContext::createCompressedBackendTexture(int width, int height,
768 SkImage::CompressionType compression,
769 const void* data, size_t dataSize,
770 GrMipMapped mipMapped,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400771 GrProtected isProtected,
772 GrGpuFinishedProc finishedProc,
773 GrGpuFinishedContext finishedContext) {
Robert Phillipsb915c942019-12-17 14:44:37 -0500774 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
775 if (!this->asDirectContext()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400776 finishedProc(finishedContext);
777 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500778 }
779
780 if (this->abandoned()) {
Greg Danielc1ad77c2020-05-06 11:40:03 -0400781 finishedProc(finishedContext);
782 return {};
Robert Phillipsb915c942019-12-17 14:44:37 -0500783 }
784
785 GrBackendFormat format = this->compressedBackendFormat(compression);
786 return this->createCompressedBackendTexture(width, height, format, data, dataSize,
Greg Danielc1ad77c2020-05-06 11:40:03 -0400787 mipMapped, isProtected, finishedProc,
788 finishedContext);
Robert Phillipsb915c942019-12-17 14:44:37 -0500789}
790
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400791void GrContext::deleteBackendTexture(GrBackendTexture backendTex) {
Brian Salomonc42eb662019-06-24 17:13:00 -0400792 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
Greg Danielf0e04f02019-12-04 15:17:54 -0500793 // For the Vulkan backend we still must destroy the backend texture when the context is
794 // abandoned.
795 if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) {
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400796 return;
797 }
798
Robert Phillipsf0313ee2019-05-21 13:51:11 -0400799 fGpu->deleteBackendTexture(backendTex);
Robert Phillips5c7a25b2019-05-20 08:38:07 -0400800}
801
Brian Osmaned58e002019-09-06 14:42:43 -0400802bool GrContext::precompileShader(const SkData& key, const SkData& data) {
803 return fGpu->precompileShader(key, data);
804}
805
Brian Salomonec22b1a2019-08-09 09:41:48 -0400806#ifdef SK_ENABLE_DUMP_GPU
Michael Ludwigdd205452020-03-30 17:16:34 -0400807#include "include/core/SkString.h"
Brian Salomonec22b1a2019-08-09 09:41:48 -0400808#include "src/utils/SkJSONWriter.h"
809SkString GrContext::dump() const {
810 SkDynamicMemoryWStream stream;
811 SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
812 writer.beginObject();
813
814 writer.appendString("backend", GrBackendApiToStr(this->backend()));
815
816 writer.appendName("caps");
817 this->caps()->dumpJSON(&writer);
818
819 writer.appendName("gpu");
820 this->fGpu->dumpJSON(&writer);
821
Robert Phillips273f1072020-05-05 13:03:07 -0400822 writer.appendName("context");
823 this->dumpJSON(&writer);
824
Brian Salomonec22b1a2019-08-09 09:41:48 -0400825 // Flush JSON to the memory stream
826 writer.endObject();
827 writer.flush();
828
829 // Null terminate the JSON data in the memory stream
830 stream.write8(0);
831
832 // Allocate a string big enough to hold all the data, then copy out of the stream
833 SkString result(stream.bytesWritten());
834 stream.copyToAndReset(result.writable_str());
835 return result;
836}
837#endif