Chromium Code Reviews| 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 { | |
|
bsalomon
2015/03/26 17:06:56
Comment on what this encapsulates? I get why it is
joshualitt
2015/03/26 18:21:43
Acknowledged.
| |
| 51 struct Run { | |
| 52 Run() : fColor(GrColor_ILLEGAL) { fVertexBounds.setLargestInverted() ; } | |
| 53 struct TextInfo { | |
|
bsalomon
2015/03/26 17:06:56
"PerFormatInfo"?
Comment somewhere that we consid
joshualitt
2015/03/26 18:21:43
Acknowledged.
| |
| 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 SkSTArray<1, 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*, const SkIRect& clipRect); | |
| 86 void flush(GrDrawTarget*, BitmapTextBlob*, int i, GrPipelineBuilder*, GrMask Format, | |
| 87 GrColor color, int paintAlpha); | |
| 88 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const GrPaint&, const GrClip&, | |
| 89 const SkMatrix& viewMatrix, int paintAlpha); | |
| 90 | |
| 91 void internalDrawText(BitmapTextBlob*, int runIndex, const SkPaint&, | |
| 92 const SkMatrix& viewMatrix, const char text[], size_t byteLength, | |
| 93 SkScalar x, SkScalar y, const SkIRect& clipRect); | |
| 94 void internalDrawPosText(BitmapTextBlob*, int runIndex, const SkPaint&, | |
| 95 const SkMatrix& viewMatrix, | |
| 96 const char text[], size_t byteLength, | |
| 97 const SkScalar pos[], int scalarsPerPosition, | |
| 98 const SkPoint& offset, const SkIRect& clipRect); | |
| 99 | |
| 100 static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, | |
| 101 const SkMatrix& viewMatrix, SkScalar x , SkScalar y); | |
| 102 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const S kMatrix& viewMatrix, | |
| 103 const SkTextBlob* blob, SkScalar x, SkScalar y, | |
| 104 SkDrawFilter* drawFilter, const SkIRect& clipRect); | |
| 105 | |
| 106 GrBatchTextStrike* fStrike; | |
|
bsalomon
2015/03/26 17:06:56
Is this a current strike that is often updated? fC
joshualitt
2015/03/26 18:21:43
I only use this to avoid getting the strike multip
| |
| 107 | |
| 108 // TODO use real cache | |
| 109 static void ClearCacheEntry(uint32_t key, BitmapTextBlob**); | |
| 110 SkTHashMap<uint32_t, BitmapTextBlob*, BitmapTextBlob::Hash> fCache; | |
| 111 | |
| 112 friend class BitmapTextBatch; | |
| 113 | |
| 114 typedef GrTextContext INHERITED; | |
| 115 }; | |
| 14 | 116 |
| 15 class GrTextStrike; | 117 class GrTextStrike; |
| 16 | 118 |
| 17 /* | 119 /* |
| 18 * This class implements GrTextContext using standard bitmap fonts | 120 * This class implements GrTextContext using standard bitmap fonts |
| 19 */ | 121 */ |
| 20 class GrBitmapTextContext : public GrTextContext { | 122 class GrBitmapTextContext : public GrTextContext { |
| 21 public: | 123 public: |
| 22 static GrBitmapTextContext* Create(GrContext*, SkGpuDevice*, const SkDevice Properties&); | 124 static GrBitmapTextContext* Create(GrContext*, SkGpuDevice*, const SkDevice Properties&); |
| 23 | 125 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 52 | 154 |
| 53 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, | 155 void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
| 54 const SkIRect& regionClipBounds); | 156 const SkIRect& regionClipBounds); |
| 55 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler* ); | 157 void appendGlyph(GrGlyph::PackedID, SkFixed left, SkFixed top, GrFontScaler* ); |
| 56 bool uploadGlyph(GrGlyph*, GrFontScaler*); | 158 bool uploadGlyph(GrGlyph*, GrFontScaler*); |
| 57 void flush(); // automatically called by destructor | 159 void flush(); // automatically called by destructor |
| 58 void finish(); | 160 void finish(); |
| 59 }; | 161 }; |
| 60 | 162 |
| 61 #endif | 163 #endif |
| OLD | NEW |