| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2014 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 GrStencilAndCoverTextContext_DEFINED | |
| 9 #define GrStencilAndCoverTextContext_DEFINED | |
| 10 | |
| 11 #include "GrTextContext.h" | |
| 12 #include "GrDrawTarget.h" | |
| 13 #include "GrStrokeInfo.h" | |
| 14 #include "SkTHash.h" | |
| 15 #include "SkTInternalLList.h" | |
| 16 #include "SkTLList.h" | |
| 17 #include "batches/GrDrawPathBatch.h" | |
| 18 | |
| 19 class GrTextStrike; | |
| 20 class GrPath; | |
| 21 class SkSurfaceProps; | |
| 22 | |
| 23 /* | |
| 24 * This class implements text rendering using stencil and cover path rendering | |
| 25 * (by the means of GrDrawTarget::drawPath). | |
| 26 * This class exposes the functionality through GrTextContext interface. | |
| 27 */ | |
| 28 class GrStencilAndCoverTextContext : public GrTextContext { | |
| 29 public: | |
| 30 static GrStencilAndCoverTextContext* Create(GrContext*, const SkSurfaceProps
&); | |
| 31 | |
| 32 virtual ~GrStencilAndCoverTextContext(); | |
| 33 | |
| 34 private: | |
| 35 GrStencilAndCoverTextContext(GrContext*, const SkSurfaceProps&); | |
| 36 | |
| 37 bool canDraw(const SkPaint& skPaint, const SkMatrix&) override { | |
| 38 return this->internalCanDraw(skPaint); | |
| 39 } | |
| 40 | |
| 41 bool internalCanDraw(const SkPaint&); | |
| 42 | |
| 43 void onDrawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint
&, | |
| 44 const SkMatrix& viewMatrix, | |
| 45 const char text[], size_t byteLength, | |
| 46 SkScalar x, SkScalar y, const SkIRect& clipBounds) override; | |
| 47 void onDrawPosText(GrDrawContext*, | |
| 48 const GrClip&, const GrPaint&, const SkPaint&, | |
| 49 const SkMatrix& viewMatrix, | |
| 50 const char text[], size_t byteLength, | |
| 51 const SkScalar pos[], int scalarsPerPosition, | |
| 52 const SkPoint& offset, const SkIRect& clipBounds) overrid
e; | |
| 53 void drawTextBlob(GrDrawContext*, const GrClip&, const SkPaint&, | |
| 54 const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x,
SkScalar y, | |
| 55 SkDrawFilter*, const SkIRect& clipBounds) override; | |
| 56 | |
| 57 class FallbackBlobBuilder; | |
| 58 | |
| 59 class TextRun { | |
| 60 public: | |
| 61 TextRun(const SkPaint& fontAndStroke); | |
| 62 ~TextRun(); | |
| 63 | |
| 64 void setText(const char text[], size_t byteLength, SkScalar x, SkScalar
y); | |
| 65 | |
| 66 void setPosText(const char text[], size_t byteLength, const SkScalar pos
[], | |
| 67 int scalarsPerPosition, const SkPoint& offset); | |
| 68 | |
| 69 void draw(GrContext*, GrDrawContext*, GrPipelineBuilder*, GrColor, const
SkMatrix&, | |
| 70 SkScalar x, SkScalar y, const SkIRect& clipBounds, | |
| 71 GrTextContext* fallbackTextContext, const SkPaint& originalSkP
aint) const; | |
| 72 | |
| 73 void releaseGlyphCache() const; | |
| 74 | |
| 75 size_t computeSizeInCache() const; | |
| 76 | |
| 77 private: | |
| 78 typedef GrDrawPathRangeBatch::InstanceData InstanceData; | |
| 79 | |
| 80 SkGlyphCache* getGlyphCache() const; | |
| 81 GrPathRange* createGlyphs(GrContext*) const; | |
| 82 void appendGlyph(const SkGlyph&, const SkPoint&, FallbackBlobBuilder*); | |
| 83 | |
| 84 GrStrokeInfo fStroke; | |
| 85 SkPaint fFont; | |
| 86 SkScalar fTextRatio; | |
| 87 float fTextInverseRatio; | |
| 88 bool fUsingRawGlyphPaths; | |
| 89 GrUniqueKey fGlyphPathsKey; | |
| 90 int fTotalGlyphCount; | |
| 91 SkAutoTUnref<InstanceData> fInstanceData; | |
| 92 int fFallbackGlyphCount; | |
| 93 SkAutoTUnref<const SkTextBlob> fFallbackTextBlob; | |
| 94 mutable SkGlyphCache* fDetachedGlyphCache; | |
| 95 mutable uint32_t fLastDrawnGlyphsID; | |
| 96 }; | |
| 97 | |
| 98 // Text blobs/caches. | |
| 99 | |
| 100 class TextBlob : public SkTLList<TextRun, 1> { | |
| 101 public: | |
| 102 typedef SkTArray<uint32_t, true> Key; | |
| 103 | |
| 104 static const Key& GetKey(const TextBlob* blob) { return blob->key(); } | |
| 105 | |
| 106 static uint32_t Hash(const Key& key) { | |
| 107 SkASSERT(key.count() > 1); // 1-length keys should be using the blob
-id hash map. | |
| 108 return SkChecksum::Murmur3(key.begin(), sizeof(uint32_t) * key.count
()); | |
| 109 } | |
| 110 | |
| 111 TextBlob(uint32_t blobId, const SkTextBlob* skBlob, const SkPaint& skPai
nt) | |
| 112 : fKey(&blobId, 1) { this->init(skBlob, skPaint); } | |
| 113 | |
| 114 TextBlob(const Key& key, const SkTextBlob* skBlob, const SkPaint& skPain
t) | |
| 115 : fKey(key) { | |
| 116 // 1-length keys are unterstood to be the blob id and must use the o
ther constructor. | |
| 117 SkASSERT(fKey.count() > 1); | |
| 118 this->init(skBlob, skPaint); | |
| 119 } | |
| 120 | |
| 121 const Key& key() const { return fKey; } | |
| 122 | |
| 123 size_t cpuMemorySize() const { return fCpuMemorySize; } | |
| 124 | |
| 125 private: | |
| 126 void init(const SkTextBlob*, const SkPaint&); | |
| 127 | |
| 128 const SkSTArray<1, uint32_t, true> fKey; | |
| 129 size_t fCpuMemorySize; | |
| 130 | |
| 131 SK_DECLARE_INTERNAL_LLIST_INTERFACE(TextBlob); | |
| 132 }; | |
| 133 | |
| 134 const TextBlob& findOrCreateTextBlob(const SkTextBlob*, const SkPaint&); | |
| 135 void purgeToFit(const TextBlob&); | |
| 136 | |
| 137 SkTHashMap<uint32_t, TextBlob*> fBlobIdCache; | |
| 138 SkTHashTable<TextBlob*, const TextBlob::Key&, TextBlob> fBlobKeyCache; | |
| 139 SkTInternalLList<TextBlob> fLRUList; | |
| 140 size_t fCacheSize; | |
| 141 | |
| 142 typedef GrTextContext INHERITED; | |
| 143 }; | |
| 144 | |
| 145 #endif | |
| OLD | NEW |