From 8a232023e192b30a2148b0c07116e43f800d3233 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Wed, 2 May 2018 13:54:11 +0000 Subject: Revert "fonts: Set up remote glyph caching to push fonts." This reverts commit 101d56359a5a5dc3b8a2a4149ac171e25eb0bec0. Reason for revert: 5 of 5 Original change's description: > fonts: Set up remote glyph caching to push fonts. > > Currently the SkStrikeClient is designed to pull fonts from the server > on demand, and to pre-fetch a batched request by analyzing the ops using > a SkTextBlobCacheDiffCanvas. This change modifies the design to support > a push based model, where the server pushes fonts required by the client > and sets up the requisite SkGlyphCaches on the client prior to > rasterizing the ops. > > This model still relies on the SkTextBlobCacheDiffCanvas for analyzing > the glyphs required for rasterizing an op. The glyph caches required for > raster are locked and missing glyphs to be sent to the client are tracked > by the SkStrikeServer. The embedder can serialize this font data at any > point, but must ensure that this data is deserialized by the > SkStrikeClient at the remote end, before rasterizing any ops analyzed > prior to serialization. Any refs on the caches are released once the > font data is serialized by the server. > > The locking of glyph caches relies on the embedder providing discardable > handles. These handles can be created on the server and serialized to be > sent to the client, and map to an instance of SkGlyphCache. This allows > the server to control the lifetime of the caches on the client. > > Bug: skia:7515 > Change-Id: Id39f346b47b60899778404bbd0429ee811d0e53b > Reviewed-on: https://skia-review.googlesource.com/120283 > Commit-Queue: Khusal Sagar > Reviewed-by: Herb Derby TBR=mtklein@google.com,herb@google.com,khushalsagar@chromium.org Change-Id: If72caf968ddcbf70b8b9d71782a2339a118ed202 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: skia:7515 Reviewed-on: https://skia-review.googlesource.com/125264 Reviewed-by: Mike Klein Commit-Queue: Mike Klein --- tools/remote_demo.cpp | 130 ++++++++++++++++---------------------------------- 1 file changed, 41 insertions(+), 89 deletions(-) (limited to 'tools/remote_demo.cpp') diff --git a/tools/remote_demo.cpp b/tools/remote_demo.cpp index 105a9b3ea7..8fc96cadb8 100644 --- a/tools/remote_demo.cpp +++ b/tools/remote_demo.cpp @@ -16,9 +16,8 @@ #include #include -#include "SkGraphics.h" #include "SkRemoteGlyphCache.h" -#include "SkScalerContext.h" +#include "SkGraphics.h" #include "SkSurface.h" static std::string gSkpName; @@ -26,46 +25,6 @@ static bool gUseGpu = true; static bool gPurgeFontCaches = true; static bool gUseProcess = true; -class ServerDiscardableManager : public SkStrikeServer::DiscardableHandleManager { -public: - ServerDiscardableManager() = default; - ~ServerDiscardableManager() override = default; - - SkDiscardableHandleId createHandle() override { return ++nextHandleId; } - bool lockHandle(SkDiscardableHandleId handleId) override { - return handleId > lastPurgedHandleId; - } - void purgeAll() { lastPurgedHandleId = nextHandleId; } - -private: - SkDiscardableHandleId nextHandleId = 0u; - SkDiscardableHandleId lastPurgedHandleId = 0u; -}; - -class ClientDiscardableManager : public SkStrikeClient::DiscardableHandleManager { -public: - class ScopedPurgeCache { - public: - ScopedPurgeCache(ClientDiscardableManager* manager) : fManager(manager) { - if (fManager) fManager->allowPurging = true; - } - ~ScopedPurgeCache() { - if (fManager) fManager->allowPurging = false; - } - - private: - ClientDiscardableManager* fManager; - }; - - ClientDiscardableManager() = default; - ~ClientDiscardableManager() override = default; - - bool deleteHandle(SkDiscardableHandleId) override { return allowPurging; } - -private: - bool allowPurging = false; -}; - static bool write_SkData(int fd, const SkData& data) { size_t size = data.size(); ssize_t bytesWritten = ::write(fd, &size, sizeof(size)); @@ -84,6 +43,7 @@ static bool write_SkData(int fd, const SkData& data) { } static sk_sp read_SkData(int fd) { + size_t size; ssize_t readSize = ::read(fd, &size, sizeof(size)); if (readSize <= 0) { @@ -132,56 +92,44 @@ private: std::chrono::duration fElapsedSeconds{0.0}; }; -static bool push_font_data(const SkPicture& pic, SkStrikeServer* strikeServer, int writeFd) { +static void build_prime_cache_spec(const SkIRect &bounds, + const SkSurfaceProps &props, + const SkPicture &pic, + SkStrikeCacheDifferenceSpec *strikeDifference) { SkMatrix deviceMatrix = SkMatrix::I(); - const SkIRect bounds = pic.cullRect().round(); - const SkSurfaceProps props(SkSurfaceProps::kLegacyFontHost_InitType); - SkTextBlobCacheDiffCanvas filter(bounds.width(), bounds.height(), deviceMatrix, props, - strikeServer); - pic.playback(&filter); - std::vector fontData; - strikeServer->writeStrikeData(&fontData); - auto data = SkData::MakeWithoutCopy(fontData.data(), fontData.size()); - return write_SkData(writeFd, *data); + SkTextBlobCacheDiffCanvas filter( + bounds.width(), bounds.height(), deviceMatrix, props, + SkScalerContextFlags::kFakeGammaAndBoostContrast, + strikeDifference); + + pic.playback(&filter); } -static void final_draw(std::string outFilename, SkData* picData, SkStrikeClient* client, - ClientDiscardableManager* discardableManager, int readFd, int writeFd) { - SkDeserialProcs procs; - auto decode = [](const void* data, size_t length, void* ctx) -> sk_sp { - return reinterpret_cast(ctx)->deserializeTypeface(data, length); - }; - procs.fTypefaceProc = decode; - procs.fTypefaceCtx = client; +static void final_draw(std::string outFilename, + SkDeserialProcs* procs, + SkData* picData, + SkStrikeClient* client) { - auto pic = SkPicture::MakeFromData(picData, &procs); + auto pic = SkPicture::MakeFromData(picData, procs); auto cullRect = pic->cullRect(); auto r = cullRect.round(); auto s = SkSurface::MakeRasterN32Premul(r.width(), r.height()); auto c = s->getCanvas(); - auto picUnderTest = SkPicture::MakeFromData(picData, &procs); + auto picUnderTest = SkPicture::MakeFromData(picData, procs); Timer drawTime; - auto randomData = SkData::MakeUninitialized(1u); for (int i = 0; i < 100; i++) { if (gPurgeFontCaches) { - ClientDiscardableManager::ScopedPurgeCache purge(discardableManager); SkGraphics::PurgeFontCache(); - SkASSERT(SkGraphics::GetFontCacheUsed() == 0u); } - drawTime.start(); if (client != nullptr) { - // Kick the renderer to send us the fonts. - write_SkData(writeFd, *randomData); - auto fontData = read_SkData(readFd); - if (fontData && !fontData->isEmpty()) { - if (!client->readStrikeData(fontData->data(), fontData->size())) - SK_ABORT("Bad serialization"); - } + SkStrikeCacheDifferenceSpec strikeDifference; + build_prime_cache_spec(r, s->props(), *picUnderTest, &strikeDifference); + client->primeStrikeCache(strikeDifference); } c->drawPicture(picUnderTest); drawTime.stop(); @@ -202,16 +150,22 @@ static void final_draw(std::string outFilename, SkData* picData, SkStrikeClient* static void gpu(int readFd, int writeFd) { if (gUseGpu) { + auto clientRPC = [readFd, writeFd](const SkData& inBuffer) { + write_SkData(writeFd, inBuffer); + return read_SkData(readFd); + }; + auto picData = read_SkData(readFd); if (picData == nullptr) { return; } - sk_sp discardableManager = sk_make_sp(); - SkStrikeClient strikeClient(discardableManager); + SkStrikeClient client{clientRPC}; - final_draw("test.png", picData.get(), &strikeClient, discardableManager.get(), readFd, - writeFd); + SkDeserialProcs procs; + client.prepareDeserializeProcs(&procs); + + final_draw("test.png", &procs, picData.get(), &client); } ::close(writeFd); @@ -223,8 +177,7 @@ static void gpu(int readFd, int writeFd) { static int renderer( const std::string& skpName, int readFd, int writeFd) { - ServerDiscardableManager discardableManager; - SkStrikeServer server(&discardableManager); + SkStrikeServer server{}; auto closeAll = [readFd, writeFd]() { ::close(writeFd); ::close(readFd); @@ -233,16 +186,11 @@ static int renderer( auto skpData = SkData::MakeFromFileName(skpName.c_str()); std::cout << "skp stream is " << skpData->size() << " bytes long " << std::endl; + SkSerialProcs procs; sk_sp stream; if (gUseGpu) { auto pic = SkPicture::MakeFromData(skpData.get()); - SkSerialProcs procs; - auto encode = [](SkTypeface* tf, void* ctx) -> sk_sp { - return reinterpret_cast(ctx)->serializeTypeface(tf); - }; - procs.fTypefaceProc = encode; - procs.fTypefaceCtx = &server; - + server.prepareSerializeProcs(&procs); stream = pic->serialize(&procs); if (!write_SkData(writeFd, *stream)) { @@ -250,18 +198,22 @@ static int renderer( return 1; } + std::vector tmpBuffer; while (true) { auto inBuffer = read_SkData(readFd); if (inBuffer == nullptr) { closeAll(); return 0; } - if (gPurgeFontCaches) discardableManager.purgeAll(); - push_font_data(*pic.get(), &server, writeFd); + + tmpBuffer.clear(); + server.serve(*inBuffer, &tmpBuffer); + auto outBuffer = SkData::MakeWithoutCopy(tmpBuffer.data(), tmpBuffer.size()); + write_SkData(writeFd, *outBuffer); } } else { stream = skpData; - final_draw("test-correct.png", stream.get(), nullptr, nullptr, -1, -1); + final_draw("test-correct.png", nullptr, stream.get(), nullptr); closeAll(); return 0; } -- cgit v1.2.3