blob: a01aa793c7ebdd87ca36ded6e59eb43c02165ac2 [file] [log] [blame]
Cary Clark5081eed2018-01-22 07:55:48 -05001#Topic Automatic_Canvas_Restore
2
3#Class SkAutoCanvasRestore
4
5Stack helper class calls SkCanvas::restoreToCount() when SkAutoCanvasRestore
6goes out of scope. Use this to guarantee that the canvas is restored to a known
7state.
8
9#Topic Overview
10
11#Subtopic Subtopics
12#ToDo manually add subtopics ##
13#Table
14#Legend
15# name # description ##
16#Legend ##
17# Constructors # functions that construct SkAutoCanvasRestore ##
18# Member_Functions # static functions and member methods ##
19#Table ##
20#Subtopic ##
21
22#Subtopic Constructors
23#Table
24#Legend
25# name # description ##
26#Legend ##
27# SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) # Preserves Canvas save count. ##
28# ~SkAutoCanvasRestore() # Restores Canvas to saved state. ##
29#Table ##
30#Subtopic ##
31
32#Subtopic Member_Functions
33#Table
34#Legend
35# name # description ##
36#Legend ##
37# restore() # Restores Canvas to saved state. ##
38#Table ##
39#Subtopic ##
40
41#Topic Overview ##
42
43#Method SkAutoCanvasRestore(SkCanvas* canvas, bool doSave)
44
45Preserves Canvas save count. Optionally saves Canvas_Clip and Canvas_Matrix.
46
47#Param canvas Canvas to guard ##
48#Param doSave call SkCanvas::save() ##
49
50#Return utility to restore Canvas state on destructor ##
51
52#Example
53#Height 128
54 SkPaint p;
55 p.setAntiAlias(true);
56 p.setTextSize(64);
57 for (SkScalar sx : { -1, 1 } ) {
58 for (SkScalar sy : { -1, 1 } ) {
59 SkAutoCanvasRestore autoRestore(canvas, true);
60 SkMatrix m = SkMatrix::MakeAll(sx, 1, 96, 0, sy, 64, 0, 0, 1);
61 canvas->concat(m);
62 canvas->drawString("R", 0, 0, p);
63 }
64 }
65##
66
67#SeeAlso SkCanvas::save SkCanvas::restore
68
69##
70
71#Method ~SkAutoCanvasRestore()
72
73Restores Canvas to saved state. Destructor is called when container goes out of
74scope.
75
76#NoExample
77##
78
79#SeeAlso SkCanvas::save SkCanvas::restore
80
81##
82
83#Method void restore()
84
85Restores Canvas to saved state immediately. Subsequent calls and
86~SkAutoCanvasRestore have no effect.
87
88#Example
89for (bool callRestore : { false, true } ) {
90 for (bool saveCanvas : {false, true} ) {
91 SkAutoCanvasRestore autoRestore(canvas, saveCanvas);
92 if (!saveCanvas) {
93 canvas->save();
94 }
95 SkDebugf("saveCanvas: %s before restore: %d\n",
96 saveCanvas ? "true" : "false", canvas->getSaveCount());
97 if (callRestore) autoRestore.restore();
98 SkDebugf("saveCanvas: %s after restore: %d\n",
99 saveCanvas ? "true" : "false", canvas->getSaveCount());
100 }
101}
102SkDebugf("final count: %d\n", canvas->getSaveCount());
103#StdOut
104saveCanvas: false before restore: 2
105saveCanvas: false after restore: 2
106saveCanvas: true before restore: 2
107saveCanvas: true after restore: 2
108saveCanvas: false before restore: 2
109saveCanvas: false after restore: 1
110saveCanvas: true before restore: 2
111saveCanvas: true after restore: 1
112final count: 1
113##
114##
115
116#SeeAlso SkCanvas::save SkCanvas::restore
117
118##
119
120#Class SkAutoCanvasRestore ##
121
122#Topic Automatic_Canvas_Restore ##