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 <khushalsagar@chromium.org>
> Reviewed-by: Herb Derby <herb@google.com>
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 <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
diff --git a/tools/remote_demo.cpp b/tools/remote_demo.cpp
index 105a9b3..8fc96ca 100644
--- a/tools/remote_demo.cpp
+++ b/tools/remote_demo.cpp
@@ -16,9 +16,8 @@
#include <thread>
#include <unistd.h>
-#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 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 sk_sp<SkData> read_SkData(int fd) {
+
size_t size;
ssize_t readSize = ::read(fd, &size, sizeof(size));
if (readSize <= 0) {
@@ -132,56 +92,44 @@
std::chrono::duration<double> 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<uint8_t> 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<SkTypeface> {
- return reinterpret_cast<SkStrikeClient*>(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 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<ClientDiscardableManager> discardableManager = sk_make_sp<ClientDiscardableManager>();
- 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 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 @@
auto skpData = SkData::MakeFromFileName(skpName.c_str());
std::cout << "skp stream is " << skpData->size() << " bytes long " << std::endl;
+ SkSerialProcs procs;
sk_sp<SkData> stream;
if (gUseGpu) {
auto pic = SkPicture::MakeFromData(skpData.get());
- SkSerialProcs procs;
- auto encode = [](SkTypeface* tf, void* ctx) -> sk_sp<SkData> {
- return reinterpret_cast<SkStrikeServer*>(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 @@
return 1;
}
+ std::vector<uint8_t> 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;
}