Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / tools / gpu / gl / GLTestContext.h
1
2 /*
3  * Copyright 2013 Google Inc.
4  *
5  * Use of this source code is governed by a BSD-style license that can be
6  * found in the LICENSE file.
7  */
8 #ifndef GLTestContext_DEFINED
9 #define GLTestContext_DEFINED
10
11 #include "include/gpu/gl/GrGLInterface.h"
12 #include "src/gpu/ganesh/gl/GrGLUtil.h"
13 #include "tools/gpu/TestContext.h"
14
15 namespace sk_gpu_test {
16 /**
17  * An offscreen OpenGL context. Provides a GrGLInterface struct of function pointers for the context
18  * This class is intended for Skia's internal testing needs and not for general use.
19  * When SK_GL is not defined the GrGLInterface will always be nullptr.
20  */
21 class GLTestContext : public TestContext {
22 public:
23     ~GLTestContext() override;
24
25     GrBackendApi backend() override { return GrBackendApi::kOpenGL; }
26
27     /** Does this represent a successfully created GL context? */
28     bool isValid() const;
29
30     const GrGLInterface* gl() const { return fGLInterface.get(); }
31
32     /** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
33     virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; }
34
35     virtual void destroyEGLImage(GrEGLImage) const { }
36
37     /**
38      * Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
39      * GL_TEXTURE_EXTERNAL_OES.
40      */
41     virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; }
42
43     void testAbandon() override;
44
45     /** Wait until all GPU work is finished. */
46     void finish() override;
47
48     void overrideVersion(const char* version, const char* shadingLanguageVersion);
49
50     /**
51      * Creates a new GL context of the same type and makes the returned context current
52      * (if not null).
53      */
54     virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
55
56     template<typename Ret, typename... Args>
57     void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...),
58                           const char* name, const char* ext = nullptr) const {
59         using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...);
60         if (!SkStrStartsWith(name, "gl")) {
61             SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix");
62             *out = nullptr;
63         } else if (ext) {
64             SkString fullname(name);
65             fullname.append(ext);
66             *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str()));
67         } else {
68             *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name));
69         }
70     }
71
72     sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override;
73
74 protected:
75     GLTestContext();
76
77     /*
78      * Methods that subclasses must call from their constructors and destructors.
79      */
80     void init(sk_sp<const GrGLInterface>);
81
82     void teardown() override;
83
84     virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
85
86 private:
87     /** Subclass provides the gl interface object if construction was successful. */
88     sk_sp<const GrGLInterface> fOriginalGLInterface;
89
90     /** The same as fOriginalGLInterface unless the version has been overridden. */
91     sk_sp<const GrGLInterface> fGLInterface;
92
93 #ifndef SK_GL
94     bool fWasInitialized = false;
95 #endif
96
97     using INHERITED = TestContext;
98 };
99
100 /**
101  * Creates platform-dependent GL context object.  The shareContext parameter is in an optional
102  * context with which to share display lists. This should be a pointer to an GLTestContext created
103  * with SkCreatePlatformGLTestContext.  NULL indicates that no sharing is to take place. Returns a
104  * valid gl context object or NULL if such can not be created.
105  */
106 GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
107                                            GLTestContext *shareContext = nullptr);
108
109 }  // namespace sk_gpu_test
110 #endif