skia2/tests/SkStrikeCacheTest.cpp
Herb Derby 3b946c1618 Check fullness and purge on every strike lookup
In the old code, the cache was checked and perged on every reattach
of a strike. That was left out of the multi-threaded code. Add the
check and purge back in to maintain cache size.

* Removed minimum cache size from setCacheSizeLimit.

Bug: skia:10046
Change-Id: I2438c83f04b6da8133c161a29604c3c3d7f58cd8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/277066
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
2020-03-16 19:59:56 +00:00

54 lines
1.4 KiB
C++

/*
* Copyright 2020 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/core/SkStrikeCache.h"
#include "src/core/SkStrikeSpec.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
DEF_TEST(SkStrikeCache_CachePurge, Reporter) {
SkStrikeCache cache;
sk_sp<SkTypeface> typeface =
ToolUtils::create_portable_typeface("serif", SkFontStyle::Italic());
SkFont font;
font.setEdging(SkFont::Edging::kAntiAlias);
font.setSubpixel(true);
font.setTypeface(typeface);
SkPaint defaultPaint;
SkStrikeSpec strikeSpec = SkStrikeSpec::MakeMask(
font, defaultPaint, SkSurfaceProps(0, kUnknown_SkPixelGeometry),
SkScalerContextFlags::kNone, SkMatrix::I());
// Initially empty cache
REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
{
sk_sp<SkStrike> strike = strikeSpec.findOrCreateStrike(&cache);
}
// Stuff in cache.
REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() > 0);
cache.purgeAll();
// Purged cache.
REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
// Smallest cache.
cache.setCacheSizeLimit(0);
{
sk_sp<SkStrike> strike = strikeSpec.findOrCreateStrike(&cache);
REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
}
REPORTER_ASSERT(Reporter, cache.getTotalMemoryUsed() == 0);
}