blob: 291dc48042ce89b7f219379d3b8f887cc6d80a68 [file] [log] [blame]
bsalomoncb31e512016-08-26 10:48:19 -07001/*
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 Osman11052242016-10-27 14:47:55 -040012// Exercises code in GrRenderTargetContext that attempts to replace a rrect clip/draw paint with
13// draw rrect.
bsalomoncb31e512016-08-26 10:48:19 -070014DEF_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);
reed66998382016-09-21 11:15:07 -070025 canvas->clipRRect(rrect, true);
bsalomoncb31e512016-08-26 10:48:19 -070026 canvas->drawPaint(p);
27 canvas->restore();
28
29 canvas->concat(zoomOut);
30 p.setColor(SK_ColorBLUE);
31 canvas->saveLayer(layerRect, nullptr);
reed66998382016-09-21 11:15:07 -070032 canvas->clipRRect(rrect, false);
bsalomoncb31e512016-08-26 10:48:19 -070033 canvas->drawPaint(p);
34 canvas->restore();
35
mtkleindbfd7ab2016-09-01 11:24:54 -070036 constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}};
37 constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN};
bsalomoncb31e512016-08-26 10:48:19 -070038 p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2,
39 SkShader::kClamp_TileMode));
40 canvas->concat(zoomOut);
41 canvas->saveLayer(layerRect, nullptr);
reed66998382016-09-21 11:15:07 -070042 canvas->clipRRect(rrect, true);
bsalomoncb31e512016-08-26 10:48:19 -070043 canvas->drawPaint(p);
44 canvas->restore();
45
mtkleindbfd7ab2016-09-01 11:24:54 -070046 constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY};
bsalomoncb31e512016-08-26 10:48:19 -070047 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);
reed66998382016-09-21 11:15:07 -070051 canvas->clipRRect(rrect, false);
bsalomoncb31e512016-08-26 10:48:19 -070052 canvas->drawPaint(p);
53 canvas->restore();
54}