aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/SkRemoteGlyphCacheTest.cpp
diff options
context:
space:
mode:
authorGravatar Khushal <khushalsagar@chromium.org>2018-05-17 10:41:40 -0700
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-17 20:50:43 +0000
commit51371a43397424ee4d3057fd5a82ec7c01eff705 (patch)
tree0ae5f93ab2ee57ddb73a3ed32633b9774c1d00c7 /tests/SkRemoteGlyphCacheTest.cpp
parente6c0fe0b8fb4fb66b0c8d3b3abac6257c3201f00 (diff)
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 <herb@google.com> Commit-Queue: Khusal Sagar <khushalsagar@chromium.org>
Diffstat (limited to 'tests/SkRemoteGlyphCacheTest.cpp')
-rw-r--r--tests/SkRemoteGlyphCacheTest.cpp57
1 files changed, 47 insertions, 10 deletions
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<SkTextBlob> buildTextBlob(sk_sp<SkTypeface> tf, int glyphCount) {
return builder.make();
}
-SkBitmap RasterBlob(sk_sp<SkTextBlob> 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<SkTextBlob> 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> discardableManager = sk_make_sp<DiscardableManager>();
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<uint8_t> 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> discardableManager = sk_make_sp<DiscardableManager>();
+ 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<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);
+ SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint);
+ COMPARE_BLOBS(expected, actual, reporter);
+ SkStrikeCache::Validate();
+}