OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrBitmapTextContext.h" | 8 #include "GrBitmapTextContext.h" |
9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "GrDefaultGeoProcFactory.h" | 10 #include "GrDefaultGeoProcFactory.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 63 |
64 GrBitmapTextContext* GrBitmapTextContext::Create(GrContext* context, | 64 GrBitmapTextContext* GrBitmapTextContext::Create(GrContext* context, |
65 const SkDeviceProperties& props
) { | 65 const SkDeviceProperties& props
) { |
66 return SkNEW_ARGS(GrBitmapTextContext, (context, props)); | 66 return SkNEW_ARGS(GrBitmapTextContext, (context, props)); |
67 } | 67 } |
68 | 68 |
69 bool GrBitmapTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatr
ix) { | 69 bool GrBitmapTextContext::canDraw(const SkPaint& paint, const SkMatrix& viewMatr
ix) { |
70 return !SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix); | 70 return !SkDraw::ShouldDrawTextAsPaths(paint, viewMatrix); |
71 } | 71 } |
72 | 72 |
73 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
nt) { | 73 inline void GrBitmapTextContext::init(GrRenderTarget* rt, const GrPaint& paint, |
74 GrTextContext::init(paint, skPaint); | 74 const SkPaint& skPaint) { |
| 75 GrTextContext::init(rt, paint, skPaint); |
75 | 76 |
76 fStrike = NULL; | 77 fStrike = NULL; |
77 | 78 |
78 fCurrTexture = NULL; | 79 fCurrTexture = NULL; |
79 fCurrVertex = 0; | 80 fCurrVertex = 0; |
80 | 81 |
81 fVertices = NULL; | 82 fVertices = NULL; |
82 fAllocVertexCount = 0; | 83 fAllocVertexCount = 0; |
83 fTotalVertexCount = 0; | 84 fTotalVertexCount = 0; |
84 } | 85 } |
85 | 86 |
86 void GrBitmapTextContext::onDrawText(const GrPaint& paint, const SkPaint& skPain
t, | 87 void GrBitmapTextContext::onDrawText(GrRenderTarget* rt, const GrPaint& paint, |
| 88 const SkPaint& skPaint, |
87 const SkMatrix& viewMatrix, | 89 const SkMatrix& viewMatrix, |
88 const char text[], size_t byteLength, | 90 const char text[], size_t byteLength, |
89 SkScalar x, SkScalar y) { | 91 SkScalar x, SkScalar y) { |
90 SkASSERT(byteLength == 0 || text != NULL); | 92 SkASSERT(byteLength == 0 || text != NULL); |
91 | 93 |
92 // nothing to draw | 94 // nothing to draw |
93 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { | 95 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { |
94 return; | 96 return; |
95 } | 97 } |
96 | 98 |
97 this->init(paint, skPaint); | 99 this->init(rt, paint, skPaint); |
98 | 100 |
99 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 101 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
100 | 102 |
101 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix); | 103 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix); |
102 SkGlyphCache* cache = autoCache.getCache(); | 104 SkGlyphCache* cache = autoCache.getCache(); |
103 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 105 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
104 | 106 |
105 // transform our starting point | 107 // transform our starting point |
106 { | 108 { |
107 SkPoint loc; | 109 SkPoint loc; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 fontScaler); | 177 fontScaler); |
176 } | 178 } |
177 | 179 |
178 fx += glyph.fAdvanceX; | 180 fx += glyph.fAdvanceX; |
179 fy += glyph.fAdvanceY; | 181 fy += glyph.fAdvanceY; |
180 } | 182 } |
181 | 183 |
182 this->finish(); | 184 this->finish(); |
183 } | 185 } |
184 | 186 |
185 void GrBitmapTextContext::onDrawPosText(const GrPaint& paint, const SkPaint& skP
aint, | 187 void GrBitmapTextContext::onDrawPosText(GrRenderTarget* rt, const GrPaint& paint
, |
| 188 const SkPaint& skPaint, |
186 const SkMatrix& viewMatrix, | 189 const SkMatrix& viewMatrix, |
187 const char text[], size_t byteLength, | 190 const char text[], size_t byteLength, |
188 const SkScalar pos[], int scalarsPerPosi
tion, | 191 const SkScalar pos[], int scalarsPerPosi
tion, |
189 const SkPoint& offset) { | 192 const SkPoint& offset) { |
190 SkASSERT(byteLength == 0 || text != NULL); | 193 SkASSERT(byteLength == 0 || text != NULL); |
191 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 194 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
192 | 195 |
193 // nothing to draw | 196 // nothing to draw |
194 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { | 197 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { |
195 return; | 198 return; |
196 } | 199 } |
197 | 200 |
198 this->init(paint, skPaint); | 201 this->init(rt, paint, skPaint); |
199 | 202 |
200 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 203 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
201 | 204 |
202 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix); | 205 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &viewMatrix); |
203 SkGlyphCache* cache = autoCache.getCache(); | 206 SkGlyphCache* cache = autoCache.getCache(); |
204 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 207 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
205 | 208 |
206 // if we have RGB, then we won't have any SkShaders so no need to use a loca
lmatrix, but for | 209 // if we have RGB, then we won't have any SkShaders so no need to use a loca
lmatrix, but for |
207 // performance reasons we just invert here instead | 210 // performance reasons we just invert here instead |
208 if (!viewMatrix.invert(&fLocalMatrix)) { | 211 if (!viewMatrix.invert(&fLocalMatrix)) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 448 |
446 // flush any accumulated draws before drawing this glyph as a path. | 449 // flush any accumulated draws before drawing this glyph as a path. |
447 this->flush(); | 450 this->flush(); |
448 | 451 |
449 SkMatrix translate; | 452 SkMatrix translate; |
450 translate.setTranslate(SkFixedToScalar(vx - SkIntToFixed(glyph->fBounds.
fLeft)), | 453 translate.setTranslate(SkFixedToScalar(vx - SkIntToFixed(glyph->fBounds.
fLeft)), |
451 SkFixedToScalar(vy - SkIntToFixed(glyph->fBounds.
fTop))); | 454 SkFixedToScalar(vy - SkIntToFixed(glyph->fBounds.
fTop))); |
452 SkPath tmpPath(*glyph->fPath); | 455 SkPath tmpPath(*glyph->fPath); |
453 tmpPath.transform(translate); | 456 tmpPath.transform(translate); |
454 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); | 457 GrStrokeInfo strokeInfo(SkStrokeRec::kFill_InitStyle); |
455 fContext->drawPath(fPaint, SkMatrix::I(), tmpPath, strokeInfo); | 458 fContext->drawPath(fRenderTarget, fPaint, SkMatrix::I(), tmpPath, stroke
Info); |
456 | 459 |
457 // remove this glyph from the vertices we need to allocate | 460 // remove this glyph from the vertices we need to allocate |
458 fTotalVertexCount -= kVerticesPerGlyph; | 461 fTotalVertexCount -= kVerticesPerGlyph; |
459 return; | 462 return; |
460 } | 463 } |
461 | 464 |
462 SkASSERT(glyph->fPlot); | 465 SkASSERT(glyph->fPlot); |
463 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); | 466 GrDrawTarget::DrawToken drawToken = fDrawTarget->getCurrentDrawToken(); |
464 glyph->fPlot->setDrawToken(drawToken); | 467 glyph->fPlot->setDrawToken(drawToken); |
465 | 468 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 fCurrVertex += 4; | 546 fCurrVertex += 4; |
544 } | 547 } |
545 | 548 |
546 void GrBitmapTextContext::flush() { | 549 void GrBitmapTextContext::flush() { |
547 if (NULL == fDrawTarget) { | 550 if (NULL == fDrawTarget) { |
548 return; | 551 return; |
549 } | 552 } |
550 | 553 |
551 if (fCurrVertex > 0) { | 554 if (fCurrVertex > 0) { |
552 GrPipelineBuilder pipelineBuilder; | 555 GrPipelineBuilder pipelineBuilder; |
553 pipelineBuilder.setFromPaint(fPaint, fContext->getRenderTarget()); | 556 pipelineBuilder.setFromPaint(fPaint, fRenderTarget); |
554 | 557 |
555 // setup our sampler state for our text texture/atlas | 558 // setup our sampler state for our text texture/atlas |
556 SkASSERT(SkIsAlign4(fCurrVertex)); | 559 SkASSERT(SkIsAlign4(fCurrVertex)); |
557 SkASSERT(fCurrTexture); | 560 SkASSERT(fCurrTexture); |
558 | 561 |
559 SkASSERT(fStrike); | 562 SkASSERT(fStrike); |
560 GrColor color = fPaint.getColor(); | 563 GrColor color = fPaint.getColor(); |
561 switch (fCurrMaskFormat) { | 564 switch (fCurrMaskFormat) { |
562 // Color bitmap text | 565 // Color bitmap text |
563 case kARGB_GrMaskFormat: { | 566 case kARGB_GrMaskFormat: { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 } | 623 } |
621 } | 624 } |
622 | 625 |
623 inline void GrBitmapTextContext::finish() { | 626 inline void GrBitmapTextContext::finish() { |
624 this->flush(); | 627 this->flush(); |
625 fTotalVertexCount = 0; | 628 fTotalVertexCount = 0; |
626 | 629 |
627 GrTextContext::finish(); | 630 GrTextContext::finish(); |
628 } | 631 } |
629 | 632 |
OLD | NEW |