• 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/gm.h"
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"
18 #include "include/effects/SkGradientShader.h"
19 
20 // Exercises code in skgpu::V1::SurfaceDrawContext that attempts to replace a rrect clip/draw
21 // paint with draw rrect.
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);
33     canvas->clipRRect(rrect, true);
34     canvas->drawPaint(p);
35     canvas->restore();
36 
37     canvas->concat(zoomOut);
38     p.setColor(SK_ColorBLUE);
39     canvas->saveLayer(layerRect, nullptr);
40     canvas->clipRRect(rrect, false);
41     canvas->drawPaint(p);
42     canvas->restore();
43 
44     constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}};
45     constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN};
46     p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2, SkTileMode::kClamp));
47     canvas->concat(zoomOut);
48     canvas->saveLayer(layerRect, nullptr);
49     canvas->clipRRect(rrect, true);
50     canvas->drawPaint(p);
51     canvas->restore();
52 
53     constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY};
54     p.setShader(SkGradientShader::MakeRadial({128.f, 128.f}, 128.f, kColors2, nullptr, 2,
55                                              SkTileMode::kClamp));
56     canvas->concat(zoomOut);
57     canvas->saveLayer(layerRect, nullptr);
58     canvas->clipRRect(rrect, false);
59     canvas->drawPaint(p);
60     canvas->restore();
61 }
62