Flutter Engine
The Flutter Engine
clip_strokerect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 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"
12#include "include/core/SkRect.h"
13#include "include/core/SkSize.h"
15
17public:
19
20 }
21
22protected:
23 SkString getName() const override { return SkString("clip_strokerect"); }
24
25 SkISize getISize() override { return SkISize::Make(200, 400); }
26
27 void onDraw(SkCanvas* canvas) override {
28 SkPaint p;
29 p.setColor(SK_ColorRED);
30 p.setAntiAlias(true);
31 p.setStyle(SkPaint::kStroke_Style);
32 p.setStrokeWidth(22);
33
34 SkRect r = SkRect::MakeXYWH(20, 20, 100, 100);
35 // setting the height of this to 19 causes failure
36 SkRect rect = SkRect::MakeXYWH(20, 0, 100, 20);
37
38 canvas->save();
39 canvas->clipRect(rect, true);
40 canvas->drawRect(r, p);
41 canvas->restore();
42
43 p.setColor(SK_ColorBLUE);
44 p.setStrokeWidth(2);
45 canvas->drawRect(rect, p);
46
47 p.setColor(SK_ColorRED);
48 p.setAntiAlias(true);
49 p.setStyle(SkPaint::kStroke_Style);
50 p.setStrokeWidth(22);
51
52 SkRect r2 = SkRect::MakeXYWH(20, 140, 100, 100);
53 // setting the height of this to 19 causes failure
54 SkRect rect2 = SkRect::MakeXYWH(20, 120, 100, 19);
55
56 canvas->save();
57 canvas->clipRect(rect2, true);
58 canvas->drawRect(r2, p);
59 canvas->restore();
60
61 p.setColor(SK_ColorBLUE);
62 p.setStrokeWidth(2);
63 canvas->drawRect(rect2, p);
64 }
65
66private:
67 using INHERITED = skiagm::GM;
68};
69
70DEF_GM(return new ClipStrokeRectGM;)
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
SkISize getISize() override
void onDraw(SkCanvas *canvas) override
SkString getName() const override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
int save()
Definition: SkCanvas.cpp:447
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: gm.h:110
#define DEF_GM(CODE)
Definition: gm.h:40
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659