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=640321e8ecfb3f9329f3bc6e1f02485f
5 REG_FIDDLE(Surface_MakeRenderTarget_2, 256, 256, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 auto test_draw = [](SkCanvas* surfaceCanvas) -> void {
8 SkFont font(nullptr, 32);
9
10 SkPaint paint;
11 paint.setAntiAlias(true);
12 // TODO: where did this setting go?
13 //paint.setLCDRenderText(true);
14 paint.setColor(0xFFBBBBBB);
15
16 surfaceCanvas->drawRect(SkRect::MakeWH(128, 64), paint);
17 paint.setColor(SK_ColorWHITE);
18 surfaceCanvas->drawString("Text", 0, 25, font, paint);
19 };
20 auto context = canvas->recordingContext();
21 SkImageInfo info = SkImageInfo::MakeN32(128, 64, kOpaque_SkAlphaType);
22 int y = 0;
23 for (auto geometry : { kRGB_H_SkPixelGeometry, kBGR_H_SkPixelGeometry,
24 kRGB_V_SkPixelGeometry, kBGR_V_SkPixelGeometry } ) {
25 SkSurfaceProps props(0, geometry);
26 sk_sp<SkSurface> surface = context
27 ? SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props)
28 : SkSurface::MakeRaster(info, &props);
29 test_draw(surface->getCanvas());
30 surface->draw(canvas, 0, y);
31 sk_sp<SkImage> image(surface->makeImageSnapshot());
32 SkAutoCanvasRestore acr(canvas, true);
33 canvas->scale(8, 8);
34 canvas->drawImage(image, 12, y / 8);
35 y += 64;
36 }
37 }
38 } // END FIDDLE
39