1 // Copyright 2019 Google LLC.
2 // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(State_Stack_a, 256, 160, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6 SkPaint paint;
7 canvas->save(); // records stack depth to restore
8 canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip
9 canvas->clear(SK_ColorRED); // draws to limit of clip
10 canvas->save(); // records stack depth to restore
11 canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored
12 canvas->clear(SK_ColorBLUE); // draws to smaller clip
13 canvas->restore(); // enlarges clip
14 canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn
15 canvas->restore(); // enlarges clip
16 canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn
17 }
18 } // END FIDDLE
19