• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=56ed920dadbf2b2967ac45fb5a9bded6
5 REG_FIDDLE(Picture_AbortCallback_abort, 256, 256, false, 0) {
6 class JustOneDraw : public SkPicture::AbortCallback {
7 public:
abort()8     bool abort() override { return fCalls++ > 0; }
9 private:
10     int fCalls = 0;
11 };
12 
draw(SkCanvas * canvas)13 void draw(SkCanvas* canvas) {
14     SkPictureRecorder recorder;
15     SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256});
16     SkPaint paint;
17     pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint);
18     paint.setColor(SK_ColorWHITE);
19     pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint);
20     sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
21     JustOneDraw callback;
22     picture->playback(canvas, &callback);
23 }
24 }  // END FIDDLE
25