Implement text rendering with NVPR
Use path rendering to render the text from outlines if supported by the
GPU. Implement this in GrStencilAndCoverTextContext by copying chunks of code
from GrBitmapTextContext.
The drawing is implemented with "instanced" path drawing functions.
Moves the creation of the "main" text context from SkGpuDevice to the
GrContext::createTextContext. This is done because the decision of which text
renderer is optimal can be made only with the internal implementation-specific
information of the context.
Remove a windows assertion from SkScalerContext_GDI::getGDIGlyphPath. The
GetGlyphOutlineW fails in fontmgr_match for the initial space char in the string
" [700] ...". According to MSDN, this is a known problem. Just return that the
glyph has no path data in these cases.
R=jvanverth@google.com, bsalomon@google.com, mtklein@google.com
Author: kkinnunen@nvidia.com
Review URL: https://codereview.chromium.org/196133014
diff --git a/src/gpu/GrStencilAndCoverTextContext.h b/src/gpu/GrStencilAndCoverTextContext.h
new file mode 100644
index 0000000..2e79f5c
--- /dev/null
+++ b/src/gpu/GrStencilAndCoverTextContext.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrStencilAndCoverTextContext_DEFINED
+#define GrStencilAndCoverTextContext_DEFINED
+
+#include "GrTextContext.h"
+#include "GrDrawState.h"
+#include "SkStrokeRec.h"
+
+class GrTextStrike;
+class GrPath;
+
+/*
+ * This class implements text rendering using stencil and cover path rendering
+ * (by the means of GrDrawTarget::drawPath).
+ * This class exposes the functionality through GrTextContext interface.
+ */
+class GrStencilAndCoverTextContext : public GrTextContext {
+public:
+ GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
+ virtual ~GrStencilAndCoverTextContext();
+
+ virtual void drawText(const GrPaint&, const SkPaint&, const char text[],
+ size_t byteLength,
+ SkScalar x, SkScalar y) SK_OVERRIDE;
+ virtual void drawPosText(const GrPaint&, const SkPaint&,
+ const char text[], size_t byteLength,
+ const SkScalar pos[], SkScalar constY,
+ int scalarsPerPosition) SK_OVERRIDE;
+
+ virtual bool canDraw(const SkPaint& paint) SK_OVERRIDE;
+
+private:
+ void init(const GrPaint&, const SkPaint&, size_t textByteLength);
+ void appendGlyph(GrGlyph::PackedID, const SkPoint&,
+ GrTextStrike*, GrFontScaler*);
+ void finish();
+
+ GrDrawState::AutoRestoreEffects fStateRestore;
+ SkScalar fTextRatio;
+ SkStrokeRec fStroke;
+ SkTDArray<const GrPath*> fPaths;
+ SkTDArray<SkMatrix> fTransforms;
+ SkPath fTmpPath;
+ SkMatrix fGlyphTransform;
+ bool fNeedsDeviceSpaceGlyphs;
+};
+
+#endif