• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#Topic Automatic_Canvas_Restore
2
3#Class SkAutoCanvasRestore
4
5#Code
6#Populate
7##
8
9Stack helper class calls SkCanvas::restoreToCount when SkAutoCanvasRestore
10goes out of scope. Use this to guarantee that the canvas is restored to a known
11state.
12
13#Method SkAutoCanvasRestore(SkCanvas* canvas, bool doSave)
14
15#Line # restores Canvas when out of scope ##
16#Populate
17
18#Example
19#Height 128
20    SkPaint p;
21    SkFont font(nullptr, 64);
22    for (SkScalar sx : { -1, 1 } ) {
23        for (SkScalar sy : { -1, 1 } ) {
24            SkAutoCanvasRestore autoRestore(canvas, true);
25            SkMatrix m = SkMatrix::MakeAll(sx, 1, 96,    0, sy, 64,   0, 0, 1);
26            canvas->concat(m);
27            canvas->drawString("R", 0, 0, font, p);
28        }
29    }
30##
31
32#SeeAlso SkCanvas::save SkCanvas::restore
33
34##
35
36#Method ~SkAutoCanvasRestore()
37
38#Line # restores Canvas to saved state ##
39#Populate
40
41#NoExample
42##
43
44#SeeAlso SkCanvas::save SkCanvas::restore
45
46##
47
48#Method void restore()
49#In Member_Function
50#Line # restores Canvas to saved state ##
51#Populate
52
53#Example
54for (bool callRestore : { false, true } ) {
55    for (bool saveCanvas : {false, true} ) {
56        SkAutoCanvasRestore autoRestore(canvas, saveCanvas);
57        if (!saveCanvas) {
58            canvas->save();
59        }
60        SkDebugf("saveCanvas: %s  before restore: %d\n",
61               saveCanvas ? "true" : "false", canvas->getSaveCount());
62        if (callRestore) autoRestore.restore();
63        SkDebugf("saveCanvas: %s  after restore: %d\n",
64               saveCanvas ? "true" : "false", canvas->getSaveCount());
65    }
66}
67SkDebugf("final count: %d\n", canvas->getSaveCount());
68#StdOut
69saveCanvas: false  before restore: 2
70saveCanvas: false  after restore: 2
71saveCanvas: true  before restore: 2
72saveCanvas: true  after restore: 2
73saveCanvas: false  before restore: 2
74saveCanvas: false  after restore: 1
75saveCanvas: true  before restore: 2
76saveCanvas: true  after restore: 1
77final count: 1
78##
79##
80
81#SeeAlso SkCanvas::save SkCanvas::restore
82
83##
84
85#Class SkAutoCanvasRestore ##
86
87#Topic Automatic_Canvas_Restore ##
88