blob: f59f633bfd120080233ef4d2f1ce1f515b580f90 [file] [log] [blame]
kkinnunenc6cb56f2014-06-24 00:12:27 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrStencilAndCoverTextContext_DEFINED
9#define GrStencilAndCoverTextContext_DEFINED
10
11#include "GrTextContext.h"
cdaltonb2808cd2014-07-25 14:13:57 -070012#include "GrDrawTarget.h"
kkinnunen50b58e62015-05-18 23:02:07 -070013#include "GrStrokeInfo.h"
kkinnunenc6cb56f2014-06-24 00:12:27 -070014
15class GrTextStrike;
16class GrPath;
cdalton855d83f2014-09-18 13:51:53 -070017class GrPathRange;
robertphillipsfcf78292015-06-19 11:49:52 -070018class SkSurfaceProps;
kkinnunenc6cb56f2014-06-24 00:12:27 -070019
20/*
21 * This class implements text rendering using stencil and cover path rendering
22 * (by the means of GrDrawTarget::drawPath).
23 * This class exposes the functionality through GrTextContext interface.
24 */
25class GrStencilAndCoverTextContext : public GrTextContext {
26public:
robertphillips2334fb62015-06-17 05:43:33 -070027 static GrStencilAndCoverTextContext* Create(GrContext*, GrDrawContext*,
robertphillipsfcf78292015-06-19 11:49:52 -070028 const SkSurfaceProps&);
jvanverth8c27a182014-10-14 08:45:50 -070029
kkinnunenc6cb56f2014-06-24 00:12:27 -070030 virtual ~GrStencilAndCoverTextContext();
31
kkinnunenc6cb56f2014-06-24 00:12:27 -070032private:
cdaltonb85a0aa2014-07-21 15:32:44 -070033 static const int kGlyphBufferSize = 1024;
34
cdalton855d83f2014-09-18 13:51:53 -070035 enum RenderMode {
36 /**
37 * This is the render mode used by drawText(), which is mainly used by
38 * the Skia unit tests. It tries match the other text backends exactly,
39 * with the exception of not implementing LCD text, and doing anti-
40 * aliasing with the built-in MSAA.
41 */
42 kMaxAccuracy_RenderMode,
43
44 /**
45 * This is the render mode used by drawPosText(). It ignores hinting and
46 * LCD text, even if the client provided positions for hinted glyphs,
47 * and renders from a canonically-sized, generic set of paths for the
48 * given typeface. In the future we should work out a system for the
49 * client to know it should not provide hinted glyph positions. This
50 * render mode also tries to use GPU stroking for fake bold, even when
51 * SK_USE_FREETYPE_EMBOLDEN is set.
52 */
53 kMaxPerformance_RenderMode,
cdaltonb2808cd2014-07-25 14:13:57 -070054 };
cdalton855d83f2014-09-18 13:51:53 -070055
bsalomon6be6f7c2015-02-26 13:05:21 -080056 GrPipelineBuilder fPipelineBuilder;
57 GrPipelineBuilder::AutoRestoreFragmentProcessors fStateRestore;
58 SkScalar fTextRatio;
59 float fTextInverseRatio;
60 SkGlyphCache* fGlyphCache;
61 GrPathRange* fGlyphs;
kkinnunen50b58e62015-05-18 23:02:07 -070062 GrStrokeInfo fStroke;
bsalomon6be6f7c2015-02-26 13:05:21 -080063 uint16_t fGlyphIndices[kGlyphBufferSize];
64 SkPoint fGlyphPositions[kGlyphBufferSize];
65 int fQueuedGlyphCount;
66 int fFallbackGlyphsIdx;
67 SkMatrix fContextInitialMatrix;
68 SkMatrix fViewMatrix;
69 SkMatrix fLocalMatrix;
70 bool fUsingDeviceSpaceGlyphs;
jvanverth0fedb192014-10-08 09:07:27 -070071
robertphillipsfcf78292015-06-19 11:49:52 -070072 GrStencilAndCoverTextContext(GrContext*, GrDrawContext*, const SkSurfaceProps&);
jvanverth8c27a182014-10-14 08:45:50 -070073
cdaltone68f7362015-03-25 14:02:37 -070074 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
mtklein36352bf2015-03-25 18:17:31 -070075 const SkPaint&, const SkMatrix& viewMatrix) override;
jvanverth8c27a182014-10-14 08:45:50 -070076
robertphillips2334fb62015-06-17 05:43:33 -070077 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070078 const SkMatrix& viewMatrix,
79 const char text[], size_t byteLength,
mtklein36352bf2015-03-25 18:17:31 -070080 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
robertphillips2334fb62015-06-17 05:43:33 -070081 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070082 const SkMatrix& viewMatrix,
83 const char text[], size_t byteLength,
84 const SkScalar pos[], int scalarsPerPosition,
mtklein36352bf2015-03-25 18:17:31 -070085 const SkPoint& offset, const SkIRect& regionClipBounds) override;
jvanverth8c27a182014-10-14 08:45:50 -070086
joshualitt570d2f82015-02-25 13:19:48 -080087 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt6e8cd962015-03-20 10:30:14 -070088 size_t textByteLength, RenderMode, const SkMatrix& viewMatrix,
89 const SkIRect& regionClipBounds);
joshualitt5531d512014-12-17 15:50:11 -080090 bool mapToFallbackContext(SkMatrix* inverse);
robertphillips2334fb62015-06-17 05:43:33 -070091 void appendGlyph(const SkGlyph&, const SkPoint&);
92 void flush();
93 void finish();
kkinnunenc6cb56f2014-06-24 00:12:27 -070094
kkinnunenc6cb56f2014-06-24 00:12:27 -070095};
96
97#endif