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