blob: 95344dd39fbea0ee3e7c4095c828ae0c88bc1f63 [file] [log] [blame]
reed@google.comac10a2d2010-12-22 21:39:39 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2010 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.
reed@google.comac10a2d2010-12-22 21:39:39 +00006 */
7
reed@google.comac10a2d2010-12-22 21:39:39 +00008#ifndef GrTextContext_DEFINED
9#define GrTextContext_DEFINED
10
11#include "GrGlyph.h"
tomhudson@google.com375ff852012-06-29 18:37:57 +000012#include "GrPaint.h"
commit-bot@chromium.orge8612d92014-01-28 22:02:07 +000013#include "SkDeviceProperties.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000014
commit-bot@chromium.orgcc40f062014-01-24 14:38:27 +000015#include "SkPostConfig.h"
16
reed@google.comac10a2d2010-12-22 21:39:39 +000017class GrContext;
tomhudson@google.com375ff852012-06-29 18:37:57 +000018class GrDrawTarget;
jvanverth@google.comc7a40fa2013-10-16 18:15:34 +000019class GrFontScaler;
reed@google.comac10a2d2010-12-22 21:39:39 +000020
jvanverth@google.comc7a40fa2013-10-16 18:15:34 +000021/*
22 * This class wraps the state for a single text render
23 */
tomhudson@google.com375ff852012-06-29 18:37:57 +000024class GrTextContext {
bsalomon@google.comf4a9c822012-03-16 14:02:46 +000025public:
jvanverth8c27a182014-10-14 08:45:50 -070026 virtual ~GrTextContext();
jvanverth0fedb192014-10-08 09:07:27 -070027
jvanverth8c27a182014-10-14 08:45:50 -070028 bool drawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
29 SkScalar x, SkScalar y);
30 bool drawPosText(const GrPaint&, const SkPaint&,
31 const char text[], size_t byteLength,
32 const SkScalar pos[], int scalarsPerPosition,
33 const SkPoint& offset);
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000034
jvanverth@google.comc7a40fa2013-10-16 18:15:34 +000035protected:
jvanverth8c27a182014-10-14 08:45:50 -070036 GrTextContext* fFallbackTextContext;
commit-bot@chromium.orge8612d92014-01-28 22:02:07 +000037 GrContext* fContext;
commit-bot@chromium.orgcbbc4812014-01-30 22:05:47 +000038 SkDeviceProperties fDeviceProperties;
39
40 GrDrawTarget* fDrawTarget;
41 SkIRect fClipRect;
commit-bot@chromium.orge8612d92014-01-28 22:02:07 +000042 GrPaint fPaint;
43 SkPaint fSkPaint;
jvanverth0fedb192014-10-08 09:07:27 -070044
45 GrTextContext(GrContext*, const SkDeviceProperties&);
46
jvanverth8c27a182014-10-14 08:45:50 -070047 virtual bool canDraw(const SkPaint& paint) = 0;
48
49 virtual void onDrawText(const GrPaint&, const SkPaint&, const char text[], size_t byteLength,
50 SkScalar x, SkScalar y) = 0;
51 virtual void onDrawPosText(const GrPaint&, const SkPaint&,
52 const char text[], size_t byteLength,
53 const SkScalar pos[], int scalarsPerPosition,
54 const SkPoint& offset) = 0;
55
jvanverth0fedb192014-10-08 09:07:27 -070056 void init(const GrPaint&, const SkPaint&);
57 void finish() { fDrawTarget = NULL; }
58
59 static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
60 static void MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
61 const char text[], size_t byteLength, SkVector* stopVector);
reed@google.comac10a2d2010-12-22 21:39:39 +000062};
63
64#endif