aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SkRemoteGlyphCacheTest.cpp
diff options
context:
space:
mode:
authorGravatar Khushal <khushalsagar@chromium.org>2018-05-22 12:13:12 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-22 19:49:45 +0000
commit35e0a1a6908492c754156d1abb785da3a9ce2a6b (patch)
tree0651f6dd710aecaec047ebcfb475053d832c8970 /tests/SkRemoteGlyphCacheTest.cpp
parent1c5489412de12ab9afdbc0085e65418ca8753b43 (diff)
fonts: Add support for distance field text to font remoting.
R=jvanverth@google.com, herb@google.com Bug: skia:7913 Change-Id: Id3f5b3e75005be9a7234df774268359b406c99a8 Reviewed-on: https://skia-review.googlesource.com/128970 Reviewed-by: Brian Salomon <bsalomon@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Khusal Sagar <khushalsagar@chromium.org>
Diffstat (limited to 'tests/SkRemoteGlyphCacheTest.cpp')
-rw-r--r--tests/SkRemoteGlyphCacheTest.cpp87
1 files changed, 77 insertions, 10 deletions
diff --git a/tests/SkRemoteGlyphCacheTest.cpp b/tests/SkRemoteGlyphCacheTest.cpp
index 811bf1be50..5d4b9ff6f3 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<SkTextBlob> buildTextBlob(sk_sp<SkTypeface> tf, int glyphCount) {
} \
}
-SkBitmap RasterBlob(sk_sp<SkTextBlob> 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<SkTextBlob> 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> discardableManager = sk_make_sp<DiscardableManager>();
@@ -102,7 +118,8 @@ DEF_TEST(SkRemoteGlyphCache_TypefaceSerialization, reporter) {
server_tf->uniqueID());
}
-DEF_TEST(SkRemoteGlyphCache_StrikeSerialization, reporter) {
+#if SK_SUPPORT_GPU
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_StrikeSerialization, reporter, ctxInfo) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
SkStrikeServer server(discardableManager.get());
SkStrikeClient client(discardableManager);
@@ -115,7 +132,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<uint8_t> serverStrikeData;
@@ -127,10 +145,11 @@ 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);
}
+#endif
DEF_TEST(SkRemoteGlyphCache_StrikeLockingServer, reporter) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
@@ -250,7 +269,8 @@ DEF_TEST(SkRemoteGlyphCache_ClientMemoryAccounting, reporter) {
SkStrikeCache::Validate();
}
-DEF_TEST(SkRemoteGlyphCache_DrawTextAsPath, reporter) {
+#if SK_SUPPORT_GPU
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsPath, reporter, ctxInfo) {
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
SkStrikeServer server(discardableManager.get());
SkStrikeClient client(discardableManager);
@@ -266,7 +286,53 @@ 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<uint8_t> 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());
+ SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext());
+ COMPARE_BLOBS(expected, actual, reporter);
+ SkStrikeCache::Validate();
+}
+#endif
+
+#if SK_SUPPORT_GPU
+DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, ctxInfo) {
+ sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
+ 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<uint8_t> serverStrikeData;
@@ -278,8 +344,9 @@ 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(), &matrix);
+ SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext(), &matrix);
COMPARE_BLOBS(expected, actual, reporter);
SkStrikeCache::Validate();
}
+#endif