1cb93a386Sopenharmony_ci/*
2cb93a386Sopenharmony_ci * Copyright 2015 Google Inc.
3cb93a386Sopenharmony_ci *
4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be
5cb93a386Sopenharmony_ci * found in the LICENSE file.
6cb93a386Sopenharmony_ci */
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci// This is an example of the translation unit that needs to be
9cb93a386Sopenharmony_ci// assembled by the fiddler program to compile into a fiddle: an
10cb93a386Sopenharmony_ci// implementation of the GetDrawOptions() and draw() functions.
11cb93a386Sopenharmony_ci
12cb93a386Sopenharmony_ci#include "tools/fiddle/fiddle_main.h"
13cb93a386Sopenharmony_ci#include "tools/gpu/ManagedBackendTexture.h"
14cb93a386Sopenharmony_ci
15cb93a386Sopenharmony_ciDrawOptions GetDrawOptions() {
16cb93a386Sopenharmony_ci    // path *should* be absolute.
17cb93a386Sopenharmony_ci    static const char path[] = "resources/images/color_wheel.png";
18cb93a386Sopenharmony_ci    return DrawOptions(256, 256, true, true, true, true, true, false, false, path,
19cb93a386Sopenharmony_ci                       GrMipmapped::kYes, 64, 64, 0, GrMipmapped::kYes);
20cb93a386Sopenharmony_ci}
21cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
22cb93a386Sopenharmony_ci    canvas->clear(SK_ColorWHITE);
23cb93a386Sopenharmony_ci    SkMatrix matrix;
24cb93a386Sopenharmony_ci    matrix.setScale(0.75f, 0.75f);
25cb93a386Sopenharmony_ci    matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s.
26cb93a386Sopenharmony_ci    SkPaint paint;
27cb93a386Sopenharmony_ci    paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
28cb93a386Sopenharmony_ci                                      SkSamplingOptions(), matrix));
29cb93a386Sopenharmony_ci    canvas->drawPaint(paint);
30cb93a386Sopenharmony_ci    SkDebugf("This is text output: %d", 2);
31cb93a386Sopenharmony_ci
32cb93a386Sopenharmony_ci    if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
33cb93a386Sopenharmony_ci        sk_sp<SkImage> tmp = SkImage::MakeFromTexture(dContext,
34cb93a386Sopenharmony_ci                                                      backEndTexture->texture(),
35cb93a386Sopenharmony_ci                                                      kTopLeft_GrSurfaceOrigin,
36cb93a386Sopenharmony_ci                                                      kRGBA_8888_SkColorType,
37cb93a386Sopenharmony_ci                                                      kOpaque_SkAlphaType,
38cb93a386Sopenharmony_ci                                                      nullptr);
39cb93a386Sopenharmony_ci
40cb93a386Sopenharmony_ci        constexpr int kSampleCnt = 0;
41cb93a386Sopenharmony_ci        sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(
42cb93a386Sopenharmony_ci                                                            dContext,
43cb93a386Sopenharmony_ci                                                            backEndTextureRenderTarget->texture(),
44cb93a386Sopenharmony_ci                                                            kTopLeft_GrSurfaceOrigin,
45cb93a386Sopenharmony_ci                                                            kSampleCnt,
46cb93a386Sopenharmony_ci                                                            kRGBA_8888_SkColorType,
47cb93a386Sopenharmony_ci                                                            nullptr, nullptr);
48cb93a386Sopenharmony_ci
49cb93a386Sopenharmony_ci        // Note: this surface should only be renderable (i.e., not textureable)
50cb93a386Sopenharmony_ci        sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(dContext,
51cb93a386Sopenharmony_ci                                                                       backEndRenderTarget,
52cb93a386Sopenharmony_ci                                                                       kTopLeft_GrSurfaceOrigin,
53cb93a386Sopenharmony_ci                                                                       kRGBA_8888_SkColorType,
54cb93a386Sopenharmony_ci                                                                       nullptr, nullptr);
55cb93a386Sopenharmony_ci    }
56cb93a386Sopenharmony_ci}
57