blob: fb132c21b59425bd357f6c64a0b0db5a9802daff [file] [log] [blame]
joshualitt1d89e8d2015-04-01 12:40:54 -07001/*
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 "GrTextContext.h"
12
joshualitt374b2f72015-07-21 08:05:03 -070013#include "GrAtlasTextBlob.h"
joshualitt1acabf32015-12-10 09:10:10 -080014#include "GrDistanceFieldAdjustTable.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070015#include "GrGeometryProcessor.h"
halcanary33779752015-10-27 14:01:05 -070016#include "SkTextBlobRunIterator.h"
joshualitt1d89e8d2015-04-01 12:40:54 -070017
joshualitt79dfb2b2015-05-11 08:58:08 -070018#ifdef GR_TEST_UTILS
19#include "GrBatchTest.h"
20#endif
21
bsalomonabd30f52015-08-13 13:34:48 -070022class GrDrawBatch;
robertphillipsea461502015-05-26 11:38:03 -070023class GrDrawContext;
robertphillips2334fb62015-06-17 05:43:33 -070024class GrDrawTarget;
joshualitt1d89e8d2015-04-01 12:40:54 -070025class GrPipelineBuilder;
joshualittb7133be2015-04-08 09:08:31 -070026class GrTextBlobCache;
joshualitt6c2c2b02015-07-24 10:37:00 -070027class SkGlyph;
joshualitt1d89e8d2015-04-01 12:40:54 -070028
29/*
30 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs.
joshualitt1d89e8d2015-04-01 12:40:54 -070031 */
joshualittdbd35932015-04-02 09:19:04 -070032class GrAtlasTextContext : public GrTextContext {
joshualitt1d89e8d2015-04-01 12:40:54 -070033public:
robertphillipsf6703fa2015-09-01 05:36:47 -070034 static GrAtlasTextContext* Create(GrContext*, const SkSurfaceProps&);
joshualitt1d89e8d2015-04-01 12:40:54 -070035
joshualitt1d89e8d2015-04-01 12:40:54 -070036private:
robertphillipsf6703fa2015-09-01 05:36:47 -070037 GrAtlasTextContext(GrContext*, const SkSurfaceProps&);
joshualitt9bd2daf2015-04-17 09:30:06 -070038 ~GrAtlasTextContext() override {}
joshualitt1d89e8d2015-04-01 12:40:54 -070039
robertphillips6ee690e2015-12-02 08:57:50 -080040 bool canDraw(const SkPaint&, const SkMatrix& viewMatrix) override;
joshualitt1d89e8d2015-04-01 12:40:54 -070041
robertphillips433625e2015-12-04 06:58:16 -080042 void onDrawText(GrDrawContext*, const GrClip&, const GrPaint&, const SkPaint&,
joshualitt1d89e8d2015-04-01 12:40:54 -070043 const SkMatrix& viewMatrix, const char text[], size_t byteLength,
44 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) override;
robertphillips433625e2015-12-04 06:58:16 -080045 void onDrawPosText(GrDrawContext*, const GrClip&, const GrPaint&,
robertphillipsccb1b572015-05-27 11:02:55 -070046 const SkPaint&, const SkMatrix& viewMatrix,
joshualitt1d89e8d2015-04-01 12:40:54 -070047 const char text[], size_t byteLength,
48 const SkScalar pos[], int scalarsPerPosition,
49 const SkPoint& offset, const SkIRect& regionClipBounds) override;
robertphillips433625e2015-12-04 06:58:16 -080050 void drawTextBlob(GrDrawContext*, const GrClip&, const SkPaint&,
joshualitt1d89e8d2015-04-01 12:40:54 -070051 const SkMatrix& viewMatrix, const SkTextBlob*, SkScalar x, SkScalar y,
52 SkDrawFilter*, const SkIRect& clipBounds) override;
53
joshualitt374b2f72015-07-21 08:05:03 -070054 typedef GrAtlasTextBlob::Run Run;
joshualitt1d89e8d2015-04-01 12:40:54 -070055 typedef Run::SubRunInfo PerSubRunInfo;
56
joshualitt9bd2daf2015-04-17 09:30:06 -070057 inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatrix);
joshualitt374b2f72015-07-21 08:05:03 -070058 GrAtlasTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint,
jvanverth157e6482015-09-09 08:05:12 -070059 const SkMatrix& viewMatrix, SkPaint* dfPaint,
60 SkScalar* textRatio);
joshualitt6c2c2b02015-07-24 10:37:00 -070061 void bmpAppendGlyph(GrAtlasTextBlob*, int runIndex, const SkGlyph&, int left, int top,
robertphillips6ee690e2015-12-02 08:57:50 -080062 GrColor color, GrFontScaler*);
joshualitt6c2c2b02015-07-24 10:37:00 -070063 bool dfAppendGlyph(GrAtlasTextBlob*, int runIndex, const SkGlyph&, SkScalar sx, SkScalar sy,
robertphillips6ee690e2015-12-02 08:57:50 -080064 GrColor color, GrFontScaler*, SkScalar textRatio,
joshualitt9bd2daf2015-04-17 09:30:06 -070065 const SkMatrix& viewMatrix);
joshualitt9a27e632015-04-06 10:53:36 -070066
joshualitt9bd2daf2015-04-17 09:30:06 -070067 // A helper for drawing BitmapText in a run of distance fields
joshualitt374b2f72015-07-21 08:05:03 -070068 inline void fallbackDrawPosText(GrAtlasTextBlob*, int runIndex,
robertphillips6ee690e2015-12-02 08:57:50 -080069 const GrClip&, GrColor color,
joshualitt9bd2daf2015-04-17 09:30:06 -070070 const SkPaint&, const SkMatrix& viewMatrix,
71 const SkTDArray<char>& fallbackTxt,
72 const SkTDArray<SkScalar>& fallbackPos,
73 int scalarsPerPosition,
robertphillips6ee690e2015-12-02 08:57:50 -080074 const SkPoint& offset);
joshualitt9bd2daf2015-04-17 09:30:06 -070075
joshualitt374b2f72015-07-21 08:05:03 -070076 void internalDrawBMPText(GrAtlasTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
joshualitt9e36c1a2015-04-14 12:17:27 -070077 GrColor color, const SkMatrix& viewMatrix,
joshualitt1d89e8d2015-04-01 12:40:54 -070078 const char text[], size_t byteLength,
robertphillips6ee690e2015-12-02 08:57:50 -080079 SkScalar x, SkScalar y);
joshualitt374b2f72015-07-21 08:05:03 -070080 void internalDrawBMPPosText(GrAtlasTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
joshualitt9bd2daf2015-04-17 09:30:06 -070081 GrColor color, const SkMatrix& viewMatrix,
82 const char text[], size_t byteLength,
83 const SkScalar pos[], int scalarsPerPosition,
robertphillips6ee690e2015-12-02 08:57:50 -080084 const SkPoint& offset);
joshualitt9bd2daf2015-04-17 09:30:06 -070085
jvanverth157e6482015-09-09 08:05:12 -070086 void internalDrawDFText(GrAtlasTextBlob*, int runIndex, const SkPaint&,
joshualitt9bd2daf2015-04-17 09:30:06 -070087 GrColor color, const SkMatrix& viewMatrix,
88 const char text[], size_t byteLength,
robertphillips6ee690e2015-12-02 08:57:50 -080089 SkScalar x, SkScalar y,
joshualitt9bd2daf2015-04-17 09:30:06 -070090 SkScalar textRatio,
91 SkTDArray<char>* fallbackTxt,
92 SkTDArray<SkScalar>* fallbackPos,
93 SkPoint* offset, const SkPaint& origPaint);
jvanverth157e6482015-09-09 08:05:12 -070094 void internalDrawDFPosText(GrAtlasTextBlob*, int runIndex, const SkPaint&,
joshualitt9bd2daf2015-04-17 09:30:06 -070095 GrColor color, const SkMatrix& viewMatrix,
96 const char text[], size_t byteLength,
97 const SkScalar pos[], int scalarsPerPosition,
robertphillips6ee690e2015-12-02 08:57:50 -080098 const SkPoint& offset,
joshualitt9bd2daf2015-04-17 09:30:06 -070099 SkScalar textRatio,
100 SkTDArray<char>* fallbackTxt,
101 SkTDArray<SkScalar>* fallbackPos);
joshualitt1d89e8d2015-04-01 12:40:54 -0700102
103 // sets up the descriptor on the blob and returns a detached cache. Client must attach
joshualitt9e36c1a2015-04-14 12:17:27 -0700104 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
joshualitt9bd2daf2015-04-17 09:30:06 -0700105 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMatrix, bool noGamma);
joshualitt374b2f72015-07-21 08:05:03 -0700106 void regenerateTextBlob(GrAtlasTextBlob* bmp, const SkPaint& skPaint, GrColor,
joshualitt9e36c1a2015-04-14 12:17:27 -0700107 const SkMatrix& viewMatrix,
joshualitt1d89e8d2015-04-01 12:40:54 -0700108 const SkTextBlob* blob, SkScalar x, SkScalar y,
robertphillips6ee690e2015-12-02 08:57:50 -0800109 SkDrawFilter* drawFilter,
jvanverth0628a522015-08-18 07:44:22 -0700110 const GrClip&);
joshualitt9e36c1a2015-04-14 12:17:27 -0700111 inline static bool HasLCD(const SkTextBlob*);
joshualitt374b2f72015-07-21 08:05:03 -0700112 inline void initDistanceFieldPaint(GrAtlasTextBlob*, SkPaint*, SkScalar* textRatio,
joshualitt64c99cc2015-04-21 09:43:03 -0700113 const SkMatrix&);
joshualitt9bd2daf2015-04-17 09:30:06 -0700114
joshualitt79dfb2b2015-05-11 08:58:08 -0700115 // Test methods
116 // TODO this is really ugly. It'd be much nicer if positioning could be moved to batch
robertphillips6ee690e2015-12-02 08:57:50 -0800117 inline GrAtlasTextBlob* createDrawTextBlob(const GrClip&, const GrPaint&,
118 const SkPaint&, const SkMatrix& viewMatrix,
119 const char text[], size_t byteLength,
120 SkScalar x, SkScalar y,
121 const SkIRect& regionClipBounds);
122 inline GrAtlasTextBlob* createDrawPosTextBlob(const GrClip&, const GrPaint&,
123 const SkPaint&, const SkMatrix& viewMatrix,
124 const char text[], size_t byteLength,
125 const SkScalar pos[], int scalarsPerPosition,
126 const SkPoint& offset,
127 const SkIRect& regionClipBounds);
joshualitt2e2202e2015-12-10 11:22:08 -0800128 const GrDistanceFieldAdjustTable* dfAdjustTable() const { return fDistanceAdjustTable; }
joshualitt79dfb2b2015-05-11 08:58:08 -0700129
joshualitt1d89e8d2015-04-01 12:40:54 -0700130 GrBatchTextStrike* fCurrStrike;
joshualittb7133be2015-04-08 09:08:31 -0700131 GrTextBlobCache* fCache;
joshualitt1acabf32015-12-10 09:10:10 -0800132 SkAutoTUnref<const GrDistanceFieldAdjustTable> fDistanceAdjustTable;
joshualitt1d89e8d2015-04-01 12:40:54 -0700133
joshualitt79dfb2b2015-05-11 08:58:08 -0700134#ifdef GR_TEST_UTILS
bsalomonabd30f52015-08-13 13:34:48 -0700135 DRAW_BATCH_TEST_FRIEND(TextBlobBatch);
joshualitt79dfb2b2015-05-11 08:58:08 -0700136#endif
137
joshualitt1d89e8d2015-04-01 12:40:54 -0700138 typedef GrTextContext INHERITED;
139};
140
141#endif