xref: /third_party/skia/tools/fiddle/fiddle_main.h (revision cb93a386)
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#ifndef fiddle_main_DEFINED
8#define fiddle_main_DEFINED
9
10#ifdef FIDDLE_BUILD_TEST
11    #include "include/core/SkCanvas.h"
12    #include "include/core/SkDocument.h"
13    #include "include/core/SkPictureRecorder.h"
14    #include "include/core/SkStream.h"
15    #include "include/core/SkSurface.h"
16    #include "include/gpu/GrDirectContext.h"
17    #include "include/gpu/gl/GrGLAssembleInterface.h"
18    #include "include/gpu/gl/GrGLInterface.h"
19#else
20    #include "skia.h"
21#endif
22
23#include <memory>
24#include <sstream>
25
26namespace sk_gpu_test {
27class GLTestContext;
28class ManagedBackendTexture;
29}  // namespace sk_gpu_test
30
31extern sk_sp<sk_gpu_test::ManagedBackendTexture> backEndTexture;
32extern GrBackendRenderTarget backEndRenderTarget;
33extern sk_sp<sk_gpu_test::ManagedBackendTexture> backEndTextureRenderTarget;
34extern SkBitmap source;
35extern sk_sp<SkImage> image;
36extern double duration; // The total duration of the animation in seconds.
37extern double frame;    // A value in [0, 1] of where we are in the animation.
38
39struct DrawOptions {
40    DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16,
41                bool textOnly, const char* s,
42                GrMipmapped mipMapping,
43                int offScreenWidth,
44                int offScreenHeight,
45                int deprecated, // TODO(jcgregorio): remove
46                GrMipmapped offScreenMipMapping)
47        : size(SkISize::Make(w, h))
48        , raster(r)
49        , gpu(g)
50        , pdf(p)
51        , skp(k)
52        , srgb(srgb)
53        , f16(f16)
54        , textOnly(textOnly)
55        , source(s)
56        , fMipMapping(mipMapping)
57        , fOffScreenWidth(offScreenWidth)
58        , fOffScreenHeight(offScreenHeight)
59        , fOffScreenMipMapping(offScreenMipMapping) {
60        // F16 mode is only valid for color correct backends.
61        SkASSERT(srgb || !f16);
62    }
63    SkISize size;
64    bool raster;
65    bool gpu;
66    bool pdf;
67    bool skp;
68    bool srgb;
69    bool f16;
70    bool textOnly;
71    const char* source;
72
73    // This flag is used when a GPU texture resource is created and exposed as a GrBackendTexture.
74    // In this case the resource is created with extra room to accommodate mipmaps.
75    // TODO: The SkImage::makeTextureImage API would need to be widened to allow this to be true
76    // for the non-backend gpu SkImages.
77    GrMipmapped fMipMapping;
78
79    // Parameters for an GPU offscreen resource exposed as a GrBackendRenderTarget
80    int         fOffScreenWidth;
81    int         fOffScreenHeight;
82    // TODO: should we also expose stencilBits here? How about the config?
83
84    GrMipmapped fOffScreenMipMapping; // only applicable if the offscreen is also textureable
85};
86
87extern DrawOptions GetDrawOptions();
88extern void SkDebugf(const char * format, ...);
89extern void draw(SkCanvas*);
90
91// There are different implementations of create_direct_context() for EGL, Mesa,
92// and a fallback to a null context.
93extern sk_sp<GrDirectContext> create_direct_context(std::ostringstream& driverinfo,
94                                                    std::unique_ptr<sk_gpu_test::GLTestContext>*);
95
96#endif  // fiddle_main_DEFINED
97