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