Home | History | Annotate | Download | only in docs
      1 #Topic Automatic_Canvas_Restore
      2 
      3 #Subtopic Overview
      4     #Subtopic Subtopic
      5     #Populate
      6     ##
      7 ##
      8 
      9 #Class SkAutoCanvasRestore
     10 
     11 Stack helper class calls SkCanvas::restoreToCount() when SkAutoCanvasRestore
     12 goes out of scope. Use this to guarantee that the canvas is restored to a known
     13 state.
     14 
     15 #Subtopic Constructor
     16 #Populate
     17 ##
     18 
     19 #Subtopic Member_Function
     20 #Populate
     21 ##
     22 
     23 #Method SkAutoCanvasRestore(SkCanvas* canvas, bool doSave)
     24 
     25 #Line # preserves Canvas save count ##
     26 Preserves 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 ##
     55 Restores Canvas to saved state. Destructor is called when container goes out of
     56 scope.
     57 
     58 #NoExample
     59 ##
     60 
     61 #SeeAlso SkCanvas::save SkCanvas::restore
     62 
     63 ##
     64 
     65 #Method void restore()
     66 #In Member_Function
     67 #Line # restores Canvas to saved state ##
     68 Restores Canvas to saved state immediately. Subsequent calls and
     69 ~SkAutoCanvasRestore have no effect.
     70 
     71 #Example
     72 for (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 }
     85 SkDebugf("final count: %d\n", canvas->getSaveCount());
     86 #StdOut
     87 saveCanvas: false  before restore: 2
     88 saveCanvas: false  after restore: 2
     89 saveCanvas: true  before restore: 2
     90 saveCanvas: true  after restore: 2
     91 saveCanvas: false  before restore: 2
     92 saveCanvas: false  after restore: 1
     93 saveCanvas: true  before restore: 2
     94 saveCanvas: true  after restore: 1
     95 final count: 1
     96 ##
     97 ##
     98 
     99 #SeeAlso SkCanvas::save SkCanvas::restore
    100 
    101 ##
    102 
    103 #Class SkAutoCanvasRestore ##
    104 
    105 #Topic Automatic_Canvas_Restore ##
    106