blob: 4c57d3cb81d251227ebc959b027515562a3027fc [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;
bsalomon1fcc01c2015-09-09 09:48:06 -070018class GrPathRangeDraw;
robertphillipsfcf78292015-06-19 11:49:52 -070019class SkSurfaceProps;
kkinnunenc6cb56f2014-06-24 00:12:27 -070020
21/*
22 * This class implements text rendering using stencil and cover path rendering
23 * (by the means of GrDrawTarget::drawPath).
24 * This class exposes the functionality through GrTextContext interface.
25 */
26class GrStencilAndCoverTextContext : public GrTextContext {
27public:
robertphillipsf6703fa2015-09-01 05:36:47 -070028 static GrStencilAndCoverTextContext* Create(GrContext*, 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:
cdalton855d83f2014-09-18 13:51:53 -070033 enum RenderMode {
34 /**
35 * This is the render mode used by drawText(), which is mainly used by
36 * the Skia unit tests. It tries match the other text backends exactly,
37 * with the exception of not implementing LCD text, and doing anti-
38 * aliasing with the built-in MSAA.
39 */
40 kMaxAccuracy_RenderMode,
41
42 /**
43 * This is the render mode used by drawPosText(). It ignores hinting and
44 * LCD text, even if the client provided positions for hinted glyphs,
45 * and renders from a canonically-sized, generic set of paths for the
46 * given typeface. In the future we should work out a system for the
47 * client to know it should not provide hinted glyph positions. This
48 * render mode also tries to use GPU stroking for fake bold, even when
49 * SK_USE_FREETYPE_EMBOLDEN is set.
50 */
51 kMaxPerformance_RenderMode,
cdaltonb2808cd2014-07-25 14:13:57 -070052 };
cdalton855d83f2014-09-18 13:51:53 -070053
bsalomon6be6f7c2015-02-26 13:05:21 -080054 SkScalar fTextRatio;
55 float fTextInverseRatio;
56 SkGlyphCache* fGlyphCache;
bsalomon1fcc01c2015-09-09 09:48:06 -070057
bsalomon6be6f7c2015-02-26 13:05:21 -080058 GrPathRange* fGlyphs;
bsalomon1fcc01c2015-09-09 09:48:06 -070059 GrPathRangeDraw* fDraw;
kkinnunen50b58e62015-05-18 23:02:07 -070060 GrStrokeInfo fStroke;
bsalomon1fcc01c2015-09-09 09:48:06 -070061 SkSTArray<32, uint16_t, true> fFallbackIndices;
62 SkSTArray<32, SkPoint, true> fFallbackPositions;
63
bsalomon6be6f7c2015-02-26 13:05:21 -080064 SkMatrix fContextInitialMatrix;
65 SkMatrix fViewMatrix;
66 SkMatrix fLocalMatrix;
67 bool fUsingDeviceSpaceGlyphs;
joshualitt9df46592015-07-09 10:55:28 -070068 SkAutoTUnref<GrRenderTarget> fRenderTarget;
69 GrClip fClip;
70 SkIRect fClipRect;
71 SkIRect fRegionClipBounds;
72 GrPaint fPaint;
73 SkPaint fSkPaint;
jvanverth0fedb192014-10-08 09:07:27 -070074
robertphillipsf6703fa2015-09-01 05:36:47 -070075 GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&);
jvanverth8c27a182014-10-14 08:45:50 -070076
cdaltone68f7362015-03-25 14:02:37 -070077 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
mtklein36352bf2015-03-25 18:17:31 -070078 const SkPaint&, const SkMatrix& viewMatrix) override;
jvanverth8c27a182014-10-14 08:45:50 -070079
robertphillipsf6703fa2015-09-01 05:36:47 -070080 void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070081 const SkMatrix& viewMatrix,
82 const char text[], size_t byteLength,
mtklein36352bf2015-03-25 18:17:31 -070083 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
robertphillipsf6703fa2015-09-01 05:36:47 -070084 void onDrawPosText(GrDrawContext*, GrRenderTarget*,
85 const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070086 const SkMatrix& viewMatrix,
87 const char text[], size_t byteLength,
88 const SkScalar pos[], int scalarsPerPosition,
mtklein36352bf2015-03-25 18:17:31 -070089 const SkPoint& offset, const SkIRect& regionClipBounds) override;
jvanverth8c27a182014-10-14 08:45:50 -070090
joshualitt570d2f82015-02-25 13:19:48 -080091 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt6e8cd962015-03-20 10:30:14 -070092 size_t textByteLength, RenderMode, const SkMatrix& viewMatrix,
93 const SkIRect& regionClipBounds);
joshualitt5531d512014-12-17 15:50:11 -080094 bool mapToFallbackContext(SkMatrix* inverse);
bsalomon1fcc01c2015-09-09 09:48:06 -070095 void appendGlyph(const SkGlyph&, const SkPoint&);
robertphillipsf6703fa2015-09-01 05:36:47 -070096 void flush(GrDrawContext* dc);
97 void finish(GrDrawContext* dc);
kkinnunenc6cb56f2014-06-24 00:12:27 -070098
bsalomon1fcc01c2015-09-09 09:48:06 -070099 typedef GrTextContext INHERITED;
kkinnunenc6cb56f2014-06-24 00:12:27 -0700100};
101
102#endif