Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
clipshader.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkGradientShader.h"
#include "tools/Resources.h"

Go to the source code of this file.

Functions

 DEF_SIMPLE_GM (clipshadermatrix, canvas, 145, 128)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( clipshadermatrix  ,
canvas  ,
145  ,
128   
)

Definition at line 22 of file clipshader.cpp.

22 {
23 auto clipSurface = SkSurfaces::Raster(SkImageInfo::MakeA8({70, 60}));
24 // Hard edged oval clip
25 clipSurface->getCanvas()->drawOval(SkRect::MakeXYWH(0, 10, 64, 44), SkPaint{});
26 auto clipShader = clipSurface->makeImageSnapshot()->makeShader(
28
29 canvas->translate(5, 0);
30 for (auto tx : {0.f, 68.5f}) {
31 for (auto ty : {0.f, 66.5f}) {
32 canvas->save();
33
34 canvas->translate(tx, ty);
35 canvas->clipShader(clipShader);
36 canvas->translate(-tx, -ty);
37
38 SkMatrix m;
39 m.setSkew(0.03f, 0.f);
40 m.setPerspY( 0.0007f);
41 m.setPerspX(-0.002f);
42 m.setScaleX(1.2f); m.setScaleY(0.8f);
43 m.preRotate(30.f);
44 canvas->concat(m);
45
46 SkPoint center = {64, 64};
47 SkAssertResult(m.invert(&m));
48 center = m.mapPoint(center);
51 auto gradient = SkGradientShader::MakeRadial(
52 center,
53 /*radius=*/32.f,
54 colors,
55 /*pos=*/nullptr,
56 std::size(colors),
58 /*flags=*/0,
59 /*localMatrix=*/nullptr);
60
62 paint.setShader(std::move(gradient));
63 canvas->drawPaint(paint);
64
65 canvas->restore();
66 }
67 }
68}
#define SkAssertResult(cond)
Definition SkAssert.h:123
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
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_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
static SkScalar center(float pos0, float pos1)
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)
const Paint & paint
PODArray< SkColor > colors
Definition SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeA8(int width, int height)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659