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 "skia.h"
13
14 // fiddle_main.h (purposefully) pollutes the global namespace with very generic identifiers like
15 // "image", "duration", "frame", and "fontMgr". As such it is something of an
16 // "implementation header" and should be included last to avoid name shadowing warnings.
17 #include "tools/fiddle/fiddle_main.h"
18
GetDrawOptions()19 DrawOptions GetDrawOptions() {
20 // path *should* be absolute.
21 static const char path[] = "resources/images/color_wheel.png";
22 return DrawOptions(256,
23 256,
24 true,
25 true,
26 true,
27 true,
28 true,
29 false,
30 false,
31 path,
32 skgpu::Mipmapped::kYes,
33 64,
34 64,
35 0,
36 skgpu::Mipmapped::kYes);
37 }
draw(SkCanvas * canvas)38 void draw(SkCanvas* canvas) {
39 canvas->clear(SK_ColorWHITE);
40 SkMatrix matrix;
41 matrix.setScale(0.75f, 0.75f);
42 matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s.
43 SkPaint paint;
44 paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
45 SkSamplingOptions(), matrix));
46 canvas->drawPaint(paint);
47 SkDebugf("This is text output: %d", 2);
48
49 if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
50 sk_sp<SkImage> tmp = SkImages::BorrowTextureFrom(dContext,
51 backEndTexture,
52 kTopLeft_GrSurfaceOrigin,
53 kRGBA_8888_SkColorType,
54 kOpaque_SkAlphaType,
55 nullptr);
56
57 constexpr int kSampleCnt = 0;
58 sk_sp<SkSurface> tmp2 = SkSurfaces::WrapBackendTexture(dContext,
59 backEndTextureRenderTarget,
60 kTopLeft_GrSurfaceOrigin,
61 kSampleCnt,
62 kRGBA_8888_SkColorType,
63 nullptr,
64 nullptr);
65
66 // Note: this surface should only be renderable (i.e., not textureable)
67 sk_sp<SkSurface> tmp3 = SkSurfaces::WrapBackendRenderTarget(dContext,
68 backEndRenderTarget,
69 kTopLeft_GrSurfaceOrigin,
70 kRGBA_8888_SkColorType,
71 nullptr,
72 nullptr);
73 }
74 }
75