Index: src/gpu/GrBitmapTextContext.h |
diff --git a/src/gpu/GrBitmapTextContext.h b/src/gpu/GrBitmapTextContext.h |
index e389f814806ac113e0e746e44d313bcfea055cb9..44ab6dfef3dbfef0976837ccb807e0b9e5bb5bd4 100644 |
--- a/src/gpu/GrBitmapTextContext.h |
+++ b/src/gpu/GrBitmapTextContext.h |
@@ -11,6 +11,127 @@ |
#include "GrTextContext.h" |
#include "GrGeometryProcessor.h" |
+#include "SkTHash.h" |
+ |
+class GrBatchTextStrike; |
+class GrPipelineBuilder; |
+ |
+/* |
+ * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. |
+ * TODO replace GrBitmapTextContext |
+ */ |
+class GrBitmapTextContextB : public GrTextContext { |
+public: |
+ static GrBitmapTextContextB* Create(GrContext*, SkGpuDevice*, const SkDeviceProperties&); |
+ |
+ virtual ~GrBitmapTextContextB(); |
+ |
+private: |
+ GrBitmapTextContextB(GrContext*, SkGpuDevice*, const SkDeviceProperties&); |
+ |
+ bool canDraw(const SkPaint& paint, const SkMatrix& viewMatrix) SK_OVERRIDE; |
+ |
+ void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength, |
+ SkScalar x, SkScalar y, const SkIRect& regionClipBounds) SK_OVERRIDE; |
+ void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
+ const SkMatrix& viewMatrix, |
+ const char text[], size_t byteLength, |
+ const SkScalar pos[], int scalarsPerPosition, |
+ const SkPoint& offset, const SkIRect& regionClipBounds) SK_OVERRIDE; |
+ void onDrawTextBlob(GrRenderTarget*, const GrClip&, const SkPaint&, |
+ const SkMatrix& viewMatrix, const SkTextBlob*, |
+ SkScalar x, SkScalar y, SkDrawFilter*, |
+ const SkIRect& clipBounds) SK_OVERRIDE; |
+ |
+ void init(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPaint&, |
+ const SkIRect& regionClipBounds); |
+ |
+ /* |
+ * A BitmapTextBlob contains a fully processed SkTextBlob, suitable for nearly immediate drawing |
+ * on the GPU. These are initially created with valid positions and colors, but invalid |
+ * texture coordinates. The BitmapTextBlob itself has a few Blob-wide properties, and also |
+ * consists of a number of runs. Runs inside a blob are flushed individually so they can be |
+ * reordered. |
+ * |
+ * The only thing, aside from a memcopy, required to flush a BitmapTextBlob is to ensure that |
Jvsquare
2015/03/27 15:07:29
Nit: "The only thing (aside from a memcopy) requir
joshualitt
2015/03/30 14:56:43
Acknowledged.
|
+ * the GrAtlas will not evict anything the Blob needs. |
+ * TODO this is currently a bug |
+ */ |
+ struct BitmapTextBlob : public SkRefCnt { |
+ // Each Run inside of the blob can have its texture coordinates regenerated if required. |
+ // To determine if regeneration is necessary, fAtlasGeneration is used. If there have been |
+ // any evictions inside of the atlas, then we will simply regenerate Runs. We could track |
+ // this at a more fine grained level, but its not clear if this is worth it, as evictions |
+ // should be fairly rare. |
+ // One additional point, each run can contain glyphs with any of the three mask formats. |
+ // We maintain separate arrays for each format type, and flush them separately. In practice |
+ // most of the time a run will have the same format type |
+ struct Run { |
+ Run() : fColor(GrColor_ILLEGAL) { fVertexBounds.setLargestInverted(); } |
+ struct PerFormatInfo { |
+ PerFormatInfo() : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) {} |
+ SkTDArray<unsigned char> fVertices; |
+ SkTDArray<GrGlyph::PackedID> fGlyphIDs; |
+ uint32_t fAtlasGeneration; |
+ }; |
+ SkAutoTUnref<const SkData> fDescriptor; |
+ SkAutoTUnref<SkTypeface> fTypeface; |
+ PerFormatInfo fInfos[kMaskFormatCount]; |
+ SkRect fVertexBounds; |
+ GrColor fColor; |
+ }; |
+ SkSTArray<1, Run, true> fRuns; |
+ struct BigGlyph { |
+ BigGlyph(const SkPath& path, int vx, int vy) : fPath(path), fVx(vx), fVy(vy) {} |
+ SkPath fPath; |
+ int fVx; |
+ int fVy; |
+ }; |
+ SkTArray<BigGlyph> fBigGlyphs; |
+ SkTextBlob* fBlob; |
+ SkMatrix fViewMatrix; |
+ SkScalar fX; |
+ SkScalar fY; |
+ SkPaint::Style fStyle; |
+ |
+ static uint32_t Hash(const uint32_t& key) { |
+ return SkChecksum::Mix(key); |
+ } |
+ }; |
+ |
+ void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top, |
+ GrFontScaler*, const SkIRect& clipRect); |
+ void flush(GrDrawTarget*, BitmapTextBlob*, int i, GrPipelineBuilder*, GrMaskFormat, |
Jvsquare
2015/03/27 15:07:29
It's not clear to me which is the main flush() her
joshualitt
2015/03/30 14:56:43
Acknowledged.
|
+ GrColor color, int paintAlpha); |
+ void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const GrPaint&, const GrClip&, |
+ const SkMatrix& viewMatrix, int paintAlpha); |
+ |
+ void internalDrawText(BitmapTextBlob*, int runIndex, const SkPaint&, |
+ const SkMatrix& viewMatrix, const char text[], size_t byteLength, |
+ SkScalar x, SkScalar y, const SkIRect& clipRect); |
+ void internalDrawPosText(BitmapTextBlob*, int runIndex, const SkPaint&, |
+ const SkMatrix& viewMatrix, |
+ const char text[], size_t byteLength, |
+ const SkScalar pos[], int scalarsPerPosition, |
+ const SkPoint& offset, const SkIRect& clipRect); |
+ |
+ static inline bool MustRegenerateBlob(const BitmapTextBlob&, const SkPaint&, |
+ const SkMatrix& viewMatrix, SkScalar x, SkScalar y); |
+ void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, const SkMatrix& viewMatrix, |
+ const SkTextBlob* blob, SkScalar x, SkScalar y, |
+ SkDrawFilter* drawFilter, const SkIRect& clipRect); |
+ |
+ GrBatchTextStrike* fCurrStrike; |
+ |
+ // TODO use real cache |
+ static void ClearCacheEntry(uint32_t key, BitmapTextBlob**); |
+ SkTHashMap<uint32_t, BitmapTextBlob*, BitmapTextBlob::Hash> fCache; |
+ |
+ friend class BitmapTextBatch; |
+ |
+ typedef GrTextContext INHERITED; |
+}; |
class GrTextStrike; |