blob: cd1d709267832aa20a82a5674b704bd339ecc2c5 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner7fde8e12019-05-01 17:28:53 -04009#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 Kleinc0bd9f92019-04-23 12:05:21 -050018#include "include/effects/SkGradientShader.h"
bsalomoncb31e512016-08-26 10:48:19 -070019
Brian Osman11052242016-10-27 14:47:55 -040020// Exercises code in GrRenderTargetContext that attempts to replace a rrect clip/draw paint with
21// draw rrect.
bsalomoncb31e512016-08-26 10:48:19 -070022DEF_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);
reed66998382016-09-21 11:15:07 -070033 canvas->clipRRect(rrect, true);
bsalomoncb31e512016-08-26 10:48:19 -070034 canvas->drawPaint(p);
35 canvas->restore();
36
37 canvas->concat(zoomOut);
38 p.setColor(SK_ColorBLUE);
39 canvas->saveLayer(layerRect, nullptr);
reed66998382016-09-21 11:15:07 -070040 canvas->clipRRect(rrect, false);
bsalomoncb31e512016-08-26 10:48:19 -070041 canvas->drawPaint(p);
42 canvas->restore();
43
mtkleindbfd7ab2016-09-01 11:24:54 -070044 constexpr SkPoint kPts[] = {{0.f, 0.f}, {256.f, 256.f}};
45 constexpr SkColor kColors1[] = {SK_ColorCYAN, SK_ColorGREEN};
Mike Reedfae8fce2019-04-03 10:27:45 -040046 p.setShader(SkGradientShader::MakeLinear(kPts, kColors1, nullptr, 2, SkTileMode::kClamp));
bsalomoncb31e512016-08-26 10:48:19 -070047 canvas->concat(zoomOut);
48 canvas->saveLayer(layerRect, nullptr);
reed66998382016-09-21 11:15:07 -070049 canvas->clipRRect(rrect, true);
bsalomoncb31e512016-08-26 10:48:19 -070050 canvas->drawPaint(p);
51 canvas->restore();
52
mtkleindbfd7ab2016-09-01 11:24:54 -070053 constexpr SkColor kColors2[] = {SK_ColorMAGENTA, SK_ColorGRAY};
bsalomoncb31e512016-08-26 10:48:19 -070054 p.setShader(SkGradientShader::MakeRadial({128.f, 128.f}, 128.f, kColors2, nullptr, 2,
Mike Reedfae8fce2019-04-03 10:27:45 -040055 SkTileMode::kClamp));
bsalomoncb31e512016-08-26 10:48:19 -070056 canvas->concat(zoomOut);
57 canvas->saveLayer(layerRect, nullptr);
reed66998382016-09-21 11:15:07 -070058 canvas->clipRRect(rrect, false);
bsalomoncb31e512016-08-26 10:48:19 -070059 canvas->drawPaint(p);
60 canvas->restore();
61}