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

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

Issue 1098653005: A small patch to enable distance field text in textblobs (Closed) Base URL: https://skia.googlesource.com/skia.git@atdfnow2
Patch Set: windows warnings 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 int fRunCount; 203 int fRunCount;
204 SkMaskFilter::BlurRec fBlurRec; 204 SkMaskFilter::BlurRec fBlurRec;
205 struct StrokeInfo { 205 struct StrokeInfo {
206 SkScalar fFrameWidth; 206 SkScalar fFrameWidth;
207 SkScalar fMiterLimit; 207 SkScalar fMiterLimit;
208 SkPaint::Join fJoin; 208 SkPaint::Join fJoin;
209 }; 209 };
210 StrokeInfo fStrokeInfo; 210 StrokeInfo fStrokeInfo;
211 GrMemoryPool* fPool; 211 GrMemoryPool* fPool;
212 212
213 enum TextType {
214 kHasDistanceField_TextType = 0x1,
215 kHasBitmap_TextType = 0x2,
216 };
217 uint8_t fTextType;
218
219 BitmapTextBlob() : fTextType(0) {}
220
213 // all glyph / vertex offsets are into these pools. 221 // all glyph / vertex offsets are into these pools.
214 unsigned char* fVertices; 222 unsigned char* fVertices;
215 GrGlyph::PackedID* fGlyphIDs; 223 GrGlyph::PackedID* fGlyphIDs;
216 Run* fRuns; 224 Run* fRuns;
217 225
218 struct Key { 226 struct Key {
219 Key() { 227 Key() {
220 sk_bzero(this, sizeof(Key)); 228 sk_bzero(this, sizeof(Key));
221 } 229 }
222 uint32_t fUniqueID; 230 uint32_t fUniqueID;
(...skipping 25 matching lines...) Expand all
248 } 256 }
249 void* operator new(size_t) { 257 void* operator new(size_t) {
250 SkFAIL("All blobs are created by placement new."); 258 SkFAIL("All blobs are created by placement new.");
251 return sk_malloc_throw(0); 259 return sk_malloc_throw(0);
252 } 260 }
253 261
254 void* operator new(size_t, void* p) { return p; } 262 void* operator new(size_t, void* p) { return p; }
255 void operator delete(void* target, void* placement) { 263 void operator delete(void* target, void* placement) {
256 ::operator delete(target, placement); 264 ::operator delete(target, placement);
257 } 265 }
266
267 bool hasDistanceField() const { return SkToBool(fTextType & kHasDistance Field_TextType); }
268 bool hasBitmap() const { return SkToBool(fTextType & kHasBitmap_TextType ); }
269 void setHasDistanceField() { fTextType |= kHasDistanceField_TextType; }
270 void setHasBitmap() { fTextType |= kHasBitmap_TextType; }
258 }; 271 };
259 272
260 typedef BitmapTextBlob::Run Run; 273 typedef BitmapTextBlob::Run Run;
261 typedef Run::SubRunInfo PerSubRunInfo; 274 typedef Run::SubRunInfo PerSubRunInfo;
262 275
263 inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatr ix); 276 inline bool canDrawAsDistanceFields(const SkPaint&, const SkMatrix& viewMatr ix);
264 BitmapTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint, 277 BitmapTextBlob* setupDFBlob(int glyphCount, const SkPaint& origPaint,
265 const SkMatrix& viewMatrix, SkGlyphCache** cache , 278 const SkMatrix& viewMatrix, SkGlyphCache** cache ,
266 SkPaint* dfPaint, SkScalar* textRatio); 279 SkPaint* dfPaint, SkScalar* textRatio);
267 void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int le ft, int top, 280 void bmpAppendGlyph(BitmapTextBlob*, int runIndex, GrGlyph::PackedID, int le ft, int top,
(...skipping 18 matching lines...) Expand all
286 SkScalar transX, SkScalar transY); 299 SkScalar transX, SkScalar transY);
287 300
288 // We have to flush SkTextBlobs differently from drawText / drawPosText 301 // We have to flush SkTextBlobs differently from drawText / drawPosText
289 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget *, const SkPaint&, 302 void flush(GrDrawTarget*, const SkTextBlob*, BitmapTextBlob*, GrRenderTarget *, const SkPaint&,
290 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie wMatrix, 303 const GrPaint&, SkDrawFilter*, const GrClip&, const SkMatrix& vie wMatrix,
291 const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar trans X, SkScalar transY); 304 const SkIRect& clipBounds, SkScalar x, SkScalar y, SkScalar trans X, SkScalar transY);
292 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&, 305 void flush(GrDrawTarget*, BitmapTextBlob*, GrRenderTarget*, const SkPaint&,
293 const GrPaint&, const GrClip&); 306 const GrPaint&, const GrClip&);
294 307
295 // A helper for drawing BitmapText in a run of distance fields 308 // A helper for drawing BitmapText in a run of distance fields
296 inline void fallbackDrawPosText(BitmapTextBlob*, GrRenderTarget*, const GrCl ip&, 309 inline void fallbackDrawPosText(BitmapTextBlob*, int runIndex,
310 GrRenderTarget*, const GrClip&,
297 const GrPaint&, 311 const GrPaint&,
298 const SkPaint&, const SkMatrix& viewMatrix, 312 const SkPaint&, const SkMatrix& viewMatrix,
299 const SkTDArray<char>& fallbackTxt, 313 const SkTDArray<char>& fallbackTxt,
300 const SkTDArray<SkScalar>& fallbackPos, 314 const SkTDArray<SkScalar>& fallbackPos,
301 int scalarsPerPosition, 315 int scalarsPerPosition,
302 const SkPoint& offset, 316 const SkPoint& offset,
303 const SkIRect& clipRect); 317 const SkIRect& clipRect);
304 318
305 void internalDrawBMPText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&, 319 void internalDrawBMPText(BitmapTextBlob*, int runIndex, SkGlyphCache*, const SkPaint&,
306 GrColor color, const SkMatrix& viewMatrix, 320 GrColor color, const SkMatrix& viewMatrix,
(...skipping 25 matching lines...) Expand all
332 // sets up the descriptor on the blob and returns a detached cache. Client must attach 346 // sets up the descriptor on the blob and returns a detached cache. Client must attach
333 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd); 347 inline static GrColor ComputeCanonicalColor(const SkPaint&, bool lcd);
334 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMa trix, bool noGamma); 348 inline SkGlyphCache* setupCache(Run*, const SkPaint&, const SkMatrix* viewMa trix, bool noGamma);
335 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran sY, 349 static inline bool MustRegenerateBlob(SkScalar* outTransX, SkScalar* outTran sY,
336 const BitmapTextBlob&, const SkPaint&, 350 const BitmapTextBlob&, const SkPaint&,
337 const SkMaskFilter::BlurRec&, 351 const SkMaskFilter::BlurRec&,
338 const SkMatrix& viewMatrix, SkScalar x , SkScalar y); 352 const SkMatrix& viewMatrix, SkScalar x , SkScalar y);
339 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor , 353 void regenerateTextBlob(BitmapTextBlob* bmp, const SkPaint& skPaint, GrColor ,
340 const SkMatrix& viewMatrix, 354 const SkMatrix& viewMatrix,
341 const SkTextBlob* blob, SkScalar x, SkScalar y, 355 const SkTextBlob* blob, SkScalar x, SkScalar y,
342 SkDrawFilter* drawFilter, const SkIRect& clipRect); 356 SkDrawFilter* drawFilter, const SkIRect& clipRect, G rRenderTarget*,
357 const GrClip&, const GrPaint&);
343 inline static bool HasLCD(const SkTextBlob*); 358 inline static bool HasLCD(const SkTextBlob*);
344 inline void initDistanceFieldPaint(SkPaint*, SkScalar* textRatio, const SkMa trix&); 359 inline void initDistanceFieldPaint(SkPaint*, SkScalar* textRatio, const SkMa trix&);
345 360
346 // Distance field text needs this table to compute a value for use in the fr agment shader. 361 // Distance field text needs this table to compute a value for use in the fr agment shader.
347 // Because the GrAtlasTextContext can go out of scope before the final flush , this needs to be 362 // Because the GrAtlasTextContext can go out of scope before the final flush , this needs to be
348 // refcnted and malloced 363 // refcnted and malloced
349 struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> { 364 struct DistanceAdjustTable : public SkNVRefCnt<DistanceAdjustTable> {
350 DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma) ; } 365 DistanceAdjustTable(float gamma) { this->buildDistanceAdjustTable(gamma) ; }
351 ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); } 366 ~DistanceAdjustTable() { SkDELETE_ARRAY(fTable); }
352 367
(...skipping 15 matching lines...) Expand all
368 bool fEnableDFRendering; 383 bool fEnableDFRendering;
369 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable; 384 SkAutoTUnref<DistanceAdjustTable> fDistanceAdjustTable;
370 385
371 friend class GrTextBlobCache; 386 friend class GrTextBlobCache;
372 friend class BitmapTextBatch; 387 friend class BitmapTextBatch;
373 388
374 typedef GrTextContext INHERITED; 389 typedef GrTextContext INHERITED;
375 }; 390 };
376 391
377 #endif 392 #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