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

Side by Side Diff: src/gpu/batches/GrAADistanceFieldPathRenderer.cpp

Issue 1535173002: Rejigger distance field path rect calcs to avoid underflow (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix comment Created 5 years 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 | « no previous file | 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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
10 10
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 scaledBounds.fRight *= scale; 335 scaledBounds.fRight *= scale;
336 scaledBounds.fBottom *= scale; 336 scaledBounds.fBottom *= scale;
337 // move the origin to an integer boundary (gives better results) 337 // move the origin to an integer boundary (gives better results)
338 SkScalar dx = SkScalarFraction(scaledBounds.fLeft); 338 SkScalar dx = SkScalarFraction(scaledBounds.fLeft);
339 SkScalar dy = SkScalarFraction(scaledBounds.fTop); 339 SkScalar dy = SkScalarFraction(scaledBounds.fTop);
340 scaledBounds.offset(-dx, -dy); 340 scaledBounds.offset(-dx, -dy);
341 // get integer boundary 341 // get integer boundary
342 SkIRect devPathBounds; 342 SkIRect devPathBounds;
343 scaledBounds.roundOut(&devPathBounds); 343 scaledBounds.roundOut(&devPathBounds);
344 // pad to allow room for antialiasing 344 // pad to allow room for antialiasing
345 devPathBounds.outset(SkScalarCeilToInt(kAntiAliasPad), SkScalarCeilToInt (kAntiAliasPad)); 345 const int intPad = SkScalarCeilToInt(kAntiAliasPad);
346 // move origin to upper left corner 346 // pre-move origin (after outset, will be 0,0)
347 devPathBounds.offsetTo(0,0); 347 int width = devPathBounds.width();
348 int height = devPathBounds.height();
349 devPathBounds.fLeft = intPad;
350 devPathBounds.fTop = intPad;
351 devPathBounds.fRight = intPad + width;
352 devPathBounds.fBottom = intPad + height;
353 devPathBounds.outset(intPad, intPad);
joshualitt 2015/12/18 17:36:45 I guess this could still overflow if width or heig
jvanverth1 2015/12/18 17:48:42 We've already caught that case in canDraw() -- we
348 354
349 // draw path to bitmap 355 // draw path to bitmap
350 SkMatrix drawMatrix; 356 SkMatrix drawMatrix;
351 drawMatrix.setTranslate(-bounds.left(), -bounds.top()); 357 drawMatrix.setTranslate(-bounds.left(), -bounds.top());
352 drawMatrix.postScale(scale, scale); 358 drawMatrix.postScale(scale, scale);
353 drawMatrix.postTranslate(kAntiAliasPad, kAntiAliasPad); 359 drawMatrix.postTranslate(kAntiAliasPad, kAntiAliasPad);
354 360
355 // setup bitmap backing 361 // setup bitmap backing
356 SkASSERT(devPathBounds.fLeft == 0); 362 SkASSERT(devPathBounds.fLeft == 0);
357 SkASSERT(devPathBounds.fTop == 0); 363 SkASSERT(devPathBounds.fTop == 0);
(...skipping 16 matching lines...) Expand all
374 rasterClip.setRect(devPathBounds); 380 rasterClip.setRect(devPathBounds);
375 draw.fRC = &rasterClip; 381 draw.fRC = &rasterClip;
376 draw.fClip = &rasterClip.bwRgn(); 382 draw.fClip = &rasterClip.bwRgn();
377 draw.fMatrix = &drawMatrix; 383 draw.fMatrix = &drawMatrix;
378 draw.fDst = dst; 384 draw.fDst = dst;
379 385
380 draw.drawPathCoverage(path, paint); 386 draw.drawPathCoverage(path, paint);
381 387
382 // generate signed distance field 388 // generate signed distance field
383 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad); 389 devPathBounds.outset(SK_DistanceFieldPad, SK_DistanceFieldPad);
384 int width = devPathBounds.width(); 390 width = devPathBounds.width();
385 int height = devPathBounds.height(); 391 height = devPathBounds.height();
386 // TODO We should really generate this directly into the plot somehow 392 // TODO We should really generate this directly into the plot somehow
387 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char)); 393 SkAutoSMalloc<1024> dfStorage(width * height * sizeof(unsigned char));
388 394
389 // Generate signed distance field 395 // Generate signed distance field
390 SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(), 396 SkGenerateDistanceFieldFromA8Image((unsigned char*)dfStorage.get(),
391 (const unsigned char*)dst.addr(), 397 (const unsigned char*)dst.addr(),
392 dst.width(), dst.height(), dst.rowByt es()); 398 dst.width(), dst.height(), dst.rowByt es());
393 399
394 // add to atlas 400 // add to atlas
395 SkIPoint16 atlasLocation; 401 SkIPoint16 atlasLocation;
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 geometry.fAntiAlias = random->nextBool(); 644 geometry.fAntiAlias = random->nextBool();
639 geometry.fGenID = random->nextU(); 645 geometry.fGenID = random->nextU();
640 646
641 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, 647 return AADistanceFieldPathBatch::Create(geometry, viewMatrix,
642 gTestStruct.fAtlas, 648 gTestStruct.fAtlas,
643 &gTestStruct.fPathCache, 649 &gTestStruct.fPathCache,
644 &gTestStruct.fPathList); 650 &gTestStruct.fPathList);
645 } 651 }
646 652
647 #endif 653 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698