| 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 "GrDrawTarget.h" | 10 #include "GrDrawTarget.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 if (NULL == fDrawTarget) { | 69 if (NULL == fDrawTarget) { |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 | 72 |
| 73 GrDrawState* drawState = fDrawTarget->drawState(); | 73 GrDrawState* drawState = fDrawTarget->drawState(); |
| 74 GrDrawState::AutoRestoreEffects are(drawState); | 74 GrDrawState::AutoRestoreEffects are(drawState); |
| 75 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); | 75 drawState->setFromPaint(fPaint, fContext->getMatrix(), fContext->getRenderTa
rget()); |
| 76 | 76 |
| 77 if (fCurrVertex > 0) { | 77 if (fCurrVertex > 0) { |
| 78 // setup our sampler state for our text texture/atlas | 78 // setup our sampler state for our text texture/atlas |
| 79 SkASSERT(GrIsALIGN4(fCurrVertex)); | 79 SkASSERT(SkIsAlign4(fCurrVertex)); |
| 80 SkASSERT(fCurrTexture); | 80 SkASSERT(fCurrTexture); |
| 81 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); | 81 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil
erp_FilterMode); |
| 82 | 82 |
| 83 // This effect could be stored with one of the cache objects (atlas?) | 83 // This effect could be stored with one of the cache objects (atlas?) |
| 84 drawState->addCoverageEffect( | 84 drawState->addCoverageEffect( |
| 85 GrDistanceFieldTextureEffect::Create(fCurrTexture, para
ms, | 85 GrDistanceFieldTextureEffect::Create(fCurrTexture, para
ms, |
| 86 fContext->getMatri
x().isSimilarity()), | 86 fContext->getMatri
x().isSimilarity()), |
| 87 kGlyphCoordsAttributeIndex)->unref(); | 87 kGlyphCoordsAttributeIndex)->unref(); |
| 88 | 88 |
| 89 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { | 89 if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 119 fCurrVertex = 0; | 119 fCurrVertex = 0; |
| 120 SkSafeSetNull(fCurrTexture); | 120 SkSafeSetNull(fCurrTexture); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 namespace { | 124 namespace { |
| 125 | 125 |
| 126 // position + texture coord | 126 // position + texture coord |
| 127 extern const GrVertexAttrib gTextVertexAttribs[] = { | 127 extern const GrVertexAttrib gTextVertexAttribs[] = { |
| 128 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, | 128 {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding
}, |
| 129 {kVec2f_GrVertexAttribType, sizeof(GrPoint), kEffect_GrVertexAttribBinding} | 129 {kVec2f_GrVertexAttribType, sizeof(SkPoint), kEffect_GrVertexAttribBinding} |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 }; | 132 }; |
| 133 | 133 |
| 134 void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed, | 134 void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed, |
| 135 GrFixed vx, GrFixed vy, | 135 SkFixed vx, SkFixed vy, |
| 136 GrFontScaler* scaler) { | 136 GrFontScaler* scaler) { |
| 137 if (NULL == fDrawTarget) { | 137 if (NULL == fDrawTarget) { |
| 138 return; | 138 return; |
| 139 } | 139 } |
| 140 if (NULL == fStrike) { | 140 if (NULL == fStrike) { |
| 141 fStrike = fContext->getFontCache()->getStrike(scaler, true); | 141 fStrike = fContext->getFontCache()->getStrike(scaler, true); |
| 142 } | 142 } |
| 143 | 143 |
| 144 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); | 144 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); |
| 145 if (NULL == glyph || glyph->fBounds.isEmpty()) { | 145 if (NULL == glyph || glyph->fBounds.isEmpty()) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 fMaxVertices = kDefaultRequestedVerts; | 250 fMaxVertices = kDefaultRequestedVerts; |
| 251 } else if (fMaxVertices > maxQuadVertices) { | 251 } else if (fMaxVertices > maxQuadVertices) { |
| 252 // don't exceed the limit of the index buffer | 252 // don't exceed the limit of the index buffer |
| 253 fMaxVertices = maxQuadVertices; | 253 fMaxVertices = maxQuadVertices; |
| 254 } | 254 } |
| 255 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, | 255 bool success = fDrawTarget->reserveVertexAndIndexSpace(fMaxVertices, |
| 256 0, | 256 0, |
| 257 GrTCast<void**>(&
fVertices), | 257 GrTCast<void**>(&
fVertices), |
| 258 NULL); | 258 NULL); |
| 259 GrAlwaysAssert(success); | 259 GrAlwaysAssert(success); |
| 260 SkASSERT(2*sizeof(GrPoint) == fDrawTarget->getDrawState().getVertexSize(
)); | 260 SkASSERT(2*sizeof(SkPoint) == fDrawTarget->getDrawState().getVertexSize(
)); |
| 261 } | 261 } |
| 262 | 262 |
| 263 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft); | 263 SkScalar dx = SkIntToScalar(glyph->fBounds.fLeft); |
| 264 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop); | 264 SkScalar dy = SkIntToScalar(glyph->fBounds.fTop); |
| 265 SkScalar width = SkIntToScalar(glyph->fBounds.width()); | 265 SkScalar width = SkIntToScalar(glyph->fBounds.width()); |
| 266 SkScalar height = SkIntToScalar(glyph->fBounds.height()); | 266 SkScalar height = SkIntToScalar(glyph->fBounds.height()); |
| 267 | 267 |
| 268 SkScalar scale = fTextRatio; | 268 SkScalar scale = fTextRatio; |
| 269 dx *= scale; | 269 dx *= scale; |
| 270 dy *= scale; | 270 dy *= scale; |
| 271 sx += dx; | 271 sx += dx; |
| 272 sy += dy; | 272 sy += dy; |
| 273 width *= scale; | 273 width *= scale; |
| 274 height *= scale; | 274 height *= scale; |
| 275 | 275 |
| 276 GrFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); | 276 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX); |
| 277 GrFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); | 277 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY); |
| 278 GrFixed tw = SkIntToFixed(glyph->fBounds.width()); | 278 SkFixed tw = SkIntToFixed(glyph->fBounds.width()); |
| 279 GrFixed th = SkIntToFixed(glyph->fBounds.height()); | 279 SkFixed th = SkIntToFixed(glyph->fBounds.height()); |
| 280 | 280 |
| 281 static const size_t kVertexSize = 2 * sizeof(SkPoint); | 281 static const size_t kVertexSize = 2 * sizeof(SkPoint); |
| 282 fVertices[2*fCurrVertex].setRectFan(sx, | 282 fVertices[2*fCurrVertex].setRectFan(sx, |
| 283 sy, | 283 sy, |
| 284 sx + width, | 284 sx + width, |
| 285 sy + height, | 285 sy + height, |
| 286 kVertexSize); | 286 kVertexSize); |
| 287 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), | 287 fVertices[2*fCurrVertex+1].setRectFan(SkFixedToFloat(texture->normalizeFixed
X(tx)), |
| 288 SkFixedToFloat(texture->normalizeFixed
Y(ty)), | 288 SkFixedToFloat(texture->normalizeFixed
Y(ty)), |
| 289 SkFixedToFloat(texture->normalizeFixed
X(tx + tw)), | 289 SkFixedToFloat(texture->normalizeFixed
X(tx + tw)), |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) | 449 SkScalarToFixed(y) - (glyph.fAdvanceY >> a
lignShift) |
| 450 + SK_FixedHalf, //d1g.fHalfSampleY, | 450 + SK_FixedHalf, //d1g.fHalfSampleY, |
| 451 fontScaler); | 451 fontScaler); |
| 452 } | 452 } |
| 453 pos += scalarsPerPosition; | 453 pos += scalarsPerPosition; |
| 454 } | 454 } |
| 455 } | 455 } |
| 456 | 456 |
| 457 this->finish(); | 457 this->finish(); |
| 458 } | 458 } |
| OLD | NEW |