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  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, 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 didConcat44 (const SkM44 &) override
 
void didSetM44 (const SkM44 &) override
 
void didScale (SkScalar x, SkScalar y) override
 
void didTranslate (SkScalar x, SkScalar y) 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 onDrawImage2 (const SkImage *image, SkScalar x, SkScalar y, const SkSamplingOptions &, const SkPaint *paint) override
 
void onDrawImageRect2 (const SkImage *, const SkRect &, const SkRect &, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint) override
 
void onDrawImageLattice2 (const SkImage *, const Lattice &, const SkRect &, SkFilterMode, const SkPaint *) override
 
void onDrawVerticesObject (const SkVertices *, SkBlendMode, const SkPaint &) override
 
void onDrawAtlas2 (const SkImage *, const SkRSXform[], const SkRect[], const SkColor[], int, SkBlendMode, const SkSamplingOptions &, const SkRect *, const SkPaint *) override
 
void onDrawEdgeAAQuad (const SkRect &, const SkPoint[4], QuadAAFlags, const SkColor4f &, SkBlendMode) 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

◆ didConcat44()

void flutter::testing::MockCanvas::didConcat44 ( const SkM44 &  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 }

◆ didRestore()

◆ didScale()

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

Definition at line 67 of file mock_canvas.cc.

References didConcat44().

Referenced by didRestore().

67  {
68  this->didConcat44(SkM44::Scale(x, y));
69 }
void didConcat44(const SkM44 &) override
Definition: mock_canvas.cc:59

◆ didSetM44()

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

Definition at line 63 of file mock_canvas.cc.

Referenced by didRestore().

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

◆ didTranslate()

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

Definition at line 71 of file mock_canvas.cc.

References didConcat44().

Referenced by didRestore().

71  {
72  this->didConcat44(SkM44::Translate(x, y));
73 }
void didConcat44(const SkM44 &) override
Definition: mock_canvas.cc:59

◆ draw_calls()

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

Definition at line 139 of file mock_canvas.h.

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

139 { 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 137 of file mock_canvas.h.

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

137 { return &internal_canvas_; }

◆ onClipPath()

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

Definition at line 156 of file mock_canvas.cc.

References flutter::path.

Referenced by didRestore().

158  {
159  draw_calls_.emplace_back(
160  DrawCall{current_layer_, ClipPathData{path, op, style}});
161  // quickReject() is handled by base class and needs accurate clip information
162  SkCanvas::onClipPath(path, op, style);
163 }
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 138 of file mock_canvas.cc.

Referenced by didRestore().

140  {
141  draw_calls_.emplace_back(
142  DrawCall{current_layer_, ClipRectData{rect, op, style}});
143  // quickReject() is handled by base class and needs accurate clip information
144  SkCanvas::onClipRect(rect, op, style);
145 }

◆ onClipRegion()

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

Definition at line 276 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

276  {
277  FML_DCHECK(false);
278 }
#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 147 of file mock_canvas.cc.

Referenced by didRestore().

149  {
150  draw_calls_.emplace_back(
151  DrawCall{current_layer_, ClipRRectData{rrect, op, style}});
152  // quickReject() is handled by base class and needs accurate clip information
153  SkCanvas::onClipRRect(rrect, op, style);
154 }

◆ onDoSaveBehind()

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

Definition at line 165 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawAnnotation()

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

Definition at line 170 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

170  {
171  FML_DCHECK(false);
172 }
#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 213 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawAtlas2()

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

Definition at line 256 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

264  {
265  FML_DCHECK(false);
266 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawBehind()

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

Definition at line 194 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawDrawable()

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

Definition at line 178 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawDRRect()

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

Definition at line 174 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

174  {
175  FML_DCHECK(false);
176 }
#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 268 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

272  {
273  FML_DCHECK(false);
274 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ onDrawImage2()

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

Definition at line 225 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawImageLattice2()

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

Definition at line 242 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawImageRect2()

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

Definition at line 233 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 209 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawPaint()

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

Definition at line 190 of file mock_canvas.cc.

Referenced by didRestore().

190  {
191  draw_calls_.emplace_back(DrawCall{current_layer_, DrawPaint{skPaint}});
192 }

◆ onDrawPatch()

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

Definition at line 182 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawPath()

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

Definition at line 102 of file mock_canvas.cc.

References flutter::path.

Referenced by didRestore().

102  {
103  draw_calls_.emplace_back(DrawCall{current_layer_, DrawPathData{path, paint}});
104 }
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 113 of file mock_canvas.cc.

Referenced by didRestore().

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

◆ onDrawPoints()

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

Definition at line 198 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawRect()

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

Definition at line 98 of file mock_canvas.cc.

Referenced by didRestore().

98  {
99  draw_calls_.emplace_back(DrawCall{current_layer_, DrawRectData{rect, paint}});
100 }

◆ onDrawRegion()

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

Definition at line 205 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawRRect()

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

Definition at line 221 of file mock_canvas.cc.

References FML_DCHECK.

Referenced by didRestore().

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

◆ onDrawShadowRec()

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

Definition at line 106 of file mock_canvas.cc.

Referenced by didRestore().

107  {
108  // See: https://bugs.chromium.org/p/skia/issues/detail?id=12125
109  (void)rec; // Can't use b/c Skia keeps this type anonymous.
110  draw_calls_.emplace_back(DrawCall{current_layer_, DrawShadowData{path}});
111 }
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 75 of file mock_canvas.cc.

Referenced by didRestore().

78  {
79  // This duplicates existing logic in SkCanvas::onDrawPicture
80  // that should probably be split out so it doesn't need to be here as well.
81  SkRect storage;
82  const SkRect* bounds = nullptr;
83  if (paint.canComputeFastBounds()) {
84  storage = text->bounds().makeOffset(x, y);
85  SkRect tmp;
86  if (this->quickReject(paint.computeFastBounds(storage, &tmp))) {
87  return;
88  }
89  bounds = &storage;
90  }
91 
92  draw_calls_.emplace_back(DrawCall{
93  current_layer_, DrawTextData{text ? text->serialize(SkSerialProcs{})
94  : SkData::MakeUninitialized(0),
95  paint, SkPoint::Make(x, y)}});
96 }
std::u16string text

◆ onDrawVerticesObject()

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

Definition at line 250 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

◆ 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: