Revert "Revert "Add a new GrResourceCache purging mechanism for purging unused resources.""
This reverts commit 20c322ef0cd04cf8e2592879d05d9f4e6cb19596.
Change-Id: I6df9a8594484837672308dc2c21c7c29b76ffa2c
Reviewed-on: https://skia-review.googlesource.com/10013
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 959a0fa..ea4f422 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -160,6 +160,12 @@
*/
void purgeAllUnlockedResources();
+ /**
+ * Purge GPU resources that haven't been used in the past 'ms' milliseconds, regardless of
+ * whether the context is currently under budget.
+ */
+ void purgeResourcesNotUsedInMs(std::chrono::milliseconds ms);
+
/** Access the context capabilities */
const GrCaps* caps() const { return fCaps; }
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index e0a7903..2d84c63 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -315,28 +315,30 @@
void makeUnbudgeted();
#ifdef SK_DEBUG
- friend class GrGpu; // for assert in GrGpu to access getGpu
+ friend class GrGpu; // for assert in GrGpu to access getGpu
#endif
+
// An index into a heap when this resource is purgeable or an array when not. This is maintained
// by the cache.
- int fCacheArrayIndex;
+ int fCacheArrayIndex;
// This value reflects how recently this resource was accessed in the cache. This is maintained
// by the cache.
- uint32_t fTimestamp;
- uint32_t fExternalFlushCntWhenBecamePurgeable;
+ uint32_t fTimestamp;
+ uint32_t fExternalFlushCntWhenBecamePurgeable;
+ GrStdSteadyClock::time_point fTimeWhenBecamePurgeable;
static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
- GrScratchKey fScratchKey;
- GrUniqueKey fUniqueKey;
+ GrScratchKey fScratchKey;
+ GrUniqueKey fUniqueKey;
// This is not ref'ed but abandon() or release() will be called before the GrGpu object
// is destroyed. Those calls set will this to NULL.
- GrGpu* fGpu;
- mutable size_t fGpuMemorySize;
+ GrGpu* fGpu;
+ mutable size_t fGpuMemorySize;
- SkBudgeted fBudgeted;
- bool fRefsWrappedObjects;
- const UniqueID fUniqueID;
+ SkBudgeted fBudgeted;
+ bool fRefsWrappedObjects;
+ const UniqueID fUniqueID;
typedef GrIORef<GrGpuResource> INHERITED;
friend class GrIORef<GrGpuResource>; // to access notifyAllCntsAreZero and notifyRefCntIsZero.
diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h
index 28c3335..5db1c24 100644
--- a/include/gpu/GrTypesPriv.h
+++ b/include/gpu/GrTypesPriv.h
@@ -8,9 +8,19 @@
#ifndef GrTypesPriv_DEFINED
#define GrTypesPriv_DEFINED
+#include <chrono>
#include "GrTypes.h"
#include "SkRefCnt.h"
+// The old libstdc++ uses the draft name "monotonic_clock" rather than "steady_clock". This might
+// not actually be monotonic, depending on how libstdc++ was built. However, this is only currently
+// used for idle resource purging so it shouldn't cause a correctness problem.
+#if defined(__GLIBCXX__) && (__GLIBCXX__ < 20130000)
+using GrStdSteadyClock = std::chrono::monotonic_clock;
+#else
+using GrStdSteadyClock = std::chrono::steady_clock;
+#endif
+
/** This enum indicates the type of antialiasing to be performed. */
enum class GrAAType : unsigned {
/** No antialiasing */