blob: e42989b90f1100a59e452843b0bf1a38e803905a [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:
joshualitt6e8cd962015-03-20 10:30:14 -070026 static GrStencilAndCoverTextContext* Create(GrContext*, SkGpuDevice*,
27 const SkDeviceProperties&);
jvanverth8c27a182014-10-14 08:45:50 -070028
kkinnunenc6cb56f2014-06-24 00:12:27 -070029 virtual ~GrStencilAndCoverTextContext();
30
kkinnunenc6cb56f2014-06-24 00:12:27 -070031private:
cdaltonb85a0aa2014-07-21 15:32:44 -070032 static const int kGlyphBufferSize = 1024;
33
cdalton855d83f2014-09-18 13:51:53 -070034 enum RenderMode {
35 /**
36 * This is the render mode used by drawText(), which is mainly used by
37 * the Skia unit tests. It tries match the other text backends exactly,
38 * with the exception of not implementing LCD text, and doing anti-
39 * aliasing with the built-in MSAA.
40 */
41 kMaxAccuracy_RenderMode,
42
43 /**
44 * This is the render mode used by drawPosText(). It ignores hinting and
45 * LCD text, even if the client provided positions for hinted glyphs,
46 * and renders from a canonically-sized, generic set of paths for the
47 * given typeface. In the future we should work out a system for the
48 * client to know it should not provide hinted glyph positions. This
49 * render mode also tries to use GPU stroking for fake bold, even when
50 * SK_USE_FREETYPE_EMBOLDEN is set.
51 */
52 kMaxPerformance_RenderMode,
cdaltonb2808cd2014-07-25 14:13:57 -070053 };
cdalton855d83f2014-09-18 13:51:53 -070054
bsalomon6be6f7c2015-02-26 13:05:21 -080055 GrPipelineBuilder fPipelineBuilder;
56 GrPipelineBuilder::AutoRestoreFragmentProcessors fStateRestore;
57 SkScalar fTextRatio;
58 float fTextInverseRatio;
59 SkGlyphCache* fGlyphCache;
60 GrPathRange* fGlyphs;
61 SkStrokeRec fStroke;
62 uint16_t fGlyphIndices[kGlyphBufferSize];
63 SkPoint fGlyphPositions[kGlyphBufferSize];
64 int fQueuedGlyphCount;
65 int fFallbackGlyphsIdx;
66 SkMatrix fContextInitialMatrix;
67 SkMatrix fViewMatrix;
68 SkMatrix fLocalMatrix;
69 bool fUsingDeviceSpaceGlyphs;
jvanverth0fedb192014-10-08 09:07:27 -070070
joshualitt6e8cd962015-03-20 10:30:14 -070071 GrStencilAndCoverTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&);
jvanverth8c27a182014-10-14 08:45:50 -070072
mtklein72c9faa2015-01-09 10:06:39 -080073 bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070074
joshualitt570d2f82015-02-25 13:19:48 -080075 virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt25d9c152015-02-18 12:29:52 -080076 const SkMatrix& viewMatrix,
joshualitt5531d512014-12-17 15:50:11 -080077 const char text[], size_t byteLength,
joshualitt6e8cd962015-03-20 10:30:14 -070078 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) SK_OVERRIDE;
joshualitt570d2f82015-02-25 13:19:48 -080079 virtual void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt25d9c152015-02-18 12:29:52 -080080 const SkMatrix& viewMatrix,
jvanverth8c27a182014-10-14 08:45:50 -070081 const char text[], size_t byteLength,
82 const SkScalar pos[], int scalarsPerPosition,
joshualitt6e8cd962015-03-20 10:30:14 -070083 const SkPoint& offset, const SkIRect& regionClipBounds) SK_OVERRIDE;
jvanverth8c27a182014-10-14 08:45:50 -070084
joshualitt570d2f82015-02-25 13:19:48 -080085 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt6e8cd962015-03-20 10:30:14 -070086 size_t textByteLength, RenderMode, const SkMatrix& viewMatrix,
87 const SkIRect& regionClipBounds);
joshualitt5531d512014-12-17 15:50:11 -080088 bool mapToFallbackContext(SkMatrix* inverse);
cdalton20b373c2014-12-01 08:38:55 -080089 void appendGlyph(const SkGlyph&, const SkPoint&);
cdaltonb85a0aa2014-07-21 15:32:44 -070090 void flush();
kkinnunenc6cb56f2014-06-24 00:12:27 -070091 void finish();
92
kkinnunenc6cb56f2014-06-24 00:12:27 -070093};
94
95#endif