2018-05-02 17:29:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2018 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2018-08-29 15:04:18 +00:00
|
|
|
#include "Resources.h"
|
2018-05-17 17:41:40 +00:00
|
|
|
#include "SkDraw.h"
|
2018-05-02 17:29:37 +00:00
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkMutex.h"
|
|
|
|
#include "SkRemoteGlyphCache.h"
|
2018-08-23 22:44:45 +00:00
|
|
|
#include "SkRemoteGlyphCacheImpl.h"
|
2018-05-02 17:29:37 +00:00
|
|
|
#include "SkStrikeCache.h"
|
|
|
|
#include "SkSurface.h"
|
2018-08-28 19:33:19 +00:00
|
|
|
#include "SkTestEmptyTypeface.h"
|
2018-05-02 17:29:37 +00:00
|
|
|
#include "SkTextBlob.h"
|
|
|
|
#include "SkTypeface_remote.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2018-05-24 18:39:01 +00:00
|
|
|
#include "text/GrTextContext.h"
|
2018-05-23 22:45:01 +00:00
|
|
|
|
2018-05-02 17:29:37 +00:00
|
|
|
class DiscardableManager : public SkStrikeServer::DiscardableHandleManager,
|
|
|
|
public SkStrikeClient::DiscardableHandleManager {
|
|
|
|
public:
|
2018-05-24 01:16:00 +00:00
|
|
|
DiscardableManager() { sk_bzero(&fCacheMissCount, sizeof(fCacheMissCount)); }
|
2018-05-02 17:29:37 +00:00
|
|
|
~DiscardableManager() override = default;
|
|
|
|
|
|
|
|
// Server implementation.
|
|
|
|
SkDiscardableHandleId createHandle() override {
|
|
|
|
// Handles starts as locked.
|
|
|
|
fLockedHandles.add(++fNextHandleId);
|
|
|
|
return fNextHandleId;
|
|
|
|
}
|
|
|
|
bool lockHandle(SkDiscardableHandleId id) override {
|
|
|
|
if (id <= fLastDeletedHandleId) return false;
|
|
|
|
fLockedHandles.add(id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client implementation.
|
|
|
|
bool deleteHandle(SkDiscardableHandleId id) override { return id <= fLastDeletedHandleId; }
|
2018-06-07 00:46:38 +00:00
|
|
|
void notifyCacheMiss(SkStrikeClient::CacheMissType type) override { fCacheMissCount[type]++; }
|
2018-08-29 23:16:25 +00:00
|
|
|
bool isHandleDeleted(SkDiscardableHandleId id) override { return id <= fLastDeletedHandleId; }
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
void unlockAll() { fLockedHandles.reset(); }
|
|
|
|
void unlockAndDeleteAll() {
|
|
|
|
unlockAll();
|
|
|
|
fLastDeletedHandleId = fNextHandleId;
|
|
|
|
}
|
|
|
|
const SkTHashSet<SkDiscardableHandleId>& lockedHandles() const { return fLockedHandles; }
|
|
|
|
SkDiscardableHandleId handleCount() { return fNextHandleId; }
|
2018-06-12 18:26:17 +00:00
|
|
|
int cacheMissCount(uint32_t type) { return fCacheMissCount[type]; }
|
2018-06-07 00:46:38 +00:00
|
|
|
bool hasCacheMiss() const {
|
|
|
|
for (uint32_t i = 0; i <= SkStrikeClient::CacheMissType::kLast; ++i) {
|
|
|
|
if (fCacheMissCount[i] > 0) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
SkDiscardableHandleId fNextHandleId = 0u;
|
|
|
|
SkDiscardableHandleId fLastDeletedHandleId = 0u;
|
|
|
|
SkTHashSet<SkDiscardableHandleId> fLockedHandles;
|
2018-05-24 01:16:00 +00:00
|
|
|
int fCacheMissCount[SkStrikeClient::CacheMissType::kLast + 1u];
|
2018-05-02 17:29:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
sk_sp<SkTextBlob> buildTextBlob(sk_sp<SkTypeface> tf, int glyphCount) {
|
|
|
|
SkPaint font;
|
|
|
|
font.setTypeface(tf);
|
|
|
|
font.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
|
|
|
font.setTextAlign(SkPaint::kLeft_Align);
|
|
|
|
font.setStyle(SkPaint::kFill_Style);
|
|
|
|
font.setHinting(SkPaint::kNormal_Hinting);
|
|
|
|
font.setTextSize(1u);
|
2018-07-19 17:41:15 +00:00
|
|
|
font.setAntiAlias(true);
|
|
|
|
font.setSubpixelText(true);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
SkRect bounds = SkRect::MakeWH(10, 10);
|
|
|
|
const auto& runBuffer = builder.allocRunPosH(font, glyphCount, 0, &bounds);
|
|
|
|
SkASSERT(runBuffer.utf8text == nullptr);
|
|
|
|
SkASSERT(runBuffer.clusters == nullptr);
|
|
|
|
|
|
|
|
for (int i = 0; i < glyphCount; i++) {
|
|
|
|
runBuffer.glyphs[i] = static_cast<SkGlyphID>(i);
|
|
|
|
runBuffer.pos[i] = SkIntToScalar(i);
|
|
|
|
}
|
|
|
|
return builder.make();
|
|
|
|
}
|
|
|
|
|
2018-08-28 20:17:55 +00:00
|
|
|
static void compare_blobs(const SkBitmap& expected, const SkBitmap& actual,
|
|
|
|
skiatest::Reporter* reporter, int tolerance = 0) {
|
|
|
|
SkASSERT(expected.width() == actual.width());
|
|
|
|
SkASSERT(expected.height() == actual.height());
|
|
|
|
for (int i = 0; i < expected.width(); ++i) {
|
|
|
|
for (int j = 0; j < expected.height(); ++j) {
|
|
|
|
SkColor expectedColor = expected.getColor(i, j);
|
|
|
|
SkColor actualColor = actual.getColor(i, j);
|
|
|
|
if (0 == tolerance) {
|
|
|
|
REPORTER_ASSERT(reporter, expectedColor == actualColor);
|
|
|
|
} else {
|
|
|
|
for (int k = 0; k < 4; ++k) {
|
|
|
|
int expectedChannel = (expectedColor >> (k*8)) & 0xff;
|
|
|
|
int actualChannel = (actualColor >> (k*8)) & 0xff;
|
|
|
|
REPORTER_ASSERT(reporter, abs(expectedChannel - actualChannel) <= tolerance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-05-17 17:41:40 +00:00
|
|
|
}
|
2018-08-28 20:17:55 +00:00
|
|
|
}
|
2018-05-17 17:41:40 +00:00
|
|
|
|
2018-05-23 22:45:01 +00:00
|
|
|
SkTextBlobCacheDiffCanvas::Settings MakeSettings(GrContext* context) {
|
|
|
|
SkTextBlobCacheDiffCanvas::Settings settings;
|
|
|
|
settings.fContextSupportsDistanceFieldText = context->supportsDistanceFieldText();
|
2018-06-07 00:46:38 +00:00
|
|
|
settings.fMaxTextureSize = context->maxTextureSize();
|
|
|
|
settings.fMaxTextureBytes = GrContextOptions().fGlyphCacheTextureMaximumBytes;
|
2018-05-23 22:45:01 +00:00
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2018-05-29 21:45:46 +00:00
|
|
|
SkBitmap RasterBlob(sk_sp<SkTextBlob> blob, int width, int height, const SkPaint& paint,
|
2018-07-19 17:41:15 +00:00
|
|
|
GrContext* context, const SkMatrix* matrix = nullptr,
|
|
|
|
SkScalar x = 0) {
|
2018-05-29 21:45:46 +00:00
|
|
|
const SkImageInfo info =
|
|
|
|
SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
|
2018-05-23 22:45:01 +00:00
|
|
|
auto surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
|
2018-05-29 21:45:46 +00:00
|
|
|
if (matrix) surface->getCanvas()->concat(*matrix);
|
2018-07-19 17:41:15 +00:00
|
|
|
surface->getCanvas()->drawTextBlob(blob.get(), x, 0, paint);
|
2018-05-02 17:29:37 +00:00
|
|
|
SkBitmap bitmap;
|
2018-05-29 21:45:46 +00:00
|
|
|
bitmap.allocN32Pixels(width, height);
|
2018-05-02 17:29:37 +00:00
|
|
|
surface->readPixels(bitmap, 0, 0);
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkRemoteGlyphCache_TypefaceSerialization, reporter) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
auto server_tf = SkTypeface::MakeDefault();
|
|
|
|
auto tf_data = server.serializeTypeface(server_tf.get());
|
|
|
|
|
|
|
|
auto client_tf = client.deserializeTypeface(tf_data->data(), tf_data->size());
|
|
|
|
REPORTER_ASSERT(reporter, client_tf);
|
2018-05-24 01:16:00 +00:00
|
|
|
REPORTER_ASSERT(reporter, static_cast<SkTypefaceProxy*>(client_tf.get())->remoteTypefaceID() ==
|
2018-05-02 17:29:37 +00:00
|
|
|
server_tf->uniqueID());
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-05-02 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 22:45:01 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_StrikeSerialization, reporter, ctxInfo) {
|
2018-05-02 17:29:37 +00:00
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-17 17:41:40 +00:00
|
|
|
const SkPaint paint;
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
// 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);
|
2018-05-23 22:45:01 +00:00
|
|
|
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
|
|
|
|
MakeSettings(ctxInfo.grContext()));
|
2018-05-02 17:29:37 +00:00
|
|
|
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);
|
|
|
|
|
2018-05-29 21:45:46 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext());
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext());
|
2018-08-28 20:17:55 +00:00
|
|
|
compare_blobs(expected, actual, reporter);
|
2018-06-07 00:46:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
2018-05-23 22:45:01 +00:00
|
|
|
|
2018-08-28 19:33:19 +00:00
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_ReleaseTypeFace, reporter, ctxInfo) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
|
|
|
|
// Server.
|
|
|
|
auto serverTf = SkTestEmptyTypeface::Make();
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
REPORTER_ASSERT(reporter, serverTf->unique());
|
|
|
|
|
|
|
|
{
|
|
|
|
const SkPaint paint;
|
|
|
|
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.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
REPORTER_ASSERT(reporter, !serverTf->unique());
|
|
|
|
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, serverTf->unique());
|
|
|
|
|
2018-05-23 22:45:01 +00:00
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-05-02 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkRemoteGlyphCache_StrikeLockingServer, reporter) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
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);
|
|
|
|
SkPaint paint;
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
|
|
|
|
// The strike from the blob should be locked after it has been drawn on the canvas.
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->lockedHandles().count() == 1u);
|
|
|
|
|
|
|
|
// Write the strike data and unlock everything. Re-analyzing the blob should lock the handle
|
|
|
|
// again.
|
|
|
|
std::vector<uint8_t> fontData;
|
|
|
|
server.writeStrikeData(&fontData);
|
|
|
|
discardableManager->unlockAll();
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->lockedHandles().count() == 0u);
|
|
|
|
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->lockedHandles().count() == 1u);
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-05-02 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkRemoteGlyphCache_StrikeDeletionServer, reporter) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
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);
|
|
|
|
SkPaint paint;
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
|
|
|
|
|
|
|
|
// Write the strike data and delete all the handles. Re-analyzing the blob should create new
|
|
|
|
// handles.
|
|
|
|
std::vector<uint8_t> fontData;
|
|
|
|
server.writeStrikeData(&fontData);
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->handleCount() == 2u);
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-05-02 17:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(SkRemoteGlyphCache_StrikePinningClient, reporter) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
SkPaint paint;
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
|
|
|
|
// Client.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
|
|
|
|
auto* clientTf = client.deserializeTypeface(serverTfData->data(), serverTfData->size()).get();
|
|
|
|
|
|
|
|
// The cache remains alive until it is pinned in the discardable manager.
|
|
|
|
SkGraphics::PurgeFontCache();
|
|
|
|
REPORTER_ASSERT(reporter, !clientTf->unique());
|
|
|
|
|
|
|
|
// Once the strike is unpinned and purged, SkStrikeClient should be the only owner of the
|
|
|
|
// clientTf.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
SkGraphics::PurgeFontCache();
|
|
|
|
REPORTER_ASSERT(reporter, clientTf->unique());
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-05-02 17:29:37 +00:00
|
|
|
}
|
2018-05-15 19:59:48 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkRemoteGlyphCache_ClientMemoryAccounting, reporter) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-15 19:59:48 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
SkPaint paint;
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
|
|
|
|
// Client.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
|
2018-06-21 18:06:30 +00:00
|
|
|
SkStrikeCache::ValidateGlyphCacheDataSize();
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-05-15 19:59:48 +00:00
|
|
|
}
|
2018-05-17 17:41:40 +00:00
|
|
|
|
2018-08-29 23:16:25 +00:00
|
|
|
DEF_TEST(SkRemoteGlyphCache_PurgesServerEntries, reporter) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
server.setMaxEntriesInDescriptorMapForTesting(1u);
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
|
|
|
|
{
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
|
|
|
|
|
|
|
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
|
|
|
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server);
|
|
|
|
SkPaint paint;
|
|
|
|
REPORTER_ASSERT(reporter, server.remoteGlyphStateMapSizeForTesting() == 0u);
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
REPORTER_ASSERT(reporter, server.remoteGlyphStateMapSizeForTesting() == 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Serialize to release the lock from the strike server and delete all current
|
|
|
|
// handles.
|
|
|
|
std::vector<uint8_t> fontData;
|
|
|
|
server.writeStrikeData(&fontData);
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
|
|
|
|
// Use a different typeface. Creating a new strike should evict the previous
|
|
|
|
// one.
|
|
|
|
{
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("Georgia", SkFontStyle());
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
|
|
|
|
|
|
|
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
|
|
|
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server);
|
|
|
|
SkPaint paint;
|
|
|
|
REPORTER_ASSERT(reporter, server.remoteGlyphStateMapSizeForTesting() == 1u);
|
|
|
|
cache_diff_canvas.drawTextBlob(serverBlob.get(), 0, 0, paint);
|
|
|
|
REPORTER_ASSERT(reporter, server.remoteGlyphStateMapSizeForTesting() == 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
2018-05-23 22:45:01 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsPath, reporter, ctxInfo) {
|
2018-05-17 17:41:40 +00:00
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-17 17:41:40 +00:00
|
|
|
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);
|
2018-05-23 22:45:01 +00:00
|
|
|
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
|
|
|
|
MakeSettings(ctxInfo.grContext()));
|
2018-05-17 17:41:40 +00:00
|
|
|
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);
|
|
|
|
|
2018-05-29 21:45:46 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext());
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext());
|
2018-08-28 20:17:55 +00:00
|
|
|
compare_blobs(expected, actual, reporter, 1);
|
2018-06-07 00:46:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
2018-06-21 18:06:30 +00:00
|
|
|
SkStrikeCache::ValidateGlyphCacheDataSize();
|
2018-07-19 17:41:15 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
2018-08-29 15:04:18 +00:00
|
|
|
sk_sp<SkTextBlob> make_blob_causing_fallback(
|
|
|
|
sk_sp<SkTypeface> targetTf, const SkTypeface* glyphTf, skiatest::Reporter* reporter) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setSubpixelText(true);
|
|
|
|
paint.setTextSize(96);
|
|
|
|
paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
|
|
|
|
paint.setTextAlign(SkPaint::kLeft_Align);
|
|
|
|
paint.setStyle(SkPaint::kFill_Style);
|
|
|
|
paint.setHinting(SkPaint::kNormal_Hinting);
|
|
|
|
|
|
|
|
paint.setTypeface(targetTf);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !SkDraw::ShouldDrawTextAsPaths(paint, SkMatrix::I()));
|
|
|
|
|
|
|
|
char s[] = "Skia";
|
|
|
|
int runSize = strlen(s);
|
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
SkRect bounds = SkRect::MakeIWH(100, 100);
|
|
|
|
const auto& runBuffer = builder.allocRunPosH(paint, runSize, 10, &bounds);
|
|
|
|
SkASSERT(runBuffer.utf8text == nullptr);
|
|
|
|
SkASSERT(runBuffer.clusters == nullptr);
|
|
|
|
|
|
|
|
glyphTf->charsToGlyphs(s, SkTypeface::kUTF8_Encoding, runBuffer.glyphs, runSize);
|
|
|
|
|
|
|
|
SkRect glyphBounds;
|
|
|
|
paint.measureText(runBuffer.glyphs, 2, &glyphBounds);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, glyphBounds.width() > SkGlyphCacheCommon::kSkSideTooBigForAtlas);
|
|
|
|
|
|
|
|
for (int i = 0; i < runSize; i++) {
|
|
|
|
runBuffer.pos[i] = i * 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.make();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsMaskWithPathFallback,
|
|
|
|
reporter, ctxInfo) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
auto serverTf = MakeResourceAsTypeface("fonts/HangingS.ttf");
|
|
|
|
// TODO: when the cq bots can handle this font remove the check.
|
|
|
|
if (serverTf == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
|
|
|
|
auto serverBlob = make_blob_causing_fallback(serverTf, serverTf.get(), reporter);
|
|
|
|
|
|
|
|
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
|
|
|
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 = make_blob_causing_fallback(clientTf, serverTf.get(), reporter);
|
|
|
|
|
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext());
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext());
|
|
|
|
compare_blobs(expected, actual, reporter);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
SkStrikeCache::ValidateGlyphCacheDataSize();
|
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
2018-07-19 17:41:15 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextXY, reporter, ctxInfo) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setSubpixelText(true);
|
|
|
|
paint.setLCDRenderText(true);
|
|
|
|
|
|
|
|
// 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.drawTextBlob(serverBlob.get(), 0.5, 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(), nullptr, 0.5);
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext(), nullptr, 0.5);
|
2018-08-28 20:17:55 +00:00
|
|
|
compare_blobs(expected, actual, reporter);
|
2018-07-19 17:41:15 +00:00
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
SkStrikeCache::ValidateGlyphCacheDataSize();
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsDFT, reporter, ctxInfo) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-23 22:45:01 +00:00
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
// A perspective transform forces fallback to dft.
|
|
|
|
SkMatrix matrix = SkMatrix::I();
|
|
|
|
matrix[SkMatrix::kMPersp0] = 0.5f;
|
|
|
|
REPORTER_ASSERT(reporter, matrix.hasPerspective());
|
2018-05-29 21:45:46 +00:00
|
|
|
SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry);
|
2018-05-24 18:39:01 +00:00
|
|
|
GrTextContext::Options options;
|
|
|
|
GrTextContext::SanitizeOptions(&options);
|
|
|
|
REPORTER_ASSERT(reporter, GrTextContext::CanDrawAsDistanceFields(
|
2018-05-23 22:45:01 +00:00
|
|
|
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);
|
2018-05-29 21:45:46 +00:00
|
|
|
const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType);
|
|
|
|
SkTextBlobCacheDiffCanvas cache_diff_canvas(10, 10, SkMatrix::I(), props, &server,
|
2018-05-23 22:45:01 +00:00
|
|
|
MakeSettings(ctxInfo.grContext()));
|
|
|
|
cache_diff_canvas.concat(matrix);
|
|
|
|
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);
|
|
|
|
|
2018-05-29 21:45:46 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, ctxInfo.grContext(), &matrix);
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext(), &matrix);
|
2018-08-28 20:17:55 +00:00
|
|
|
compare_blobs(expected, actual, reporter);
|
2018-06-07 00:46:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
2018-06-21 18:06:30 +00:00
|
|
|
SkStrikeCache::ValidateGlyphCacheDataSize();
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-05-17 17:41:40 +00:00
|
|
|
}
|
2018-05-24 01:16:00 +00:00
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_CacheMissReporting, reporter, ctxInfo) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
2018-06-01 20:47:21 +00:00
|
|
|
SkStrikeClient client(discardableManager, false);
|
2018-05-24 01:16:00 +00:00
|
|
|
|
|
|
|
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.
|
2018-05-29 21:45:46 +00:00
|
|
|
SkPaint paint;
|
|
|
|
SkMatrix matrix = SkMatrix::I();
|
|
|
|
RasterBlob(clientBlob, 10, 10, paint, ctxInfo.grContext(), &matrix);
|
2018-05-24 01:16:00 +00:00
|
|
|
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();
|
|
|
|
}
|
2018-06-05 17:32:12 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkRemoteGlyphCache_SearchOfDesperation, reporter) {
|
2018-06-12 18:26:17 +00:00
|
|
|
// Build proxy typeface on the client for initializing the cache.
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
auto tfData = server.serializeTypeface(serverTf.get());
|
|
|
|
auto clientTf = client.deserializeTypeface(tfData->data(), tfData->size());
|
|
|
|
REPORTER_ASSERT(reporter, clientTf);
|
|
|
|
|
2018-06-05 17:32:12 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
2018-06-12 18:26:17 +00:00
|
|
|
paint.setTypeface(clientTf);
|
2018-06-05 17:32:12 +00:00
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
|
|
|
|
auto lostGlyphID = SkPackedGlyphID(1, SK_FixedHalf, SK_FixedHalf);
|
|
|
|
const uint8_t glyphImage[] = {0xFF, 0xFF};
|
|
|
|
|
2018-06-21 19:15:50 +00:00
|
|
|
SkStrikeCache strikeCache;
|
|
|
|
|
2018-06-05 17:32:12 +00:00
|
|
|
// Build a fallback cache.
|
|
|
|
{
|
|
|
|
SkAutoDescriptor ad;
|
|
|
|
SkScalerContextRec rec;
|
|
|
|
SkScalerContextEffects effects;
|
|
|
|
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
|
|
|
|
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
|
|
|
|
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
|
|
|
|
|
2018-06-21 19:15:50 +00:00
|
|
|
auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
|
2018-06-05 17:32:12 +00:00
|
|
|
auto glyph = fallbackCache->getRawGlyphByID(lostGlyphID);
|
|
|
|
glyph->fMaskFormat = SkMask::kA8_Format;
|
|
|
|
glyph->fHeight = 1;
|
|
|
|
glyph->fWidth = 2;
|
|
|
|
fallbackCache->initializeImage(glyphImage, glyph->computeImageSize(), glyph);
|
|
|
|
glyph->fImage = (void *)glyphImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we can find the fall back cache.
|
|
|
|
{
|
|
|
|
SkAutoDescriptor ad;
|
|
|
|
SkScalerContextRec rec;
|
|
|
|
SkScalerContextEffects effects;
|
|
|
|
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
|
|
|
|
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
|
|
|
|
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
|
2018-06-21 19:15:50 +00:00
|
|
|
auto testCache = strikeCache.findStrikeExclusive(*desc);
|
2018-06-05 17:32:12 +00:00
|
|
|
REPORTER_ASSERT(reporter, !(testCache == nullptr));
|
|
|
|
}
|
|
|
|
|
2018-06-12 18:26:17 +00:00
|
|
|
// Create the target cache.
|
|
|
|
SkExclusiveStrikePtr testCache;
|
|
|
|
SkAutoDescriptor ad;
|
|
|
|
SkScalerContextRec rec;
|
|
|
|
SkScalerContextEffects effects;
|
|
|
|
SkScalerContextFlags flags = SkScalerContextFlags::kNone;
|
|
|
|
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
|
|
|
|
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
|
2018-06-21 19:15:50 +00:00
|
|
|
testCache = strikeCache.findStrikeExclusive(*desc);
|
2018-06-12 18:26:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, testCache == nullptr);
|
2018-06-21 19:15:50 +00:00
|
|
|
testCache = strikeCache.createStrikeExclusive(*desc,
|
2018-06-12 18:26:17 +00:00
|
|
|
clientTf->createScalerContext(effects, desc));
|
2018-06-21 19:15:50 +00:00
|
|
|
auto scalerProxy = static_cast<SkScalerContextProxy*>(testCache->getScalerContext());
|
|
|
|
scalerProxy->initCache(testCache.get(), &strikeCache);
|
2018-06-12 18:26:17 +00:00
|
|
|
|
|
|
|
// Look for the lost glyph.
|
2018-06-05 17:32:12 +00:00
|
|
|
{
|
2018-06-12 18:26:17 +00:00
|
|
|
const auto& lostGlyph = testCache->getGlyphIDMetrics(
|
|
|
|
lostGlyphID.code(), lostGlyphID.getSubXFixed(), lostGlyphID.getSubYFixed());
|
|
|
|
testCache->findImage(lostGlyph);
|
2018-06-05 17:32:12 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, lostGlyph.fHeight == 1);
|
|
|
|
REPORTER_ASSERT(reporter, lostGlyph.fWidth == 2);
|
|
|
|
REPORTER_ASSERT(reporter, lostGlyph.fMaskFormat == SkMask::kA8_Format);
|
2018-06-12 18:26:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, memcmp(lostGlyph.fImage, glyphImage, sizeof(glyphImage)) == 0);
|
2018-06-05 17:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 18:26:17 +00:00
|
|
|
// Look for the lost glyph with a different sub-pix position.
|
2018-06-05 17:32:12 +00:00
|
|
|
{
|
2018-06-12 18:26:17 +00:00
|
|
|
const auto& lostGlyph =
|
|
|
|
testCache->getGlyphIDMetrics(lostGlyphID.code(), SK_FixedQuarter, SK_FixedQuarter);
|
|
|
|
testCache->findImage(lostGlyph);
|
2018-06-05 17:32:12 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, lostGlyph.fHeight == 1);
|
|
|
|
REPORTER_ASSERT(reporter, lostGlyph.fWidth == 2);
|
|
|
|
REPORTER_ASSERT(reporter, lostGlyph.fMaskFormat == SkMask::kA8_Format);
|
2018-06-12 18:26:17 +00:00
|
|
|
REPORTER_ASSERT(reporter, memcmp(lostGlyph.fImage, glyphImage, sizeof(glyphImage)) == 0);
|
2018-06-05 17:32:12 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 18:26:17 +00:00
|
|
|
for (uint32_t i = 0; i <= SkStrikeClient::CacheMissType::kLast; ++i) {
|
|
|
|
if (i == SkStrikeClient::CacheMissType::kGlyphMetricsFallback ||
|
|
|
|
i == SkStrikeClient::CacheMissType::kFontMetrics) {
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->cacheMissCount(i) == 2);
|
|
|
|
} else {
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->cacheMissCount(i) == 0);
|
|
|
|
}
|
2018-06-05 17:32:12 +00:00
|
|
|
}
|
2018-06-21 19:15:50 +00:00
|
|
|
strikeCache.validateGlyphCacheDataSize();
|
2018-06-05 17:32:12 +00:00
|
|
|
|
2018-06-12 18:26:17 +00:00
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
2018-06-05 17:32:12 +00:00
|
|
|
}
|
2018-06-13 16:44:23 +00:00
|
|
|
|
|
|
|
DEF_TEST(SkRemoteGlyphCache_ReWriteGlyph, reporter) {
|
|
|
|
// Build proxy typeface on the client for initializing the cache.
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
auto tfData = server.serializeTypeface(serverTf.get());
|
|
|
|
auto clientTf = client.deserializeTypeface(tfData->data(), tfData->size());
|
|
|
|
REPORTER_ASSERT(reporter, clientTf);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorRED);
|
|
|
|
|
|
|
|
auto lostGlyphID = SkPackedGlyphID(1, SK_FixedHalf, SK_FixedHalf);
|
|
|
|
const uint8_t glyphImage[] = {0xFF, 0xFF};
|
|
|
|
uint32_t realMask;
|
|
|
|
uint32_t fakeMask;
|
|
|
|
|
2018-06-21 19:15:50 +00:00
|
|
|
SkStrikeCache strikeCache;
|
|
|
|
|
2018-06-13 16:44:23 +00:00
|
|
|
{
|
|
|
|
SkAutoDescriptor ad;
|
|
|
|
SkScalerContextRec rec;
|
|
|
|
SkScalerContextEffects effects;
|
|
|
|
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
|
|
|
|
paint.setTypeface(serverTf);
|
|
|
|
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
|
|
|
|
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
|
|
|
|
|
|
|
|
auto context = serverTf->createScalerContext(effects, desc, false);
|
|
|
|
SkGlyph glyph;
|
|
|
|
glyph.initWithGlyphID(lostGlyphID);
|
|
|
|
context->getMetrics(&glyph);
|
|
|
|
realMask = glyph.fMaskFormat;
|
|
|
|
REPORTER_ASSERT(reporter, realMask != MASK_FORMAT_UNKNOWN);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build a fallback cache.
|
|
|
|
{
|
|
|
|
SkAutoDescriptor ad;
|
|
|
|
SkScalerContextRec rec;
|
|
|
|
SkScalerContextEffects effects;
|
|
|
|
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
|
|
|
|
paint.setTypeface(clientTf);
|
|
|
|
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
|
|
|
|
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
|
|
|
|
|
2018-06-21 19:15:50 +00:00
|
|
|
auto fallbackCache = strikeCache.findOrCreateStrikeExclusive(*desc, effects, *clientTf);
|
2018-06-13 16:44:23 +00:00
|
|
|
auto glyph = fallbackCache->getRawGlyphByID(lostGlyphID);
|
|
|
|
fakeMask = (realMask == SkMask::kA8_Format) ? SkMask::kBW_Format : SkMask::kA8_Format;
|
|
|
|
glyph->fMaskFormat = fakeMask;
|
|
|
|
glyph->fHeight = 1;
|
|
|
|
glyph->fWidth = 2;
|
|
|
|
fallbackCache->initializeImage(glyphImage, glyph->computeImageSize(), glyph);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Send over the real glyph and make sure the client cache stays intact.
|
|
|
|
{
|
|
|
|
SkAutoDescriptor ad;
|
|
|
|
SkScalerContextEffects effects;
|
|
|
|
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
|
|
|
|
paint.setTypeface(serverTf);
|
2018-09-17 15:39:51 +00:00
|
|
|
auto* cacheState = server.getOrCreateCache(
|
|
|
|
paint, SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType),
|
|
|
|
SkMatrix::I(), flags, &effects);
|
2018-08-23 20:16:31 +00:00
|
|
|
cacheState->addGlyph(lostGlyphID, false);
|
2018-06-13 16:44:23 +00:00
|
|
|
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
REPORTER_ASSERT(reporter,
|
2018-06-21 19:15:50 +00:00
|
|
|
client.readStrikeData(
|
|
|
|
serverStrikeData.data(),
|
|
|
|
serverStrikeData.size()));
|
2018-06-13 16:44:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
SkAutoDescriptor ad;
|
|
|
|
SkScalerContextRec rec;
|
|
|
|
SkScalerContextEffects effects;
|
|
|
|
SkScalerContextFlags flags = SkScalerContextFlags::kFakeGammaAndBoostContrast;
|
|
|
|
paint.setTypeface(clientTf);
|
|
|
|
SkScalerContext::MakeRecAndEffects(paint, nullptr, nullptr, flags, &rec, &effects, false);
|
|
|
|
auto desc = SkScalerContext::AutoDescriptorGivenRecAndEffects(rec, effects, &ad);
|
|
|
|
|
2018-06-21 19:15:50 +00:00
|
|
|
auto fallbackCache = strikeCache.findStrikeExclusive(*desc);
|
2018-06-13 16:44:23 +00:00
|
|
|
REPORTER_ASSERT(reporter, fallbackCache.get() != nullptr);
|
|
|
|
auto glyph = fallbackCache->getRawGlyphByID(lostGlyphID);
|
|
|
|
REPORTER_ASSERT(reporter, glyph->fMaskFormat == fakeMask);
|
|
|
|
|
|
|
|
// Try overriding the image, it should stay the same.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
memcmp(glyph->fImage, glyphImage, glyph->computeImageSize()) == 0);
|
|
|
|
const uint8_t newGlyphImage[] = {0, 0};
|
|
|
|
fallbackCache->initializeImage(newGlyphImage, glyph->computeImageSize(), glyph);
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
memcmp(glyph->fImage, glyphImage, glyph->computeImageSize()) == 0);
|
|
|
|
}
|
|
|
|
|
2018-06-21 19:15:50 +00:00
|
|
|
strikeCache.validateGlyphCacheDataSize();
|
2018-06-13 16:44:23 +00:00
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|