Flutter Engine
flutter::testing::MockCanvas Class Reference

#include <mock_canvas.h>

Inheritance diagram for flutter::testing::MockCanvas:

Classes

struct  ClipPathData
 
struct  ClipRectData
 
struct  ClipRRectData
 
struct  ConcatMatrix44Data
 
struct  ConcatMatrixData
 
struct  DrawCall
 
struct  DrawPaint
 
struct  DrawPathData
 
struct  DrawPictureData
 
struct  DrawRectData
 
struct  DrawShadowData
 
struct  DrawTextData
 
struct  RestoreData
 
struct  SaveData
 
struct  SaveLayerData
 
struct  SetMatrixData
 

Public Types

using DrawCallData = std::variant< SaveData, SaveLayerData, RestoreData, ConcatMatrixData, ConcatMatrix44Data, SetMatrixData, DrawRectData, DrawPathData, DrawTextData, DrawPictureData, DrawShadowData, ClipRectData, ClipRRectData, ClipPathData, DrawPaint >
 

Public Member Functions

 MockCanvas ()
 
 ~MockCanvas () override
 
SkNWayCanvas * internal_canvas ()
 
const std::vector< DrawCall > & draw_calls () const
 

Protected Member Functions

void willSave () override
 
SaveLayerStrategy getSaveLayerStrategy (const SaveLayerRec &rec) override
 
void willRestore () override
 
void didRestore () override
 
void didConcat (const SkMatrix &matrix) override
 
void didConcat44 (const SkM44 &) override
 
void didScale (SkScalar x, SkScalar y) override
 
void didTranslate (SkScalar x, SkScalar y) override
 
void didSetMatrix (const SkMatrix &matrix) override
 
void onDrawRect (const SkRect &rect, const SkPaint &paint) override
 
void onDrawPath (const SkPath &path, const SkPaint &paint) override
 
void onDrawTextBlob (const SkTextBlob *text, SkScalar x, SkScalar y, const SkPaint &paint) override
 
void onDrawShadowRec (const SkPath &path, const SkDrawShadowRec &rec) override
 
void onDrawPicture (const SkPicture *picture, const SkMatrix *matrix, const SkPaint *paint) override
 
void onClipRect (const SkRect &rect, SkClipOp op, ClipEdgeStyle style) override
 
void onClipRRect (const SkRRect &rrect, SkClipOp op, ClipEdgeStyle style) override
 
void onClipPath (const SkPath &path, SkClipOp op, ClipEdgeStyle style) override
 
bool onDoSaveBehind (const SkRect *) override
 
void onDrawAnnotation (const SkRect &, const char[], SkData *) override
 
void onDrawDRRect (const SkRRect &, const SkRRect &, const SkPaint &) override
 
void onDrawDrawable (SkDrawable *, const SkMatrix *) override
 
void onDrawPatch (const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode, const SkPaint &) override
 
void onDrawPaint (const SkPaint &) override
 
void onDrawBehind (const SkPaint &) override
 
void onDrawPoints (PointMode, size_t, const SkPoint[], const SkPaint &) override
 
void onDrawRegion (const SkRegion &, const SkPaint &) override
 
void onDrawOval (const SkRect &, const SkPaint &) override
 
void onDrawArc (const SkRect &, SkScalar, SkScalar, bool, const SkPaint &) override
 
void onDrawRRect (const SkRRect &, const SkPaint &) override
 
void onDrawImage (const SkImage *image, SkScalar x, SkScalar y, const SkPaint *paint) override
 
void onDrawImageRect (const SkImage *, const SkRect *, const SkRect &, const SkPaint *, SrcRectConstraint) override
 
void onDrawImageNine (const SkImage *, const SkIRect &, const SkRect &, const SkPaint *) override
 
void onDrawImageLattice (const SkImage *, const Lattice &, const SkRect &, const SkPaint *) override
 
void onDrawVerticesObject (const SkVertices *, SkBlendMode, const SkPaint &) override
 
void onDrawAtlas (const SkImage *, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkRect *, const SkPaint *) override
 
