aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/text/GrTextContext.h
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2018-05-24 14:39:01 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-24 20:41:08 +0000
commit26cbe5130aa9839b5429b9507363ce2474091808 (patch)
tree5d10df1e2a768bf31af6ccbd2fd636f44f7c98b6 /src/gpu/text/GrTextContext.h
parent4a0ad501e4919e06bcf7a7ef4adec8f28818946b (diff)
Rename GrAtlasTextContext -> GrTextContext
Change-Id: I309b39425afc9b45095241eeb299096bc426afed Reviewed-on: https://skia-review.googlesource.com/130029 Reviewed-by: Herb Derby <herb@google.com> Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src/gpu/text/GrTextContext.h')
-rw-r--r--src/gpu/text/GrTextContext.h206
1 files changed, 206 insertions, 0 deletions
diff --git a/src/gpu/text/GrTextContext.h b/src/gpu/text/GrTextContext.h
new file mode 100644
index 0000000000..b5bb22f3d5
--- /dev/null
+++ b/src/gpu/text/GrTextContext.h
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrAtlasTextContext_DEFINED
+#define GrAtlasTextContext_DEFINED
+
+#include "GrAtlasTextBlob.h"
+#include "GrDistanceFieldAdjustTable.h"
+#include "GrGeometryProcessor.h"
+#include "GrTextUtils.h"
+#include "SkTextBlobRunIterator.h"
+
+#if GR_TEST_UTILS
+#include "GrDrawOpTest.h"
+#endif
+
+class GrDrawOp;
+class GrTextBlobCache;
+class SkGlyph;
+
+/*
+ * Renders text using some kind of an atlas, ie BitmapText or DistanceField text
+ */
+class GrTextContext {
+public:
+ struct Options {
+ /**
+ * Below this size (in device space) distance field text will not be used. Negative means
+ * use a default value.
+ */
+ SkScalar fMinDistanceFieldFontSize = -1.f;
+ /**
+ * Above this size (in device space) distance field text will not be used and glyphs will
+ * be rendered from outline as individual paths. Negative means use a default value.
+ */
+ SkScalar fMaxDistanceFieldFontSize = -1.f;
+ /** Forces all distance field vertices to use 3 components, not just when in perspective. */
+ bool fDistanceFieldVerticesAlwaysHaveW = false;
+ };
+
+ static std::unique_ptr<GrTextContext> Make(const Options& options);
+
+ void drawText(GrContext*, GrTextUtils::Target*, const GrClip&, const SkPaint&,
+ const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
+ size_t byteLength, SkScalar x, SkScalar y, const SkIRect& regionClipBounds);
+ void drawPosText(GrContext*, GrTextUtils::Target*, const GrClip&, const SkPaint&,
+ const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
+ size_t byteLength, const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset, const SkIRect& regionClipBounds);
+ void drawTextBlob(GrContext*, GrTextUtils::Target*, const GrClip&, const SkPaint&,
+ const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*,
+ SkScalar x, SkScalar y, SkDrawFilter*, const SkIRect& clipBounds);
+
+ std::unique_ptr<GrDrawOp> createOp_TestingOnly(GrContext*, GrTextContext*,
+ GrRenderTargetContext*, const SkPaint&,
+ const SkMatrix& viewMatrix, const char* text,
+ int x, int y);
+
+ static void SanitizeOptions(Options* options);
+ static bool CanDrawAsDistanceFields(const SkPaint& skPaint, const SkMatrix& viewMatrix,
+ const SkSurfaceProps& props,
+ bool contextSupportsDistanceFieldText,
+ const Options& options);
+ static void InitDistanceFieldPaint(GrAtlasTextBlob* blob,
+ SkPaint* skPaint,
+ const SkMatrix& viewMatrix,
+ const Options& options,
+ SkScalar* textRatio,
+ SkScalerContextFlags* flags);
+
+private:
+ GrTextContext(const Options& options);
+
+ class FallbackTextHelper {
+ public:
+ FallbackTextHelper(const SkMatrix& viewMatrix,
+ const SkPaint& pathPaint,
+ const GrGlyphCache* glyphCache,
+ SkScalar textRatio)
+ : fViewMatrix(viewMatrix)
+ , fTextSize(pathPaint.getTextSize())
+ , fMaxTextSize(glyphCache->getGlyphSizeLimit())
+ , fTextRatio(textRatio)
+ , fTransformedFallbackTextSize(fMaxTextSize)
+ , fUseTransformedFallback(false) {
+ fMaxScale = viewMatrix.getMaxScale();
+ }
+
+ void appendText(const SkGlyph& glyph, int count, const char* text, SkPoint glyphPos);
+ void drawText(GrAtlasTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&,
+ const GrTextUtils::Paint&, SkScalerContextFlags);
+
+ private:
+ SkTDArray<char> fFallbackTxt;
+ SkTDArray<SkPoint> fFallbackPos;
+
+ const SkMatrix& fViewMatrix;
+ SkScalar fTextSize;
+ SkScalar fMaxTextSize;
+ SkScalar fTextRatio;
+ SkScalar fTransformedFallbackTextSize;
+ SkScalar fMaxScale;
+ bool fUseTransformedFallback;
+ };
+
+ // sets up the descriptor on the blob and returns a detached cache. Client must attach
+ static SkColor ComputeCanonicalColor(const SkPaint&, bool lcd);
+ // Determines if we need to use fake gamma (and contrast boost):
+ static SkScalerContextFlags ComputeScalerContextFlags(const GrColorSpaceInfo&);
+ void regenerateTextBlob(GrAtlasTextBlob* bmp,
+ GrGlyphCache*,
+ const GrShaderCaps&,
+ const GrTextUtils::Paint&,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const SkSurfaceProps&,
+ const SkTextBlob* blob, SkScalar x, SkScalar y,
+ SkDrawFilter* drawFilter) const;
+
+ static bool HasLCD(const SkTextBlob*);
+
+ sk_sp<GrAtlasTextBlob> makeDrawTextBlob(GrTextBlobCache*, GrGlyphCache*,
+ const GrShaderCaps&,
+ const GrTextUtils::Paint&,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const SkSurfaceProps&,
+ const char text[], size_t byteLength,
+ SkScalar x, SkScalar y) const;
+
+ sk_sp<GrAtlasTextBlob> makeDrawPosTextBlob(GrTextBlobCache*, GrGlyphCache*,
+ const GrShaderCaps&,
+ const GrTextUtils::Paint&,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const SkSurfaceProps&,
+ const char text[], size_t byteLength,
+ const SkScalar pos[],
+ int scalarsPerPosition,
+ const SkPoint& offset) const;
+
+ // Functions for appending BMP text to GrAtlasTextBlob
+ static void DrawBmpText(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength, SkScalar x, SkScalar y);
+
+ static void DrawBmpPosText(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags, const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength, const SkScalar pos[],
+ int scalarsPerPosition, const SkPoint& offset);
+
+ static void DrawBmpTextAsPaths(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix, const char text[],
+ size_t byteLength, SkScalar x, SkScalar y);
+
+ static void DrawBmpPosTextAsPaths(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix,
+ const char text[], size_t byteLength,
+ const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset);
+
+ // functions for appending distance field text
+ void drawDFText(GrAtlasTextBlob* blob, int runIndex, GrGlyphCache*, const SkSurfaceProps&,
+ const GrTextUtils::Paint& paint, SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x,
+ SkScalar y) const;
+
+ void drawDFPosText(GrAtlasTextBlob* blob, int runIndex, GrGlyphCache*,
+ const SkSurfaceProps&, const GrTextUtils::Paint& paint,
+ SkScalerContextFlags scalerContextFlags,
+ const SkMatrix& viewMatrix, const char text[],
+ size_t byteLength, const SkScalar pos[], int scalarsPerPosition,
+ const SkPoint& offset) const;
+
+ static void BmpAppendGlyph(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
+ sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy,
+ GrColor color, SkGlyphCache*, SkScalar textRatio, bool needsXform);
+
+ static void DfAppendGlyph(GrAtlasTextBlob*, int runIndex, GrGlyphCache*,
+ sk_sp<GrTextStrike>*, const SkGlyph&, SkScalar sx, SkScalar sy,
+ GrColor color, SkGlyphCache* cache, SkScalar textRatio);
+
+ const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable.get(); }
+
+ sk_sp<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
+
+ Options fOptions;
+
+#if GR_TEST_UTILS
+ static const SkScalerContextFlags kTextBlobOpScalerContextFlags =
+ SkScalerContextFlags::kFakeGammaAndBoostContrast;
+ GR_DRAW_OP_TEST_FRIEND(GrAtlasTextOp);
+#endif
+};
+
+#endif