halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 1 | /* |
| 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 Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 12 | #include "include/gpu/ganesh/SkSurfaceGanesh.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 13 | #include "tools/fiddle/fiddle_main.h" |
Robert Phillips | b87975c | 2020-12-08 11:51:02 -0500 | [diff] [blame] | 14 | #include "tools/gpu/ManagedBackendTexture.h" |
| 15 | |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 16 | DrawOptions GetDrawOptions() { |
| 17 | // path *should* be absolute. |
Hal Canary | 036fe5f | 2017-12-11 10:26:18 -0500 | [diff] [blame] | 18 | static const char path[] = "resources/images/color_wheel.png"; |
Kevin Lubick | df73d16 | 2023-09-11 11:56:53 -0400 | [diff] [blame] | 19 | 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); |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 34 | } |
| 35 | void draw(SkCanvas* canvas) { |
| 36 | canvas->clear(SK_ColorWHITE); |
| 37 | SkMatrix matrix; |
| 38 | matrix.setScale(0.75f, 0.75f); |
Joe Gregorio | 1e735c0 | 2017-04-19 14:05:14 -0400 | [diff] [blame] | 39 | matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s. |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 40 | SkPaint paint; |
Mike Reed | 99c9446 | 2020-12-08 13:16:56 -0500 | [diff] [blame] | 41 | paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, |
| 42 | SkSamplingOptions(), matrix)); |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 43 | canvas->drawPaint(paint); |
Joe Gregorio | 1fd1823 | 2017-02-13 11:39:43 -0500 | [diff] [blame] | 44 | SkDebugf("This is text output: %d", 2); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 45 | |
Adlai Holler | 14dc791 | 2020-08-11 15:48:49 +0000 | [diff] [blame] | 46 | if (auto dContext = GrAsDirectContext(canvas->recordingContext())) { |
Kevin Lubick | 77472bf | 2023-03-24 07:11:17 -0400 | [diff] [blame] | 47 | sk_sp<SkImage> tmp = SkImages::BorrowTextureFrom(dContext, |
| 48 | backEndTexture, |
| 49 | kTopLeft_GrSurfaceOrigin, |
| 50 | kRGBA_8888_SkColorType, |
| 51 | kOpaque_SkAlphaType, |
| 52 | nullptr); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 53 | |
Robert Phillips | b87975c | 2020-12-08 11:51:02 -0500 | [diff] [blame] | 54 | constexpr int kSampleCnt = 0; |
Kevin Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 55 | sk_sp<SkSurface> tmp2 = SkSurfaces::WrapBackendTexture(dContext, |
| 56 | backEndTextureRenderTarget, |
| 57 | kTopLeft_GrSurfaceOrigin, |
| 58 | kSampleCnt, |
| 59 | kRGBA_8888_SkColorType, |
| 60 | nullptr, |
| 61 | nullptr); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 62 | |
Robert Phillips | c34aa9d | 2017-11-17 14:59:43 -0500 | [diff] [blame] | 63 | // Note: this surface should only be renderable (i.e., not textureable) |
Kevin Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 64 | sk_sp<SkSurface> tmp3 = SkSurfaces::WrapBackendRenderTarget(dContext, |
| 65 | backEndRenderTarget, |
| 66 | kTopLeft_GrSurfaceOrigin, |
| 67 | kRGBA_8888_SkColorType, |
| 68 | nullptr, |
| 69 | nullptr); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 70 | } |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 71 | } |