Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "src/gpu/GrManagedResource.h" |
| 9 | |
| 10 | #include "src/gpu/GrGpuResourcePriv.h" |
| 11 | #include "src/gpu/GrTexture.h" |
| 12 | |
Jim Van Verth | 5c69393 | 2020-03-27 13:24:00 -0400 | [diff] [blame^] | 13 | |
| 14 | #ifdef SK_TRACE_MANAGED_RESOURCES |
| 15 | std::atomic<uint32_t> GrManagedResource::fKeyCounter{0}; |
| 16 | #endif |
| 17 | |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 18 | void GrTextureResource::addIdleProc(GrTexture* owningTexture, |
| 19 | sk_sp<GrRefCntedCallback> idleProc) const { |
| 20 | SkASSERT(!fOwningTexture || fOwningTexture == owningTexture); |
| 21 | fOwningTexture = owningTexture; |
| 22 | fIdleProcs.push_back(std::move(idleProc)); |
| 23 | } |
| 24 | |
| 25 | int GrTextureResource::idleProcCnt() const { return fIdleProcs.count(); } |
| 26 | |
| 27 | sk_sp<GrRefCntedCallback> GrTextureResource::idleProc(int i) const { return fIdleProcs[i]; } |
| 28 | |
| 29 | void GrTextureResource::resetIdleProcs() const { fIdleProcs.reset(); } |
| 30 | |
| 31 | void GrTextureResource::removeOwningTexture() const { fOwningTexture = nullptr; } |
| 32 | |
| 33 | void GrTextureResource::notifyQueuedForWorkOnGpu() const { ++fNumOwners; } |
| 34 | |
| 35 | void GrTextureResource::notifyFinishedWithWorkOnGpu() const { |
| 36 | SkASSERT(fNumOwners); |
| 37 | if (--fNumOwners || !fIdleProcs.count()) { |
| 38 | return; |
| 39 | } |
| 40 | if (fOwningTexture) { |
| 41 | if (fOwningTexture->resourcePriv().hasRef()) { |
| 42 | // Wait for the texture to become idle in the cache to call the procs. |
| 43 | return; |
| 44 | } |
| 45 | fOwningTexture->callIdleProcsOnBehalfOfResource(); |
| 46 | } else { |
| 47 | fIdleProcs.reset(); |
| 48 | } |
| 49 | } |