Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
SkAutoCanvasRestore Class Reference

#include <SkCanvas.h>

Public Member Functions

 SkAutoCanvasRestore (SkCanvas *canvas, bool doSave)
 
 ~SkAutoCanvasRestore ()
 
void restore ()
 

Detailed Description

Stack helper class calls SkCanvas::restoreToCount when SkAutoCanvasRestore goes out of scope. Use this to guarantee that the canvas is restored to a known state.

Definition at line 2639 of file SkCanvas.h.

Constructor & Destructor Documentation

◆ SkAutoCanvasRestore()

SkAutoCanvasRestore::SkAutoCanvasRestore ( SkCanvas canvas,
bool  doSave 
)
inline

Preserves SkCanvas::save() count. Optionally saves SkCanvas clip and SkCanvas matrix.

Parameters
canvasSkCanvas to guard
doSavecall SkCanvas::save()
Returns
utility to restore SkCanvas state on destructor

Definition at line 2648 of file SkCanvas.h.

2648 : fCanvas(canvas), fSaveCount(0) {
2649 if (fCanvas) {
2650 fSaveCount = canvas->getSaveCount();
2651 if (doSave) {
2652 canvas->save();
2653 }
2654 }
2655 }
int getSaveCount() const
Definition: SkCanvas.cpp:431
int save()
Definition: SkCanvas.cpp:447

◆ ~SkAutoCanvasRestore()

SkAutoCanvasRestore::~SkAutoCanvasRestore ( )
inline

Restores SkCanvas to saved state. Destructor is called when container goes out of scope.

Definition at line 2660 of file SkCanvas.h.

2660 {
2661 if (fCanvas) {
2662 fCanvas->restoreToCount(fSaveCount);
2663 }
2664 }
void restoreToCount(int saveCount)
Definition: SkCanvas.cpp:478

Member Function Documentation

◆ restore()

void SkAutoCanvasRestore::restore ( )
inline

Restores SkCanvas to saved state immediately. Subsequent calls and ~SkAutoCanvasRestore() have no effect.

Definition at line 2669 of file SkCanvas.h.

2669 {
2670 if (fCanvas) {
2671 fCanvas->restoreToCount(fSaveCount);
2672 fCanvas = nullptr;
2673 }
2674 }

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