From d416083eef5b144f65a8de67725ad49264f90884 Mon Sep 17 00:00:00 2001 From: Khushal Date: Wed, 23 May 2018 18:16:00 -0700 Subject: Reland fonts: Cleanup cache miss logging for font remoting. This reverts commit fc6cf92e4b21c92ead769fae557534056eac6d83. TBR=herb@google.com Bug: skia:7913 Change-Id: I93301e49839fdb895a5f1f5845bb9975981c69fc Reviewed-on: https://skia-review.googlesource.com/129880 Reviewed-by: Khusal Sagar Commit-Queue: Khusal Sagar --- tests/SkRemoteGlyphCacheTest.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) (limited to 'tests/SkRemoteGlyphCacheTest.cpp') diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp index aa26fbeea8..23e684315e 100644 --- a/tests/SkRemoteGlyphCacheTest.cpp +++ b/tests/SkRemoteGlyphCacheTest.cpp @@ -22,7 +22,7 @@ class DiscardableManager : public SkStrikeServer::DiscardableHandleManager, public SkStrikeClient::DiscardableHandleManager { public: - DiscardableManager() = default; + DiscardableManager() { sk_bzero(&fCacheMissCount, sizeof(fCacheMissCount)); } ~DiscardableManager() override = default; // Server implementation. @@ -39,6 +39,7 @@ public: // Client implementation. bool deleteHandle(SkDiscardableHandleId id) override { return id <= fLastDeletedHandleId; } + void NotifyCacheMiss(SkStrikeClient::CacheMissType type) override { fCacheMissCount[type]++; } void unlockAll() { fLockedHandles.reset(); } void unlockAndDeleteAll() { @@ -47,11 +48,13 @@ public: } const SkTHashSet& lockedHandles() const { return fLockedHandles; } SkDiscardableHandleId handleCount() { return fNextHandleId; } + int cacheMissCount(SkStrikeClient::CacheMissType type) { return fCacheMissCount[type]; } private: SkDiscardableHandleId fNextHandleId = 0u; SkDiscardableHandleId fLastDeletedHandleId = 0u; SkTHashSet fLockedHandles; + int fCacheMissCount[SkStrikeClient::CacheMissType::kLast + 1u]; }; sk_sp buildTextBlob(sk_sp tf, int glyphCount) { @@ -114,7 +117,7 @@ DEF_TEST(SkRemoteGlyphCache_TypefaceSerialization, reporter) { auto client_tf = client.deserializeTypeface(tf_data->data(), tf_data->size()); REPORTER_ASSERT(reporter, client_tf); - REPORTER_ASSERT(reporter, SkTypefaceProxy::DownCast(client_tf.get())->remoteTypefaceID() == + REPORTER_ASSERT(reporter, static_cast(client_tf.get())->remoteTypefaceID() == server_tf->uniqueID()); // Must unlock everything on termination, otherwise valgrind complains about memory leaks. @@ -373,4 +376,34 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, c // Must unlock everything on termination, otherwise valgrind complains about memory leaks. discardableManager->unlockAndDeleteAll(); } + +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_CacheMissReporting, reporter, ctxInfo) { + sk_sp discardableManager = sk_make_sp(); + SkStrikeServer server(discardableManager.get()); + SkStrikeClient client(discardableManager); + + auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle()); + auto tfData = server.serializeTypeface(serverTf.get()); + auto clientTf = client.deserializeTypeface(tfData->data(), tfData->size()); + REPORTER_ASSERT(reporter, clientTf); + int glyphCount = 10; + auto clientBlob = buildTextBlob(clientTf, glyphCount); + + // Raster the client-side blob without the glyph data, we should get cache miss notifications. + SkPaint paint; + SkMatrix matrix = SkMatrix::I(); + RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext(), &matrix); + REPORTER_ASSERT(reporter, + discardableManager->cacheMissCount(SkStrikeClient::kFontMetrics) == 1); + REPORTER_ASSERT(reporter, + discardableManager->cacheMissCount(SkStrikeClient::kGlyphMetrics) == 10); + + // There shouldn't be any image or path requests, since we mark the glyph as empty on a cache + // miss. + REPORTER_ASSERT(reporter, discardableManager->cacheMissCount(SkStrikeClient::kGlyphImage) == 0); + REPORTER_ASSERT(reporter, discardableManager->cacheMissCount(SkStrikeClient::kGlyphPath) == 0); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); +} #endif -- cgit v1.2.3