OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkPath.h" | 9 #include "SkPath.h" |
10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
11 | 11 |
12 // Exercises code in GrDrawContext that attempts to replace a rrect clip/draw pa
int with draw rrect. | 12 // Exercises code in GrDrawContext that attempts to replace a rrect clip/draw pa
int with draw rrect. |
13 DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256) { | 13 DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256) { |
14 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(10.f, 10.f, 236.f, 236.
f), 30.f, 40.f); | 14 SkRRect rrect = SkRRect::MakeRectXY(SkRect::MakeXYWH(10.f, 10.f, 236.f, 236.
f), 30.f, 40.f); |
15 | 15 |
16 SkPaint p; | 16 SkPaint p; |
17 p.setColor(SK_ColorRED); | 17 p.setColor(SK_ColorRED); |
18 | 18 |
19 SkMatrix zoomOut; | 19 SkMatrix zoomOut; |
20 zoomOut.setScale(0.7f, 0.7f, 128.f, 128.f); | 20 zoomOut.setScale(0.7f, 0.7f, 128.f, 128.f); |
21 | 21 |
22 const SkRect layerRect = SkRect::MakeWH(256.f, 256.f); | 22 const SkRect layerRect = SkRect::MakeWH(256.f, 256.f); |
23 canvas->saveLayer(layerRect, nullptr); | 23 canvas->saveLayer(layerRect, nullptr); |
24 canvas->clipRRect(rrect, SkCanvas::kIntersect_Op, true); | 24 canvas->clipRRect(rrect, true); |
25 canvas->drawPaint(p); | 25 canvas->drawPaint(p); |
26 canvas->restore(); | 26 canvas->restore(); |
27 | 27 |
28 canvas->concat(zoomOut); | 28 canvas->concat(zoomOut); |
29 p.setColor(SK_ColorBLUE); | 29 p.setColor(SK_ColorBLUE); |
30 canvas->saveLayer(layerRect, nullptr); | 30 canvas->saveLayer(layerRect, nullptr); |
31 canvas->clipRRect(rrect, SkCanvas::kIntersect_Op, false); | 31 canvas->clipRRect(rrect, false); |
32 canvas->drawPaint(p); | 32 canvas->drawPaint(p); |
33 canvas->restore(); | 33 canvas->restore(); |
34 | 34 |
35 constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}}; | 35 constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}}; |
36 constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN}; | 36 constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN}; |
37 p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2, | 37 p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2, |
38 SkShader::kClamp_TileMode)); | 38 SkShader::kClamp_TileMode)); |
39 canvas->concat(zoomOut); | 39 canvas->concat(zoomOut); |
40 canvas->saveLayer(layerRect, nullptr); | 40 canvas->saveLayer(layerRect, nullptr); |
41 canvas->clipRRect(rrect, SkCanvas::kIntersect_Op, true); | 41 canvas->clipRRect(rrect, true); |
42 canvas->drawPaint(p); | 42 canvas->drawPaint(p); |
43 canvas->restore(); | 43 canvas->restore(); |
44 | 44 |
45 constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY}; | 45 constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY}; |
46 p.setShader(SkGradientShader::MakeRadial({128.f, 128.f}, 128.f, kColors2, nu
llptr, 2, | 46 p.setShader(SkGradientShader::MakeRadial({128.f, 128.f}, 128.f, kColors2, nu
llptr, 2, |
47 SkShader::kClamp_TileMode)); | 47 SkShader::kClamp_TileMode)); |
48 canvas->concat(zoomOut); | 48 canvas->concat(zoomOut); |
49 canvas->saveLayer(layerRect, nullptr); | 49 canvas->saveLayer(layerRect, nullptr); |
50 canvas->clipRRect(rrect, SkCanvas::kIntersect_Op, false); | 50 canvas->clipRRect(rrect, false); |
51 canvas->drawPaint(p); | 51 canvas->drawPaint(p); |
52 canvas->restore(); | 52 canvas->restore(); |
53 } | 53 } |
OLD | NEW |