aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/SkAutoCanvasRestore_Reference.bmh
blob: 361fb767caf6763a20c215830825802b1627a323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#Topic Automatic_Canvas_Restore

#Class SkAutoCanvasRestore

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.

#Topic Overview

#Subtopic Subtopics
#ToDo manually add subtopics ##
#Table
#Legend
# name             # description                                   ##
#Legend ##
# Constructors     # functions that construct SkAutoCanvasRestore  ##
# Member_Functions # static functions and member methods           ##
#Table ##
#Subtopic ##

#Subtopic Constructors
#Table
#Legend
# name                                               # description                    ##
#Legend ##
# SkAutoCanvasRestore(SkCanvas* canvas, bool doSave) # preserves Canvas save count    ##
# ~SkAutoCanvasRestore()                             # restores Canvas to saved state ##
#Table ##
#Subtopic ##

#Subtopic Member_Functions
#Table
#Legend
# name                             # description                    ##
#Legend ##
# restore()                        # restores Canvas to saved state ##
#Table ##
#Subtopic ##

#Topic Overview ##

#Method SkAutoCanvasRestore(SkCanvas* canvas, bool doSave)

#Line # preserves Canvas save count ##
Preserves Canvas save count. Optionally saves Canvas_Clip and Canvas_Matrix.

#Param canvas  Canvas to guard ##
#Param doSave  call SkCanvas::save() ##

#Return utility to restore Canvas state on destructor ##

#Example
#Height 128
    SkPaint p;
    p.setAntiAlias(true);
    p.setTextSize(64);
    for (SkScalar sx : { -1, 1 } ) {
        for (SkScalar sy : { -1, 1 } ) {
            SkAutoCanvasRestore autoRestore(canvas, true);
            SkMatrix m = SkMatrix::MakeAll(sx, 1, 96,    0, sy, 64,   0, 0, 1);
            canvas->concat(m);
            canvas->drawString("R", 0, 0, p);
        }
    }
##

#SeeAlso SkCanvas::save SkCanvas::restore

##

#Method ~SkAutoCanvasRestore()

#Line # restores Canvas to saved state ##
Restores Canvas to saved state. Destructor is called when container goes out of
scope.

#NoExample
##

#SeeAlso SkCanvas::save SkCanvas::restore

##

#Method void restore()

#Line # restores Canvas to saved state ##
Restores Canvas to saved state immediately. Subsequent calls and
~SkAutoCanvasRestore have no effect.

#Example
for (bool callRestore : { false, true } ) {
    for (bool saveCanvas : {false, true} ) {
        SkAutoCanvasRestore autoRestore(canvas, saveCanvas);
        if (!saveCanvas) {
            canvas->save();
        }
        SkDebugf("saveCanvas: %s  before restore: %d\n",
               saveCanvas ? "true" : "false", canvas->getSaveCount());
        if (callRestore) autoRestore.restore();
        SkDebugf("saveCanvas: %s  after restore: %d\n",
               saveCanvas ? "true" : "false", canvas->getSaveCount());
    }
}
SkDebugf("final count: %d\n", canvas->getSaveCount());
#StdOut
saveCanvas: false  before restore: 2
saveCanvas: false  after restore: 2
saveCanvas: true  before restore: 2
saveCanvas: true  after restore: 2
saveCanvas: false  before restore: 2
saveCanvas: false  after restore: 1
saveCanvas: true  before restore: 2
saveCanvas: true  after restore: 1
final count: 1
##
##

#SeeAlso SkCanvas::save SkCanvas::restore

##

#Class SkAutoCanvasRestore ##

#Topic Automatic_Canvas_Restore ##