From 51371a43397424ee4d3057fd5a82ec7c01eff705 Mon Sep 17 00:00:00 2001 From: Khushal Date: Thu, 17 May 2018 10:41:40 -0700 Subject: fonts: Handle fallback to using paths for text rendering for remoting. SkRemoteGlyphCache only sends images for glyphs, even for cases where the gpu falls back to drawing text as paths. This includes cases in SkDraw::ShouldDrawTextAsPaths and when the glyph exceeds the max bounds that can fit on the atlas. Fix this by identifying these cases in the renderer and sending paths instead. Note: We still don't handle distance field text correctly. R=herb@google.com, bsalomon@google.com Bug: skia:7913 Change-Id: I17d4eccbeaa2e995ae67b61c76cebd27f8280329 Reviewed-on: https://skia-review.googlesource.com/128203 Reviewed-by: Herb Derby Commit-Queue: Khusal Sagar --- tests/SkRemoteGlyphCacheTest.cpp | 57 +++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'tests/SkRemoteGlyphCacheTest.cpp') diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp index dbe36d1e6a..811bf1be50 100644 --- a/tests/SkRemoteGlyphCacheTest.cpp +++ b/tests/SkRemoteGlyphCacheTest.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "SkDraw.h" #include "SkGraphics.h" #include "SkMutex.h" #include "SkRemoteGlyphCache.h" @@ -71,9 +72,15 @@ sk_sp buildTextBlob(sk_sp tf, int glyphCount) { return builder.make(); } -SkBitmap RasterBlob(sk_sp blob, int width, int height) { +#define COMPARE_BLOBS(expected, actual, reporter) \ + for (int i = 0; i < expected.width(); ++i) { \ + for (int j = 0; j < expected.height(); ++j) { \ + REPORTER_ASSERT(reporter, expected.getColor(i, j) == actual.getColor(i, j)); \ + } \ + } + +SkBitmap RasterBlob(sk_sp blob, int width, int height, const SkPaint& paint) { auto surface = SkSurface::MakeRasterN32Premul(width, height); - SkPaint paint; surface->getCanvas()->drawTextBlob(blob.get(), 0u, 0u, paint); SkBitmap bitmap; bitmap.allocN32Pixels(width, height); @@ -99,6 +106,7 @@ DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) { sk_sp discardableManager = sk_make_sp(); SkStrikeServer server(discardableManager.get()); SkStrikeClient client(discardableManager); + const SkPaint paint; // Server. auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle()); @@ -108,7 +116,6 @@ DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) { auto serverBlob = buildTextBlob(serverTf, glyphCount); const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server); - SkPaint paint; cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint); std::vector serverStrikeData; @@ -120,13 +127,9 @@ DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) { client.readStrikeData(serverStrikeData.data(), serverStrikeData.size())); auto clientBlob = buildTextBlob(clientTf, glyphCount); - SkBitmap expected = RasterBlob(serverBlob, 10, 10); - SkBitmap actual = RasterBlob(clientBlob, 10, 10); - for (int i = 0; i < expected.width(); ++i) { - for (int j = 0; j < expected.height(); ++j) { - REPORTER_ASSERT(reporter, expected.getColor(i, j) == actual.getColor(i, j)); - } - } + SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint); + SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint); + COMPARE_BLOBS(expected, actual, reporter); } DEF_TEST(SkRemoteGlyphCache_StrikeLockingServer, reporter) { @@ -246,3 +249,37 @@ DEF_TEST(SkRemoteGlyphCache_ClientMemoryAccounting, reporter) { client.readStrikeData(serverStrikeData.data(), serverStrikeData.size())); SkStrikeCache::Validate(); } + +DEF_TEST(SkRemoteGlyphCache_DrawTextAsPath, reporter) { + sk_sp discardableManager = sk_make_sp(); + SkStrikeServer server(discardableManager.get()); + SkStrikeClient client(discardableManager); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(0); + REPORTER_ASSERT(reporter, SkDraw::ShouldDrawTextAsPaths(paint, SkMatrix::I())); + + // 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); + 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); + SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint); + COMPARE_BLOBS(expected, actual, reporter); + SkStrikeCache::Validate(); +} -- cgit v1.2.3