aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/fiddle/draw.cpp
blob: 05866e316b3f94d5b764c06e301e1d5e6b824313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

// This is an example of the translation unit that needs to be
// assembled by the fiddler program to compile into a fiddle: an
// implementation of the GetDrawOptions() and draw() functions.

#include "fiddle_main.h"
DrawOptions GetDrawOptions() {
    // path *should* be absolute.
    static const char path[] = "resources/images/color_wheel.png";
    return DrawOptions(256, 256, true, true, true, true, true, false, false, path,
                       GrMipMapped::kYes, 64, 64, 0, GrMipMapped::kYes);
}
void draw(SkCanvas* canvas) {
    canvas->clear(SK_ColorWHITE);
    SkMatrix matrix;
    matrix.setScale(0.75f, 0.75f);
    matrix.preRotate(frame * 30.0f * duration); // If an animation, rotate at 30 deg/s.
    SkPaint paint;
    paint.setShader(image->makeShader(SkShader::kRepeat_TileMode,
                                      SkShader::kRepeat_TileMode,
                                      &matrix));
    canvas->drawPaint(paint);
    SkDebugf("This is text output: %d", 2);

    GrContext* context = canvas->getGrContext();
    if (context) {
        sk_sp<SkImage> tmp = SkImage::MakeFromTexture(context,
                                                      backEndTexture,
                                                      kTopLeft_GrSurfaceOrigin,
                                                      kOpaque_SkAlphaType,
                                                      nullptr);

        // TODO: this sampleCnt parameter here should match that set in the options!
        sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(context,
                                                                  backEndTextureRenderTarget,
                                                                  kTopLeft_GrSurfaceOrigin,
                                                                  0, nullptr, nullptr);

        // Note: this surface should only be renderable (i.e., not textureable)
        sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(context,
                                                                       backEndRenderTarget,
                                                                       kTopLeft_GrSurfaceOrigin,
                                                                       nullptr, nullptr);
    }

}