• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
12 // Exercises code in GrRenderTargetContext that attempts to replace a rrect clip/draw paint with
13 // draw rrect.
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);
25     canvas->clipRRect(rrect, true);
26     canvas->drawPaint(p);
27     canvas->restore();
28 
29     canvas->concat(zoomOut);
30     p.setColor(SK_ColorBLUE);
31     canvas->saveLayer(layerRect, nullptr);
32     canvas->clipRRect(rrect, false);
33     canvas->drawPaint(p);
34     canvas->restore();
35 
36     constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}};
37     constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN};
38     p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2,
39                                              SkShader::kClamp_TileMode));
40     canvas->concat(zoomOut);
41     canvas->saveLayer(layerRect, nullptr);
42     canvas->clipRRect(rrect, true);
43     canvas->drawPaint(p);
44     canvas->restore();
45 
46     constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY};
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);
51     canvas->clipRRect(rrect, false);
52     canvas->drawPaint(p);
53     canvas->restore();
54 }
55