blob: 44b33a593dc95f1ce3f09f54aab0f0fa5149d24e [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:
bsalomon6be6f7c2015-02-26 13:05:21 -080033 SkScalar fTextRatio;
34 float fTextInverseRatio;
35 SkGlyphCache* fGlyphCache;
bsalomon1fcc01c2015-09-09 09:48:06 -070036
bsalomon6be6f7c2015-02-26 13:05:21 -080037 GrPathRange* fGlyphs;
bsalomon1fcc01c2015-09-09 09:48:06 -070038 GrPathRangeDraw* fDraw;
kkinnunen50b58e62015-05-18 23:02:07 -070039 GrStrokeInfo fStroke;
bsalomon1fcc01c2015-09-09 09:48:06 -070040 SkSTArray<32, uint16_t, true> fFallbackIndices;
41 SkSTArray<32, SkPoint, true> fFallbackPositions;
42
bsalomon6be6f7c2015-02-26 13:05:21 -080043 SkMatrix fViewMatrix;
44 SkMatrix fLocalMatrix;
joshualitt9df46592015-07-09 10:55:28 -070045 SkAutoTUnref<GrRenderTarget> fRenderTarget;
46 GrClip fClip;
47 SkIRect fClipRect;
48 SkIRect fRegionClipBounds;
49 GrPaint fPaint;
50 SkPaint fSkPaint;
jvanverth0fedb192014-10-08 09:07:27 -070051
robertphillipsf6703fa2015-09-01 05:36:47 -070052 GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&);
jvanverth8c27a182014-10-14 08:45:50 -070053
cdaltone68f7362015-03-25 14:02:37 -070054 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
mtklein36352bf2015-03-25 18:17:31 -070055 const SkPaint&, const SkMatrix& viewMatrix) override;
jvanverth8c27a182014-10-14 08:45:50 -070056
robertphillipsf6703fa2015-09-01 05:36:47 -070057 void onDrawText(GrDrawContext*, GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070058 const SkMatrix& viewMatrix,
59 const char text[], size_t byteLength,
mtklein36352bf2015-03-25 18:17:31 -070060 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
robertphillipsf6703fa2015-09-01 05:36:47 -070061 void onDrawPosText(GrDrawContext*, GrRenderTarget*,
62 const GrClip&, const GrPaint&, const SkPaint&,
cdaltone68f7362015-03-25 14:02:37 -070063 const SkMatrix& viewMatrix,
64 const char text[], size_t byteLength,
65 const SkScalar pos[], int scalarsPerPosition,
mtklein36352bf2015-03-25 18:17:31 -070066 const SkPoint& offset, const SkIRect& regionClipBounds) override;
jvanverth8c27a182014-10-14 08:45:50 -070067
cdalton7d5c9502015-10-03 13:28:35 -070068 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, size_t textByteLength,
69 const SkMatrix& viewMatrix, const SkIRect& regionClipBounds);
bsalomon1fcc01c2015-09-09 09:48:06 -070070 void appendGlyph(const SkGlyph&, const SkPoint&);
robertphillipsf6703fa2015-09-01 05:36:47 -070071 void flush(GrDrawContext* dc);
72 void finish(GrDrawContext* dc);
kkinnunenc6cb56f2014-06-24 00:12:27 -070073
bsalomon1fcc01c2015-09-09 09:48:06 -070074 typedef GrTextContext INHERITED;
kkinnunenc6cb56f2014-06-24 00:12:27 -070075};
76
77#endif