Flutter Engine
The Flutter Engine
Functions
clipdrawdraw.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/SkRect.h"
#include "include/core/SkRegion.h"

Go to the source code of this file.

Functions

static void Draw (SkCanvas *canvas, const SkRect &rect)
 
 DEF_SIMPLE_GM_BG (clipdrawdraw, canvas, 512, 512, 0xFFCCCCCC)
 
 DEF_SIMPLE_GM (clip_region, canvas, 256, 256)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( clip_region  ,
canvas  ,
256  ,
256   
)

Definition at line 57 of file clipdrawdraw.cpp.

57 {
58 SkRegion rgn({ 10, 10, 100, 100 });
59
60 canvas->save();
61 canvas->clipRegion(rgn);
62 canvas->drawColor(SK_ColorRED);
63 canvas->restore();
64
65 SkRect bounds = { 30, 30, 80, 80 };
66 canvas->saveLayer(&bounds, nullptr);
67 canvas->clipRegion(rgn);
68 canvas->drawColor(SK_ColorBLUE);
69 canvas->restore();
70}
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
Optional< SkRect > bounds
Definition: SkRecords.h:189

◆ DEF_SIMPLE_GM_BG()

DEF_SIMPLE_GM_BG ( clipdrawdraw  ,
canvas  ,
512  ,
512  ,
0xFFCCCCCC   
)

Definition at line 43 of file clipdrawdraw.cpp.

43 {
44 // Vertical remnant
45 const SkRect rect1 = SkRect::MakeLTRB(136.5f, 137.5f, 338.5f, 293.5f);
46
47 // Horizontal remnant
48 // 179.488 rounds the right way (i.e., 179), 179.499 rounds the wrong way (i.e., 180)
49 const SkRect rect2 = SkRect::MakeLTRB(207.5f, 179.499f, 530.5f, 429.5f);
50
51 Draw(canvas, rect1);
52 Draw(canvas, rect2);
53}
static void Draw(SkCanvas *canvas, const SkRect &rect)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646

◆ Draw()

static void Draw ( SkCanvas canvas,
const SkRect rect 
)
static

Definition at line 24 of file clipdrawdraw.cpp.

24 {
25 SkPaint p;
26 p.setAntiAlias(false);
27
28 const SkRect bigRect = SkRect::MakeWH(600, 600);
29
30 canvas->save();
31 // draw a black rect through the clip
32 canvas->save();
33 canvas->clipRect(rect);
34 canvas->drawRect(bigRect, p);
35 canvas->restore();
36
37 // now draw the white rect on top
38 p.setColor(SK_ColorWHITE);
39 canvas->drawRect(rect, p);
40 canvas->restore();
41}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
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
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609