blob: 98c60fb1ef6a6c575db2dbf56a3e4488a79d1e59 [file] [log] [blame]
halcanarydecb21e2015-12-10 07:52:45 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8// This is an example of the translation unit that needs to be
9// assembled by the fiddler program to compile into a fiddle: an
10// implementation of the GetDrawOptions() and draw() functions.
11
Kevin Lubick5c93acf2023-05-09 12:11:43 -040012#include "include/gpu/ganesh/SkSurfaceGanesh.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "tools/fiddle/fiddle_main.h"
Robert Phillipsb87975c2020-12-08 11:51:02 -050014#include "tools/gpu/ManagedBackendTexture.h"
15
halcanarydecb21e2015-12-10 07:52:45 -080016DrawOptions GetDrawOptions() {
17 // path *should* be absolute.
Hal Canary036fe5f2017-12-11 10:26:18 -050018 static const char path[] = "resources/images/color_wheel.png";
Kevin Lubickdf73d162023-09-11 11:56:53 -040019 return DrawOptions(256,
20 256,
21 true,
22 true,
23 true,
24 true,
25 true,
26 false,
27 false,
28 path,
29 skgpu::Mipmapped::kYes,
30 64,
31 64,
32 0,
33 skgpu::Mipmapped::kYes);
halcanarydecb21e2015-12-10 07:52:45 -080034}
35void draw(SkCanvas* canvas) {
36 canvas->clear(SK_ColorWHITE);
37 SkMatrix matrix;
38 matrix.setScale(0.75f, 0.75f);
Joe Gregorio1e735c02017-04-19 14:05:14 -040039 matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s.
halcanarydecb21e2015-12-10 07:52:45 -080040 SkPaint paint;
Mike Reed99c94462020-12-08 13:16:56 -050041 paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
42 SkSamplingOptions(), matrix));
halcanarydecb21e2015-12-10 07:52:45 -080043 canvas->drawPaint(paint);
Joe Gregorio1fd18232017-02-13 11:39:43 -050044 SkDebugf("This is text output: %d", 2);
Robert Phillips57e08282017-11-16 14:59:48 -050045
Adlai Holler14dc7912020-08-11 15:48:49 +000046 if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
Kevin Lubick77472bf2023-03-24 07:11:17 -040047 sk_sp<SkImage> tmp = SkImages::BorrowTextureFrom(dContext,
48 backEndTexture,
49 kTopLeft_GrSurfaceOrigin,
50 kRGBA_8888_SkColorType,
51 kOpaque_SkAlphaType,
52 nullptr);
Robert Phillips57e08282017-11-16 14:59:48 -050053
Robert Phillipsb87975c2020-12-08 11:51:02 -050054 constexpr int kSampleCnt = 0;
Kevin Lubick5c93acf2023-05-09 12:11:43 -040055 sk_sp<SkSurface> tmp2 = SkSurfaces::WrapBackendTexture(dContext,
56 backEndTextureRenderTarget,
57 kTopLeft_GrSurfaceOrigin,
58 kSampleCnt,
59 kRGBA_8888_SkColorType,
60 nullptr,
61 nullptr);
Robert Phillips57e08282017-11-16 14:59:48 -050062
Robert Phillipsc34aa9d2017-11-17 14:59:43 -050063 // Note: this surface should only be renderable (i.e., not textureable)
Kevin Lubick5c93acf2023-05-09 12:11:43 -040064 sk_sp<SkSurface> tmp3 = SkSurfaces::WrapBackendRenderTarget(dContext,
65 backEndRenderTarget,
66 kTopLeft_GrSurfaceOrigin,
67 kRGBA_8888_SkColorType,
68 nullptr,
69 nullptr);
Robert Phillips57e08282017-11-16 14:59:48 -050070 }
halcanarydecb21e2015-12-10 07:52:45 -080071}