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 "GrContext.h"
12     #include "SkCanvas.h"
13     #include "SkDocument.h"
14     #include "SkPictureRecorder.h"
15     #include "SkStream.h"
16     #include "SkSurface.h"
17     #include "gl/GrGLAssembleInterface.h"
18     #include "gl/GrGLInterface.h"
19 #else
20     #include "skia.h"
21 #endif
22 
23 #include <memory>
24 #include <sstream>
25 
26 extern GrBackendTexture backEndTexture;
27 extern GrBackendRenderTarget backEndRenderTarget;
28 extern GrBackendTexture backEndTextureRenderTarget;
29 extern SkBitmap source;
30 extern sk_sp<SkImage> image;
31 extern double duration; // The total duration of the animation in seconds.
32 extern double frame;    // A value in [0, 1] of where we are in the animation.
33 
34 namespace sk_gpu_test {
35 class GLTestContext;
36 }
37 
38 struct DrawOptions {
DrawOptionsDrawOptions39     DrawOptions(int w, int h, bool r, bool g, bool p, bool k, bool srgb, bool f16,
40                 bool textOnly, const char* s,
41                 GrMipMapped mipMapping,
42                 int offScreenWidth,
43                 int offScreenHeight,
44                 int offScreenSampleCount,
45                 GrMipMapped offScreenMipMapping)
46         : size(SkISize::Make(w, h))
47         , raster(r)
48         , gpu(g)
49         , pdf(p)
50         , skp(k)
51         , srgb(srgb)
52         , f16(f16)
53         , textOnly(textOnly)
54         , source(s)
55         , fMipMapping(mipMapping)
56         , fOffScreenWidth(offScreenWidth)
57         , fOffScreenHeight(offScreenHeight)
58         , fOffScreenSampleCount(offScreenSampleCount)
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 accomodate 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     int         fOffScreenSampleCount;
83     // TODO: should we also expose stencilBits here? How about the config?
84 
85     GrMipMapped fOffScreenMipMapping; // only applicable if the offscreen is also textureable
86 };
87 
88 extern DrawOptions GetDrawOptions();
89 extern void SkDebugf(const char * format, ...);
90 extern void draw(SkCanvas*);
91 
92 // There are different implementations of create_grcontext() for EGL, Mesa,
93 // and a fallback to a null context.
94 extern sk_sp<GrContext> create_grcontext(std::ostringstream& driverinfo,
95                                          std::unique_ptr<sk_gpu_test::GLTestContext>* glContext);
96 
97 #endif  // fiddle_main_DEFINED
98