1/*
2 * Copyright 2015 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 GrAtlasTextContext_DEFINED
9#define GrAtlasTextContext_DEFINED
10
11#include "GrAtlasTextBlob.h"
12#include "GrDistanceFieldAdjustTable.h"
13#include "GrGeometryProcessor.h"
14#include "SkTextBlobRunIterator.h"
15
16#ifdef GR_TEST_UTILS
17#include "GrBatchTest.h"
18#endif
19
20class GrDrawBatch;
21class GrDrawContext;
22class GrDrawTarget;
23class GrPipelineBuilder;
24class GrTextBlobCache;
25class SkGlyph;
26
27/*
28 * Renders text using some kind of an atlas, ie BitmapText or DistanceField text
29 */
30class GrAtlasTextContext {
31public:
32    static GrAtlasTextContext* Create();
33
34    bool canDraw(const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&,
35                 const GrShaderCaps&);
36    void drawText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&,
37                  const SkMatrix& viewMatrix, const SkSurfaceProps&, const char text[],
38                  size_t byteLength, SkScalar x, SkScalar y,
39                  const SkIRect& regionClipBounds);
40    void drawPosText(GrContext*, GrDrawContext*, const GrClip&, const GrPaint&,
41                     const SkPaint&, const SkMatrix& viewMatrix, const SkSurfaceProps&,
42                     const char text[], size_t byteLength,
43                     const SkScalar pos[], int scalarsPerPosition,
44                     const SkPoint& offset, const SkIRect& regionClipBounds);
45    void drawTextBlob(GrContext*, GrDrawContext*, const GrClip&, const SkPaint&,
46                      const SkMatrix& viewMatrix, const SkSurfaceProps&, const SkTextBlob*,
47                      SkScalar x, SkScalar y,
48                      SkDrawFilter*, const SkIRect& clipBounds);
49
50private:
51    GrAtlasTextContext();
52
53    // sets up the descriptor on the blob and returns a detached cache.  Client must attach
54    inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
55    static void RegenerateTextBlob(GrAtlasTextBlob* bmp,
56                                   GrBatchFontCache*,
57                                   const GrShaderCaps&,
58                                   const SkPaint& skPaint, GrColor,
59                                   const SkMatrix& viewMatrix,
60                                   const SkSurfaceProps&,
61                                   const SkTextBlob* blob, SkScalar x, SkScalar y,
62                                   SkDrawFilter* drawFilter);
63    inline static bool HasLCD(const SkTextBlob*);
64
65    static inline GrAtlasTextBlob* CreateDrawTextBlob(GrTextBlobCache*,
66                                                      GrBatchFontCache*, const GrShaderCaps&,
67                                                      const GrPaint&,
68                                                      const SkPaint&, const SkMatrix& viewMatrix,
69                                                      const SkSurfaceProps&,
70                                                      const char text[], size_t byteLength,
71                                                      SkScalar x, SkScalar y);
72    static inline GrAtlasTextBlob* CreateDrawPosTextBlob(GrTextBlobCache*, GrBatchFontCache*,
73                                                         const GrShaderCaps&,
74                                                         const GrPaint&,
75                                                         const SkPaint&, const SkMatrix& viewMatrix,
76                                                         const SkSurfaceProps&,
77                                                         const char text[], size_t byteLength,
78                                                         const SkScalar pos[],
79                                                         int scalarsPerPosition,
80                                                         const SkPoint& offset);
81    const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; }
82
83    SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
84
85#ifdef GR_TEST_UTILS
86    DRAW_BATCH_TEST_FRIEND(TextBlobBatch);
87#endif
88};
89
90#endif
91