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 "GrDistanceFieldTextContext.h" | 8 #include "GrDistanceFieldTextContext.h" |
9 #include "GrAtlas.h" | 9 #include "GrAtlas.h" |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 static const int kMediumDFFontLimit = 64; | 37 static const int kMediumDFFontLimit = 64; |
38 static const int kLargeDFFontSize = 128; | 38 static const int kLargeDFFontSize = 128; |
39 | 39 |
40 namespace { | 40 namespace { |
41 // position + texture coord | 41 // position + texture coord |
42 extern const GrVertexAttrib gTextVertexAttribs[] = { | 42 extern const GrVertexAttrib gTextVertexAttribs[] = { |
43 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, | 43 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBindin
g}, |
44 {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding} | 44 {kVec2f_GrVertexAttribType, sizeof(SkPoint) , kEffect_GrVertexAttribBinding} |
45 }; | 45 }; |
46 | 46 |
| 47 static const size_t kTextVASize = 2 * sizeof(SkPoint); |
| 48 |
47 // position + color + texture coord | 49 // position + color + texture coord |
48 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { | 50 extern const GrVertexAttrib gTextVertexWithColorAttribs[] = { |
49 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, | 51 {kVec2f_GrVertexAttribType, 0, kPosition_Gr
VertexAttribBinding}, |
50 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, | 52 {kVec4ub_GrVertexAttribType, sizeof(SkPoint), kColor_GrVer
texAttribBinding}, |
51 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} | 53 {kVec2f_GrVertexAttribType, sizeof(SkPoint) + sizeof(GrColor), kEffect_GrVe
rtexAttribBinding} |
52 }; | 54 }; |
53 | 55 |
| 56 static const size_t kTextVAColorSize = 2 * sizeof(SkPoint) + sizeof(GrColor); |
| 57 |
54 }; | 58 }; |
55 | 59 |
56 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, | 60 GrDistanceFieldTextContext::GrDistanceFieldTextContext(GrContext* context, |
57 const SkDeviceProperties&
properties, | 61 const SkDeviceProperties&
properties, |
58 bool enable) | 62 bool enable) |
59 : GrTextContext(context, pro
perties) { | 63 : GrTextContext(context, pro
perties) { |
60 #if SK_FORCE_DISTANCEFIELD_FONTS | 64 #if SK_FORCE_DISTANCEFIELD_FONTS |
61 fEnableDFRendering = true; | 65 fEnableDFRendering = true; |
62 #else | 66 #else |
63 fEnableDFRendering = enable; | 67 fEnableDFRendering = enable; |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 } | 339 } |
336 | 340 |
337 bool useColorVerts = !fUseLCDText; | 341 bool useColorVerts = !fUseLCDText; |
338 | 342 |
339 if (NULL == fVertices) { | 343 if (NULL == fVertices) { |
340 // If we need to reserve vertices allow the draw target to suggest | 344 // If we need to reserve vertices allow the draw target to suggest |
341 // a number of verts to reserve and whether to perform a flush. | 345 // a number of verts to reserve and whether to perform a flush. |
342 fMaxVertices = kMinRequestedVerts; | 346 fMaxVertices = kMinRequestedVerts; |
343 if (useColorVerts) { | 347 if (useColorVerts) { |
344 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
bs>( | 348 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorAttri
bs>( |
345 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs)); | 349 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs), |
| 350 kTextVAColorSize); |
346 } else { | 351 } else { |
347 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 352 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
348 SK_ARRAY_COUNT(gTextVertexAt
tribs)); | 353 SK_ARRAY_COUNT(gTextVertexAt
tribs), |
| 354 kTextVASize); |
349 } | 355 } |
350 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); | 356 bool flush = fDrawTarget->geometryHints(&fMaxVertices, NULL); |
351 if (flush) { | 357 if (flush) { |
352 this->flushGlyphs(); | 358 this->flushGlyphs(); |
353 fContext->flush(); | 359 fContext->flush(); |
354 if (useColorVerts) { | 360 if (useColorVerts) { |
355 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA
ttribs>( | 361 fDrawTarget->drawState()->setVertexAttribs<gTextVertexWithColorA
ttribs>( |
356 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs)); | 362 SK_ARRAY_COUNT(gTextVertexWi
thColorAttribs), |
| 363 kTextVAColorSize); |
357 } else { | 364 } else { |
358 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( | 365 fDrawTarget->drawState()->setVertexAttribs<gTextVertexAttribs>( |
359 SK_ARRAY_COUNT(gTextVertexAt
tribs)); | 366 SK_ARRAY_COUNT(gTextVertexAt
tribs), |
| 367 kTextVASize); |
360 } | 368 } |
361 } | 369 } |
362 fMaxVertices = kDefaultRequestedVerts; | 370 fMaxVertices = kDefaultRequestedVerts; |
363 // ignore return, no point in flushing again. | 371 // ignore return, no point in flushing again. |
364 fDrawTarget->geometryHints(&fMaxVertices, NULL); | 372 fDrawTarget->geometryHints(&fMaxVertices, NULL); |
365 | 373 |
366 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); | 374 int maxQuadVertices = 4 * fContext->getQuadIndexBuffer()->maxQuads(); |
367 if (fMaxVertices < kMinRequestedVerts) { | 375 if (fMaxVertices < kMinRequestedVerts) { |
368 fMaxVertices = kDefaultRequestedVerts; | 376 fMaxVertices = kDefaultRequestedVerts; |
369 } else if (fMaxVertices > maxQuadVertices) { | 377 } else if (fMaxVertices > maxQuadVertices) { |
(...skipping 29 matching lines...) Expand all Loading... |
399 r.fLeft = sx; | 407 r.fLeft = sx; |
400 r.fTop = sy; | 408 r.fTop = sy; |
401 r.fRight = sx + width; | 409 r.fRight = sx + width; |
402 r.fBottom = sy + height; | 410 r.fBottom = sy + height; |
403 | 411 |
404 fVertexBounds.growToInclude(r); | 412 fVertexBounds.growToInclude(r); |
405 | 413 |
406 size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint)) | 414 size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint)) |
407 : (2 * sizeof(SkPoint) + sizeof(GrColor)); | 415 : (2 * sizeof(SkPoint) + sizeof(GrColor)); |
408 | 416 |
409 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); | 417 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexStride()); |
410 | 418 |
411 SkPoint* positions = reinterpret_cast<SkPoint*>( | 419 SkPoint* positions = reinterpret_cast<SkPoint*>( |
412 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); | 420 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); |
413 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); | 421 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize); |
414 | 422 |
415 // The texture coords are last in both the with and without color vertex lay
outs. | 423 // The texture coords are last in both the with and without color vertex lay
outs. |
416 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( | 424 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( |
417 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; | 425 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint))
; |
418 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), | 426 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), |
419 SkFixedToFloat(texture->normalizeFixedY(ty)), | 427 SkFixedToFloat(texture->normalizeFixedY(ty)), |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), | 652 SkScalarToFixed(x) - (glyph.fAdvanceX >> a
lignShift), |
645 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), | 653 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift), |
646 fontScaler); | 654 fontScaler); |
647 } | 655 } |
648 pos += scalarsPerPosition; | 656 pos += scalarsPerPosition; |
649 } | 657 } |
650 } | 658 } |
651 | 659 |
652 this->finish(); | 660 this->finish(); |
653 } | 661 } |
OLD | NEW |