/src/skia/tools/gpu/gl/GLTestContext.h
Line | Count | Source (jump to first uncovered line) |
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/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 | 0 | GrBackendApi backend() override { return GrBackendApi::kOpenGL; } |
26 | | |
27 | | /** Does this represent a successfully created GL context? */ |
28 | | bool isValid() const; |
29 | | |
30 | 183 | 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 | 0 | virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; } |
34 | | |
35 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | const char* name, const char* ext = nullptr) const { |
59 | 0 | using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...); |
60 | 0 | if (!SkStrStartsWith(name, "gl")) { |
61 | 0 | SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix"); |
62 | 0 | *out = nullptr; |
63 | 0 | } else if (ext) { |
64 | 0 | SkString fullname(name); |
65 | 0 | fullname.append(ext); |
66 | 0 | *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str())); |
67 | 0 | } else { |
68 | 0 | *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name)); |
69 | 0 | } |
70 | 0 | } Unexecuted instantiation: void sk_gpu_test::GLTestContext::getGLProcAddress<void, unsigned int, int*>(void (**)(unsigned int, int*), char const*, char const*) const Unexecuted instantiation: void sk_gpu_test::GLTestContext::getGLProcAddress<void, int, unsigned int*>(void (**)(int, unsigned int*), char const*, char const*) const Unexecuted instantiation: void sk_gpu_test::GLTestContext::getGLProcAddress<void, int, unsigned int const*>(void (**)(int, unsigned int const*), char const*, char const*) const Unexecuted instantiation: void sk_gpu_test::GLTestContext::getGLProcAddress<void, unsigned int, unsigned int>(void (**)(unsigned int, unsigned int), char const*, char const*) const Unexecuted instantiation: void sk_gpu_test::GLTestContext::getGLProcAddress<void, unsigned int>(void (**)(unsigned int), char const*, char const*) const Unexecuted instantiation: void sk_gpu_test::GLTestContext::getGLProcAddress<void, unsigned int, unsigned int, unsigned int*>(void (**)(unsigned int, unsigned int, unsigned int*), char const*, char const*) const Unexecuted instantiation: void sk_gpu_test::GLTestContext::getGLProcAddress<void, unsigned int, unsigned int, unsigned long*>(void (**)(unsigned int, unsigned int, unsigned long*), char const*, char const*) const |
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 |