• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * 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.
6  */
7 
8 #ifndef GrTextContext_DEFINED
9 #define GrTextContext_DEFINED
10 
11 #include "GrClip.h"
12 #include "GrGlyph.h"
13 #include "GrPaint.h"
14 #include "SkDeviceProperties.h"
15 #include "SkPostConfig.h"
16 
17 class GrClip;
18 class GrContext;
19 class GrDrawTarget;
20 class GrFontScaler;
21 class SkDrawFilter;
22 class SkGpuDevice;
23 class SkTextBlob;
24 
25 /*
26  * This class wraps the state for a single text render
27  */
28 class GrTextContext {
29 public:
30     virtual ~GrTextContext();
31 
32     void drawText(GrRenderTarget* rt, const GrClip&,  const GrPaint&, const SkPaint&,
33                   const SkMatrix& viewMatrix, const char text[], size_t byteLength, SkScalar x,
34                   SkScalar y, const SkIRect& clipBounds);
35     void drawPosText(GrRenderTarget* rt, const GrClip&, const GrPaint&, const SkPaint&,
36                      const SkMatrix& viewMatrix,
37                      const char text[], size_t byteLength,
38                      const SkScalar pos[], int scalarsPerPosition,
39                      const SkPoint& offset, const SkIRect& clipBounds);
40     virtual void drawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&,
41                               const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y,
42                               SkDrawFilter*, const SkIRect& clipBounds);
43 
44 protected:
45     GrTextContext*                 fFallbackTextContext;
46     GrContext*                     fContext;
47     // TODO we probably don't really need to store a back pointer to the owning SkGpuDevice, except
48     // we need to be able to call drawPath on it in the event no other text context can draw the
49     // text.  We might be able to move this logic to context though.  This is unreffed because
50     // GrTextContext is completely owned by SkGpuDevice
51     SkGpuDevice*                   fGpuDevice;
52     SkDeviceProperties             fDeviceProperties;
53 
54     SkAutoTUnref<GrRenderTarget>   fRenderTarget;
55     GrClip                         fClip;
56     GrDrawTarget*                  fDrawTarget;
57     SkIRect                        fClipRect;
58     SkIRect                        fRegionClipBounds;
59     GrPaint                        fPaint;
60     SkPaint                        fSkPaint;
61 
62     GrTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&);
63 
64     virtual bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
65                          const SkPaint&, const SkMatrix& viewMatrix) = 0;
66 
67     virtual void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
68                             const SkMatrix& viewMatrix, const char text[], size_t byteLength,
69                             SkScalar x, SkScalar y, const SkIRect& clipBounds) = 0;
70     virtual void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
71                                const SkMatrix& viewMatrix,
72                                const char text[], size_t byteLength,
73                                const SkScalar pos[], int scalarsPerPosition,
74                                const SkPoint& offset, const SkIRect& clipBounds) = 0;
75 
76     void drawTextAsPath(const SkPaint& origPaint, const SkMatrix& viewMatrix,
77                         const char text[], size_t byteLength, SkScalar x, SkScalar y,
78                         const SkIRect& clipBounds);
79     void drawPosTextAsPath(const SkPaint& origPaint, const SkMatrix& viewMatrix,
80                            const char text[], size_t byteLength,
81                            const SkScalar pos[], int scalarsPerPosition,
82                            const SkPoint& offset, const SkIRect& clipBounds);
83 
84     void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&,
85               const SkIRect& regionClipBounds);
finish()86     void finish() { fDrawTarget = NULL; }
87 
88     static GrFontScaler* GetGrFontScaler(SkGlyphCache* cache);
89     // sets extent in stopVector and returns glyph count
90     static int MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheProc,
91                            const char text[], size_t byteLength, SkVector* stopVector);
92 
93     friend class BitmapTextBatch;
94 };
95 
96 #endif
97