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 8 #include "gm.h" 9 #include "SkColorFilter.h" 10 #include "SkBlurMaskFilter.h" 11 12 namespace skiagm { 13 14 /** 15 * This test exercises bug 1719. An anti-aliased blurred path is rendered through a soft clip. On 16 * the GPU a scratch texture was used to hold the original path mask as well as the blurred path 17 * result. The same texture is then incorrectly used to generate the soft clip mask for the draw. 18 * Thus the same texture is used for both the blur mask and soft mask in a single draw. 19 * 20 * The correct image should look like a thin stroked round rect. 21 */ 22 class SkBug1719GM : public GM { 23 public: 24 SkBug1719GM() {} 25 26 protected: 27 virtual SkString onShortName() SK_OVERRIDE { 28 return SkString("skbug1719"); 29 } 30 31 virtual SkISize onISize() SK_OVERRIDE { 32 return SkISize::Make(300, 100); 33 } 34 35 virtual void onDrawBackground(SkCanvas* canvas) SK_OVERRIDE { 36 SkPaint bgPaint; 37 bgPaint.setColor(0xFF303030); 38 canvas->drawPaint(bgPaint); 39 } 40 41 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE { 42 canvas->translate(SkIntToScalar(-800), SkIntToScalar(-650)); 43 44 // The data is lifted from an SKP that exhibited the bug. 45 46 // This is a round rect. 47 SkPath clipPath; 48 clipPath.moveTo(832.f, 654.f); 49 clipPath.lineTo(1034.f, 654.f); 50 clipPath.cubicTo(1038.4183f, 654.f, 1042.f, 657.58173f, 1042.f, 662.f); 51 clipPath.lineTo(1042.f, 724.f); 52 clipPath.cubicTo(1042.f, 728.41827f, 1038.4183f, 732.f, 1034.f, 732.f); 53 clipPath.lineTo(832.f, 732.f); 54 clipPath.cubicTo(827.58173f, 732.f, 824.f, 728.41827f, 824.f, 724.f); 55 clipPath.lineTo(824.f, 662.f); 56 clipPath.cubicTo(824.f, 657.58173f, 827.58173f, 654.f, 832.f, 654.f); 57 clipPath.close(); 58 59 // This is a round rect nested inside a rect. 60 SkPath drawPath; 61 drawPath.moveTo(823.f, 653.f); 62 drawPath.lineTo(1043.f, 653.f); 63 drawPath.lineTo(1043.f, 733.f); 64 drawPath.lineTo(823.f, 733.f); 65 drawPath.lineTo(823.f, 653.f); 66 drawPath.close(); 67 drawPath.moveTo(832.f, 654.f); 68 drawPath.lineTo(1034.f, 654.f); 69 drawPath.cubicTo(1038.4183f, 654.f, 1042.f, 657.58173f, 1042.f, 662.f); 70 drawPath.lineTo(1042.f, 724.f); 71 drawPath.cubicTo(1042.f, 728.41827f, 1038.4183f, 732.f, 1034.f, 732.f); 72 drawPath.lineTo(832.f, 732.f); 73 drawPath.cubicTo(827.58173f, 732.f, 824.f, 728.41827f, 824.f, 724.f); 74 drawPath.lineTo(824.f, 662.f); 75 drawPath.cubicTo(824.f, 657.58173f, 827.58173f, 654.f, 832.f, 654.f); 76 drawPath.close(); 77 drawPath.setFillType(SkPath::kEvenOdd_FillType); 78 79 SkPaint paint; 80 paint.setAntiAlias(true); 81 paint.setColor(0xFF000000); 82 paint.setMaskFilter( 83 SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 84 0.78867501f, 85 SkBlurMaskFilter::kHighQuality_BlurFlag))->unref(); 86 paint.setColorFilter( 87 SkColorFilter::CreateModeFilter(0xBFFFFFFF, SkXfermode::kSrcIn_Mode))->unref(); 88 89 canvas->clipPath(clipPath, SkRegion::kIntersect_Op, true); 90 canvas->drawPath(drawPath, paint); 91 } 92 93 private: 94 95 typedef GM INHERITED; 96 }; 97 98 ////////////////////////////////////////////////////////////////////////////// 99 100 DEF_GM(return new SkBug1719GM;) 101 102 } 103