OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkGpuDevice.h" | 8 #include "SkGpuDevice.h" |
9 | 9 |
10 #include "GrBlurUtils.h" | 10 #include "GrBlurUtils.h" |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); | 389 fDrawContext->drawPaint(fRenderTarget, fClip, grPaint, *draw.fMatrix); |
390 } | 390 } |
391 | 391 |
392 // must be in SkCanvas::PointMode order | 392 // must be in SkCanvas::PointMode order |
393 static const GrPrimitiveType gPointMode2PrimtiveType[] = { | 393 static const GrPrimitiveType gPointMode2PrimtiveType[] = { |
394 kPoints_GrPrimitiveType, | 394 kPoints_GrPrimitiveType, |
395 kLines_GrPrimitiveType, | 395 kLines_GrPrimitiveType, |
396 kLineStrip_GrPrimitiveType | 396 kLineStrip_GrPrimitiveType |
397 }; | 397 }; |
398 | 398 |
| 399 // suppress antialiasing on axis-aligned integer-coordinate lines |
| 400 static bool needs_antialiasing(SkCanvas::PointMode mode, size_t count, const SkP
oint pts[]) { |
| 401 if (mode == SkCanvas::PointMode::kPoints_PointMode) { |
| 402 return false; |
| 403 } |
| 404 if (count == 2) { |
| 405 // We do not antialias as long as the primary axis of the line is intege
r-aligned, even if |
| 406 // the other coordinates are not. This does mean the two end pixels of t
he line will be |
| 407 // sharp even when they shouldn't be, but turning antialiasing on (as th
ings stand |
| 408 // currently) means that the line will turn into a two-pixel-wide blur.
While obviously a |
| 409 // more complete fix is possible down the road, for the time being we ac
cept the error on |
| 410 // the two end pixels as being the lesser of two evils. |
| 411 if (pts[0].fX == pts[1].fX) { |
| 412 return ((int) pts[0].fX) != pts[0].fX; |
| 413 } |
| 414 if (pts[0].fY == pts[1].fY) { |
| 415 return ((int) pts[0].fY) != pts[0].fY; |
| 416 } |
| 417 } |
| 418 return true; |
| 419 } |
| 420 |
399 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, | 421 void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode, |
400 size_t count, const SkPoint pts[], const SkPaint& p
aint) { | 422 size_t count, const SkPoint pts[], const SkPaint& p
aint) { |
401 CHECK_FOR_ANNOTATION(paint); | 423 CHECK_FOR_ANNOTATION(paint); |
402 CHECK_SHOULD_DRAW(draw); | 424 CHECK_SHOULD_DRAW(draw); |
403 | 425 |
404 SkScalar width = paint.getStrokeWidth(); | 426 SkScalar width = paint.getStrokeWidth(); |
405 if (width < 0) { | 427 if (width < 0) { |
406 return; | 428 return; |
407 } | 429 } |
408 | 430 |
409 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { | 431 if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mod
e) { |
410 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); | 432 GrStrokeInfo strokeInfo(paint, SkPaint::kStroke_Style); |
411 GrPaint grPaint; | 433 GrPaint grPaint; |
412 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatri
x, true, | 434 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatri
x, true, |
413 &grPaint)) { | 435 &grPaint)) { |
414 return; | 436 return; |
415 } | 437 } |
416 SkPath path; | 438 SkPath path; |
417 path.setIsVolatile(true); | 439 path.setIsVolatile(true); |
418 path.moveTo(pts[0]); | 440 path.moveTo(pts[0]); |
419 path.lineTo(pts[1]); | 441 path.lineTo(pts[1]); |
420 fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, pat
h, strokeInfo); | 442 fDrawContext->drawPath(fRenderTarget, fClip, grPaint, *draw.fMatrix, pat
h, strokeInfo); |
421 return; | 443 return; |
422 } | 444 } |
423 | 445 |
424 // we only handle hairlines and paints without path effects or mask filters, | 446 // we only handle non-antialiased hairlines and paints without path effects
or mask filters, |
425 // else we let the SkDraw call our drawPath() | 447 // else we let the SkDraw call our drawPath() |
426 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter()) { | 448 if (width > 0 || paint.getPathEffect() || paint.getMaskFilter() || |
| 449 (paint.isAntiAlias() && needs_antialiasing(mode, count, pts))) { |
427 draw.drawPoints(mode, count, pts, paint, true); | 450 draw.drawPoints(mode, count, pts, paint, true); |
428 return; | 451 return; |
429 } | 452 } |
430 | 453 |
431 GrPaint grPaint; | 454 GrPaint grPaint; |
432 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t
rue, &grPaint)) { | 455 if (!SkPaint2GrPaint(this->context(), fRenderTarget, paint, *draw.fMatrix, t
rue, &grPaint)) { |
433 return; | 456 return; |
434 } | 457 } |
435 | 458 |
436 fDrawContext->drawVertices(fRenderTarget, | 459 fDrawContext->drawVertices(fRenderTarget, |
(...skipping 1416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1853 #endif | 1876 #endif |
1854 } | 1877 } |
1855 | 1878 |
1856 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { | 1879 SkImageFilter::Cache* SkGpuDevice::getImageFilterCache() { |
1857 // We always return a transient cache, so it is freed after each | 1880 // We always return a transient cache, so it is freed after each |
1858 // filter traversal. | 1881 // filter traversal. |
1859 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); | 1882 return SkImageFilter::Cache::Create(kDefaultImageFilterCacheSize); |
1860 } | 1883 } |
1861 | 1884 |
1862 #endif | 1885 #endif |
OLD | NEW |