| 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 "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "SkDraw.h" | 22 #include "SkDraw.h" |
| 23 #include "SkGlyphCache.h" | 23 #include "SkGlyphCache.h" |
| 24 #include "SkGpuDevice.h" | 24 #include "SkGpuDevice.h" |
| 25 #include "SkGr.h" | 25 #include "SkGr.h" |
| 26 | 26 |
| 27 static const int kGlyphCoordsAttributeIndex = 1; | 27 static const int kGlyphCoordsAttributeIndex = 1; |
| 28 | 28 |
| 29 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, | 29 SK_CONF_DECLARE(bool, c_DumpFontCache, "gpu.dumpFontCache", false, |
| 30 "Dump the contents of the font cache before every purge."); | 30 "Dump the contents of the font cache before every purge."); |
| 31 | 31 |
| 32 bool GrBitmapTextContext::CanDraw(const SkPaint& paint, const SkMatrix& ctm) { | |
| 33 return !SkDraw::ShouldDrawTextAsPaths(paint, ctm); | |
| 34 } | |
| 35 | |
| 36 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, | 32 GrBitmapTextContext::GrBitmapTextContext(GrContext* context, |
| 37 const GrPaint& grPaint, | |
| 38 const SkPaint& skPaint, | |
| 39 const SkDeviceProperties& properties) | 33 const SkDeviceProperties& properties) |
| 40 : GrTextContext(context, grPaint, skPaint
, properties) { | 34 : GrTextContext(context, properties) { |
| 41 fStrike = NULL; | 35 fStrike = NULL; |
| 42 | 36 |
| 43 fCurrTexture = NULL; | 37 fCurrTexture = NULL; |
| 44 fCurrVertex = 0; | 38 fCurrVertex = 0; |
| 45 | 39 |
| 46 fVertices = NULL; | 40 fVertices = NULL; |
| 47 fMaxVertices = 0; | 41 fMaxVertices = 0; |
| 48 } | 42 } |
| 49 | 43 |
| 50 GrBitmapTextContext::~GrBitmapTextContext() { | 44 GrBitmapTextContext::~GrBitmapTextContext() { |
| 51 this->flushGlyphs(); | 45 this->flushGlyphs(); |
| 52 } | 46 } |
| 53 | 47 |
| 48 bool GrBitmapTextContext::canDraw(const SkPaint& paint) { |
| 49 return !SkDraw::ShouldDrawTextAsPaths(paint, fContext->getMatrix()); |
| 50 } |
| 51 |
| 54 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { | 52 static inline GrColor skcolor_to_grcolor_nopremultiply(SkColor c) { |
| 55 unsigned r = SkColorGetR(c); | 53 unsigned r = SkColorGetR(c); |
| 56 unsigned g = SkColorGetG(c); | 54 unsigned g = SkColorGetG(c); |
| 57 unsigned b = SkColorGetB(c); | 55 unsigned b = SkColorGetB(c); |
| 58 return GrColorPackRGBA(r, g, b, 0xff); | 56 return GrColorPackRGBA(r, g, b, 0xff); |
| 59 } | 57 } |
| 60 | 58 |
| 61 void GrBitmapTextContext::flushGlyphs() { | 59 void GrBitmapTextContext::flushGlyphs() { |
| 62 if (NULL == fDrawTarget) { | 60 if (NULL == fDrawTarget) { |
| 63 return; | 61 return; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 4, 6); | 108 4, 6); |
| 111 | 109 |
| 112 fDrawTarget->resetVertexSource(); | 110 fDrawTarget->resetVertexSource(); |
| 113 fVertices = NULL; | 111 fVertices = NULL; |
| 114 fMaxVertices = 0; | 112 fMaxVertices = 0; |
| 115 fCurrVertex = 0; | 113 fCurrVertex = 0; |
| 116 SkSafeSetNull(fCurrTexture); | 114 SkSafeSetNull(fCurrTexture); |
| 117 } | 115 } |
| 118 } | 116 } |
| 119 | 117 |
| 120 void GrBitmapTextContext::drawText(const char text[], size_t byteLength, | 118 inline void GrBitmapTextContext::init(const GrPaint& paint, const SkPaint& skPai
nt) { |
| 119 GrTextContext::init(paint, skPaint); |
| 120 |
| 121 fStrike = NULL; |
| 122 |
| 123 fCurrTexture = NULL; |
| 124 fCurrVertex = 0; |
| 125 |
| 126 fVertices = NULL; |
| 127 fMaxVertices = 0; |
| 128 } |
| 129 |
| 130 inline void GrBitmapTextContext::finish() { |
| 131 flushGlyphs(); |
| 132 |
| 133 GrTextContext::finish(); |
| 134 } |
| 135 |
| 136 void GrBitmapTextContext::drawText(const GrPaint& paint, const SkPaint& skPaint,
|
| 137 const char text[], size_t byteLength, |
| 121 SkScalar x, SkScalar y) { | 138 SkScalar x, SkScalar y) { |
| 122 SkASSERT(byteLength == 0 || text != NULL); | 139 SkASSERT(byteLength == 0 || text != NULL); |
| 123 | 140 |
| 124 // nothing to draw | 141 // nothing to draw |
| 125 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { | 142 if (text == NULL || byteLength == 0 /*|| fRC->isEmpty()*/) { |
| 126 return; | 143 return; |
| 127 } | 144 } |
| 128 | 145 |
| 146 this->init(paint, skPaint); |
| 147 |
| 129 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 148 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 130 | 149 |
| 131 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); | 150 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); |
| 132 SkGlyphCache* cache = autoCache.getCache(); | 151 SkGlyphCache* cache = autoCache.getCache(); |
| 133 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 152 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 134 | 153 |
| 135 // transform our starting point | 154 // transform our starting point |
| 136 { | 155 { |
| 137 SkPoint loc; | 156 SkPoint loc; |
| 138 fContext->getMatrix().mapXY(x, y, &loc); | 157 fContext->getMatrix().mapXY(x, y, &loc); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 glyph.getSubXFixed(), | 213 glyph.getSubXFixed(), |
| 195 glyph.getSubYFixed()), | 214 glyph.getSubYFixed()), |
| 196 SkFixedFloorToFixed(fx), | 215 SkFixedFloorToFixed(fx), |
| 197 SkFixedFloorToFixed(fy), | 216 SkFixedFloorToFixed(fy), |
| 198 fontScaler); | 217 fontScaler); |
| 199 } | 218 } |
| 200 | 219 |
| 201 fx += glyph.fAdvanceX; | 220 fx += glyph.fAdvanceX; |
| 202 fy += glyph.fAdvanceY; | 221 fy += glyph.fAdvanceY; |
| 203 } | 222 } |
| 223 |
| 224 this->finish(); |
| 204 } | 225 } |
| 205 | 226 |
| 206 /////////////////////////////////////////////////////////////////////////////// | 227 /////////////////////////////////////////////////////////////////////////////// |
| 207 // Copied from SkDraw | 228 // Copied from SkDraw |
| 208 | 229 |
| 209 // last parameter is interpreted as SkFixed [x, y] | 230 // last parameter is interpreted as SkFixed [x, y] |
| 210 // return the fixed position, which may be rounded or not by the caller | 231 // return the fixed position, which may be rounded or not by the caller |
| 211 // e.g. subpixel doesn't round | 232 // e.g. subpixel doesn't round |
| 212 typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); | 233 typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); |
| 213 | 234 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 return (mtype & SkMatrix::kScale_Mask) ? | 309 return (mtype & SkMatrix::kScale_Mask) ? |
| 289 MapOnlyScaleXProc : MapOnlyTransXProc; | 310 MapOnlyScaleXProc : MapOnlyTransXProc; |
| 290 } | 311 } |
| 291 } else { | 312 } else { |
| 292 return MapXYProc; | 313 return MapXYProc; |
| 293 } | 314 } |
| 294 } | 315 } |
| 295 | 316 |
| 296 /////////////////////////////////////////////////////////////////////////////// | 317 /////////////////////////////////////////////////////////////////////////////// |
| 297 | 318 |
| 298 void GrBitmapTextContext::drawPosText(const char text[], size_t byteLength, | 319 void GrBitmapTextContext::drawPosText(const GrPaint& paint, const SkPaint& skPai
nt, |
| 320 const char text[], size_t byteLength, |
| 299 const SkScalar pos[], SkScalar constY, | 321 const SkScalar pos[], SkScalar constY, |
| 300 int scalarsPerPosition) { | 322 int scalarsPerPosition) { |
| 301 SkASSERT(byteLength == 0 || text != NULL); | 323 SkASSERT(byteLength == 0 || text != NULL); |
| 302 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); | 324 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); |
| 303 | 325 |
| 304 // nothing to draw | 326 // nothing to draw |
| 305 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { | 327 if (text == NULL || byteLength == 0/* || fRC->isEmpty()*/) { |
| 306 return; | 328 return; |
| 307 } | 329 } |
| 308 | 330 |
| 331 this->init(paint, skPaint); |
| 332 |
| 309 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); | 333 SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc(); |
| 310 | 334 |
| 311 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); | 335 SkAutoGlyphCache autoCache(fSkPaint, &fDeviceProperties, &fContext->getMa
trix()); |
| 312 SkGlyphCache* cache = autoCache.getCache(); | 336 SkGlyphCache* cache = autoCache.getCache(); |
| 313 GrFontScaler* fontScaler = GetGrFontScaler(cache); | 337 GrFontScaler* fontScaler = GetGrFontScaler(cache); |
| 314 | 338 |
| 315 // store original matrix before we reset, so we can use it to transform posi
tions | 339 // store original matrix before we reset, so we can use it to transform posi
tions |
| 316 SkMatrix ctm = fContext->getMatrix(); | 340 SkMatrix ctm = fContext->getMatrix(); |
| 317 GrContext::AutoMatrix autoMatrix; | 341 GrContext::AutoMatrix autoMatrix; |
| 318 autoMatrix.setIdentity(fContext, &fPaint); | 342 autoMatrix.setIdentity(fContext, &fPaint); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 glyph.getSubXFixed(), | 456 glyph.getSubXFixed(), |
| 433 glyph.getSubYFixed()), | 457 glyph.getSubYFixed()), |
| 434 SkFixedFloorToFixed(fx), | 458 SkFixedFloorToFixed(fx), |
| 435 SkFixedFloorToFixed(fy), | 459 SkFixedFloorToFixed(fy), |
| 436 fontScaler); | 460 fontScaler); |
| 437 } | 461 } |
| 438 pos += scalarsPerPosition; | 462 pos += scalarsPerPosition; |
| 439 } | 463 } |
| 440 } | 464 } |
| 441 } | 465 } |
| 466 |
| 467 this->finish(); |
| 442 } | 468 } |
| 443 | 469 |
| 444 namespace { | 470 namespace { |
| 445 | 471 |
| 446 // position + texture coord | 472 // position + texture coord |
| 447 extern const GrVertexAttrib gTextVertexAttribs[] = { | 473 extern const GrVertexAttrib gTextVertexAttribs[] = { |
| 448 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 474 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
| 449 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} | 475 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} |
| 450 }; | 476 }; |
| 451 | 477 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 SkFixedToFloat(vx + width), | 621 SkFixedToFloat(vx + width), |
| 596 SkFixedToFloat(vy + height), | 622 SkFixedToFloat(vy + height), |
| 597 2 * sizeof(SkPoint)); | 623 2 * sizeof(SkPoint)); |
| 598 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), | 624 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), |
| 599 SkFixedToFloat(texture->normalizeFixed
Y(ty)), | 625 SkFixedToFloat(texture->normalizeFixed
Y(ty)), |
| 600 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), | 626 SkFixedToFloat(texture->normalizeFixed
X(tx + width)), |
| 601 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), | 627 SkFixedToFloat(texture->normalizeFixed
Y(ty + height)), |
| 602 2 * sizeof(SkPoint)); | 628 2 * sizeof(SkPoint)); |
| 603 fCurrVertex += 4; | 629 fCurrVertex += 4; |
| 604 } | 630 } |
| OLD | NEW |