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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "tools/fiddle/fiddle_main.h" |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 13 | DrawOptions GetDrawOptions() { |
| 14 | // path *should* be absolute. |
Hal Canary | 036fe5f | 2017-12-11 10:26:18 -0500 | [diff] [blame] | 15 | static const char path[] = "resources/images/color_wheel.png"; |
Robert Phillips | c34aa9d | 2017-11-17 14:59:43 -0500 | [diff] [blame] | 16 | return DrawOptions(256, 256, true, true, true, true, true, false, false, path, |
| 17 | GrMipMapped::kYes, 64, 64, 0, GrMipMapped::kYes); |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 18 | } |
| 19 | void draw(SkCanvas* canvas) { |
| 20 | canvas->clear(SK_ColorWHITE); |
| 21 | SkMatrix matrix; |
| 22 | matrix.setScale(0.75f, 0.75f); |
Joe Gregorio | 1e735c0 | 2017-04-19 14:05:14 -0400 | [diff] [blame] | 23 | 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] | 24 | SkPaint paint; |
Mike Reed | fae8fce | 2019-04-03 10:27:45 -0400 | [diff] [blame] | 25 | paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &matrix)); |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 26 | canvas->drawPaint(paint); |
Joe Gregorio | 1fd1823 | 2017-02-13 11:39:43 -0500 | [diff] [blame] | 27 | SkDebugf("This is text output: %d", 2); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 28 | |
| 29 | GrContext* context = canvas->getGrContext(); |
| 30 | if (context) { |
| 31 | sk_sp<SkImage> tmp = SkImage::MakeFromTexture(context, |
| 32 | backEndTexture, |
| 33 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 34 | kRGBA_8888_SkColorType, |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 35 | kOpaque_SkAlphaType, |
| 36 | nullptr); |
| 37 | |
Robert Phillips | c34aa9d | 2017-11-17 14:59:43 -0500 | [diff] [blame] | 38 | // TODO: this sampleCnt parameter here should match that set in the options! |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 39 | sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(context, |
| 40 | backEndTextureRenderTarget, |
| 41 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 42 | 0, kRGBA_8888_SkColorType, |
| 43 | nullptr, nullptr); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 44 | |
Robert Phillips | c34aa9d | 2017-11-17 14:59:43 -0500 | [diff] [blame] | 45 | // Note: this surface should only be renderable (i.e., not textureable) |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 46 | sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(context, |
| 47 | backEndRenderTarget, |
| 48 | kTopLeft_GrSurfaceOrigin, |
Greg Daniel | faa095e | 2017-12-19 13:15:02 -0500 | [diff] [blame] | 49 | kRGBA_8888_SkColorType, |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 50 | nullptr, nullptr); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 51 | } |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 52 | } |