void onDrawEdgeAAQuad (const SkRect &, const SkPoint[4], QuadAAFlags, const SkColor4f &, SkBlendMode) override
 
void onDrawEdgeAAImageSet (const ImageSetEntry[], int, const SkPoint[], const SkMatrix[], const SkPaint *, SrcRectConstraint) override
 
void onClipRegion (const SkRegion &, SkClipOp) override
 

Detailed Description

Definition at line 35 of file mock_canvas.h.

Member Typedef Documentation

◆ DrawCallData

Constructor & Destructor Documentation

◆ MockCanvas()

flutter::testing::MockCanvas::MockCanvas ( )

Definition at line 19 of file mock_canvas.cc.

20  : SkCanvasVirtualEnforcer<SkCanvas>(kSize.fWidth, kSize.fHeight),
21  internal_canvas_(imageInfo().width(), imageInfo().height()),
22  current_layer_(0) {
23  internal_canvas_.addCanvas(this);
24 }
constexpr SkISize kSize
Definition: mock_canvas.cc:17

◆ ~MockCanvas()

flutter::testing::MockCanvas::~MockCanvas ( )
override

Definition at line 26 of file mock_canvas.cc.

26  {
27  EXPECT_EQ(current_layer_, 0);
28 }

Member Function Documentation

◆ didConcat()

void flutter::testing::MockCanvas::didConcat ( const SkMatrix &  matrix)
overrideprotected

Definition at line 59 of file mock_canvas.cc.

Referenced by didRestore(), didScale(), and didTranslate().

59  {
60  draw_calls_.emplace_back(DrawCall{current_layer_, ConcatMatrixData{matrix}});
61 }

◆ didConcat44()

void flutter::testing::MockCanvas::didConcat44 ( const SkM44 &  matrix)
overrideprotected

Definition at line 63 of file mock_canvas.cc.

Referenced by didRestore().

63  {
64  draw_calls_.emplace_back(
65  DrawCall{current_layer_, ConcatMatrix44Data{matrix}});
66 }

◆ didRestore()

◆ didScale()

void flutter::testing::MockCanvas::didScale ( SkScalar  x,
SkScalar  y 
)
overrideprotected

Definition at line 68 of file mock_canvas.cc.

References didConcat().

Referenced by didRestore().

68  {
69  SkMatrix m;
70  m.setScale(x, y);
71  this->didConcat(m);
72 }
void didConcat(const SkMatrix &matrix) override
Definition: mock_canvas.cc:59

◆ didSetMatrix()

void flutter::testing::MockCanvas::didSetMatrix ( const SkMatrix &  matrix)
overrideprotected

Definition at line 80 of file mock_canvas.cc.

Referenced by didRestore().

80  {
81  draw_calls_.emplace_back(DrawCall{current_layer_, SetMatrixData{matrix}});
82 }

◆ didTranslate()

void flutter::testing::MockCanvas::didTranslate ( SkScalar  x,
SkScalar  y 
)
overrideprotected

Definition at line 74 of file mock_canvas.cc.

References didConcat().

Referenced by didRestore().

74  {
75  SkMatrix m;
76  m.setTranslate(x, y);
77  this->didConcat(m);
78 }
void didConcat(const SkMatrix &matrix) override
Definition: mock_canvas.cc:59

◆ draw_calls()

const std::vector<DrawCall>& flutter::testing::MockCanvas::draw_calls ( ) const
inline

Definition at line 144 of file mock_canvas.h.

References getSaveLayerStrategy(), willRestore(), and willSave().

144 { return draw_calls_; }

◆ getSaveLayerStrategy()

SkCanvas::SaveLayerStrategy flutter::testing::MockCanvas::getSaveLayerStrategy ( const SaveLayerRec &  rec)
overrideprotected

Definition at line 36 of file mock_canvas.cc.

Referenced by draw_calls().

