blob: 3b4cd9bf373447df8b727e721f944ed1a5b8e5d4 [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"
kkinnunenc6cb56f2014-06-24 00:12:27 -070013#include "SkStrokeRec.h"
14
15class GrTextStrike;
16class GrPath;
cdalton855d83f2014-09-18 13:51:53 -070017class GrPathRange;
kkinnunenc6cb56f2014-06-24 00:12:27 -070018
19/*
20 * This class implements text rendering using stencil and cover path rendering
21 * (by the means of GrDrawTarget::drawPath).
22 * This class exposes the functionality through GrTextContext interface.
23 */
24class GrStencilAndCoverTextContext : public GrTextContext {
25public:
jvanverth8c27a182014-10-14 08:45:50 -070026 static GrStencilAndCoverTextContext* Create(GrContext*, const SkDeviceProperties&);
27
kkinnunenc6cb56f2014-06-24 00:12:27 -070028 virtual ~GrStencilAndCoverTextContext();
29
kkinnunenc6cb56f2014-06-24 00:12:27 -070030private:
cdaltonb85a0aa2014-07-21 15:32:44 -070031 static const int kGlyphBufferSize = 1024;
32
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
egdaniel8dd688b2015-01-22 10:16:09 -080054 GrPipelineBuilder fPipelineBuilder;
55 GrPipelineBuilder::AutoRestoreEffects fStateRestore;
jvanverth0fedb192014-10-08 09:07:27 -070056 SkScalar fTextRatio;
57 float fTextInverseRatio;
58 SkGlyphCache* fGlyphCache;
59 GrPathRange* fGlyphs;
cdalton20b373c2014-12-01 08:38:55 -080060 SkStrokeRec fStroke;
61 uint16_t fGlyphIndices[kGlyphBufferSize];
62 SkPoint fGlyphPositions[kGlyphBufferSize];
63 int fQueuedGlyphCount;
64 int fFallbackGlyphsIdx;
jvanverth0fedb192014-10-08 09:07:27 -070065 SkMatrix fContextInitialMatrix;
joshualitt5531d512014-12-17 15:50:11 -080066 SkMatrix fViewMatrix;
joshualitt290c09b2014-12-19 13:45:20 -080067 SkMatrix fLocalMatrix;
cdalton20b373c2014-12-01 08:38:55 -080068 bool fUsingDeviceSpaceGlyphs;
jvanverth0fedb192014-10-08 09:07:27 -070069
jvanverth8c27a182014-10-14 08:45:50 -070070 GrStencilAndCoverTextContext(GrContext*, const SkDeviceProperties&);
71
mtklein72c9faa2015-01-09 10:06:39 -080072 bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070073
joshualitt29070592015-02-25 13:04:43 -080074 virtual void onDrawText(GrRenderTarget*, const GrPaint&, const SkPaint&,
joshualitt25d9c152015-02-18 12:29:52 -080075 const SkMatrix& viewMatrix,
joshualitt5531d512014-12-17 15:50:11 -080076 const char text[], size_t byteLength,
jvanverthaab626c2014-10-16 08:04:39 -070077 SkScalar x, SkScalar y) SK_OVERRIDE;
joshualitt29070592015-02-25 13:04:43 -080078 virtual void onDrawPosText(GrRenderTarget*, const GrPaint&, const SkPaint&,
joshualitt25d9c152015-02-18 12:29:52 -080079 const SkMatrix& viewMatrix,
jvanverth8c27a182014-10-14 08:45:50 -070080 const char text[], size_t byteLength,
81 const SkScalar pos[], int scalarsPerPosition,
82 const SkPoint& offset) SK_OVERRIDE;
83
joshualitt29070592015-02-25 13:04:43 -080084 void init(GrRenderTarget*, const GrPaint&, const SkPaint&, size_t textByteLength, RenderMode,
85 const SkMatrix& viewMatrix);
joshualitt5531d512014-12-17 15:50:11 -080086 bool mapToFallbackContext(SkMatrix* inverse);
cdalton20b373c2014-12-01 08:38:55 -080087 void appendGlyph(const SkGlyph&, const SkPoint&);
cdaltonb85a0aa2014-07-21 15:32:44 -070088 void flush();
kkinnunenc6cb56f2014-06-24 00:12:27 -070089 void finish();
90
kkinnunenc6cb56f2014-06-24 00:12:27 -070091};
92
93#endif