State_Stack_a.cpp 1.0 KB

12345678910111213141516171819
  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. // HASH=bb1dbfdca3aedf716beb6f07e2aab065
  5. REG_FIDDLE(State_Stack_a, 256, 160, false, 0) {
  6. void draw(SkCanvas* canvas) {
  7. SkPaint paint;
  8. canvas->save(); // records stack depth to restore
  9. canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip
  10. canvas->clear(SK_ColorRED); // draws to limit of clip
  11. canvas->save(); // records stack depth to restore
  12. canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored
  13. canvas->clear(SK_ColorBLUE); // draws to smaller clip
  14. canvas->restore(); // enlarges clip
  15. canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn
  16. canvas->restore(); // enlarges clip
  17. canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn
  18. }
  19. } // END FIDDLE