37  {
38  // saveLayer calls this prior to running, so we use it to track saveLayer
39  // calls
40  draw_calls_.emplace_back(DrawCall{
41  current_layer_,
42  SaveLayerData{rec.fBounds ? *rec.fBounds : SkRect(),
43  rec.fPaint ? *rec.fPaint : SkPaint(),
44  rec.fBackdrop ? sk_ref_sp<SkImageFilter>(rec.fBackdrop)
45  : sk_sp<SkImageFilter>(),
46  current_layer_ + 1}});
47  current_layer_++; // Must go here; func params order of eval is undefined
48  return kNoLayer_SaveLayerStrategy;
49 }

◆ internal_canvas()

SkNWayCanvas* flutter::testing::MockCanvas::internal_canvas ( )
inline

Definition at line 142 of file mock_canvas.h.

Referenced by flutter::testing::LayerTestBase< ThreadTest >::LayerTestBase().

142 { return &internal_canvas_; }

◆ onClipPath()

void flutter::testing::MockCanvas::onClipPath ( const SkPath &  path,
SkClipOp  op,
ClipEdgeStyle  style 
)
overrideprotected

Definition at line 160 of file mock_canvas.cc.

References flutter::path.

Referenced by didRestore().

162  {
163  draw_calls_.emplace_back(
164  DrawCall{current_layer_, ClipPathData{path, op, style}});
165 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32

◆ onClipRect()

void flutter::testing::MockCanvas::onClipRect ( const SkRect &  rect,
SkClipOp  op,
ClipEdgeStyle  style 
)
overrideprotected

Definition at line 146 of file mock_canvas.cc.

Referenced by didRestore().

148  {
149  draw_calls_.emplace_back(
150  DrawCall{current_layer_, ClipRectData{rect, op, style}});
151 }

◆ onClipRegion()

void flutter::testing::MockCanvas::onClipRegion ( const SkRegion &  ,
SkClipOp   
)
overrideprotected

Definition at line 290 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

290  {
291  FML_DCHECK(false);
292 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onClipRRect()

void flutter::testing::MockCanvas::onClipRRect ( const SkRRect &  rrect,
SkClipOp  op,
ClipEdgeStyle  style 
)
overrideprotected

Definition at line 153 of file mock_canvas.cc.

Referenced by didRestore().

155  {
156  draw_calls_.emplace_back(
157  DrawCall{current_layer_, ClipRRectData{rrect, op, style}});
158 }

◆ onDoSaveBehind()

bool flutter::testing::MockCanvas::onDoSaveBehind ( const SkRect *  )
overrideprotected

Definition at line 167 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

167  {
168  FML_DCHECK(false);
169  return false;
170 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawAnnotation()

void flutter::testing::MockCanvas::onDrawAnnotation ( const SkRect &  ,
const char  [],
SkData *   
)
overrideprotected

Definition at line 172 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

172  {
173  FML_DCHECK(false);
174 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawArc()

void flutter::testing::MockCanvas::onDrawArc ( const SkRect &  ,
SkScalar  ,
SkScalar  ,
bool  ,
const SkPaint &   
)
overrideprotected

Definition at line 215 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

219  {
220  FML_DCHECK(false);
221 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawAtlas()

void flutter::testing::MockCanvas::onDrawAtlas ( const SkImage *  ,
const SkRSXform  [],
const SkRect  [],
const SkColor  [],
int  ,
SkBlendMode  ,
const SkRect *  ,
const SkPaint *   
)
overrideprotected

Definition at line 262 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

269  {
270  FML_DCHECK(false);
271 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawBehind()

void flutter::testing::MockCanvas::onDrawBehind ( const SkPaint &  )
overrideprotected

Definition at line 196 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

196  {
197  FML_DCHECK(false);
198 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawDrawable()

void flutter::testing::MockCanvas::onDrawDrawable ( SkDrawable *  ,
const SkMatrix *   
)
overrideprotected

Definition at line 180 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

180  {
181  FML_DCHECK(false);
182 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawDRRect()

void flutter::testing::MockCanvas::onDrawDRRect ( const SkRRect &  ,
const SkRRect &  ,
const SkPaint &   
)
overrideprotected

Definition at line 176 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

176  {
177  FML_DCHECK(false);
178 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawEdgeAAImageSet()

void flutter::testing::MockCanvas::onDrawEdgeAAImageSet ( const ImageSetEntry  [],
int  ,
const SkPoint  [],
const SkMatrix  [],
const SkPaint *  ,
SrcRectConstraint   
)
overrideprotected

Definition at line 281 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

286  {
287  FML_DCHECK(false);
288 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawEdgeAAQuad()

void flutter::testing::MockCanvas::onDrawEdgeAAQuad ( const SkRect &  ,
const SkPoint  [4],
QuadAAFlags  ,
const SkColor4f &  ,
SkBlendMode   
)
overrideprotected

Definition at line 273 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

277  {
278  FML_DCHECK(false);
279 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawImage()

void flutter::testing::MockCanvas::onDrawImage ( const SkImage *  image,
SkScalar  x,
SkScalar  y,
const SkPaint *  paint 
)
overrideprotected

Definition at line 227 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

230  {
231  FML_DCHECK(false);
232 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawImageLattice()

void flutter::testing::MockCanvas::onDrawImageLattice ( const SkImage *  ,
const Lattice &  ,
const SkRect &  ,
const SkPaint *   
)
overrideprotected

Definition at line 249 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

252  {
253  FML_DCHECK(false);
254 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawImageNine()

void flutter::testing::MockCanvas::onDrawImageNine ( const SkImage *  ,
const SkIRect &  ,
const SkRect &  ,
const SkPaint *   
)
overrideprotected

Definition at line 242 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

245  {
246  FML_DCHECK(false);
247 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawImageRect()

void flutter::testing::MockCanvas::onDrawImageRect ( const SkImage *  ,
const SkRect *  ,
const SkRect &  ,
const SkPaint *  ,
SrcRectConstraint   
)
overrideprotected

Definition at line 234 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

238  {
239  FML_DCHECK(false);
240 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawOval()

void flutter::testing::MockCanvas::onDrawOval ( const SkRect &  ,
const SkPaint &   
)
overrideprotected

Definition at line 211 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

211  {
212  FML_DCHECK(false);
213 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawPaint()

void flutter::testing::MockCanvas::onDrawPaint ( const SkPaint &  skPaint)
overrideprotected

Definition at line 192 of file mock_canvas.cc.

Referenced by didRestore().

192  {
193  draw_calls_.emplace_back(DrawCall{current_layer_, DrawPaint{skPaint}});
194 }

◆ onDrawPatch()

void flutter::testing::MockCanvas::onDrawPatch ( const SkPoint  [12],
const SkColor  [4],
const SkPoint  [4],
SkBlendMode  ,
const SkPaint &   
)
overrideprotected

Definition at line 184 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

188  {
189  FML_DCHECK(false);
190 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawPath()

void flutter::testing::MockCanvas::onDrawPath ( const SkPath &  path,
const SkPaint &  paint 
)
overrideprotected

Definition at line 111 of file mock_canvas.cc.

References flutter::path.

Referenced by didRestore().

111  {
112  draw_calls_.emplace_back(DrawCall{current_layer_, DrawPathData{path, paint}});
113 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32

◆ onDrawPicture()

void flutter::testing::MockCanvas::onDrawPicture ( const SkPicture *  picture,
const SkMatrix *  matrix,
const SkPaint *  paint 
)
overrideprotected

Definition at line 121 of file mock_canvas.cc.

Referenced by didRestore().

123  {
124  // This duplicates existing logic in SkCanvas::onDrawPicture
125  // that should probably be split out so it doesn't need to be here as well.
126  if (!paint || paint->canComputeFastBounds()) {
127  SkRect bounds = picture->cullRect();
128  if (paint) {
129  paint->computeFastBounds(bounds, &bounds);
130  }
131  if (matrix) {
132  matrix->mapRect(&bounds);
133  }
134  if (this->quickReject(bounds)) {
135  return;
136  }
137  }
138 
139  draw_calls_.emplace_back(DrawCall{
140  current_layer_,
141  DrawPictureData{
142  picture ? picture->serialize() : SkData::MakeUninitialized(0),
143  paint ? *paint : SkPaint(), matrix ? *matrix : SkMatrix()}});
144 }

◆ onDrawPoints()

void flutter::testing::MockCanvas::onDrawPoints ( PointMode  ,
size_t  ,
const SkPoint  [],
const SkPaint &   
)
overrideprotected

Definition at line 200 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

203  {
204  FML_DCHECK(false);
205 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawRect()

void flutter::testing::MockCanvas::onDrawRect ( const SkRect &  rect,
const SkPaint &  paint 
)
overrideprotected

Definition at line 107 of file mock_canvas.cc.

Referenced by didRestore().

107  {
108  draw_calls_.emplace_back(DrawCall{current_layer_, DrawRectData{rect, paint}});
109 }

◆ onDrawRegion()

void flutter::testing::MockCanvas::onDrawRegion ( const SkRegion &  ,
const SkPaint &   
)
overrideprotected

Definition at line 207 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

207  {
208  FML_DCHECK(false);
209 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawRRect()

void flutter::testing::MockCanvas::onDrawRRect ( const SkRRect &  ,
const SkPaint &   
)
overrideprotected

Definition at line 223 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

223  {
224  FML_DCHECK(false);
225 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawShadowRec()

void flutter::testing::MockCanvas::onDrawShadowRec ( const SkPath &  path,
const SkDrawShadowRec &  rec 
)
overrideprotected

Definition at line 115 of file mock_canvas.cc.

Referenced by didRestore().

116  {
117  (void)rec; // Can't use b/c Skia keeps this type anonymous.
118  draw_calls_.emplace_back(DrawCall{current_layer_, DrawShadowData{path}});
119 }
DEF_SWITCHES_START snapshot asset path
Definition: switches.h:32

◆ onDrawTextBlob()

void flutter::testing::MockCanvas::onDrawTextBlob ( const SkTextBlob *  text,
SkScalar  x,
SkScalar  y,
const SkPaint &  paint 
)
overrideprotected

Definition at line 84 of file mock_canvas.cc.

Referenced by didRestore().

87  {
88  // This duplicates existing logic in SkCanvas::onDrawPicture
89  // that should probably be split out so it doesn't need to be here as well.
90  SkRect storage;
91  const SkRect* bounds = nullptr;
92  if (paint.canComputeFastBounds()) {
93  storage = text->bounds().makeOffset(x, y);
94  SkRect tmp;
95  if (this->quickReject(paint.computeFastBounds(storage, &tmp))) {
96  return;
97  }
98  bounds = &storage;
99  }
100 
101  draw_calls_.emplace_back(DrawCall{
102  current_layer_, DrawTextData{text ? text->serialize(SkSerialProcs{})
103  : SkData::MakeUninitialized(0),
104  paint, SkPoint::Make(x, y)}});
105 }

◆ onDrawVerticesObject()

void flutter::testing::MockCanvas::onDrawVerticesObject ( const SkVertices *  ,
SkBlendMode  ,
const SkPaint &   
)
overrideprotected

Definition at line 256 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

258  {
259  FML_DCHECK(false);
260 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ willRestore()

void flutter::testing::MockCanvas::willRestore ( )
overrideprotected

Definition at line 51 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by draw_calls().

51  {
52  FML_DCHECK(current_layer_ > 0);
53 
54  draw_calls_.emplace_back(
55  DrawCall{current_layer_, RestoreData{current_layer_ - 1}});
56  current_layer_--; // Must go here; func params order of eval is undefined
57 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ willSave()

void flutter::testing::MockCanvas::willSave ( )
overrideprotected

Definition at line 30 of file mock_canvas.cc.

Referenced by draw_calls().

30  {
31  draw_calls_.emplace_back(
32  DrawCall{current_layer_, SaveData{current_layer_ + 1}});
33  current_layer_++; // Must go here; func params order of eval is undefined
34 }

The documentation for this class was generated from the following files: