Flutter Engine
The Flutter Engine
rrectclipdrawpaint.cpp
Go to the documentation of this file.
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"
15#include "include/core/SkRect.h"
19
20// Exercises code in skgpu::V1::SurfaceDrawContext that attempts to replace a rrect clip/draw
21// paint with draw rrect.
22DEF_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,
56 canvas->concat(zoomOut);
57 canvas->saveLayer(layerRect, nullptr);
58 canvas->clipRRect(rrect, false);
59 canvas->drawPaint(p);
60 canvas->restore();
61}
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:296
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
SkRRect rrect
Definition: SkRecords.h:232
static constexpr SkPoint kPts[kPtsCount]
Definition: emptypath.cpp:123
DEF_SIMPLE_GM(rrect_clip_draw_paint, canvas, 256, 256)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609