From 65b7bfcf61c5d925bf0066a2b40dd6ef7cf82595 Mon Sep 17 00:00:00 2001 From: Herb Derby Date: Tue, 5 Jun 2018 13:32:12 -0400 Subject: Glyph search of desperation Change-Id: I0ae768c5517c3ee3f6822fea0926b3f27214a0e4 Reviewed-on: https://skia-review.googlesource.com/132260 Commit-Queue: Herb Derby Reviewed-by: Mike Klein --- tests/SkRemoteGlyphCacheTest.cpp | 106 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'tests/SkRemoteGlyphCacheTest.cpp') diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp index af73158eb9..359c506950 100644 --- a/tests/SkRemoteGlyphCacheTest.cpp +++ b/tests/SkRemoteGlyphCacheTest.cpp @@ -408,3 +408,109 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_CacheMissReporting, report // Must unlock everything on termination, otherwise valgrind complains about memory leaks. discardableManager->unlockAndDeleteAll(); } + +DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) { + SkPaint paint; + paint.setAntiAlias(true); + auto typeface = SkTypeface::MakeFromName("monospace", SkFontStyle()); + paint.setTypeface(typeface); + paint.setColor(SK_ColorRED); + + auto lostGlyphID = SkPackedGlyphID(1, SK_FixedHalf, SK_FixedHalf); + + const uint8_t glyphImage[] = {0xFF, 0xFF}; + + // Build a fallback cache. + { + SkAutoDescriptor ad; + SkScalerContextRec rec; + SkScalerContextEffects effects; + SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast; + SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false); + auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad); + + auto fallbackCache = SkStrikeCache::FindOrCreateStrikeExclusive(*desc, effects, *typeface); + auto glyph = fallbackCache->getRawGlyphByID(lostGlyphID); + glyph->fMaskFormat = SkMask::kA8_Format; + glyph->fHeight = 1; + glyph->fWidth = 2; + fallbackCache->initializeImage(glyphImage, glyph->computeImageSize(), glyph); + glyph->fImage = (void *)glyphImage; + } + + // Make sure we can find the fall back cache. + { + SkAutoDescriptor ad; + SkScalerContextRec rec; + SkScalerContextEffects effects; + SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast; + SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false); + auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad); + auto testCache = SkStrikeCache::FindStrikeExclusive(*desc); + REPORTER_ASSERT(reporter, !(testCache == nullptr)); + } + + // Make sure we can't find the target cache. + { + SkAutoDescriptor ad; + SkScalerContextRec rec; + SkScalerContextEffects effects; + SkScalerContextFlags flags = SkScalerContextFlags::kNone; + SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false); + auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad); + auto testCache = SkStrikeCache::FindStrikeExclusive(*desc); + REPORTER_ASSERT(reporter, testCache == nullptr); + } + + { + SkGlyph lostGlyph; + lostGlyph.initWithGlyphID(lostGlyphID); + + SkAutoDescriptor ad; + SkScalerContextRec rec; + SkScalerContextEffects effects; + SkScalerContextFlags flags = SkScalerContextFlags::kNone; + SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false); + auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad); + SkArenaAlloc alloc{100}; + auto found = SkStrikeCache::DesperationSearchForImage(*desc, &lostGlyph, &alloc); + REPORTER_ASSERT(reporter, found); + REPORTER_ASSERT(reporter, lostGlyph.fHeight == 1); + REPORTER_ASSERT(reporter, lostGlyph.fWidth == 2); + REPORTER_ASSERT(reporter, lostGlyph.fMaskFormat == SkMask::kA8_Format); + } + + { + SkGlyph lostGlyph; + auto reallyLostGlyphID = SkPackedGlyphID(1, SK_FixedQuarter, SK_FixedQuarter); + lostGlyph.initWithGlyphID(reallyLostGlyphID); + + SkAutoDescriptor ad; + SkScalerContextRec rec; + SkScalerContextEffects effects; + SkScalerContextFlags flags = SkScalerContextFlags::kNone; + SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false); + auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad); + SkArenaAlloc alloc{100}; + auto found = SkStrikeCache::DesperationSearchForImage(*desc, &lostGlyph, &alloc); + REPORTER_ASSERT(reporter, found); + REPORTER_ASSERT(reporter, lostGlyph.fHeight == 1); + REPORTER_ASSERT(reporter, lostGlyph.fWidth == 2); + REPORTER_ASSERT(reporter, lostGlyph.fMaskFormat == SkMask::kA8_Format); + } + + // Make sure we can't find the target cache again. + { + SkAutoDescriptor ad; + SkScalerContextRec rec; + SkScalerContextEffects effects; + SkScalerContextFlags flags = SkScalerContextFlags::kNone; + SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false); + auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad); + auto testCache = SkStrikeCache::FindStrikeExclusive(*desc); + REPORTER_ASSERT(reporter, testCache == nullptr); + } + + SkStrikeCache::Validate(); + +} -- cgit v1.2.3