1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
4cb93a386Sopenharmony_ci// HASH=67b6609471a3f1ed0f4b1657004cdecb
5cb93a386Sopenharmony_ciREG_FIDDLE(Surface_MakeRenderTarget, 256, 64, false, 0) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
7cb93a386Sopenharmony_ci    SkFont font(nullptr, 32);
8cb93a386Sopenharmony_ci    SkPaint paint;
9cb93a386Sopenharmony_ci
10cb93a386Sopenharmony_ci    auto dContext = GrAsDirectContext(canvas->recordingContext());
11cb93a386Sopenharmony_ci    if (!dContext) {
12cb93a386Sopenharmony_ci        return;
13cb93a386Sopenharmony_ci    }
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ci    SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType);
16cb93a386Sopenharmony_ci    for (auto surfaceOrigin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) {
17cb93a386Sopenharmony_ci        auto gpuSurface(SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info, 0,
18cb93a386Sopenharmony_ci                                                    surfaceOrigin, nullptr));
19cb93a386Sopenharmony_ci        auto surfaceCanvas = gpuSurface->getCanvas();
20cb93a386Sopenharmony_ci        surfaceCanvas->clear(SK_ColorWHITE);
21cb93a386Sopenharmony_ci        surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
22cb93a386Sopenharmony_ci        sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
23cb93a386Sopenharmony_ci        canvas->drawImage(image, 0, 0);
24cb93a386Sopenharmony_ci        canvas->translate(0, 128);
25cb93a386Sopenharmony_ci    }
26cb93a386Sopenharmony_ci}
27cb93a386Sopenharmony_ci}  // END FIDDLE
28