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