• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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 "experimental/graphite/src/Resource.h"
9 
10 namespace skgpu {
11 
Resource(const Gpu * gpu)12 Resource::Resource(const Gpu* gpu) : fGpu(gpu), fUsageRefCnt(1), fCommandBufferRefCnt(0) {
13     // Normally the array index will always be set before the cache tries to read so there isn't
14     // a worry about this not being initialized. However, when we try to validate the cache in
15     // debug builds we may try to read a resources index before it has actually been set by the
16     // cache
17     SkDEBUGCODE(fCacheArrayIndex = -1);
18 }
19 
~Resource()20 Resource::~Resource() {
21     // The cache should have released or destroyed this resource.
22     SkASSERT(this->wasDestroyed());
23 }
24 
notifyARefIsZero(LastRemovedRef removedRef) const25 void Resource::notifyARefIsZero(LastRemovedRef removedRef) const {
26     // TODO: Eventually we'll go through the cache to release the resource, but for now we just do
27     // this immediately.
28     SkASSERT(removedRef == LastRemovedRef::kUsageRef);
29     Resource* mutableThis = const_cast<Resource*>(this);
30     mutableThis->freeGpuData();
31 }
32 
freeGpuData()33 void Resource::freeGpuData() {
34     SkASSERT(fGpu);
35     this->onFreeGpuData();
36     fGpu = nullptr;
37     delete this;
38 }
39 
40 } // namespace skgpu
41 
42