Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: src/gpu/GrDistanceFieldTextContext.cpp

Issue 432443002: Add vertex bounds check for distance field rendering. (Closed) Base URL: https://skia.googlesource.com/skia.git@df-effectcache-7-28
Patch Set: Clean up whitespace. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 #else 62 #else
63 fEnableDFRendering = enable; 63 fEnableDFRendering = enable;
64 #endif 64 #endif
65 fStrike = NULL; 65 fStrike = NULL;
66 fGammaTexture = NULL; 66 fGammaTexture = NULL;
67 67
68 fCurrVertex = 0; 68 fCurrVertex = 0;
69 fEffectTextureUniqueID = SK_InvalidUniqueID; 69 fEffectTextureUniqueID = SK_InvalidUniqueID;
70 fEffectColor = GrColor_ILLEGAL; 70 fEffectColor = GrColor_ILLEGAL;
71 fEffectFlags = 0; 71 fEffectFlags = 0;
72 72
73 fVertices = NULL; 73 fVertices = NULL;
74
75 fVertexBounds.setLargestInverted();
74 } 76 }
75 77
76 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() { 78 GrDistanceFieldTextContext::~GrDistanceFieldTextContext() {
77 this->flushGlyphs(); 79 this->flushGlyphs();
78 SkSafeSetNull(fGammaTexture); 80 SkSafeSetNull(fGammaTexture);
79 } 81 }
80 82
81 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) { 83 bool GrDistanceFieldTextContext::canDraw(const SkPaint& paint) {
82 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) { 84 if (!fEnableDFRendering && !paint.isDistanceFieldTextTEMP()) {
83 return false; 85 return false;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff()); 220 drawState->setBlendFunc(fPaint.getSrcBlendCoeff(), fPaint.getDstBlen dCoeff());
219 //drawState->setColor(fPaint.getColor()); 221 //drawState->setColor(fPaint.getColor());
220 // We're using per-vertex color. 222 // We're using per-vertex color.
221 SkASSERT(drawState->hasColorVertexAttribute()); 223 SkASSERT(drawState->hasColorVertexAttribute());
222 drawState->setColor(0xFFFFFFFF); 224 drawState->setColor(0xFFFFFFFF);
223 } 225 }
224 int nGlyphs = fCurrVertex / 4; 226 int nGlyphs = fCurrVertex / 4;
225 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer()); 227 fDrawTarget->setIndexSourceToBuffer(fContext->getQuadIndexBuffer());
226 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType, 228 fDrawTarget->drawIndexedInstances(kTriangles_GrPrimitiveType,
227 nGlyphs, 229 nGlyphs,
228 4, 6); 230 4, 6, &fVertexBounds);
229 fCurrVertex = 0; 231 fCurrVertex = 0;
232 fVertexBounds.setLargestInverted();
230 } 233 }
234
231 fDrawTarget->resetVertexSource(); 235 fDrawTarget->resetVertexSource();
232 fVertices = NULL; 236 fVertices = NULL;
233 } 237 }
234 238
235 void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed, 239 void GrDistanceFieldTextContext::drawPackedGlyph(GrGlyph::PackedID packed,
236 SkFixed vx, SkFixed vy, 240 SkFixed vx, SkFixed vy,
237 GrFontScaler* scaler) { 241 GrFontScaler* scaler) {
238 GrGlyph* glyph = fStrike->getGlyph(packed, scaler); 242 GrGlyph* glyph = fStrike->getGlyph(packed, scaler);
239 if (NULL == glyph || glyph->fBounds.isEmpty()) { 243 if (NULL == glyph || glyph->fBounds.isEmpty()) {
240 return; 244 return;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn set); 326 SkScalar width = SkIntToScalar(glyph->fBounds.width() - 2*SK_DistanceFieldIn set);
323 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField Inset); 327 SkScalar height = SkIntToScalar(glyph->fBounds.height() - 2*SK_DistanceField Inset);
324 328
325 SkScalar scale = fTextRatio; 329 SkScalar scale = fTextRatio;
326 dx *= scale; 330 dx *= scale;
327 dy *= scale; 331 dy *= scale;
328 sx += dx; 332 sx += dx;
329 sy += dy; 333 sy += dy;
330 width *= scale; 334 width *= scale;
331 height *= scale; 335 height *= scale;
332 336
333 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset); 337 SkFixed tx = SkIntToFixed(glyph->fAtlasLocation.fX + SK_DistanceFieldInset);
334 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset); 338 SkFixed ty = SkIntToFixed(glyph->fAtlasLocation.fY + SK_DistanceFieldInset);
335 SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset); 339 SkFixed tw = SkIntToFixed(glyph->fBounds.width() - 2*SK_DistanceFieldInset);
336 SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset) ; 340 SkFixed th = SkIntToFixed(glyph->fBounds.height() - 2*SK_DistanceFieldInset) ;
337 341
342 SkRect r;
343 r.fLeft = SkFixedToFloat(sx);
344 r.fTop = SkFixedToFloat(sy);
345 r.fRight = SkFixedToFloat(sx + width);
346 r.fBottom = SkFixedToFloat(sy + height);
347
348 fVertexBounds.growToInclude(r);
349
338 size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint)) 350 size_t vertSize = fUseLCDText ? (2 * sizeof(SkPoint))
339 : (2 * sizeof(SkPoint) + sizeof(GrColor)); 351 : (2 * sizeof(SkPoint) + sizeof(GrColor));
340 352
341 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize()); 353 SkASSERT(vertSize == fDrawTarget->getDrawState().getVertexSize());
342 354
343 SkPoint* positions = reinterpret_cast<SkPoint*>( 355 SkPoint* positions = reinterpret_cast<SkPoint*>(
344 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex); 356 reinterpret_cast<intptr_t>(fVertices) + vertSize * fCurrVertex);
345 positions->setRectFan(sx, sy, sx + width, sy + height, vertSize); 357 positions->setRectFan(r.fLeft, r.fTop, r.fRight, r.fBottom, vertSize);
346 358
347 // The texture coords are last in both the with and without color vertex lay outs. 359 // The texture coords are last in both the with and without color vertex lay outs.
348 SkPoint* textureCoords = reinterpret_cast<SkPoint*>( 360 SkPoint* textureCoords = reinterpret_cast<SkPoint*>(
349 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ; 361 reinterpret_cast<intptr_t>(positions) + vertSize - sizeof(SkPoint)) ;
350 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)), 362 textureCoords->setRectFan(SkFixedToFloat(texture->normalizeFixedX(tx)),
351 SkFixedToFloat(texture->normalizeFixedY(ty)), 363 SkFixedToFloat(texture->normalizeFixedY(ty)),
352 SkFixedToFloat(texture->normalizeFixedX(tx + tw)), 364 SkFixedToFloat(texture->normalizeFixedX(tx + tw)),
353 SkFixedToFloat(texture->normalizeFixedY(ty + th)), 365 SkFixedToFloat(texture->normalizeFixedY(ty + th)),
354 vertSize); 366 vertSize);
355 if (!fUseLCDText) { 367 if (!fUseLCDText) {
356 // color comes after position. 368 // color comes after position.
357 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1); 369 GrColor* colors = reinterpret_cast<GrColor*>(positions + 1);
358 for (int i = 0; i < 4; ++i) { 370 for (int i = 0; i < 4; ++i) {
359 *colors = fPaint.getColor(); 371 *colors = fPaint.getColor();
360 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(color s) + vertSize); 372 colors = reinterpret_cast<GrColor*>(reinterpret_cast<intptr_t>(color s) + vertSize);
361 } 373 }
362 } 374 }
363 375
364 fCurrVertex += 4; 376 fCurrVertex += 4;
365 } 377 }
366 378
367 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint & skPaint) { 379 inline void GrDistanceFieldTextContext::init(const GrPaint& paint, const SkPaint & skPaint) {
368 GrTextContext::init(paint, skPaint); 380 GrTextContext::init(paint, skPaint);
369 381
370 fStrike = NULL; 382 fStrike = NULL;
371 383
372 fCurrVertex = 0; 384 fCurrVertex = 0;
373 385
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift), 631 SkScalarToFixed(x) - (glyph.fAdvanceX >> a lignShift),
620 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift), 632 SkScalarToFixed(y) - (glyph.fAdvanceY >> a lignShift),
621 fontScaler); 633 fontScaler);
622 } 634 }
623 pos += scalarsPerPosition; 635 pos += scalarsPerPosition;
624 } 636 }
625 } 637 }
626 638
627 this->finish(); 639 this->finish();
628 } 640 }
OLDNEW
« no previous file with comments | « src/gpu/GrDistanceFieldTextContext.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698