| 1 |
/* |
| 2 |
* Copyright 2025 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 |
#ifndef skgpu_graphite_ThreadSafeResourceProvider_DEFINED |
| 9 |
#define skgpu_graphite_ThreadSafeResourceProvider_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "src/base/SkSpinlock.h" |
| 13 |
#include "src/gpu/GpuTypesPriv.h" |
| 14 |
|
| 15 |
#include <memory> |
| 16 |
|
| 17 |
class SkTraceMemoryDump; |
| 18 |
|
| 19 |
namespace skgpu::graphite { |
| 20 |
|
| 21 |
class ResourceProvider; |
| 22 |
class Sampler; |
| 23 |
struct SamplerDesc; |
| 24 |
|
| 25 |
// The ThreadSafeResourceProvider wraps a backend-specific ResourceProvider and guards its |
| 26 |
// usage via a SpinLock. It exposes the smallest API surface required. |
| 27 |
// Note that once ResourceCaches are thread safe this could be replaced with the Context's |
| 28 |
// ResourceProvider. |
| 29 |
class ThreadSafeResourceProvider { |
| 30 |
public: |
| 31 |
ThreadSafeResourceProvider(std::unique_ptr<ResourceProvider>); |
| 32 |
|
| 33 |
sk_sp<Sampler> findOrCreateCompatibleSampler(const SamplerDesc&) SK_EXCLUDES(fSpinLock); |
| 34 |
|
| 35 |
#if defined(SK_DEBUG) |
| 36 |
size_t getResourceCacheLimit() const SK_EXCLUDES(fSpinLock); |
| 37 |
size_t getResourceCacheCurrentBudgetedBytes() const SK_EXCLUDES(fSpinLock); |
| 38 |
size_t getResourceCacheCurrentPurgeableBytes() const SK_EXCLUDES(fSpinLock); |
| 39 |
#endif |
| 40 |
|
| 41 |
void dumpMemoryStatistics(SkTraceMemoryDump*) const SK_EXCLUDES(fSpinLock); |
| 42 |
void freeGpuResources() SK_EXCLUDES(fSpinLock); |
| 43 |
void purgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime) SK_EXCLUDES(fSpinLock); |
| 44 |
void forceProcessReturnedResources() SK_EXCLUDES(fSpinLock); |
| 45 |
|
| 46 |
protected: |
| 47 |
mutable SkSpinlock fSpinLock; |
| 48 |
|
| 49 |
std::unique_ptr<ResourceProvider> fWrappedProvider SK_GUARDED_BY(fSpinLock); |
| 50 |
}; |
| 51 |
|
| 52 |
} // namespace skgpu::graphite |
| 53 |
|
| 54 |
#endif // skgpu_graphite_ThreadSafeResourceProvider_DEFINED |