aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkGlyphRun.h
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-07-23 16:20:53 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-26 18:16:46 +0000
commit1347144e3ef790c9431d18a8005dcf8914899b1d (patch)
tree212383343d996fcc2a9249760f93bff317ec4490 /src/core/SkGlyphRun.h
parent97e858f359d165b35a304a840d43c2b6412fc241 (diff)
Centralize bitmap glyph positioning
Centralize all text drawing for bitmap devices into SkGlyphRunListDrawer. All drawing decisions are encapsulated in this class, and its behavior only depends on contant properties of the device. The method drawForBitmap will probably have to be converted to a template based in preliminary performance numbers. Change-Id: Id21567c1511eee9d2e9e20c7ae93544530cfdb81 Reviewed-on: https://skia-review.googlesource.com/143106 Reviewed-by: Mike Klein <mtklein@google.com> Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/core/SkGlyphRun.h')
-rw-r--r--src/core/SkGlyphRun.h56
1 files changed, 48 insertions, 8 deletions
diff --git a/src/core/SkGlyphRun.h b/src/core/SkGlyphRun.h
index f3b4ff34e3..8348fe9013 100644
--- a/src/core/SkGlyphRun.h
+++ b/src/core/SkGlyphRun.h
@@ -12,16 +12,19 @@
#include <memory>
#include <vector>
+#include "SkArenaAlloc.h"
#include "SkDescriptor.h"
#include "SkMask.h"
#include "SkPath.h"
#include "SkPoint.h"
+#include "SkSurfaceProps.h"
#include "SkTemplates.h"
#include "SkTextBlob.h"
#include "SkTypes.h"
class SkBaseDevice;
class SkGlyphRunList;
+class SkRasterClip;
template <typename T>
class SkSpan {
@@ -69,7 +72,6 @@ public:
template <typename PerGlyphPos>
void forEachGlyphAndPosition(PerGlyphPos perGlyph) const;
-
// The temporaryShunt calls are to allow inter-operating with existing code while glyph runs
// are developed.
void temporaryShuntToDrawPosText(SkBaseDevice* device, SkPoint origin);
@@ -102,13 +104,43 @@ private:
SkPaint fRunPaint;
};
-template <typename PerGlyphPos>
-inline void SkGlyphRun::forEachGlyphAndPosition(PerGlyphPos perGlyph) const {
- SkPoint* ptCursor = fPositions.data();
- for (auto glyphID : fGlyphIDs) {
- perGlyph(glyphID, *ptCursor++);
- }
-}
+class SkGlyphRunListDrawer {
+public:
+ // Constructor for SkBitmpapDevice.
+ SkGlyphRunListDrawer(
+ const SkSurfaceProps& props, SkColorType colorType, SkScalerContextFlags flags);
+
+ using PerMask = std::function<void(const SkMask&)>;
+ using PerMaskCreator = std::function<PerMask(const SkPaint&, SkArenaAlloc* alloc)>;
+ using PerPath = std::function<void(const SkPath&, const SkMatrix&)>;
+ using PerPathCreator = std::function<PerPath(const SkPaint&, SkArenaAlloc* alloc)>;
+ void drawForBitmap(
+ SkGlyphRunList* glyphRunList, const SkMatrix& deviceMatrix,
+ PerMaskCreator perMaskCreator, PerPathCreator perPathCreator);
+
+private:
+ static bool ShouldDrawAsPath(const SkPaint& paint, const SkMatrix& matrix);
+ bool ensureBitmapBuffers(size_t runSize);
+ void drawGlyphRunAsPaths(
+ SkGlyphRun* glyphRun, SkPoint origin,
+ const SkSurfaceProps& props, PerPath perPath) const;
+ void drawGlyphRunAsSubpixelMask(
+ SkGlyphCache* cache, SkGlyphRun* glyphRun,
+ SkPoint origin, const SkMatrix& deviceMatrix,
+ PerMask perMask);
+ void drawGlyphRunAsFullpixelMask(
+ SkGlyphCache* cache, SkGlyphRun* glyphRun,
+ SkPoint origin, const SkMatrix& deviceMatrix,
+ PerMask perMask);
+ // The props as on the actual device.
+ const SkSurfaceProps fDeviceProps;
+ // The props for when the bitmap device can't draw LCD text.
+ const SkSurfaceProps fBitmapFallbackProps;
+ const SkColorType fColorType;
+ const SkScalerContextFlags fScalerContextFlags;
+ size_t fMaxRunSize{0};
+ SkAutoTMalloc<SkPoint> fPositions;
+};
class SkGlyphRunList {
const SkPaint* fOriginalPaint{nullptr}; // This should be deleted soon.
@@ -269,4 +301,12 @@ private:
SkGlyphIDSet fGlyphIDSet;
};
+template <typename PerGlyphPos>
+inline void SkGlyphRun::forEachGlyphAndPosition(PerGlyphPos perGlyph) const {
+ SkPoint* ptCursor = fPositions.data();
+ for (auto glyphID : fGlyphIDs) {
+ perGlyph(glyphID, *ptCursor++);
+ }
+}
+
#endif // SkGlyphRunInfo_DEFINED