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 | |
| 12 | #include "fiddle_main.h" |
| 13 | DrawOptions GetDrawOptions() { |
| 14 | // path *should* be absolute. |
mtklein | 5dbd274 | 2016-08-02 11:13:48 -0700 | [diff] [blame] | 15 | static const char path[] = "resources/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; |
halcanary | d096459 | 2016-03-25 11:29:34 -0700 | [diff] [blame] | 25 | paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, |
| 26 | SkShader::kRepeat_TileMode, |
| 27 | &matrix)); |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 28 | canvas->drawPaint(paint); |
Joe Gregorio | 1fd1823 | 2017-02-13 11:39:43 -0500 | [diff] [blame] | 29 | SkDebugf("This is text output: %d", 2); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 30 | |
| 31 | GrContext* context = canvas->getGrContext(); |
| 32 | if (context) { |
| 33 | sk_sp<SkImage> tmp = SkImage::MakeFromTexture(context, |
| 34 | backEndTexture, |
| 35 | kTopLeft_GrSurfaceOrigin, |
| 36 | kOpaque_SkAlphaType, |
| 37 | nullptr); |
| 38 | |
Robert Phillips | c34aa9d | 2017-11-17 14:59:43 -0500 | [diff] [blame] | 39 | // TODO: this sampleCnt parameter here should match that set in the options! |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 40 | sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(context, |
| 41 | backEndTextureRenderTarget, |
| 42 | kTopLeft_GrSurfaceOrigin, |
| 43 | 0, nullptr, nullptr); |
| 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, |
| 49 | nullptr, nullptr); |
Robert Phillips | 57e0828 | 2017-11-16 14:59:48 -0500 | [diff] [blame] | 50 | } |
| 51 | |
halcanary | decb21e | 2015-12-10 07:52:45 -0800 | [diff] [blame] | 52 | } |