bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 "SkPath.h" |
| 10 | #include "SkGradientShader.h" |
| 11 | |
Brian Osman | 1105224 | 2016-10-27 14:47:55 -0400 | [diff] [blame] | 12 | // Exercises code in GrRenderTargetContext that attempts to replace a rrect clip/draw paint with |
| 13 | // draw rrect. |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 14 | DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256) { |
| 15 | SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(10.f, 10.f, 236.f, 236.f), 30.f, 40.f); |
| 16 | |
| 17 | SkPaint p; |
| 18 | p.setColor(SK_ColorRED); |
| 19 | |
| 20 | SkMatrix zoomOut; |
| 21 | zoomOut.setScale(0.7f, 0.7f, 128.f, 128.f); |
| 22 | |
| 23 | const SkRect layerRect = SkRect::MakeWH(256.f, 256.f); |
| 24 | canvas->saveLayer(layerRect, nullptr); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 25 | canvas->clipRRect(rrect, true); |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 26 | canvas->drawPaint(p); |
| 27 | canvas->restore(); |
| 28 | |
| 29 | canvas->concat(zoomOut); |
| 30 | p.setColor(SK_ColorBLUE); |
| 31 | canvas->saveLayer(layerRect, nullptr); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 32 | canvas->clipRRect(rrect, false); |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 33 | canvas->drawPaint(p); |
| 34 | canvas->restore(); |
| 35 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 36 | constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}}; |
| 37 | constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN}; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 38 | p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2, |
| 39 | SkShader::kClamp_TileMode)); |
| 40 | canvas->concat(zoomOut); |
| 41 | canvas->saveLayer(layerRect, nullptr); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 42 | canvas->clipRRect(rrect, true); |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 43 | canvas->drawPaint(p); |
| 44 | canvas->restore(); |
| 45 | |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 46 | constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY}; |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 47 | p.setShader(SkGradientShader::MakeRadial({128.f, 128.f}, 128.f, kColors2, nullptr, 2, |
| 48 | SkShader::kClamp_TileMode)); |
| 49 | canvas->concat(zoomOut); |
| 50 | canvas->saveLayer(layerRect, nullptr); |
reed | 6699838 | 2016-09-21 11:15:07 -0700 | [diff] [blame] | 51 | canvas->clipRRect(rrect, false); |
bsalomon | cb31e51 | 2016-08-26 10:48:19 -0700 | [diff] [blame] | 52 | canvas->drawPaint(p); |
| 53 | canvas->restore(); |
| 54 | } |