OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrBitmapTextContext_DEFINED | 8 #ifndef GrBitmapTextContext_DEFINED |
9 #define GrBitmapTextContext_DEFINED | 9 #define GrBitmapTextContext_DEFINED |
10 | 10 |
11 #include "GrTextContext.h" | 11 #include "GrTextContext.h" |
12 | 12 |
13 #include "GrGeometryProcessor.h" | 13 #include "GrGeometryProcessor.h" |
| 14 #include "SkTHash.h" |
| 15 |
| 16 class GrBatchTextStrike; |
| 17 class GrPipelineBuilder; |
| 18 |
| 19 /* |
| 20 * This class implements GrTextContext using standard bitmap fonts, and can also
process textblobs. |
| 21 * TODO replace GrBitmapTextContext |
| 22 */ |
| 23 class GrBitmapTextContextB : public GrTextContext { |
| 24 public: |
| 25 static GrBitmapTextContextB* Create(GrContext*, SkGpuDevice*, const SkDevice
Properties&); |
| 26 |
| 27 virtual ~GrBitmapTextContextB(); |
| 28 |
| 29 private: |
| 30 GrBitmapTextContextB(GrContext*, SkGpuDevice*, const SkDeviceProperties&); |
| 31 |
| 32 bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE; |
| 33 |
| 34 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain
t&, |
| 35 const SkMatrix& viewMatrix, const char text[], size_t byteLe
ngth, |
| 36 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) SK_
OVERRIDE; |
| 37 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP
aint&, |
| 38 const SkMatrix& viewMatrix, |
| 39 const char text[], size_t byteLength, |
| 40 const SkScalar pos[], int scalarsPerPosition, |
| 41 const SkPoint& offset, const SkIRect& regionClipBounds) S
K_OVERRIDE; |
| 42 void onDrawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&, |
| 43 const SkMatrix& viewMatrix, const SkTextBlob*, |
| 44 SkScalar x, SkScalar y, SkDrawFilter*, |
| 45 const SkIRect& clipBounds) SK_OVERRIDE; |
| 46 |
| 47 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 48 const SkIRect& regionClipBounds); |
| 49 |
| 50 struct BitmapTextBlob : public SkRefCnt { |
| 51 struct Run : public SkRefCnt { |
| 52 Run() : fColor(GrColor_ILLEGAL) { fVertexBounds.setLargestInverted()
; } |
| 53 struct TextInfo { |
| 54 TextInfo() : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGenerat
ion) {} |
| 55 SkTDArray<unsigned char> fVertices; |
| 56 SkTDArray<GrGlyph::PackedID> fGlyphIDs; |
| 57 uint32_t fAtlasGeneration; |
| 58 }; |
| 59 SkAutoTUnref<const SkData> fDescriptor; |
| 60 SkAutoTUnref<SkTypeface> fTypeface; |
| 61 TextInfo fInfos[kMaskFormatCount]; |
| 62 SkRect fVertexBounds; |
| 63 GrColor fColor; |
| 64 }; |
| 65 SkTArray<Run, true> fRuns; |
| 66 struct BigGlyph { |
| 67 BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx),
fVy(vy) {} |
| 68 SkPath fPath; |
| 69 int fVx; |
| 70 int fVy; |
| 71 }; |
| 72 SkTArray<BigGlyph> fBigGlyphs; |
| 73 SkTextBlob* fBlob; |
| 74 SkMatrix fViewMatrix; |
| 75 SkScalar fX; |
| 76 SkScalar fY; |
| 77 SkPaint::Style fStyle; |
| 78 |
| 79 static uint32_t Hash(const uint32_t& key) { |
| 80 return SkChecksum::Mix(key); |
| 81 } |
| 82 }; |
| 83 |
| 84 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left,
int top, |
| 85 GrFontScaler*); |
| 86 void flush(BitmapTextBlob*, int i, GrPipelineBuilder*, GrMaskFormat); |
| 87 void flush(BitmapTextBlob*); // automatically called by dest
ructor |
| 88 void finish(BitmapTextBlob*); |
| 89 |
| 90 void internalDrawText(BitmapTextBlob*, int runIndex, GrRenderTarget*, const
GrClip&, |
| 91 const GrPaint&, const SkPaint&, |
| 92 const SkMatrix& viewMatrix, const char text[], size_t
byteLength, |
| 93 SkScalar x, SkScalar y, const SkIRect& regionClipBound
s); |
| 94 void internalDrawPosText(BitmapTextBlob*, int runIndex, GrRenderTarget*, con
st GrClip&, |
| 95 const GrPaint&, const SkPaint&, const SkMatrix& vie
wMatrix, |
| 96 const char text[], size_t byteLength, |
| 97 const SkScalar pos[], int scalarsPerPosition, |
| 98 const SkPoint& offset, const SkIRect& regionClipBou
nds); |
| 99 |
| 100 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, |
| 101 const SkMatrix& viewMatrix, SkScalar x
, SkScalar y); |
| 102 void regenerateTextBlob(BitmapTextBlob* bmp, GrRenderTarget* rt, const GrCli
p& clip, |
| 103 const SkPaint& skPaint, const SkMatrix& viewMatrix, |
| 104 const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 105 SkDrawFilter* drawFilter, const SkIRect& clipBounds)
; |
| 106 |
| 107 GrBatchTextStrike* fStrike; |
| 108 |
| 109 // TODO use real cache |
| 110 static void ClearCacheEntry(uint32_t key, BitmapTextBlob**); |
| 111 SkTHashMap<uint32_t, BitmapTextBlob*, BitmapTextBlob::Hash> fCache; |
| 112 |
| 113 friend class BitmapTextBatch; |
| 114 |
| 115 typedef GrTextContext INHERITED; |
| 116 }; |
14 | 117 |
15 class GrTextStrike; | 118 class GrTextStrike; |
16 | 119 |
17 /* | 120 /* |
18 * This class implements GrTextContext using standard bitmap fonts | 121 * This class implements GrTextContext using standard bitmap fonts |
19 */ | 122 */ |
20 class GrBitmapTextContext : public GrTextContext { | 123 class GrBitmapTextContext : public GrTextContext { |
21 public: | 124 public: |
22 static GrBitmapTextContext* Create(GrContext*, SkGpuDevice*, const SkDevice
Properties&); | 125 static GrBitmapTextContext* Create(GrContext*, SkGpuDevice*, const SkDevice
Properties&); |
23 | 126 |
(...skipping 28 matching lines...) Expand all Loading... |
52 | 155 |
53 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, | 156 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
54 const SkIRect& regionClipBounds); | 157 const SkIRect& regionClipBounds); |
55 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*
); | 158 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler*
); |
56 bool uploadGlyph(GrGlyph*, GrFontScaler*); | 159 bool uploadGlyph(GrGlyph*, GrFontScaler*); |
57 void flush(); // automatically called by destructor | 160 void flush(); // automatically called by destructor |
58 void finish(); | 161 void finish(); |
59 }; | 162 }; |
60 | 163 |
61 #endif | 164 #endif |
OLD | NEW |