Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: src/gpu/GrAtlasTextContext.h

Issue 1082843002: Initial CL to add distance field support to GrAtlasTextContext (Closed) Base URL: https://skia.googlesource.com/skia.git@attryst2
Patch Set: windows warnigns Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 GrAtlasTextContext_DEFINED 8 #ifndef GrAtlasTextContext_DEFINED
9 #define GrAtlasTextContext_DEFINED 9 #define GrAtlasTextContext_DEFINED
10 10
(...skipping 10 matching lines...) Expand all
21 class GrBatchTextStrike; 21 class GrBatchTextStrike;
22 class GrPipelineBuilder; 22 class GrPipelineBuilder;
23 class GrTextBlobCache; 23 class GrTextBlobCache;
24 24
25 /* 25 /*
26 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs. 26 * This class implements GrTextContext using standard bitmap fonts, and can also process textblobs.
27 * TODO replace GrBitmapTextContext 27 * TODO replace GrBitmapTextContext
28 */ 28 */
29 class GrAtlasTextContext : public GrTextContext { 29 class GrAtlasTextContext : public GrTextContext {
30 public: 30 public:
31 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr operties&); 31 static GrAtlasTextContext* Create(GrContext*, SkGpuDevice*, const SkDevicePr operties&,
32 bool enableDistanceFields);
32 33
33 private: 34 private:
34 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&); 35 GrAtlasTextContext(GrContext*, SkGpuDevice*, const SkDeviceProperties&,
36 bool enableDistanceFields);
37 ~GrAtlasTextContext() override {}
35 38
36 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&, 39 bool canDraw(const GrRenderTarget*, const GrClip&, const GrPaint&,
37 const SkPaint&, const SkMatrix& viewMatrix) override; 40 const SkPaint&, const SkMatrix& viewMatrix) override;
38 41
39 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain t&, 42 void onDrawText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkPain t&,
40 const SkMatrix& viewMatrix, const char text[], size_t byteLe ngth, 43 const SkMatrix& viewMatrix, const char text[], size_t byteLe ngth,
41 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove rride; 44 SkScalar x, SkScalar y, const SkIRect& regionClipBounds) ove rride;
42 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP aint&, 45 void onDrawPosText(GrRenderTarget*, const GrClip&, const GrPaint&, const SkP aint&,
43 const SkMatrix& viewMatrix, 46 const SkMatrix& viewMatrix,
44 const char text[], size_t byteLength, 47 const char text[], size_t byteLength,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 , fInitialized(false) 94 , fInitialized(false)
92 , fDrawAsPaths(false) { 95 , fDrawAsPaths(false) {
93 fVertexBounds.setLargestInverted(); 96 fVertexBounds.setLargestInverted();
94 } 97 }
95 struct SubRunInfo { 98 struct SubRunInfo {
96 SubRunInfo() 99 SubRunInfo()
97 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration) 100 : fAtlasGeneration(GrBatchAtlas::kInvalidAtlasGeneration)
98 , fGlyphStartIndex(0) 101 , fGlyphStartIndex(0)
99 , fGlyphEndIndex(0) 102 , fGlyphEndIndex(0)
100 , fVertexStartIndex(0) 103 , fVertexStartIndex(0)
101 , fVertexEndIndex(0) {} 104 , fVertexEndIndex(0)
105 , fDrawAsDistanceFields(false) {}
102 GrMaskFormat fMaskFormat; 106 GrMaskFormat fMaskFormat;
103 uint64_t fAtlasGeneration; 107 uint64_t fAtlasGeneration;
104 uint32_t fGlyphStartIndex; 108 uint32_t fGlyphStartIndex;
105 uint32_t fGlyphEndIndex; 109 uint32_t fGlyphEndIndex;
106 size_t fVertexStartIndex; 110 size_t fVertexStartIndex;
107 size_t fVertexEndIndex; 111 size_t fVertexEndIndex;
108 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken; 112 GrBatchAtlas::BulkUseTokenUpdater fBulkUseToken;
113
114 // distance field properties
115 bool fDrawAsDistanceFields;
116 bool fUseLCDText;
109 }; 117 };
110 118
111 class SubRunInfoArray { 119 class SubRunInfoArray {
112 public: 120 public:
113 SubRunInfoArray() 121 SubRunInfoArray()
114 : fSubRunCount(0) 122 : fSubRunCount(0)
115 , fSubRunAllocation(kMinSubRuns) { 123 , fSubRunAllocation(kMinSubRuns) {
116 fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get()); 124 fPtr = reinterpret_cast<SubRunInfo*>(fSubRunStorage.get());
117 this->push_back(); 125 this->push_back();
118 } 126 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 228
221 void* operator new(size_t, void* p) { return p; } 229 void* operator new(size_t, void* p) { return p; }
222 void operator delete(void* target, void* placement) { 230 void operator delete(void* target, void* placement) {
223 ::operator delete(target, placement); 231 ::operator delete(target, placement);
224 } 232 }
225 }; 233 };
226 234
227 typedef BitmapTextBlob::Run Run; 235 typedef BitmapTextBlob::Run Run;
228 typedef Run::SubRunInfo PerSubRunInfo; 236 typedef Run::SubRunInfo PerSubRunInfo;
229 237
230 void appendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int left, int top, 238 inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatr ix);
231 GrColor color, GrFontScaler*, const SkIRect& clipRect); 239 BitmapTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint,
240 const SkMatrix& viewMatrix, SkGlyphCache** cache ,
241 SkPaint* dfPaint, SkScalar* textRatio);
242 void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int le ft, int top,
243 GrColor color, GrFontScaler*, const SkIRect& clipRect);
244 bool dfAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, SkScala r sx, SkScalar sy,
245 GrColor color, GrFontScaler*, const SkIRect& clipRect, Sk Scalar textRatio,
246 const SkMatrix& viewMatrix);
247 inline void appendGlyphPath(BitmapTextBlob* blob, GrGlyph* glyph,
248 GrFontScaler* scaler, int x, int y);
249 inline void appendGlyphCommon(BitmapTextBlob*, Run*, Run::SubRunInfo*,
250 const SkRect& positions, GrColor color,
251 size_t vertexStride, bool useVertexColor,
252 GrGlyph::PackedID);
232 253
233 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&, SkDrawFilter*, 254 inline void flushRunAsPaths(const SkTextBlob::RunIterator&, const SkPaint&, SkDrawFilter*,
234 const SkMatrix& viewMatrix, const SkIRect& clipB ounds, SkScalar x, 255 const SkMatrix& viewMatrix, const SkIRect& clipB ounds, SkScalar x,
235 SkScalar y); 256 SkScalar y);
236 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor, 257 inline void flushRun(GrDrawTarget*, GrPipelineBuilder*, BitmapTextBlob*, int run, GrColor,
237 uint8_t paintAlpha, SkScalar transX, SkScalar transY); 258 SkScalar transX, SkScalar transY, const SkPaint&);
238 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt, 259 inline void flushBigGlyphs(BitmapTextBlob* cacheBlob, GrRenderTarget* rt,
239 const GrPaint& grPaint, const GrClip& clip, 260 const GrPaint& grPaint, const GrClip& clip,
240 SkScalar transX, SkScalar transY); 261 SkScalar transX, SkScalar transY);
241 262
242 // We have to flush SkTextBlobs differently from drawText / drawPosText 263 // We have to flush SkTextBlobs differently from drawText / drawPosText
243 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget *, const SkPaint&, 264 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget *, const SkPaint&,
244 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie wMatrix, 265 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie wMatrix,
245 const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar trans X, SkScalar transY); 266 const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar trans X, SkScalar transY);
246 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, 267 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&,
247 const GrPaint&, const GrClip&, const SkMatrix& viewMatrix); 268 const GrPaint&, const GrClip&);
248 269
249 void internalDrawText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const Sk Paint&, 270 // A helper for drawing BitmapText in a run of distance fields
250 GrColor color, const SkMatrix& viewMatrix, 271 inline void fallbackDrawPosText(GrRenderTarget*, const GrClip&,
251 const char text[], size_t byteLength, 272 const GrPaint&,
252 SkScalar x, SkScalar y, const SkIRect& clipRect); 273 const SkPaint&, const SkMatrix& viewMatrix,
253 void internalDrawPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, 274 const SkTDArray<char>& fallbackTxt,
275 const SkTDArray<SkScalar>& fallbackPos,
276 int scalarsPerPosition,
277 const SkPoint& offset,
278 const SkIRect& clipRect);
279
280 void internalDrawBMPText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
254 GrColor color, const SkMatrix& viewMatrix, 281 GrColor color, const SkMatrix& viewMatrix,
255 const char text[], size_t byteLength, 282 const char text[], size_t byteLength,
256 const SkScalar pos[], int scalarsPerPosition, 283 SkScalar x, SkScalar y, const SkIRect& clipRect);
257 const SkPoint& offset, const SkIRect& clipRect); 284 void internalDrawBMPPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, co nst SkPaint&,
285 GrColor color, const SkMatrix& viewMatrix,
286 const char text[], size_t byteLength,
287 const SkScalar pos[], int scalarsPerPosition,
288 const SkPoint& offset, const SkIRect& clipRect);
289
290 void internalDrawDFText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
291 GrColor color, const SkMatrix& viewMatrix,
292 const char text[], size_t byteLength,
293 SkScalar x, SkScalar y, const SkIRect& clipRect,
294 SkScalar textRatio,
295 SkTDArray<char>* fallbackTxt,
296 SkTDArray<SkScalar>* fallbackPos,
297 SkPoint* offset, const SkPaint& origPaint);
298 void internalDrawDFPosText(BitmapTextBlob*, int runIndex, SkGlyphCache*, con st SkPaint&,
299 GrColor color, const SkMatrix& viewMatrix,
300 const char text[], size_t byteLength,
301 const SkScalar pos[], int scalarsPerPosition,
302 const SkPoint& offset, const SkIRect& clipRect,
303 SkScalar textRatio,
304 SkTDArray<char>* fallbackTxt,
305 SkTDArray<SkScalar>* fallbackPos);
258 306
259 // sets up the descriptor on the blob and returns a detached cache. Client must attach 307 // sets up the descriptor on the blob and returns a detached cache. Client must attach
260 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); 308 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
261 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix& viewMa trix); 309 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMa trix, bool noGamma);
262 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran sY, 310 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran sY,
263 const BitmapTextBlob&, const SkPaint&, 311 const BitmapTextBlob&, const SkPaint&,
264 const SkMaskFilter::BlurRec&, 312 const SkMaskFilter::BlurRec&,
265 const SkMatrix& viewMatrix, SkScalar x , SkScalar y); 313 const SkMatrix& viewMatrix, SkScalar x , SkScalar y);
266 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor , 314 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor ,
267 const SkMatrix& viewMatrix, 315 const SkMatrix& viewMatrix,
268 const SkTextBlob* blob, SkScalar x, SkScalar y, 316 const SkTextBlob* blob, SkScalar x, SkScalar y,
269 SkDrawFilter* drawFilter, const SkIRect& clipRect); 317 SkDrawFilter* drawFilter, const SkIRect& clipRect);
270 inline static bool HasLCD(const SkTextBlob*); 318 inline static bool HasLCD(const SkTextBlob*);
319 inline void initDistanceFieldPaint(SkPaint*, SkScalar* textRatio, const SkMa trix&);
320
321 // Distance field text needs this table to compute a value for use in the fr agment shader.
322 // Because the GrAtlasTextContext can go out of scope before the final flush , this needs to be
323 // refcnted and malloced
324 struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> {
325 DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma) ; }
326 ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); }
327
328 void buildDistanceAdjustTable(float gamma);
329
330 SkScalar& operator[] (int i) {
331 return fTable[i];
332 }
333
334 const SkScalar& operator[] (int i) const {
335 return fTable[i];
336 }
337
338 SkScalar* fTable;
339 };
271 340
272 GrBatchTextStrike* fCurrStrike; 341 GrBatchTextStrike* fCurrStrike;
273 GrTextBlobCache* fCache; 342 GrTextBlobCache* fCache;
343 bool fEnableDFRendering;
344 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable;
274 345
275 friend class GrTextBlobCache; 346 friend class GrTextBlobCache;
276 friend class BitmapTextBatch; 347 friend class BitmapTextBatch;
277 348
278 typedef GrTextContext INHERITED; 349 typedef GrTextContext INHERITED;
279 }; 350 };
280 351
281 #endif 352 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrAtlasTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698