blob: df76a457f8337810e902f7454e2672f13349ef68 [file] [log] [blame]
Jim Van Verth3e192162020-03-10 16:23:16 -04001/*
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
13void GrTextureResource::addIdleProc(GrTexture* owningTexture,
14 sk_sp<GrRefCntedCallback> idleProc) const {
15 SkASSERT(!fOwningTexture || fOwningTexture == owningTexture);
16 fOwningTexture = owningTexture;
17 fIdleProcs.push_back(std::move(idleProc));
18}
19
20int GrTextureResource::idleProcCnt() const { return fIdleProcs.count(); }
21
22sk_sp<GrRefCntedCallback> GrTextureResource::idleProc(int i) const { return fIdleProcs[i]; }
23
24void GrTextureResource::resetIdleProcs() const { fIdleProcs.reset(); }
25
26void GrTextureResource::removeOwningTexture() const { fOwningTexture = nullptr; }
27
28void GrTextureResource::notifyQueuedForWorkOnGpu() const { ++fNumOwners; }
29
30void GrTextureResource::notifyFinishedWithWorkOnGpu() const {
31 SkASSERT(fNumOwners);
32 if (--fNumOwners || !fIdleProcs.count()) {
33 return;
34 }
35 if (fOwningTexture) {
36 if (fOwningTexture->resourcePriv().hasRef()) {
37 // Wait for the texture to become idle in the cache to call the procs.
38 return;
39 }
40 fOwningTexture->callIdleProcsOnBehalfOfResource();
41 } else {
42 fIdleProcs.reset();
43 }
44}