/* * Copyright 2020 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef GrRefCnt_DEFINED #define GrRefCnt_DEFINED #include "include/core/SkRefCnt.h" #include "include/private/base/SkAssert.h" #include "include/private/base/SkDebug.h" #include <cstddef> #include <type_traits> // We have to use auto for the function pointers here because if the actual functions live on the // base class of T we need the function here to be a pointer to a function of the base class and not // a function on T. Thus we can't have something like void(T::*Ref)() since we may need T or we may // need some base class of T. template <typename T, auto Ref, auto Unref> class gr_sp { … }; //////////////////////////////////////////////////////////////////////////////////////////////////// /** * Shared pointer class to wrap classes that support a refCommandBuffer() and unrefCommandBuffer() * interface. * * This class supports copying, moving, and assigning an sk_sp into it. In general these commands do * not modify the sk_sp at all but just call refCommandBuffer() on the underlying object. * * This class is designed to be used by GrGpuResources/graphite::Resources that need to track when * they are in use on gpu (usually via a command buffer) separately from tracking if there are any * current logical usages in Skia. This allows for a scratch resources to be reused for new draw * calls even if it is in use on the GPU. */ gr_cb; //////////////////////////////////////////////////////////////////////////////////////////////////// /** * This class mimics sk_sp but instead of calling unref it calls recycle instead. */ gr_rp; /** * Returns a gr_rp wrapping the provided ptr AND calls ref on it (if not null). * * This is different than the semantics of the constructor for gr_rp, which just wraps the ptr, * effectively "adopting" it. */ template <typename T> gr_rp<T> gr_ref_rp(T* obj) { … } template <typename T> gr_rp<T> gr_ref_rp(const T* obj) { … } #endif