Flutter Engine
The Flutter Engine
drawregionmodes.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"
19#include "include/core/SkSize.h"
25
27public:
29
30protected:
31 SkString getName() const override { return SkString("drawregionmodes"); }
32
33 SkISize getISize() override { return SkISize::Make(375, 500); }
34
35 void onOnceBeforeDraw() override {
36 fRegion.op({50, 50, 100, 100}, SkRegion::kUnion_Op);
37 fRegion.op({50, 100, 150, 150}, SkRegion::kUnion_Op);
38 }
39
40 void onDraw(SkCanvas* canvas) override {
41 canvas->clear(SK_ColorGREEN);
42
45 paint.setColor(SK_ColorRED);
46 paint.setAntiAlias(true);
47
48 canvas->save();
49 canvas->translate(-50.0f, 75.0f);
50 canvas->rotate(-45.0f);
51 canvas->drawRegion(fRegion, paint);
52
53 canvas->translate(125.0f, 125.0f);
54 paint.setImageFilter(SkImageFilters::Blur(5.0f, 5.0f, nullptr, nullptr));
55 canvas->drawRegion(fRegion, paint);
56
57 canvas->translate(-125.0f, 125.0f);
58 paint.setImageFilter(nullptr);
60 canvas->drawRegion(fRegion, paint);
61
62 canvas->translate(-125.0f, -125.0f);
63 paint.setMaskFilter(nullptr);
65 float intervals[] = { 5.0f, 5.0f };
66 paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f));
67 canvas->drawRegion(fRegion, paint);
68
69 canvas->restore();
70
71 canvas->translate(100, 325);
72 paint.setPathEffect(nullptr);
74 SkPoint points[] = { SkPoint::Make(50.0f, 50.0f), SkPoint::Make(150.0f, 150.0f) };
76 paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2,
78 canvas->drawRegion(fRegion, paint);
79 }
80
81private:
82 SkRegion fRegion;
83
84 using INHERITED = skiagm::GM;
85};
86DEF_GM( return new DrawRegionModesGM; )
static const int points[]
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
void onDraw(SkCanvas *canvas) override
SkISize getISize() override
void onOnceBeforeDraw() override
SkString getName() const override
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clear(SkColor color)
Definition: SkCanvas.h:1199
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
void drawRegion(const SkRegion &region, const SkPaint &paint)
Definition: SkCanvas.cpp:1685
int save()
Definition: SkCanvas.cpp:447
static sk_sp< SkPathEffect > Make(const SkScalar intervals[], int count, SkScalar phase)
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)
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition: SkPaint.h:193
@ kUnion_Op
target unioned with operand
Definition: SkRegion.h:369
bool op(const SkIRect &rect, Op op)
Definition: SkRegion.h:384
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
#define DEF_GM(CODE)
Definition: gm.h:40
PODArray< SkColor > colors
Definition: SkRecords.h:276
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173