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