aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkGlyphRun.h
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-06-21 16:03:47 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-28 03:36:16 +0000
commite2e52e46ca63540d429656baeee48fd3a402be26 (patch)
tree574c2f990282798988f47a5519a5ed5f3a990569 /src/core/SkGlyphRun.h
parent0ce5ab9d3122bcd9dce65ecb51a0da973da09816 (diff)
Remove drawTextBlob from device use drawGlyphRunList
Convert all backends to use GlyphRunList instead of text blobs. If the device did not originally implement drawTextBlob it will be simulated by drawPosText on the device. Other changes: Change to using an origin from absolulte positioning. The GPU code uses origin change to update blobs under translation. Change cluster to use const uint32_t instead of just uint32_t. Add SkPaint to runs. The draw filter is hosted up to the canavas level and applied there. Change-Id: Ib105b6bd26b67db55f1c954e37c79fbdcaa9d4a2 Reviewed-on: https://skia-review.googlesource.com/137224 Reviewed-by: Herb Derby <herb@google.com> Reviewed-by: Khusal Sagar <khushalsagar@chromium.org> Reviewed-by: Hal Canary <halcanary@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core/SkGlyphRun.h')
-rw-r--r--src/core/SkGlyphRun.h100
1 files changed, 87 insertions, 13 deletions
diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h
index 739ad0bc38..6f9041c443 100644
--- a/src/core/SkGlyphRun.h
+++ b/src/core/SkGlyphRun.h
@@ -16,9 +16,11 @@
#include "SkMask.h"
#include "SkPath.h"
#include "SkPoint.h"
+#include "SkTextBlob.h"
#include "SkTypes.h"
class SkBaseDevice;
+class SkDrawFilter;
template <typename T>
class SkSpan {
@@ -74,11 +76,12 @@ public:
size_t fUniqueOffset, uint16_t fUniqueSize,
SkSpan<SkGlyphID> scratchGlyphs,
SkSpan<const char> text,
- SkSpan<uint32_t> clusters);
+ SkSpan<const uint32_t> clusters,
+ SkPaint&& runPaint);
// The temporaryShunt calls are to allow inter-operating with existing code while glyph runs
// are developed.
- void temporaryShuntToDrawPosText(const SkPaint& paint, SkBaseDevice* device);
+ void temporaryShuntToDrawPosText(SkBaseDevice* device, SkPoint origin);
using TemporaryShuntCallback = std::function<void(size_t, const char*, const SkScalar*)>;
void temporaryShuntToCallback(TemporaryShuntCallback callback);
@@ -90,6 +93,21 @@ public:
SkSpan<const SkGlyphID> uniqueGlyphIDs() const {
return fRunInfo.uniqueGlyphIDs(fUniqueOffset, fUniqueSize);
}
+ SkSpan<SkGlyphID> shuntGlyphsIDs() const {
+ return fTemporaryShuntGlyphIDs;
+ }
+
+ const SkPaint& paint() const {
+ return fRunPaint;
+ }
+
+ SkSpan<const uint32_t> clusters() const {
+ return fClusters;
+ }
+
+ SkSpan<const char> text() const {
+ return fText;
+ }
private:
const SkIndexedRunInfo& fRunInfo;
@@ -103,18 +121,39 @@ private:
// Original text from SkTextBlob if present. Will be empty of not present.
const SkSpan<const char> fText;
// Original clusters from SkTextBlob if present. Will be empty if not present.
- const SkSpan<uint32_t> fClusters;
+ const SkSpan<const uint32_t> fClusters;
+ // Paint for this run modified to have glyph encoding and left alignment.
+ const SkPaint fRunPaint;
};
class SkGlyphRunList {
- const uint64_t fUniqueID{0};
SkSpan<SkGlyphRun> fGlyphRuns;
+ SkPoint fOrigin = {0, 0};
+
+ // The text blob is needed to hookup the call back that the SkTextBlob destructor calls. It
+ // should be used for nothing else
+ const SkTextBlob* fTemporaryTextBlobShunt{nullptr};
public:
SkGlyphRunList() = default;
- SkGlyphRunList(SkSpan<SkGlyphRun> glyphRuns, uint64_t uniqueID);
+ // Blob maybe null.
+ SkGlyphRunList(SkSpan<SkGlyphRun> glyphRuns, SkPoint origin, const SkTextBlob* blob);
+
+ uint64_t uniqueID() const;
+ bool anyRunsLCD() const;
+ void temporaryShuntBlobnotifyAddedToCache(uint32_t cacheID) const;
+
+ bool canCache() const { return fTemporaryTextBlobShunt != nullptr; }
+ ptrdiff_t runCount() const { return fGlyphRuns.size(); }
+ size_t totalGlyphCount() const {
+ size_t glyphCount = 0;
+ for(const auto& run : fGlyphRuns) {
+ glyphCount += run.runSize();
+ }
+ return glyphCount;
+ }
- uint64_t uniqueID() const { return fUniqueID; }
+ SkPoint origin() const { return fOrigin; }
auto begin() -> decltype(fGlyphRuns.begin()) { return fGlyphRuns.begin(); }
auto end() -> decltype(fGlyphRuns.end()) { return fGlyphRuns.end(); }
@@ -122,6 +161,30 @@ public:
auto operator [] (ptrdiff_t i) -> decltype(fGlyphRuns[i]) { return fGlyphRuns[i]; }
};
+class SkGlyphRunListIterator {
+public:
+ explicit SkGlyphRunListIterator(SkGlyphRunList* list) : fList{*list} {}
+
+ bool done() const { return fIndex == fList.size(); }
+ void next() { fIndex += 1;}
+ uint32_t glyphCount() const { return fList[fIndex].runSize(); }
+ const uint16_t* glyphs() const { return fList[fIndex].shuntGlyphsIDs().data(); }
+ const SkScalar* pos() const { return (const SkScalar*)fList[fIndex].positions().data(); }
+ const SkPoint& offset() const { return fZero; }
+ void applyFontToPaint(SkPaint* paint) const { *paint = fList[fIndex].paint(); }
+ SkTextBlob::GlyphPositioning positioning() const { return SkTextBlob::kFull_Positioning; }
+ const uint32_t* clusters() const { return fList[fIndex].clusters().data(); }
+ uint32_t textSize() const { return fList[fIndex].text().size(); }
+ const char* text() const { return fList[fIndex].text().data(); }
+
+ bool isLCD() const { return fList[fIndex].paint().isLCDRenderText(); }
+
+private:
+ static constexpr SkPoint fZero{0,0};
+ ptrdiff_t fIndex{0};
+ SkGlyphRunList& fList;
+};
+
// A faster set implementation that does not need any initialization, and reading the set items
// is order the number of items, and not the size of the universe.
// This implementation is based on the paper by Briggs and Torczon, "An Efficient Representation
@@ -154,10 +217,14 @@ public:
const SkScalar xpos[], SkScalar constY);
void prepareDrawPosText(
const SkPaint& paint, const void* bytes, size_t byteLength, const SkPoint pos[]);
- void prepareTextBlob(const SkPaint& paint, const SkTextBlob& blob, SkPoint origin);
+ void prepareTextBlob(
+ const SkPaint& paint, const SkTextBlob& blob, SkPoint origin, SkDrawFilter* filter);
- SkGlyphRunList* useGlyphRunList();
+ void draw(SkBaseDevice* device);
+
+ // Public for testing only.
SkGlyphRun* useGlyphRun();
+ SkGlyphRunList* useGlyphRunList();
private:
size_t runSize() const;
@@ -165,20 +232,27 @@ private:
void initialize();
SkGlyphID* addDenseAndUnique(const SkPaint& paint, const void* bytes, size_t byteLength);
void addGlyphRunToList(
- SkGlyphID* temporaryShuntGlyphIDs, SkSpan<const char> text, SkSpan<uint32_t> clusters);
+ const SkPaint& runPaint,
+ SkGlyphID* temporaryShuntGlyphIDs,
+ SkSpan<const char> text,
+ SkSpan<const uint32_t> clusters);
void drawText(
const SkPaint& paint, const void* bytes, size_t byteLength, SkPoint origin,
- SkSpan<const char> text, SkSpan<uint32_t> clusters);
+ SkSpan<const char> text, SkSpan<const uint32_t> clusters);
void drawPosTextH(
const SkPaint& paint, const void* bytes, size_t byteLength,
const SkScalar* xpos, SkScalar constY,
- SkSpan<const char> text, SkSpan<uint32_t> clusters);
+ SkSpan<const char> text, SkSpan<const uint32_t> clusters);
void drawPosText(
const SkPaint& paint, const void* bytes, size_t byteLength, const SkPoint* pos,
- SkSpan<const char> text, SkSpan<uint32_t> clusters);
+ SkSpan<const char> text, SkSpan<const uint32_t> clusters);
+
+ const SkTextBlob* fTemporaryTextBlobShunt{nullptr};
- uint64_t fUniqueID{0};
+ // The point passed into drawTextBlob. This allows the GPU back end to detect and adjust for
+ // translations.
+ SkPoint fOrigin;
std::vector<uint16_t> fDenseIndex;
std::vector<SkPoint> fPositions;