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