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.
|
|
|
|
*/
|
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkGraphics.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkTextBlob.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/private/SkMutex.h"
|
2022-02-03 19:09:07 +00:00
|
|
|
#include "include/private/chromium/GrSlug.h"
|
2021-12-10 17:23:57 +00:00
|
|
|
#include "include/private/chromium/SkChromeRemoteGlyphCache.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkDraw.h"
|
2022-01-05 15:00:32 +00:00
|
|
|
#include "src/core/SkFontPriv.h"
|
2022-02-07 15:30:47 +00:00
|
|
|
#include "src/core/SkReadBuffer.h"
|
2020-02-14 16:47:35 +00:00
|
|
|
#include "src/core/SkScalerCache.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkStrikeCache.h"
|
2019-06-03 15:36:01 +00:00
|
|
|
#include "src/core/SkStrikeSpec.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkSurfacePriv.h"
|
|
|
|
#include "src/core/SkTypeface_remote.h"
|
2021-07-06 16:21:37 +00:00
|
|
|
#include "src/gpu/GrCaps.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2021-03-04 15:13:22 +00:00
|
|
|
#include "src/gpu/text/GrSDFTControl.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tools/Resources.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
#include "tools/fonts/TestEmptyTypeface.h"
|
2018-05-02 17:29:37 +00:00
|
|
|
|
2022-02-18 16:15:46 +00:00
|
|
|
// Since SkRemoteGlyphCache is not re-entrant, we can't use it while drawing slugs to simulate
|
|
|
|
// text blobs in the GPU stack.
|
|
|
|
#if !defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE)
|
|
|
|
|
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 {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
2018-05-02 17:29:37 +00:00
|
|
|
// Handles starts as locked.
|
|
|
|
fLockedHandles.add(++fNextHandleId);
|
|
|
|
return fNextHandleId;
|
|
|
|
}
|
|
|
|
bool lockHandle(SkDiscardableHandleId id) override {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
2018-05-02 17:29:37 +00:00
|
|
|
if (id <= fLastDeletedHandleId) return false;
|
|
|
|
fLockedHandles.add(id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client implementation.
|
2019-03-15 21:43:15 +00:00
|
|
|
bool deleteHandle(SkDiscardableHandleId id) override {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
|
|
|
return id <= fLastDeletedHandleId;
|
|
|
|
}
|
|
|
|
|
2021-02-03 19:29:54 +00:00
|
|
|
void notifyCacheMiss(SkStrikeClient::CacheMissType type, int fontSize) override {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
2019-03-15 21:43:15 +00:00
|
|
|
fCacheMissCount[type]++;
|
|
|
|
}
|
|
|
|
bool isHandleDeleted(SkDiscardableHandleId id) override {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
|
|
|
return id <= fLastDeletedHandleId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void unlockAll() {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
|
|
|
fLockedHandles.reset();
|
|
|
|
}
|
2018-05-02 17:29:37 +00:00
|
|
|
void unlockAndDeleteAll() {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
|
|
|
fLockedHandles.reset();
|
2018-05-02 17:29:37 +00:00
|
|
|
fLastDeletedHandleId = fNextHandleId;
|
|
|
|
}
|
2019-03-15 21:43:15 +00:00
|
|
|
const SkTHashSet<SkDiscardableHandleId>& lockedHandles() const {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
|
|
|
return fLockedHandles;
|
|
|
|
}
|
|
|
|
SkDiscardableHandleId handleCount() {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
|
|
|
return fNextHandleId;
|
|
|
|
}
|
|
|
|
int cacheMissCount(uint32_t type) {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
|
|
|
return fCacheMissCount[type];
|
|
|
|
}
|
2018-06-07 00:46:38 +00:00
|
|
|
bool hasCacheMiss() const {
|
2019-05-10 16:16:17 +00:00
|
|
|
SkAutoMutexExclusive l(fMutex);
|
2019-03-15 21:43:15 +00:00
|
|
|
|
2018-06-07 00:46:38 +00:00
|
|
|
for (uint32_t i = 0; i <= SkStrikeClient::CacheMissType::kLast; ++i) {
|
2019-10-23 16:52:33 +00:00
|
|
|
if (fCacheMissCount[i] > 0) { return true; }
|
2018-06-07 00:46:38 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-05-21 15:27:40 +00:00
|
|
|
void resetCacheMissCounts() {
|
|
|
|
SkAutoMutexExclusive l(fMutex);
|
|
|
|
sk_bzero(&fCacheMissCount, sizeof(fCacheMissCount));
|
|
|
|
}
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
private:
|
2019-03-15 21:43:15 +00:00
|
|
|
// The tests below run in parallel on multiple threads and use the same
|
|
|
|
// process global SkStrikeCache. So the implementation needs to be
|
|
|
|
// thread-safe.
|
|
|
|
mutable SkMutex fMutex;
|
|
|
|
|
2018-05-02 17:29:37 +00:00
|
|
|
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) {
|
2018-11-21 20:10:08 +00:00
|
|
|
SkFont font;
|
2018-05-02 17:29:37 +00:00
|
|
|
font.setTypeface(tf);
|
2019-05-07 20:50:29 +00:00
|
|
|
font.setHinting(SkFontHinting::kNormal);
|
2018-11-21 20:10:08 +00:00
|
|
|
font.setSize(1u);
|
|
|
|
font.setEdging(SkFont::Edging::kAntiAlias);
|
|
|
|
font.setSubpixel(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
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
sk_sp<SkSurface> MakeSurface(int width, int height, GrRecordingContext* rContext) {
|
2018-11-08 21:40:26 +00:00
|
|
|
const SkImageInfo info =
|
|
|
|
SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType);
|
2020-07-23 17:54:35 +00:00
|
|
|
return SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info);
|
2018-11-08 21:40:26 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 17:05:14 +00:00
|
|
|
SkSurfaceProps FindSurfaceProps(GrRecordingContext* rContext) {
|
2020-07-23 17:54:35 +00:00
|
|
|
auto surface = MakeSurface(1, 1, rContext);
|
2018-11-08 21:40:26 +00:00
|
|
|
return surface->props();
|
|
|
|
}
|
|
|
|
|
2018-05-29 21:45:46 +00:00
|
|
|
SkBitmap RasterBlob(sk_sp<SkTextBlob> blob, int width, int height, const SkPaint& paint,
|
2020-07-23 17:54:35 +00:00
|
|
|
GrRecordingContext* rContext, const SkMatrix* matrix = nullptr,
|
2018-07-19 17:41:15 +00:00
|
|
|
SkScalar x = 0) {
|
2020-07-23 17:54:35 +00:00
|
|
|
auto surface = MakeSurface(width, height, rContext);
|
2022-02-03 19:09:07 +00:00
|
|
|
if (matrix) {
|
|
|
|
surface->getCanvas()->concat(*matrix);
|
|
|
|
}
|
2019-03-22 21:05:14 +00:00
|
|
|
surface->getCanvas()->drawTextBlob(blob.get(), x, height/2, 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;
|
|
|
|
}
|
|
|
|
|
2022-02-07 15:30:47 +00:00
|
|
|
SkBitmap RasterBlobThroughSlug(sk_sp<SkTextBlob> blob, int width, int height, const SkPaint& paint,
|
|
|
|
GrRecordingContext* rContext, const SkMatrix* matrix = nullptr,
|
|
|
|
SkScalar x = 0) {
|
|
|
|
auto surface = MakeSurface(width, height, rContext);
|
|
|
|
if (matrix) {
|
|
|
|
surface->getCanvas()->concat(*matrix);
|
|
|
|
}
|
|
|
|
auto canvas = surface->getCanvas();
|
|
|
|
auto slug = GrSlug::ConvertBlob(canvas, *blob, {x, height/2.0f}, paint);
|
|
|
|
slug->draw(canvas);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocN32Pixels(width, height);
|
|
|
|
surface->readPixels(bitmap, 0, 0);
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap RasterSlug(sk_sp<GrSlug> slug, int width, int height, const SkPaint& paint,
|
2022-02-03 19:09:07 +00:00
|
|
|
GrRecordingContext* rContext, const SkMatrix* matrix = nullptr,
|
|
|
|
SkScalar x = 0) {
|
|
|
|
auto surface = MakeSurface(width, height, rContext);
|
2022-02-18 22:25:52 +00:00
|
|
|
auto canvas = surface->getCanvas();
|
2022-02-03 19:09:07 +00:00
|
|
|
if (matrix) {
|
2022-02-18 22:25:52 +00:00
|
|
|
canvas->concat(*matrix);
|
2022-02-03 19:09:07 +00:00
|
|
|
}
|
|
|
|
slug->draw(canvas);
|
|
|
|
SkBitmap bitmap;
|
|
|
|
bitmap.allocN32Pixels(width, height);
|
|
|
|
surface->readPixels(bitmap, 0, 0);
|
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2018-05-02 17:29:37 +00:00
|
|
|
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) {
|
2020-07-23 17:54:35 +00:00
|
|
|
auto dContext = ctxInfo.directContext();
|
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);
|
2020-07-23 17:54:35 +00:00
|
|
|
auto props = FindSurfaceProps(dContext);
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, dContext->supportsDistanceFieldText());
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, dContext);
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, dContext);
|
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();
|
|
|
|
}
|
|
|
|
|
2022-02-03 19:09:07 +00:00
|
|
|
static void use_padding_options(GrContextOptions* options) {
|
|
|
|
options->fSupportBilerpFromGlyphAtlas = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_CONTEXTS(SkRemoteGlyphCache_StrikeSerializationSlug,
|
|
|
|
sk_gpu_test::GrContextFactory::IsRenderingContext,
|
|
|
|
reporter, ctxInfo, use_padding_options) {
|
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
const SkPaint paint;
|
|
|
|
|
|
|
|
// Server.
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
|
|
|
auto props = FindSurfaceProps(dContext);
|
|
|
|
std::unique_ptr<SkCanvas> analysisCanvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, dContext->supportsDistanceFieldText());
|
|
|
|
|
|
|
|
// Generate strike updates.
|
|
|
|
(void)GrSlug::ConvertBlob(analysisCanvas.get(), *serverBlob, {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);
|
|
|
|
|
2022-02-07 15:30:47 +00:00
|
|
|
SkBitmap expected = RasterBlobThroughSlug(serverBlob, 10, 10, paint, dContext);
|
|
|
|
SkBitmap actual = RasterBlobThroughSlug(clientBlob, 10, 10, paint, dContext);
|
|
|
|
compare_blobs(expected, actual, reporter);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_CONTEXTS(SkRemoteGlyphCache_SlugSerialization,
|
|
|
|
sk_gpu_test::GrContextFactory::IsRenderingContext,
|
|
|
|
reporter, ctxInfo, use_padding_options) {
|
|
|
|
auto dContext = ctxInfo.directContext();
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
const SkPaint paint;
|
|
|
|
|
|
|
|
// Server.
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
|
|
|
auto props = FindSurfaceProps(dContext);
|
|
|
|
std::unique_ptr<SkCanvas> analysisCanvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, dContext->supportsDistanceFieldText());
|
|
|
|
|
|
|
|
// Generate strike updates.
|
2022-02-18 22:25:52 +00:00
|
|
|
auto srcSlug = GrSlug::ConvertBlob(analysisCanvas.get(), *serverBlob, {0.3f, 0}, paint);
|
2022-02-22 14:59:48 +00:00
|
|
|
auto dstSlugData = srcSlug->serialize();
|
2022-02-07 15:30:47 +00:00
|
|
|
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
|
|
|
|
// Client.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
|
|
|
|
|
|
|
|
SkBitmap expected = RasterSlug(srcSlug, 10, 10, paint, dContext);
|
2022-02-22 14:59:48 +00:00
|
|
|
auto dstSlug = client.deserializeSlug(dstSlugData->data(), dstSlugData->size());
|
2022-02-18 22:25:52 +00:00
|
|
|
REPORTER_ASSERT(reporter, dstSlug != nullptr);
|
2022-02-07 15:30:47 +00:00
|
|
|
SkBitmap actual = RasterSlug(dstSlug, 10, 10, paint, dContext);
|
2022-02-03 19:09:07 +00:00
|
|
|
compare_blobs(expected, actual, reporter);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
2018-08-28 19:33:19 +00:00
|
|
|
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.
|
2019-03-20 16:08:46 +00:00
|
|
|
auto serverTf = TestEmptyTypeface::Make();
|
2018-08-28 19:33:19 +00:00
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
REPORTER_ASSERT(reporter, serverTf->unique());
|
|
|
|
|
|
|
|
{
|
|
|
|
const SkPaint paint;
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, ctxInfo.directContext()->supportsDistanceFieldText());
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-08-28 19:33:19 +00:00
|
|
|
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);
|
|
|
|
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas =
|
|
|
|
server.makeAnalysisCanvas(10, 10, props, nullptr, true);
|
2018-05-02 17:29:37 +00:00
|
|
|
SkPaint paint;
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-02 17:29:37 +00:00
|
|
|
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);
|
|
|
|
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas =
|
|
|
|
server.makeAnalysisCanvas(10, 10, props, nullptr, true);
|
2018-05-02 17:29:37 +00:00
|
|
|
SkPaint paint;
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-02 17:29:37 +00:00
|
|
|
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);
|
2019-09-04 23:19:22 +00:00
|
|
|
|
|
|
|
// Another analysis pass, to ensure that deleting handles after a complete cache hit still
|
|
|
|
// works. This is a regression test for crbug.com/999682.
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2019-09-04 23:19:22 +00:00
|
|
|
server.writeStrikeData(&fontData);
|
|
|
|
REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
|
|
|
|
|
2018-05-02 17:29:37 +00:00
|
|
|
discardableManager->unlockAndDeleteAll();
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-02 17:29:37 +00:00
|
|
|
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);
|
|
|
|
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas =
|
|
|
|
server.makeAnalysisCanvas(10, 10, props, nullptr, true);
|
2018-05-02 17:29:37 +00:00
|
|
|
SkPaint paint;
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-02 17:29:37 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas =
|
|
|
|
server.makeAnalysisCanvas(10, 10, props, nullptr, true);
|
2018-05-15 19:59:48 +00:00
|
|
|
SkPaint paint;
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-15 19:59:48 +00:00
|
|
|
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
|
|
|
|
// Client.
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
|
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);
|
|
|
|
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas =
|
|
|
|
server.makeAnalysisCanvas(10, 10, props, nullptr, true);
|
2018-08-29 23:16:25 +00:00
|
|
|
SkPaint paint;
|
2019-08-27 20:03:45 +00:00
|
|
|
REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 0u);
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2019-08-27 20:03:45 +00:00
|
|
|
REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 1u);
|
2018-08-29 23:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas =
|
|
|
|
server.makeAnalysisCanvas(10, 10, props, nullptr, true);
|
2018-08-29 23:16:25 +00:00
|
|
|
SkPaint paint;
|
2019-08-27 20:03:45 +00:00
|
|
|
REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 1u);
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2019-08-27 20:03:45 +00:00
|
|
|
REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 1u);
|
2018-08-29 23:16:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
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);
|
2019-06-03 15:36:01 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2019-06-06 14:50:56 +00:00
|
|
|
SkStrikeSpec::ShouldDrawAsPath(paint, SkFont(), SkMatrix::I()));
|
2018-05-17 17:41:40 +00:00
|
|
|
|
|
|
|
// Server.
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
2020-07-06 14:56:46 +00:00
|
|
|
auto props = FindSurfaceProps(direct);
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, direct->supportsDistanceFieldText());
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-17 17:41:40 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct);
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct);
|
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-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) {
|
2018-11-23 18:08:33 +00:00
|
|
|
SkFont font;
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setSize(96);
|
2019-05-07 20:50:29 +00:00
|
|
|
font.setHinting(SkFontHinting::kNormal);
|
2018-11-23 18:08:33 +00:00
|
|
|
font.setTypeface(targetTf);
|
2018-08-29 15:04:18 +00:00
|
|
|
|
2019-06-03 15:36:01 +00:00
|
|
|
REPORTER_ASSERT(reporter,
|
2019-06-06 14:50:56 +00:00
|
|
|
!SkStrikeSpec::ShouldDrawAsPath(SkPaint(), font, SkMatrix::I()));
|
2018-08-29 15:04:18 +00:00
|
|
|
|
|
|
|
char s[] = "Skia";
|
|
|
|
int runSize = strlen(s);
|
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
SkRect bounds = SkRect::MakeIWH(100, 100);
|
2018-11-23 18:08:33 +00:00
|
|
|
const auto& runBuffer = builder.allocRunPosH(font, runSize, 10, &bounds);
|
2018-08-29 15:04:18 +00:00
|
|
|
SkASSERT(runBuffer.utf8text == nullptr);
|
|
|
|
SkASSERT(runBuffer.clusters == nullptr);
|
|
|
|
|
2019-04-16 18:37:38 +00:00
|
|
|
SkFont(sk_ref_sp(glyphTf)).textToGlyphs(s, strlen(s), SkTextEncoding::kUTF8,
|
|
|
|
runBuffer.glyphs, runSize);
|
2018-08-29 15:04:18 +00:00
|
|
|
|
|
|
|
SkRect glyphBounds;
|
2018-11-23 18:08:33 +00:00
|
|
|
font.getWidths(runBuffer.glyphs, 1, nullptr, &glyphBounds);
|
2018-08-29 15:04:18 +00:00
|
|
|
|
2019-01-16 16:23:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, glyphBounds.width() > SkStrikeCommon::kSkSideTooBigForAtlas);
|
2018-08-29 15:04:18 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < runSize; i++) {
|
|
|
|
runBuffer.pos[i] = i * 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.make();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsMaskWithPathFallback,
|
|
|
|
reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
2018-08-29 15:04:18 +00:00
|
|
|
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);
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
auto props = FindSurfaceProps(direct);
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, direct->supportsDistanceFieldText());
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-08-29 15:04:18 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct);
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct);
|
2018-08-29 15:04:18 +00:00
|
|
|
compare_blobs(expected, actual, reporter);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
2019-03-22 21:05:14 +00:00
|
|
|
#if 0
|
|
|
|
// TODO: turn this one when I figure out how to deal with the pixel variance from linear
|
|
|
|
// interpolation from GPU to GPU.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextAsSDFTWithAllARGBFallback,
|
|
|
|
reporter, ctxInfo) {
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
auto serverTf = ToolUtils::planet_typeface();
|
|
|
|
// TODO: when the cq bots can handle this font remove the check.
|
|
|
|
if (serverTf == nullptr) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
|
|
|
|
auto makeBlob = [&reporter](sk_sp<SkTypeface> typeface) {
|
|
|
|
SkFont font;
|
|
|
|
font.setSubpixel(true);
|
|
|
|
font.setSize(96);
|
2019-05-07 20:50:29 +00:00
|
|
|
font.setHinting(SkFontHinting::kNormal);
|
2019-03-22 21:05:14 +00:00
|
|
|
font.setTypeface(typeface);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !SkDraw::ShouldDrawTextAsPaths(font, SkPaint(), SkMatrix::I()));
|
|
|
|
|
|
|
|
// Mercury to Uranus.
|
|
|
|
SkGlyphID glyphs[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
|
|
|
|
|
|
|
SkTextBlobBuilder builder;
|
|
|
|
SkRect bounds = SkRect::MakeIWH(100, 100);
|
|
|
|
const auto& runBuffer = builder.allocRunPosH(font, SK_ARRAY_COUNT(glyphs), 100, &bounds);
|
|
|
|
SkASSERT(runBuffer.utf8text == nullptr);
|
|
|
|
SkASSERT(runBuffer.clusters == nullptr);
|
|
|
|
|
|
|
|
std::copy(std::begin(glyphs), std::end(glyphs), runBuffer.glyphs);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(glyphs); i++) {
|
|
|
|
runBuffer.pos[i] = i * 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
return builder.make();
|
|
|
|
};
|
|
|
|
|
|
|
|
auto serverBlob = makeBlob(serverTf);
|
|
|
|
|
|
|
|
auto props = FindSurfaceProps(ctxInfo.grContext());
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, ctxInfo.directContext()->supportsDistanceFieldText());
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 400, paint);
|
2019-03-22 21:05:14 +00:00
|
|
|
|
|
|
|
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 = makeBlob(clientTf);
|
|
|
|
|
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 800, 800, paint, ctxInfo.grContext());
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 800, 800, paint, ctxInfo.grContext());
|
|
|
|
|
|
|
|
// Pixel variance can be high because of the atlas placement, and large scaling in the linear
|
|
|
|
// interpolation.
|
|
|
|
compare_blobs(expected, actual, reporter, 36);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-07-19 17:41:15 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_DrawTextXY, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
2018-07-19 17:41:15 +00:00
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
|
|
|
// Server.
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
2020-07-06 14:56:46 +00:00
|
|
|
auto props = FindSurfaceProps(direct);
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, direct->supportsDistanceFieldText());
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0.5, 0, paint);
|
2018-07-19 17:41:15 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct, nullptr, 0.5);
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct, 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());
|
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) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
2021-06-08 16:46:36 +00:00
|
|
|
if (!direct->priv().caps()->shaderCaps()->supportsDistanceFieldText()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-23 22:45:01 +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-23 22:45:01 +00:00
|
|
|
SkPaint paint;
|
2018-12-03 21:52:59 +00:00
|
|
|
SkFont font;
|
2018-05-23 22:45:01 +00:00
|
|
|
|
2019-10-10 15:06:20 +00:00
|
|
|
// A scale transform forces fallback to dft.
|
2020-05-21 16:11:27 +00:00
|
|
|
SkMatrix matrix = SkMatrix::Scale(16, 16);
|
2021-03-04 15:13:22 +00:00
|
|
|
GrSDFTControl control = direct->priv().asRecordingContext()->priv().getSDFTControl(true);
|
2022-01-05 15:00:32 +00:00
|
|
|
SkScalar approximateDeviceTextSize = SkFontPriv::ApproximateTransformedTextSize(font, matrix);
|
|
|
|
REPORTER_ASSERT(reporter, control.isSDFT(approximateDeviceTextSize, paint));
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
// Server.
|
|
|
|
auto serverTf = SkTypeface::MakeFromName("monospace", SkFontStyle());
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
|
|
|
|
int glyphCount = 10;
|
|
|
|
auto serverBlob = buildTextBlob(serverTf, glyphCount);
|
2020-09-24 18:49:00 +00:00
|
|
|
const SkSurfaceProps props;
|
2021-05-06 12:59:26 +00:00
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
10, 10, props, nullptr, direct->supportsDistanceFieldText());
|
|
|
|
cache_diff_canvas->concat(matrix);
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
|
2018-05-23 22:45:01 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct, &matrix);
|
|
|
|
SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct, &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-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();
|
2020-07-06 14:56:46 +00:00
|
|
|
RasterBlob(clientBlob, 10, 10, paint, ctxInfo.directContext(), &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
|
|
|
|
2019-05-21 15:27:40 +00:00
|
|
|
sk_sp<SkTextBlob> MakeEmojiBlob(sk_sp<SkTypeface> serverTf, SkScalar textSize,
|
|
|
|
sk_sp<SkTypeface> clientTf = nullptr) {
|
|
|
|
SkFont font;
|
|
|
|
font.setTypeface(serverTf);
|
|
|
|
font.setSize(textSize);
|
|
|
|
|
|
|
|
const char* text = ToolUtils::emoji_sample_text();
|
|
|
|
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
|
|
|
|
if (clientTf == nullptr) return blob;
|
|
|
|
|
|
|
|
SkSerialProcs s_procs;
|
|
|
|
s_procs.fTypefaceProc = [](SkTypeface*, void* ctx) -> sk_sp<SkData> {
|
|
|
|
return SkData::MakeUninitialized(1u);
|
|
|
|
};
|
|
|
|
auto serialized = blob->serialize(s_procs);
|
|
|
|
|
|
|
|
SkDeserialProcs d_procs;
|
|
|
|
d_procs.fTypefaceCtx = &clientTf;
|
|
|
|
d_procs.fTypefaceProc = [](const void* data, size_t length, void* ctx) -> sk_sp<SkTypeface> {
|
|
|
|
return *(static_cast<sk_sp<SkTypeface>*>(ctx));
|
|
|
|
};
|
|
|
|
return SkTextBlob::Deserialize(serialized->data(), serialized->size(), d_procs);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_TypefaceWithNoPaths, reporter, ctxInfo) {
|
2020-07-06 14:56:46 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
2019-05-21 15:27:40 +00:00
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, false);
|
|
|
|
|
|
|
|
auto serverTf = ToolUtils::emoji_typeface();
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
auto clientTf = client.deserializeTypeface(serverTfData->data(), serverTfData->size());
|
|
|
|
|
2021-05-06 12:59:26 +00:00
|
|
|
auto props = FindSurfaceProps(direct);
|
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
500, 500, props, nullptr, direct->supportsDistanceFieldText());
|
2019-05-30 11:40:51 +00:00
|
|
|
for (SkScalar textSize : { 70, 180, 270, 340}) {
|
2019-05-21 15:27:40 +00:00
|
|
|
auto serverBlob = MakeEmojiBlob(serverTf, textSize);
|
2021-05-06 12:59:26 +00:00
|
|
|
|
2019-05-21 15:27:40 +00:00
|
|
|
SkPaint paint;
|
2021-05-06 12:59:26 +00:00
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
|
2019-05-21 15:27:40 +00:00
|
|
|
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
2019-10-22 20:06:22 +00:00
|
|
|
if (!serverStrikeData.empty()) {
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
client.readStrikeData(serverStrikeData.data(),
|
|
|
|
serverStrikeData.size()));
|
|
|
|
}
|
2019-05-21 15:27:40 +00:00
|
|
|
auto clientBlob = MakeEmojiBlob(serverTf, textSize, clientTf);
|
|
|
|
REPORTER_ASSERT(reporter, clientBlob);
|
|
|
|
|
2020-07-06 14:56:46 +00:00
|
|
|
RasterBlob(clientBlob, 500, 500, paint, direct);
|
2019-05-21 15:27:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
discardableManager->resetCacheMissCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
2022-02-02 18:27:10 +00:00
|
|
|
|
|
|
|
class SkRemoteGlyphCacheTest {
|
|
|
|
public:
|
|
|
|
static sk_sp<SkTextBlob> MakeNormalBlob(SkPaint* paint,
|
|
|
|
sk_sp<SkTypeface> serverTf, bool asPaths, SkScalar textSize,
|
|
|
|
sk_sp<SkTypeface> clientTf = nullptr) {
|
|
|
|
SkFont font;
|
|
|
|
font.setTypeface(serverTf);
|
|
|
|
font.setSize(textSize);
|
|
|
|
|
|
|
|
const char* text = "Hel lo";
|
|
|
|
if (asPaths) {
|
|
|
|
font.setupForAsPaths(paint);
|
|
|
|
} else {
|
|
|
|
SkFont font2(font);
|
|
|
|
font2.setupForAsPaths(paint);
|
|
|
|
}
|
|
|
|
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
|
|
|
|
if (clientTf == nullptr) return blob;
|
|
|
|
|
|
|
|
SkSerialProcs s_procs;
|
|
|
|
s_procs.fTypefaceProc = [](SkTypeface*, void* ctx) -> sk_sp<SkData> {
|
|
|
|
return SkData::MakeUninitialized(1u);
|
|
|
|
};
|
|
|
|
auto serialized = blob->serialize(s_procs);
|
|
|
|
|
|
|
|
SkDeserialProcs d_procs;
|
|
|
|
d_procs.fTypefaceCtx = &clientTf;
|
|
|
|
d_procs.fTypefaceProc = [](const void* data, size_t length, void* ctx) -> sk_sp<SkTypeface> {
|
|
|
|
return *(static_cast<sk_sp<SkTypeface>*>(ctx));
|
|
|
|
};
|
|
|
|
return SkTextBlob::Deserialize(serialized->data(), serialized->size(), d_procs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_TypefaceWithPaths_MaskThenPath,
|
|
|
|
reporter, ctxInfo) {
|
|
|
|
auto direct = ctxInfo.directContext();
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, true);
|
|
|
|
|
|
|
|
auto serverTf = ToolUtils::create_portable_typeface();
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
auto clientTf = client.deserializeTypeface(serverTfData->data(), serverTfData->size());
|
|
|
|
|
|
|
|
auto props = FindSurfaceProps(direct);
|
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
500, 500, props, nullptr, direct->supportsDistanceFieldText());
|
|
|
|
SkPaint paint;
|
|
|
|
using Rgct = SkRemoteGlyphCacheTest;
|
|
|
|
|
|
|
|
// Draw from mask out of the strike which provides paths.
|
|
|
|
{
|
|
|
|
auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTf, true, 64);
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
|
|
|
|
}
|
|
|
|
// Draw from path out of the strike which provides paths.
|
|
|
|
{
|
|
|
|
auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTf, false, 440);
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
|
|
|
|
}
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
if (!serverStrikeData.empty()) {
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
client.readStrikeData(serverStrikeData.data(),
|
|
|
|
serverStrikeData.size()));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTf, true, 64, clientTf);
|
|
|
|
REPORTER_ASSERT(reporter, clientBlob);
|
|
|
|
|
|
|
|
RasterBlob(clientBlob, 100, 100, paint, direct);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
discardableManager->resetCacheMissCounts();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTf, false, 440, clientTf);
|
|
|
|
REPORTER_ASSERT(reporter, clientBlob);
|
|
|
|
|
|
|
|
RasterBlob(clientBlob, 100, 100, paint, direct);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
discardableManager->resetCacheMissCounts();
|
|
|
|
}
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRemoteGlyphCache_TypefaceWithPaths_PathThenMask,
|
|
|
|
reporter, ctxInfo) {
|
|
|
|
auto direct = ctxInfo.directContext();
|
|
|
|
sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
|
|
|
|
SkStrikeServer server(discardableManager.get());
|
|
|
|
SkStrikeClient client(discardableManager, true);
|
|
|
|
|
|
|
|
auto serverTf = ToolUtils::create_portable_typeface();
|
|
|
|
auto serverTfData = server.serializeTypeface(serverTf.get());
|
|
|
|
auto clientTf = client.deserializeTypeface(serverTfData->data(), serverTfData->size());
|
|
|
|
|
|
|
|
auto props = FindSurfaceProps(direct);
|
|
|
|
std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
|
|
|
|
500, 500, props, nullptr, direct->supportsDistanceFieldText());
|
|
|
|
SkPaint paint;
|
|
|
|
using Rgct = SkRemoteGlyphCacheTest;
|
|
|
|
|
|
|
|
// Draw from path out of the strike which provides paths.
|
|
|
|
{
|
|
|
|
auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTf, false, 440);
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
|
|
|
|
}
|
|
|
|
// Draw from mask out of the strike which provides paths.
|
|
|
|
{
|
|
|
|
auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTf, true, 64);
|
|
|
|
cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
|
|
|
|
}
|
|
|
|
std::vector<uint8_t> serverStrikeData;
|
|
|
|
server.writeStrikeData(&serverStrikeData);
|
|
|
|
if (!serverStrikeData.empty()) {
|
|
|
|
REPORTER_ASSERT(reporter,
|
|
|
|
client.readStrikeData(serverStrikeData.data(),
|
|
|
|
serverStrikeData.size()));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTf, true, 64, clientTf);
|
|
|
|
REPORTER_ASSERT(reporter, clientBlob);
|
|
|
|
|
|
|
|
RasterBlob(clientBlob, 100, 100, paint, direct);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
discardableManager->resetCacheMissCounts();
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTf, false, 440, clientTf);
|
|
|
|
REPORTER_ASSERT(reporter, clientBlob);
|
|
|
|
|
|
|
|
RasterBlob(clientBlob, 100, 100, paint, direct);
|
|
|
|
REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
|
|
|
|
discardableManager->resetCacheMissCounts();
|
|
|
|
}
|
|
|
|
// Must unlock everything on termination, otherwise valgrind complains about memory leaks.
|
|
|
|
discardableManager->unlockAndDeleteAll();
|
|
|
|
}
|
2022-02-18 16:15:46 +00:00
|
|
|
#endif
|