skbug1719.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2013 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "gm/gm.h"
  8. #include "include/core/SkBlendMode.h"
  9. #include "include/core/SkBlurTypes.h"
  10. #include "include/core/SkCanvas.h"
  11. #include "include/core/SkColorFilter.h"
  12. #include "include/core/SkMaskFilter.h"
  13. #include "include/core/SkPaint.h"
  14. #include "include/core/SkPath.h"
  15. #include "include/core/SkScalar.h"
  16. /**
  17. * This test exercises bug 1719. An anti-aliased blurred path is rendered through a soft clip. On
  18. * the GPU a scratch texture was used to hold the original path mask as well as the blurred path
  19. * result. The same texture is then incorrectly used to generate the soft clip mask for the draw.
  20. * Thus the same texture is used for both the blur mask and soft mask in a single draw.
  21. *
  22. * The correct image should look like a thin stroked round rect.
  23. */
  24. DEF_SIMPLE_GM_BG(skbug1719, canvas, 300, 100, 0xFF303030) {
  25. canvas->translate(SkIntToScalar(-800), SkIntToScalar(-650));
  26. // The data is lifted from an SKP that exhibited the bug.
  27. // This is a round rect.
  28. SkPath clipPath;
  29. clipPath.moveTo(832.f, 654.f);
  30. clipPath.lineTo(1034.f, 654.f);
  31. clipPath.cubicTo(1038.4183f, 654.f, 1042.f, 657.58173f, 1042.f, 662.f);
  32. clipPath.lineTo(1042.f, 724.f);
  33. clipPath.cubicTo(1042.f, 728.41827f, 1038.4183f, 732.f, 1034.f, 732.f);
  34. clipPath.lineTo(832.f, 732.f);
  35. clipPath.cubicTo(827.58173f, 732.f, 824.f, 728.41827f, 824.f, 724.f);
  36. clipPath.lineTo(824.f, 662.f);
  37. clipPath.cubicTo(824.f, 657.58173f, 827.58173f, 654.f, 832.f, 654.f);
  38. clipPath.close();
  39. // This is a round rect nested inside a rect.
  40. SkPath drawPath;
  41. drawPath.moveTo(823.f, 653.f);
  42. drawPath.lineTo(1043.f, 653.f);
  43. drawPath.lineTo(1043.f, 733.f);
  44. drawPath.lineTo(823.f, 733.f);
  45. drawPath.lineTo(823.f, 653.f);
  46. drawPath.close();
  47. drawPath.moveTo(832.f, 654.f);
  48. drawPath.lineTo(1034.f, 654.f);
  49. drawPath.cubicTo(1038.4183f, 654.f, 1042.f, 657.58173f, 1042.f, 662.f);
  50. drawPath.lineTo(1042.f, 724.f);
  51. drawPath.cubicTo(1042.f, 728.41827f, 1038.4183f, 732.f, 1034.f, 732.f);
  52. drawPath.lineTo(832.f, 732.f);
  53. drawPath.cubicTo(827.58173f, 732.f, 824.f, 728.41827f, 824.f, 724.f);
  54. drawPath.lineTo(824.f, 662.f);
  55. drawPath.cubicTo(824.f, 657.58173f, 827.58173f, 654.f, 832.f, 654.f);
  56. drawPath.close();
  57. drawPath.setFillType(SkPath::kEvenOdd_FillType);
  58. SkPaint paint;
  59. paint.setAntiAlias(true);
  60. paint.setColor(0xFF000000);
  61. paint.setMaskFilter(
  62. SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 0.78867501f));
  63. paint.setColorFilter(SkColorFilters::Blend(0xBFFFFFFF, SkBlendMode::kSrcIn));
  64. canvas->clipPath(clipPath, true);
  65. canvas->drawPath(drawPath, paint);
  66. }