Flutter Engine
The Flutter Engine
GLTestContext.h
Go to the documentation of this file.
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
14
15namespace 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 */
21class GLTestContext : public TestContext {
22public:
23 ~GLTestContext() override;
24
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 void overrideVersion(const char* version, const char* shadingLanguageVersion);
46
47 /**
48 * Creates a new GL context of the same type and makes the returned context current
49 * (if not null).
50 */
51 virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
52
53 template<typename Ret, typename... Args>
55 const char* name, const char* ext = nullptr) const {
56 using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...);
57 if (!SkStrStartsWith(name, "gl")) {
58 SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix");
59 *out = nullptr;
60 } else if (ext) {
62 fullname.append(ext);
63 *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str()));
64 } else {
65 *out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name));
66 }
67 }
68
70
71protected:
73
74 /*
75 * Methods that subclasses must call from their constructors and destructors.
76 */
78
79 void teardown() override;
80
81 virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
82
83private:
84 /** Subclass provides the gl interface object if construction was successful. */
85 sk_sp<const GrGLInterface> fOriginalGLInterface;
86
87 /** The same as fOriginalGLInterface unless the version has been overridden. */
88 sk_sp<const GrGLInterface> fGLInterface;
89
90 using INHERITED = TestContext;
91};
92
93/**
94 * Creates platform-dependent GL context object. The shareContext parameter is in an optional
95 * context with which to share display lists. This should be a pointer to an GLTestContext created
96 * with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a
97 * valid gl context object or NULL if such can not be created.
98 */
100 GLTestContext *shareContext = nullptr);
101
102} // namespace sk_gpu_test
103#endif
const char * options
#define GR_GL_FUNCTION_TYPE
Definition: GrGLConfig.h:27
void(* GrGLFuncPtr)()
Definition: GrGLInterface.h:17
unsigned int GrGLuint
Definition: GrGLTypes.h:113
GrGLStandard
Definition: GrGLTypes.h:19
void * GrEGLImage
Definition: GrGLTypes.h:165
GrBackendApi
Definition: GrTypes.h:95
#define SK_ABORT(message,...)
Definition: SkAssert.h:70
static bool SkStrStartsWith(const char string[], const char prefixStr[])
Definition: SkString.h:26
void(* Proc)(SkCanvas *, const SkRect &, const SkPaint &)
Definition: blurrect.cpp:42
const char * c_str() const
Definition: SkString.h:133
GrBackendApi backend() override
Definition: GLTestContext.h:25
virtual std::unique_ptr< GLTestContext > makeNew() const
Definition: GLTestContext.h:51
void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE **out)(Args...), const char *name, const char *ext=nullptr) const
Definition: GLTestContext.h:54
virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const =0
virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const
Definition: GLTestContext.h:41
virtual void destroyEGLImage(GrEGLImage) const
Definition: GLTestContext.h:35
const GrGLInterface * gl() const
Definition: GLTestContext.h:30
void init(sk_sp< const GrGLInterface >)
sk_sp< GrDirectContext > makeContext(const GrContextOptions &options) override
void overrideVersion(const char *version, const char *shadingLanguageVersion)
virtual GrEGLImage texture2DToEGLImage(GrGLuint) const
Definition: GLTestContext.h:33
T * get() const
Definition: SkRefCnt.h:303
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
GLTestContext * CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, GLTestContext *shareContext)