• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "tools/fiddle/fiddle_main.h"
13 #include "tools/gpu/ManagedBackendTexture.h"
14 
GetDrawOptions()15 DrawOptions GetDrawOptions() {
16     // path *should* be absolute.
17     static const char path[] = "resources/images/color_wheel.png";
18     return DrawOptions(256, 256, true, true, true, true, true, false, false, path,
19                        GrMipmapped::kYes, 64, 64, 0, GrMipmapped::kYes);
20 }
draw(SkCanvas * canvas)21 void draw(SkCanvas* canvas) {
22     canvas->clear(SK_ColorWHITE);
23     SkMatrix matrix;
24     matrix.setScale(0.75f, 0.75f);
25     matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s.
26     SkPaint paint;
27     paint.setShader(image->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
28                                       SkSamplingOptions(), matrix));
29     canvas->drawPaint(paint);
30     SkDebugf("This is text output: %d", 2);
31 
32     if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
33         sk_sp<SkImage> tmp = SkImage::MakeFromTexture(dContext,
34                                                       backEndTexture,
35                                                       kTopLeft_GrSurfaceOrigin,
36                                                       kRGBA_8888_SkColorType,
37                                                       kOpaque_SkAlphaType,
38                                                       nullptr);
39 
40         constexpr int kSampleCnt = 0;
41         sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(
42                                                             dContext,
43                                                             backEndTextureRenderTarget,
44                                                             kTopLeft_GrSurfaceOrigin,
45                                                             kSampleCnt,
46                                                             kRGBA_8888_SkColorType,
47                                                             nullptr, nullptr);
48 
49         // Note: this surface should only be renderable (i.e., not textureable)
50         sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(dContext,
51                                                                        backEndRenderTarget,
52                                                                        kTopLeft_GrSurfaceOrigin,
53                                                                        kRGBA_8888_SkColorType,
54                                                                        nullptr, nullptr);
55     }
56 }
57