/* * Copyright 2015 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrManagedResource_DEFINED #define GrManagedResource_DEFINED #include "include/core/SkRefCnt.h" #include "include/private/base/SkAssert.h" #include "include/private/base/SkDebug.h" #include "include/private/base/SkMutex.h" #include "include/private/base/SkNoncopyable.h" #include "include/private/base/SkThreadAnnotations.h" #include "src/core/SkTHash.h" #include "src/gpu/ganesh/GrSurface.h" #include <atomic> #include <cstdint> #include <utility> // uncomment to enable tracing of resource refs #ifdef SK_DEBUG #define SK_TRACE_MANAGED_RESOURCES #endif /** \class GrManagedResource GrManagedResource is the base class for GPU resources that may be shared by multiple objects, in particular objects that are tracked by a command buffer. When an existing owner wants to share a reference, it calls ref(). When an owner wants to release its reference, it calls unref(). When the shared object's reference count goes to zero as the result of an unref() call, its (virtual) destructor is called. It is an error for the destructor to be called explicitly (or via the object going out of scope on the stack or calling delete) if getRefCnt() > 1. This is nearly identical to SkRefCntBase. The exceptions are that unref() takes a GrGpu, and any derived classes must implement freeGPUData(). */ class GrManagedResource : SkNoncopyable { … }; // This subclass allows for recycling class GrRecycledResource : public GrManagedResource { … }; /** \class GrTextureResource GrTextureResource is the base class for managed texture resources, and implements the basic releaseProc functionality for them. */ class GrTextureResource : public GrManagedResource { … }; #endif