aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2018-01-09 12:34:11 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-24 22:57:11 +0000
commita8a51cee422f527b0c276a17fef0f8eb036278d8 (patch)
treee45d14d0c2b4327a4b994d6e0e637b6aa395408c /src/core
parentb6f7025955d65ab2e98995f26cac1d7ef1ba1e91 (diff)
Start of cross process SkScalerContext.
Change-Id: I16d9293cbc0bef1bdce1260d1bd9b43d8853d070 Reviewed-on: https://skia-review.googlesource.com/93641 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkScalerContext.cpp16
-rw-r--r--src/core/SkScalerContext.h5
-rw-r--r--src/core/SkTypeface_remote.cpp41
-rw-r--r--src/core/SkTypeface_remote.h159
4 files changed, 221 insertions, 0 deletions
diff --git a/src/core/SkScalerContext.cpp b/src/core/SkScalerContext.cpp
index f1ac9c18da..a3d1fbd5d1 100644
--- a/src/core/SkScalerContext.cpp
+++ b/src/core/SkScalerContext.cpp
@@ -1253,4 +1253,20 @@ std::unique_ptr<SkDescriptor> SkScalerContext::DescriptorGivenRecAndEffects(
return desc;
}
+void SkScalerContext::DescriptorBufferGiveRec(const SkScalerContextRec& rec, void* buffer) {
+ SkScalerContextEffects noEffects;
+ SkBinaryWriteBuffer peBuffer, mfBuffer;
+ generate_descriptor(rec, noEffects, &peBuffer, &mfBuffer, (SkDescriptor*)buffer);
+}
+
+bool SkScalerContext::CheckBufferSizeForRec(const SkScalerContextRec& rec,
+ const SkScalerContextEffects& effects,
+ size_t size) {
+ SkBinaryWriteBuffer peBuffer, mfBuffer;
+
+ return size >= calculate_size_and_flatten(rec, effects, &peBuffer, &mfBuffer);
+}
+
+
+
diff --git a/src/core/SkScalerContext.h b/src/core/SkScalerContext.h
index 05d12637b2..9ad22d24d4 100644
--- a/src/core/SkScalerContext.h
+++ b/src/core/SkScalerContext.h
@@ -291,6 +291,11 @@ public:
const SkScalerContextRec& rec,
const SkScalerContextEffects& effects);
+ static void DescriptorBufferGiveRec(const SkScalerContextRec& rec, void* buffer);
+ static bool CheckBufferSizeForRec(const SkScalerContextRec& rec,
+ const SkScalerContextEffects& effects,
+ size_t size);
+
static SkMaskGamma::PreBlend GetMaskPreBlend(const SkScalerContextRec& rec);
const SkScalerContextRec& getRec() const { return fRec; }
diff --git a/src/core/SkTypeface_remote.cpp b/src/core/SkTypeface_remote.cpp
new file mode 100644
index 0000000000..9d8a9afae4
--- /dev/null
+++ b/src/core/SkTypeface_remote.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkPaint.h"
+
+#include "SkSemaphore.h"
+#include "SkTypeface_remote.h"
+#include <iostream>
+
+SkScalerContextProxy::SkScalerContextProxy(
+ sk_sp<SkTypeface> tf,
+ const SkScalerContextEffects& effects,
+ const SkDescriptor* desc,
+ SkRemoteScalerContext* rsc)
+ : SkScalerContext{std::move(tf), effects, desc}
+ , fRemote{rsc} {}
+
+void SkScalerContextProxy::generateMetrics(SkGlyph* glyph) {
+ fRemote->generateMetrics(*this->typefaceProxy(), this->getRec(), glyph);
+}
+
+void SkScalerContextProxy::generateImage(const SkGlyph& glyph) {
+ fRemote->generateImage(*this->typefaceProxy(), this->getRec(), glyph);
+}
+
+void SkScalerContextProxy::generatePath(SkGlyphID glyphID, SkPath* path) {
+ fRemote->generatePath(*this->typefaceProxy(), this->getRec(), glyphID, path);
+}
+
+void SkScalerContextProxy::generateFontMetrics(SkPaint::FontMetrics* metrics) {
+ fRemote->generateFontMetrics(*this->typefaceProxy(), this->getRec(), metrics);
+}
+
+SkTypefaceProxy* SkScalerContextProxy::typefaceProxy() {
+ auto up = this->getTypeface();
+ return (SkTypefaceProxy *)up;
+}
diff --git a/src/core/SkTypeface_remote.h b/src/core/SkTypeface_remote.h
new file mode 100644
index 0000000000..0b6948e88b
--- /dev/null
+++ b/src/core/SkTypeface_remote.h
@@ -0,0 +1,159 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkRemoteTypeface_DEFINED
+#define SkRemoteTypeface_DEFINED
+
+#include "SkAdvancedTypefaceMetrics.h"
+#include "SkDescriptor.h"
+#include "SkFontDescriptor.h"
+#include "SkFontStyle.h"
+#include "SkScalerContext.h"
+#include "SkTypeface.h"
+
+#include <thread>
+
+class SkTypefaceProxy;
+
+class SkRemoteScalerContext {
+public:
+ virtual ~SkRemoteScalerContext() {}
+ // TODO: do metrics need effects?
+ virtual void generateFontMetrics(
+ const SkTypefaceProxy& tf,
+ const SkScalerContextRec& rec,
+ SkPaint::FontMetrics*) = 0;
+ virtual void generateMetrics(
+ const SkTypefaceProxy& tf,
+ const SkScalerContextRec& rec,
+ SkGlyph* glyph) = 0;
+ virtual void generateImage(
+ const SkTypefaceProxy& tf,
+ const SkScalerContextRec& rec,
+ const SkGlyph& glyph) = 0;
+ virtual void generatePath(
+ const SkTypefaceProxy& tf,
+ const SkScalerContextRec& rec,
+ SkGlyphID glyph, SkPath* path) = 0;
+};
+
+class SkScalerContextProxy : public SkScalerContext {
+public:
+ SkScalerContextProxy(
+ sk_sp<SkTypeface> tf,
+ const SkScalerContextEffects& effects,
+ const SkDescriptor* desc,
+ SkRemoteScalerContext* rsc);
+
+protected:
+ unsigned generateGlyphCount(void) override { SK_ABORT("Should never be called."); return 0;}
+ uint16_t generateCharToGlyph(SkUnichar uni) override {
+ SK_ABORT("Should never be called.");
+ return 0;
+ }
+ void generateAdvance(SkGlyph* glyph) override { this->generateMetrics(glyph); }
+ void generateMetrics(SkGlyph* glyph) override;
+ void generateImage(const SkGlyph& glyph) override;
+ void generatePath(SkGlyphID glyphID, SkPath* path) override;
+ void generateFontMetrics(SkPaint::FontMetrics* metrics) override;
+
+private:
+ SkTypefaceProxy* typefaceProxy();
+ SkRemoteScalerContext* const fRemote;
+ typedef SkScalerContext INHERITED;
+};
+
+class SkTypefaceProxy : public SkTypeface {
+public:
+ SkTypefaceProxy(
+ SkFontID fontId,
+ std::thread::id threadId,
+ const SkFontStyle& style,
+ bool isFixed,
+ SkRemoteScalerContext* rsc)
+ : INHERITED{style, false}
+ , fFontId{fontId}
+ , fThreadId{threadId}
+ , fRsc{rsc} { }
+ SkFontID fontID() const {return fFontId;}
+protected:
+ int onGetUPEM() const override { SK_ABORT("Should never be called."); return 0; }
+ SkStreamAsset* onOpenStream(int* ttcIndex) const override {
+ SK_ABORT("Should never be called.");
+ return nullptr;
+ }
+ std::unique_ptr<SkFontData> onMakeFontData() const override {
+ SK_ABORT("Should never be called.");
+ return nullptr;
+ }
+ int onGetVariationDesignPosition(SkFontArguments::VariationPosition::Coordinate coordinates[],
+ int coordinateCount) const override {
+ SK_ABORT("Should never be called.");
+ return 0;
+ }
+ void onGetFamilyName(SkString* familyName) const override {
+ SK_ABORT("Should never be called.");
+ }
+ SkTypeface::LocalizedStrings* onCreateFamilyNameIterator() const override {
+ SK_ABORT("Should never be called.");
+ return nullptr;
+ }
+ int onGetTableTags(SkFontTableTag tags[]) const override {
+ SK_ABORT("Should never be called.");
+ return 0;
+ }
+ size_t onGetTableData(SkFontTableTag, size_t offset, size_t length, void* data) const override {
+ SK_ABORT("Should never be called.");
+ return 0;
+ }
+ SkScalerContext* onCreateScalerContext(const SkScalerContextEffects& effects,
+ const SkDescriptor* desc) const override {
+ //std::cout << fFontId << fThreadId;
+
+ return new SkScalerContextProxy(sk_ref_sp(const_cast<SkTypefaceProxy*>(this)), effects,
+ desc, fRsc);
+
+ }
+ void onFilterRec(SkScalerContextRec* rec) const override {
+ // Add all the device information here.
+ rec->fPost2x2[0][0] = 0.5f;
+
+ // This would be the best place to run the host SkTypeface_* onFilterRec.
+ // Can we move onFilterRec to the FongMgr, that way we don't need to cross the boundary to
+ // filter.
+ }
+ void onGetFontDescriptor(SkFontDescriptor*, bool*) const override {
+ SK_ABORT("Should never be called.");
+ }
+ std::unique_ptr<SkAdvancedTypefaceMetrics> onGetAdvancedMetrics() const override {
+ SK_ABORT("Should never be called.");
+ return nullptr;
+ }
+ int onCharsToGlyphs(const void* chars, Encoding,
+ uint16_t glyphs[], int glyphCount) const override {
+ SK_ABORT("Should never be called.");
+ return 0;
+ }
+ int onCountGlyphs() const override {
+ SK_ABORT("Should never be called.");
+ return 0;
+ }
+
+ void* onGetCTFontRef() const override {
+ SK_ABORT("Should never be called.");
+ return nullptr;
+ }
+
+private:
+ const SkFontID fFontId;
+ const std::thread::id fThreadId;
+ SkRemoteScalerContext* const fRsc;
+
+ typedef SkTypeface INHERITED;
+};
+
+#endif // SkRemoteTypeface_DEFINED