aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ClipStackTest.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-01-06 13:54:58 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-06 19:42:08 +0000
commit19f0ed5b83a6ddf163a78bcb1c701f6020e6a17c (patch)
tree1f95cbab5eae57a734aeee489099b9b9f97f2331 /tests/ClipStackTest.cpp
parent9953737bcf885a52c08ade6c503f2202e4dd9aa5 (diff)
Purge clip masks when they are no longer findable.
This improves memory usage when the content contains frequently changing clips implemented as masks. BUG=chromium:676459 Change-Id: I06ea5f9fe1cff9564ea136bad9fe97f6ecd77ad9 Reviewed-on: https://skia-review.googlesource.com/6629 Commit-Queue: Brian Salomon <bsalomon@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'tests/ClipStackTest.cpp')
-rw-r--r--tests/ClipStackTest.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
index bb5cc4ad9e..a85f0168b2 100644
--- a/tests/ClipStackTest.cpp
+++ b/tests/ClipStackTest.cpp
@@ -13,7 +13,9 @@
#include "SkRegion.h"
#if SK_SUPPORT_GPU
+#include "GrClipStackClip.h"
#include "GrReducedClip.h"
+#include "GrResourceCache.h"
typedef GrReducedClip::ElementList ElementList;
typedef GrReducedClip::InitialState InitialState;
#endif
@@ -1407,3 +1409,51 @@ DEF_TEST(ClipStack, reporter) {
test_reduced_clip_stack_aa(reporter);
#endif
}
+
+//////////////////////////////////////////////////////////////////////////////
+
+#if SK_SUPPORT_GPU
+sk_sp<GrTexture> GrClipStackClip::testingOnly_createClipMask(GrContext* context) const {
+ const GrReducedClip reducedClip(*fStack, SkRect::MakeWH(512, 512), 0);
+ return this->createSoftwareClipMask(context, reducedClip);
+}
+
+// Verify that clip masks are freed up when the clip state that generated them goes away.
+DEF_GPUTEST_FOR_ALL_CONTEXTS(ClipMaskCache, reporter, ctxInfo) {
+ // This test uses resource key tags which only function in debug builds.
+#ifdef SK_DEBUG
+ GrContext* context = ctxInfo.grContext();
+ SkClipStack stack;
+
+ SkPath path;
+ path.addCircle(10, 10, 8);
+ path.addCircle(15, 15, 8);
+ path.setFillType(SkPath::kEvenOdd_FillType);
+
+ static const char* kTag = GrClipStackClip::kMaskTestTag;
+ GrResourceCache* cache = context->getResourceCache();
+
+ static constexpr int kN = 5;
+
+ for (int i = 0; i < kN; ++i) {
+ SkMatrix m;
+ m.setTranslate(0.5, 0.5);
+ stack.save();
+ stack.clipPath(path, m, SkClipOp::kIntersect, true);
+ auto mask = GrClipStackClip(&stack).testingOnly_createClipMask(context);
+ REPORTER_ASSERT(reporter, 0 == strcmp(mask->getUniqueKey().tag(), kTag));
+ // Make sure mask isn't pinned in cache.
+ mask.reset(nullptr);
+ context->flush();
+ REPORTER_ASSERT(reporter, i + 1 == cache->countUniqueKeysWithTag(kTag));
+ }
+
+ for (int i = 0; i < kN; ++i) {
+ stack.restore();
+ cache->purgeAsNeeded();
+ REPORTER_ASSERT(reporter, kN - (i + 1) == cache->countUniqueKeysWithTag(kTag));
+ }
+#endif
+}
+
+#endif