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