From 3e7548ca60d9139b650e1f099e6c724b3711dd81 Mon Sep 17 00:00:00 2001 From: Khushal Date: Wed, 23 May 2018 15:45:01 -0700 Subject: Reland fonts: Add support for distance field text to font remoting. This reverts commit 7257e22e43a56a5f4f772b687034580061cd011f. TBR=herb@google.com, bsalomon@google.com Bug: skia:7913 Change-Id: I51ca5bccdda64cd98e2ad59874e7136ee58cec10 Reviewed-on: https://skia-review.googlesource.com/129809 Reviewed-by: Khusal Sagar Commit-Queue: Khusal Sagar --- tests/SkRemoteGlyphCacheTest.cpp | 111 +++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 10 deletions(-) (limited to 'tests/SkRemoteGlyphCacheTest.cpp') diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp index 811bf1be50..aa26fbeea8 100644 --- a/tests/SkRemoteGlyphCacheTest.cpp +++ b/tests/SkRemoteGlyphCacheTest.cpp @@ -15,6 +15,10 @@ #include "SkTypeface_remote.h" #include "Test.h" +#if SK_SUPPORT_GPU +#include "text/GrAtlasTextContext.h" +#endif + class DiscardableManager : public SkStrikeServer::DiscardableHandleManager, public SkStrikeClient::DiscardableHandleManager { public: @@ -79,14 +83,26 @@ sk_sp buildTextBlob(sk_sp tf, int glyphCount) { } \ } -SkBitmap RasterBlob(sk_sp blob, int width, int height, const SkPaint& paint) { - auto surface = SkSurface::MakeRasterN32Premul(width, height); +#if SK_SUPPORT_GPU +SkTextBlobCacheDiffCanvas::Settings MakeSettings(GrContext* context) { + SkTextBlobCacheDiffCanvas::Settings settings; + settings.fContextSupportsDistanceFieldText = context->supportsDistanceFieldText(); + return settings; +} + +SkBitmap RasterBlob(sk_sp blob, int width, int height, const SkPaint& paint, + GrContext* context, const SkMatrix* matrix = nullptr) { + const SkImageInfo info = + SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); + auto surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); + if (matrix) surface->getCanvas()->concat(*matrix); surface->getCanvas()->drawTextBlob(blob.get(), 0u, 0u, paint); SkBitmap bitmap; bitmap.allocN32Pixels(width, height); surface->readPixels(bitmap, 0, 0); return bitmap; } +#endif DEF_TEST(SkRemoteGlyphCache_TypefaceSerialization, reporter) { sk_sp discardableManager = sk_make_sp(); @@ -100,9 +116,13 @@ DEF_TEST(SkRemoteGlyphCache_TypefaceSerialization, reporter) { REPORTER_ASSERT(reporter, client_tf); REPORTER_ASSERT(reporter, SkTypefaceProxy::DownCast(client_tf.get())->remoteTypefaceID() == server_tf->uniqueID()); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); } -DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) { +#if SK_SUPPORT_GPU +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_StrikeSerialization, reporter, ctxInfo) { sk_sp discardableManager = sk_make_sp(); SkStrikeServer server(discardableManager.get()); SkStrikeClient client(discardableManager); @@ -115,7 +135,8 @@ DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) { int glyphCount = 10; auto serverBlob = buildTextBlob(serverTf, glyphCount); const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); - SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server); + SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server, + MakeSettings(ctxInfo.grContext())); cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint); std::vector serverStrikeData; @@ -127,10 +148,14 @@ DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) { client.readStrikeData(serverStrikeData.data(), serverStrikeData.size())); auto clientBlob = buildTextBlob(clientTf, glyphCount); - SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint); - SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint); + SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext()); + SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext()); COMPARE_BLOBS(expected, actual, reporter); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); } +#endif DEF_TEST(SkRemoteGlyphCache_StrikeLockingServer, reporter) { sk_sp discardableManager = sk_make_sp(); @@ -161,6 +186,9 @@ DEF_TEST(SkRemoteGlyphCache_StrikeLockingServer, reporter) { cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint); REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u); REPORTER_ASSERT(reporter, discardableManager->lockedHandles().count() == 1u); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); } DEF_TEST(SkRemoteGlyphCache_StrikeDeletionServer, reporter) { @@ -186,6 +214,9 @@ DEF_TEST(SkRemoteGlyphCache_StrikeDeletionServer, reporter) { discardableManager->unlockAndDeleteAll(); cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint); REPORTER_ASSERT(reporter, discardableManager->handleCount() == 2u); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); } DEF_TEST(SkRemoteGlyphCache_StrikePinningClient, reporter) { @@ -222,6 +253,9 @@ DEF_TEST(SkRemoteGlyphCache_StrikePinningClient, reporter) { discardableManager->unlockAndDeleteAll(); SkGraphics::PurgeFontCache(); REPORTER_ASSERT(reporter, clientTf->unique()); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); } DEF_TEST(SkRemoteGlyphCache_ClientMemoryAccounting, reporter) { @@ -248,9 +282,13 @@ DEF_TEST(SkRemoteGlyphCache_ClientMemoryAccounting, reporter) { REPORTER_ASSERT(reporter, client.readStrikeData(serverStrikeData.data(), serverStrikeData.size())); SkStrikeCache::Validate(); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); } -DEF_TEST(SkRemoteGlyphCache_DrawTextAsPath, reporter) { +#if SK_SUPPORT_GPU +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsPath, reporter, ctxInfo) { sk_sp discardableManager = sk_make_sp(); SkStrikeServer server(discardableManager.get()); SkStrikeClient client(discardableManager); @@ -266,7 +304,8 @@ DEF_TEST(SkRemoteGlyphCache_DrawTextAsPath, reporter) { int glyphCount = 10; auto serverBlob = buildTextBlob(serverTf, glyphCount); const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); - SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server); + SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server, + MakeSettings(ctxInfo.grContext())); cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint); std::vector serverStrikeData; @@ -278,8 +317,60 @@ DEF_TEST(SkRemoteGlyphCache_DrawTextAsPath, reporter) { client.readStrikeData(serverStrikeData.data(), serverStrikeData.size())); auto clientBlob = buildTextBlob(clientTf, glyphCount); - SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint); - SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint); + SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext()); + SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext()); COMPARE_BLOBS(expected, actual, reporter); SkStrikeCache::Validate(); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); +} +#endif + +#if SK_SUPPORT_GPU +DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, ctxInfo) { + sk_sp discardableManager = sk_make_sp(); + SkStrikeServer server(discardableManager.get()); + SkStrikeClient client(discardableManager); + SkPaint paint; + + // A perspective transform forces fallback to dft. + SkMatrix matrix = SkMatrix::I(); + matrix[SkMatrix::kMPersp0] = 0.5f; + REPORTER_ASSERT(reporter, matrix.hasPerspective()); + SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); + GrAtlasTextContext::Options options; + GrAtlasTextContext::SanitizeOptions(&options); + REPORTER_ASSERT(reporter, GrAtlasTextContext::CanDrawAsDistanceFields( + paint, matrix, surfaceProps, true, options)); + + // Server. + auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle()); + auto serverTfData = server.serializeTypeface(serverTf.get()); + + int glyphCount = 10; + auto serverBlob = buildTextBlob(serverTf, glyphCount); + const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); + SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server, + MakeSettings(ctxInfo.grContext())); + cache_diff_canvas.concat(matrix); + cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint); + + std::vector serverStrikeData; + server.writeStrikeData(&serverStrikeData); + + // Client. + auto clientTf = client.deserializeTypeface(serverTfData->data(), serverTfData->size()); + REPORTER_ASSERT(reporter, + client.readStrikeData(serverStrikeData.data(), serverStrikeData.size())); + auto clientBlob = buildTextBlob(clientTf, glyphCount); + + SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext(), &matrix); + SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext(), &matrix); + COMPARE_BLOBS(expected, actual, reporter); + SkStrikeCache::Validate(); + + // Must unlock everything on termination, otherwise valgrind complains about memory leaks. + discardableManager->unlockAndDeleteAll(); } +#endif -- cgit v1.2.3