xref: /aosp_15_r20/external/skia/docs/examples/Canvas_drawPicture_4.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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(Canvas_drawPicture_4, 256, 256, false, 0) {
draw(SkCanvas * canvas)5 void draw(SkCanvas* canvas) {
6     SkPaint paint;
7     SkPictureRecorder recorder;
8     SkCanvas* recordingCanvas = recorder.beginRecording(50, 50);
9     for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) {
10         paint.setColor(color);
11         recordingCanvas->drawRect({10, 10, 30, 40}, paint);
12         recordingCanvas->translate(10, 10);
13         recordingCanvas->scale(1.2f, 1.4f);
14     }
15     sk_sp<SkPicture> playback = recorder.finishRecordingAsPicture();
16     SkMatrix matrix;
17     matrix.reset();
18     for (auto alpha : { 70, 140, 210 } ) {
19     paint.setAlpha(alpha);
20     canvas->drawPicture(playback, &matrix, &paint);
21     matrix.preTranslate(70, 70);
22     }
23 }
24 }  // END FIDDLE
25