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=5c7629c15e9ac93f098335e72560fa2e
5 REG_FIDDLE(Surface_MakeRenderTarget_3, 256, 256, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 SkFont font(nullptr, 32);
8 SkPaint paint;
9 auto context = canvas->recordingContext();
10 if (!context) {
11 canvas->drawString("GPU only!", 20, 40, font, paint);
12 return;
13 }
14 SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType);
15 auto gpuSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
16 auto surfaceCanvas = gpuSurface->getCanvas();
17 surfaceCanvas->clear(SK_ColorWHITE);
18 surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
19 sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
20 canvas->drawImage(image, 0, 0);
21 }
22 } // END FIDDLE
23