OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #include "GrStencilAndCoverTextContext.h" | 8 #include "GrStencilAndCoverTextContext.h" |
9 #include "GrAtlasTextContext.h" | 9 #include "GrAtlasTextContext.h" |
10 #include "GrDrawContext.h" | 10 #include "GrDrawContext.h" |
11 #include "GrDrawTarget.h" | 11 #include "GrDrawTarget.h" |
12 #include "GrPath.h" | 12 #include "GrPath.h" |
13 #include "GrPathRange.h" | 13 #include "GrPathRange.h" |
14 #include "GrResourceProvider.h" | 14 #include "GrResourceProvider.h" |
15 #include "SkAutoKern.h" | 15 #include "SkAutoKern.h" |
16 #include "SkDraw.h" | 16 #include "SkDraw.h" |
17 #include "SkDrawProcs.h" | 17 #include "SkDrawProcs.h" |
18 #include "SkGlyphCache.h" | 18 #include "SkGlyphCache.h" |
19 #include "SkGpuDevice.h" | 19 #include "SkGpuDevice.h" |
20 #include "SkPath.h" | 20 #include "SkPath.h" |
21 #include "SkTextMapStateProc.h" | 21 #include "SkTextMapStateProc.h" |
22 #include "SkTextFormatParams.h" | 22 #include "SkTextFormatParams.h" |
23 | 23 |
24 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context, | 24 GrStencilAndCoverTextContext::GrStencilAndCoverTextContext(GrContext* context, |
25 GrDrawContext* drawCo
ntext, | |
26 const SkDevicePropert
ies& properties) | 25 const SkDevicePropert
ies& properties) |
27 : GrTextContext(context, drawContext, properties) | 26 : GrTextContext(context, properties) |
28 , fStroke(SkStrokeRec::kFill_InitStyle) | 27 , fStroke(SkStrokeRec::kFill_InitStyle) |
29 , fQueuedGlyphCount(0) | 28 , fQueuedGlyphCount(0) |
30 , fFallbackGlyphsIdx(kGlyphBufferSize) { | 29 , fFallbackGlyphsIdx(kGlyphBufferSize) { |
31 } | 30 } |
32 | 31 |
33 GrStencilAndCoverTextContext* | 32 GrStencilAndCoverTextContext* |
34 GrStencilAndCoverTextContext::Create(GrContext* context, GrDrawContext* drawCont
ext, | 33 GrStencilAndCoverTextContext::Create(GrContext* context, const SkDevicePropertie
s& props) { |
35 const SkDeviceProperties& props, bool fallb
ackUsesDFT) { | |
36 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText
Context, | 34 GrStencilAndCoverTextContext* textContext = SkNEW_ARGS(GrStencilAndCoverText
Context, |
37 (context, drawContext
, props)); | 35 (context, props)); |
38 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, draw
Context, | 36 textContext->fFallbackTextContext = GrAtlasTextContext::Create(context, prop
s, false); |
39 props, fallba
ckUsesDFT); | |
40 | 37 |
41 return textContext; | 38 return textContext; |
42 } | 39 } |
43 | 40 |
44 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { | 41 GrStencilAndCoverTextContext::~GrStencilAndCoverTextContext() { |
45 } | 42 } |
46 | 43 |
47 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt, | 44 bool GrStencilAndCoverTextContext::canDraw(const GrRenderTarget* rt, |
48 const GrClip& clip, | 45 const GrClip& clip, |
49 const GrPaint& paint, | 46 const GrPaint& paint, |
(...skipping 17 matching lines...) Expand all Loading... |
67 && viewMatrix.hasPerspective()) { | 64 && viewMatrix.hasPerspective()) { |
68 return false; | 65 return false; |
69 } | 66 } |
70 | 67 |
71 // No color bitmap fonts. | 68 // No color bitmap fonts. |
72 SkScalerContext::Rec rec; | 69 SkScalerContext::Rec rec; |
73 SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec); | 70 SkScalerContext::MakeRec(skPaint, &fDeviceProperties, NULL, &rec); |
74 return rec.getFormat() != SkMask::kARGB32_Format; | 71 return rec.getFormat() != SkMask::kARGB32_Format; |
75 } | 72 } |
76 | 73 |
77 void GrStencilAndCoverTextContext::onDrawText(GrRenderTarget* rt, | 74 void GrStencilAndCoverTextContext::onDrawText(GrDrawContext* drawContext, GrRend
erTarget* rt, |
78 const GrClip& clip, | 75 const GrClip& clip, |
79 const GrPaint& paint, | 76 const GrPaint& paint, |
80 const SkPaint& skPaint, | 77 const SkPaint& skPaint, |
81 const SkMatrix& viewMatrix, | 78 const SkMatrix& viewMatrix, |
82 const char text[], | 79 const char text[], |
83 size_t byteLength, | 80 size_t byteLength, |
84 SkScalar x, SkScalar y, | 81 SkScalar x, SkScalar y, |
85 const SkIRect& regionClipBounds) { | 82 const SkIRect& regionClipBounds) { |
86 SkASSERT(byteLength == 0 || text != NULL); | 83 SkASSERT(byteLength == 0 || text != NULL); |
87 | 84 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 SkAutoKern autokern; | 147 SkAutoKern autokern; |
151 | 148 |
152 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); | 149 SkFixed fixedSizeRatio = SkScalarToFixed(fTextRatio); |
153 | 150 |
154 SkFixed fx = SkScalarToFixed(x); | 151 SkFixed fx = SkScalarToFixed(x); |
155 SkFixed fy = SkScalarToFixed(y); | 152 SkFixed fy = SkScalarToFixed(y); |
156 while (text < stop) { | 153 while (text < stop) { |
157 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); | 154 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
158 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); | 155 fx += SkFixedMul(autokern.adjust(glyph), fixedSizeRatio); |
159 if (glyph.fWidth) { | 156 if (glyph.fWidth) { |
160 this->appendGlyph(glyph, SkPoint::Make(SkFixedToScalar(fx), SkFixedT
oScalar(fy))); | 157 this->appendGlyph(drawContext, glyph, |
| 158 SkPoint::Make(SkFixedToScalar(fx), SkFixedToScalar
(fy))); |
161 } | 159 } |
162 | 160 |
163 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); | 161 fx += SkFixedMul(glyph.fAdvanceX, fixedSizeRatio); |
164 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); | 162 fy += SkFixedMul(glyph.fAdvanceY, fixedSizeRatio); |
165 } | 163 } |
166 | 164 |
167 this->finish(); | 165 this->finish(drawContext); |
168 } | 166 } |
169 | 167 |
170 void GrStencilAndCoverTextContext::onDrawPosText(GrRenderTarget* rt, | 168 void GrStencilAndCoverTextContext::onDrawPosText(GrDrawContext* drawContext, |
| 169 GrRenderTarget* rt, |
171 const GrClip& clip, | 170 const GrClip& clip, |
172 const GrPaint& paint, | 171 const GrPaint& paint, |
173 const SkPaint& skPaint, | 172 const SkPaint& skPaint, |
174 const SkMatrix& viewMatrix, | 173 const SkMatrix& viewMatrix, |
175 const char text[], | 174 const char text[], |
176 size_t byteLength, | 175 size_t byteLength, |
177 const SkScalar pos[], | 176 const SkScalar pos[], |
178 int scalarsPerPosition, | 177 int scalarsPerPosition, |
179 const SkPoint& offset, | 178 const SkPoint& offset, |
180 const SkIRect& regionClipBounds
) { | 179 const SkIRect& regionClipBounds
) { |
(...skipping 23 matching lines...) Expand all Loading... |
204 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); | 203 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition); |
205 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); | 204 SkTextAlignProc alignProc(fSkPaint.getTextAlign()); |
206 while (text < stop) { | 205 while (text < stop) { |
207 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); | 206 const SkGlyph& glyph = glyphCacheProc(fGlyphCache, &text, 0, 0); |
208 if (glyph.fWidth) { | 207 if (glyph.fWidth) { |
209 SkPoint tmsLoc; | 208 SkPoint tmsLoc; |
210 tmsProc(pos, &tmsLoc); | 209 tmsProc(pos, &tmsLoc); |
211 SkPoint loc; | 210 SkPoint loc; |
212 alignProc(tmsLoc, glyph, &loc); | 211 alignProc(tmsLoc, glyph, &loc); |
213 | 212 |
214 this->appendGlyph(glyph, loc); | 213 this->appendGlyph(drawContext, glyph, loc); |
215 } | 214 } |
216 pos += scalarsPerPosition; | 215 pos += scalarsPerPosition; |
217 } | 216 } |
218 | 217 |
219 this->finish(); | 218 this->finish(drawContext); |
220 } | 219 } |
221 | 220 |
222 static GrPathRange* get_gr_glyphs(GrContext* ctx, | 221 static GrPathRange* get_gr_glyphs(GrContext* ctx, |
223 const SkTypeface* typeface, | 222 const SkTypeface* typeface, |
224 const SkDescriptor* desc, | 223 const SkDescriptor* desc, |
225 const GrStrokeInfo& stroke) { | 224 const GrStrokeInfo& stroke) { |
226 | 225 |
227 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom
ain(); | 226 static const GrUniqueKey::Domain kPathGlyphDomain = GrUniqueKey::GenerateDom
ain(); |
228 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt(); | 227 int strokeDataCount = stroke.computeUniqueKeyFragmentData32Cnt(); |
229 GrUniqueKey glyphKey; | 228 GrUniqueKey glyphKey; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 403 } |
405 inverse->preScale(1, -1); | 404 inverse->preScale(1, -1); |
406 } else { | 405 } else { |
407 inverse->setScale(1, -1); | 406 inverse->setScale(1, -1); |
408 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse
. | 407 const SkMatrix& unflip = *inverse; // unflip is equal to its own inverse
. |
409 fViewMatrix.preConcat(unflip); | 408 fViewMatrix.preConcat(unflip); |
410 } | 409 } |
411 return true; | 410 return true; |
412 } | 411 } |
413 | 412 |
414 inline void GrStencilAndCoverTextContext::appendGlyph(const SkGlyph& glyph, cons
t SkPoint& pos) { | 413 inline void GrStencilAndCoverTextContext::appendGlyph(GrDrawContext* drawContext
, |
| 414 const SkGlyph& glyph, cons
t SkPoint& pos) { |
415 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) { | 415 if (fQueuedGlyphCount >= fFallbackGlyphsIdx) { |
416 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx); | 416 SkASSERT(fQueuedGlyphCount == fFallbackGlyphsIdx); |
417 this->flush(); | 417 this->flush(drawContext); |
418 } | 418 } |
419 | 419 |
420 // Stick the glyphs we can't draw at the end of the buffer, growing backward
s. | 420 // Stick the glyphs we can't draw at the end of the buffer, growing backward
s. |
421 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ? | 421 int index = (SkMask::kARGB32_Format == glyph.fMaskFormat) ? |
422 --fFallbackGlyphsIdx : fQueuedGlyphCount++; | 422 --fFallbackGlyphsIdx : fQueuedGlyphCount++; |
423 | 423 |
424 fGlyphIndices[index] = glyph.getGlyphID(); | 424 fGlyphIndices[index] = glyph.getGlyphID(); |
425 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio *
pos.y()); | 425 fGlyphPositions[index].set(fTextInverseRatio * pos.x(), -fTextInverseRatio *
pos.y()); |
426 } | 426 } |
427 | 427 |
428 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) { | 428 static const SkScalar* get_xy_scalar_array(const SkPoint* pointArray) { |
429 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint)); | 429 GR_STATIC_ASSERT(2 * sizeof(SkScalar) == sizeof(SkPoint)); |
430 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX)); | 430 GR_STATIC_ASSERT(0 == offsetof(SkPoint, fX)); |
431 | 431 |
432 return &pointArray[0].fX; | 432 return &pointArray[0].fX; |
433 } | 433 } |
434 | 434 |
435 void GrStencilAndCoverTextContext::flush() { | 435 void GrStencilAndCoverTextContext::flush(GrDrawContext* drawContext) { |
436 if (fQueuedGlyphCount > 0) { | 436 if (fQueuedGlyphCount > 0) { |
437 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor
(), | 437 SkAutoTUnref<GrPathProcessor> pp(GrPathProcessor::Create(fPaint.getColor
(), |
438 fViewMatrix, | 438 fViewMatrix, |
439 fLocalMatrix)); | 439 fLocalMatrix)); |
440 | 440 |
441 fDrawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs, | 441 drawContext->drawPaths(&fPipelineBuilder, pp, fGlyphs, |
442 fGlyphIndices, GrPathRange::kU16_PathIndexType, | 442 fGlyphIndices, GrPathRange::kU16_PathIndexType, |
443 get_xy_scalar_array(fGlyphPositions), | 443 get_xy_scalar_array(fGlyphPositions), |
444 GrPathRendering::kTranslate_PathTransformType, | 444 GrPathRendering::kTranslate_PathTransformType, |
445 fQueuedGlyphCount, GrPathRendering::kWinding_Fil
lType); | 445 fQueuedGlyphCount, GrPathRendering::kWinding_Fill
Type); |
446 | 446 |
447 fQueuedGlyphCount = 0; | 447 fQueuedGlyphCount = 0; |
448 } | 448 } |
449 | 449 |
450 if (fFallbackGlyphsIdx < kGlyphBufferSize) { | 450 if (fFallbackGlyphsIdx < kGlyphBufferSize) { |
451 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; | 451 int fallbackGlyphCount = kGlyphBufferSize - fFallbackGlyphsIdx; |
452 | 452 |
453 GrPaint paintFallback(fPaint); | 453 GrPaint paintFallback(fPaint); |
454 | 454 |
455 SkPaint skPaintFallback(fSkPaint); | 455 SkPaint skPaintFallback(fSkPaint); |
(...skipping 11 matching lines...) Expand all Loading... |
467 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s
kPaintFallback, | 467 fFallbackTextContext->drawPosText(fRenderTarget, fClip, paintFallback, s
kPaintFallback, |
468 fViewMatrix, (char*)&fGlyphIndices[fFa
llbackGlyphsIdx], | 468 fViewMatrix, (char*)&fGlyphIndices[fFa
llbackGlyphsIdx], |
469 2 * fallbackGlyphCount, | 469 2 * fallbackGlyphCount, |
470 get_xy_scalar_array(&fGlyphPositions[f
FallbackGlyphsIdx]), | 470 get_xy_scalar_array(&fGlyphPositions[f
FallbackGlyphsIdx]), |
471 2, SkPoint::Make(0, 0), fRegionClipBou
nds); | 471 2, SkPoint::Make(0, 0), fRegionClipBou
nds); |
472 | 472 |
473 fFallbackGlyphsIdx = kGlyphBufferSize; | 473 fFallbackGlyphsIdx = kGlyphBufferSize; |
474 } | 474 } |
475 } | 475 } |
476 | 476 |
477 void GrStencilAndCoverTextContext::finish() { | 477 void GrStencilAndCoverTextContext::finish(GrDrawContext* drawContext) { |
478 this->flush(); | 478 this->flush(drawContext); |
479 | 479 |
480 fGlyphs->unref(); | 480 fGlyphs->unref(); |
481 fGlyphs = NULL; | 481 fGlyphs = NULL; |
482 | 482 |
483 SkGlyphCache::AttachCache(fGlyphCache); | 483 SkGlyphCache::AttachCache(fGlyphCache); |
484 fGlyphCache = NULL; | 484 fGlyphCache = NULL; |
485 | 485 |
486 fPipelineBuilder.stencil()->setDisabled(); | 486 fPipelineBuilder.stencil()->setDisabled(); |
487 fStateRestore.set(NULL); | 487 fStateRestore.set(NULL); |
488 fViewMatrix = fContextInitialMatrix; | 488 fViewMatrix = fContextInitialMatrix; |
489 } | 489 } |
490 | 490 |
OLD | NEW |