2011-07-28 14:26:00 +00:00
|
|
|
|
|
|
|
/*
|
2013-02-28 20:16:25 +00:00
|
|
|
* Copyright 2013 Google Inc.
|
2011-07-28 14:26:00 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-03-31 17:59:06 +00:00
|
|
|
#ifndef GLTestContext_DEFINED
|
|
|
|
#define GLTestContext_DEFINED
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2019-05-22 17:13:58 +00:00
|
|
|
#include "include/gpu/gl/GrGLInterface.h"
|
2020-08-26 19:27:03 +00:00
|
|
|
#include "src/gpu/gl/GrGLUtil.h"
|
2019-05-22 20:23:43 +00:00
|
|
|
#include "tools/gpu/TestContext.h"
|
2019-05-22 17:13:58 +00:00
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
namespace sk_gpu_test {
|
2010-12-23 15:00:45 +00:00
|
|
|
/**
|
2016-05-11 17:09:18 +00:00
|
|
|
* An offscreen OpenGL context. Provides a GrGLInterface struct of function pointers for the context
|
|
|
|
* This class is intended for Skia's internal testing needs and not for general use.
|
2020-03-19 19:54:28 +00:00
|
|
|
* When SK_GL is not defined the GrGLInterface will always be nullptr.
|
2010-12-23 15:00:45 +00:00
|
|
|
*/
|
2016-05-11 17:09:18 +00:00
|
|
|
class GLTestContext : public TestContext {
|
2010-12-21 16:26:39 +00:00
|
|
|
public:
|
2017-03-22 16:05:03 +00:00
|
|
|
~GLTestContext() override;
|
2010-12-21 16:26:39 +00:00
|
|
|
|
2020-08-14 02:58:04 +00:00
|
|
|
GrBackendApi backend() override { return GrBackendApi::kOpenGL; }
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
/** Does this represent a successfully created GL context? */
|
|
|
|
bool isValid() const;
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2020-08-26 19:27:03 +00:00
|
|
|
const GrGLInterface* gl() const { return fGLInterface.get(); }
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2015-11-22 22:51:00 +00:00
|
|
|
/** Used for testing EGLImage integration. Take a GL_TEXTURE_2D and wraps it in an EGL Image */
|
2017-08-28 14:34:05 +00:00
|
|
|
virtual GrEGLImage texture2DToEGLImage(GrGLuint /*texID*/) const { return nullptr; }
|
2016-03-31 01:56:19 +00:00
|
|
|
|
|
|
|
virtual void destroyEGLImage(GrEGLImage) const { }
|
2015-11-22 22:51:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Used for testing EGLImage integration. Takes a EGLImage and wraps it in a
|
|
|
|
* GL_TEXTURE_EXTERNAL_OES.
|
|
|
|
*/
|
|
|
|
virtual GrGLuint eglImageToExternalTexture(GrEGLImage) const { return 0; }
|
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
void testAbandon() override;
|
2014-07-29 15:01:52 +00:00
|
|
|
|
2016-05-11 18:55:36 +00:00
|
|
|
/** Wait until all GPU work is finished. */
|
|
|
|
void finish() override;
|
|
|
|
|
2020-08-26 19:27:03 +00:00
|
|
|
void overrideVersion(const char* version, const char* shadingLanguageVersion);
|
|
|
|
|
2015-11-22 22:51:00 +00:00
|
|
|
/**
|
|
|
|
* Creates a new GL context of the same type and makes the returned context current
|
|
|
|
* (if not null).
|
|
|
|
*/
|
2016-11-03 18:40:50 +00:00
|
|
|
virtual std::unique_ptr<GLTestContext> makeNew() const { return nullptr; }
|
2015-11-22 22:51:00 +00:00
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
template<typename Ret, typename... Args>
|
|
|
|
void getGLProcAddress(Ret(GR_GL_FUNCTION_TYPE** out)(Args...),
|
|
|
|
const char* name, const char* ext = nullptr) const {
|
|
|
|
using Proc = Ret(GR_GL_FUNCTION_TYPE*)(Args...);
|
|
|
|
if (!SkStrStartsWith(name, "gl")) {
|
2017-08-16 14:53:04 +00:00
|
|
|
SK_ABORT("getGLProcAddress: proc name must have 'gl' prefix");
|
2016-10-04 18:08:45 +00:00
|
|
|
*out = nullptr;
|
|
|
|
} else if (ext) {
|
|
|
|
SkString fullname(name);
|
|
|
|
fullname.append(ext);
|
|
|
|
*out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(fullname.c_str()));
|
|
|
|
} else {
|
|
|
|
*out = reinterpret_cast<Proc>(this->onPlatformGetProcAddress(name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-13 20:13:31 +00:00
|
|
|
sk_sp<GrDirectContext> makeContext(const GrContextOptions& options) override;
|
2017-07-25 14:05:01 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
protected:
|
2016-03-31 17:59:06 +00:00
|
|
|
GLTestContext();
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2015-06-23 20:23:44 +00:00
|
|
|
/*
|
2020-02-21 20:46:27 +00:00
|
|
|
* Methods that subclasses must call from their constructors and destructors.
|
2015-06-23 20:23:44 +00:00
|
|
|
*/
|
2020-02-21 20:46:27 +00:00
|
|
|
void init(sk_sp<const GrGLInterface>);
|
2016-03-31 01:56:19 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
void teardown() override;
|
2016-03-31 01:56:19 +00:00
|
|
|
|
|
|
|
virtual GrGLFuncPtr onPlatformGetProcAddress(const char *) const = 0;
|
2015-06-23 20:23:44 +00:00
|
|
|
|
|
|
|
private:
|
2020-08-26 19:27:03 +00:00
|
|
|
/** Subclass provides the gl interface object if construction was successful. */
|
|
|
|
sk_sp<const GrGLInterface> fOriginalGLInterface;
|
|
|
|
|
|
|
|
/** The same as fOriginalGLInterface unless the version has been overridden. */
|
|
|
|
sk_sp<const GrGLInterface> fGLInterface;
|
|
|
|
|
2020-03-19 19:54:28 +00:00
|
|
|
#ifndef SK_GL
|
|
|
|
bool fWasInitialized = false;
|
|
|
|
#endif
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = TestContext;
|
2016-05-11 17:09:18 +00:00
|
|
|
};
|
2016-03-31 01:56:19 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
/**
|
|
|
|
* Creates platform-dependent GL context object. The shareContext parameter is in an optional
|
2016-03-31 17:59:06 +00:00
|
|
|
* context with which to share display lists. This should be a pointer to an GLTestContext created
|
2016-05-11 17:09:18 +00:00
|
|
|
* with SkCreatePlatformGLTestContext. NULL indicates that no sharing is to take place. Returns a
|
|
|
|
* valid gl context object or NULL if such can not be created.
|
2014-10-09 12:24:15 +00:00
|
|
|
*/
|
2016-05-11 17:09:18 +00:00
|
|
|
GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
|
|
|
|
GLTestContext *shareContext = nullptr);
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
} // namespace sk_gpu_test
|
2010-12-23 15:00:45 +00:00
|
|
|
#endif
|