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"
|
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.
|
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
|
|
|
|
2018-10-12 13:31:11 +00:00
|
|
|
virtual GrBackendApi backend() override { return GrBackendApi::kOpenGL; }
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2017-07-13 19:07:54 +00:00
|
|
|
bool isValid() const { return SkToBool(this->gl()); }
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2017-12-07 17:33:05 +00:00
|
|
|
const GrGLInterface* gl() const { return fGL.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
|
|
|
|
2016-01-14 17:24:09 +00:00
|
|
|
/** Used for testing GL_TEXTURE_RECTANGLE integration. */
|
2019-02-08 17:33:08 +00:00
|
|
|
GrGLuint createTextureRectangle(int width, int height, GrGLenum internalFormat,
|
|
|
|
GrGLenum externalFormat, GrGLenum externalType, GrGLvoid* data);
|
2016-01-14 17:24:09 +00:00
|
|
|
|
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
|
|
|
/** Ensures all work is submitted to the GPU for execution. */
|
|
|
|
void submit() override;
|
|
|
|
|
|
|
|
/** Wait until all GPU work is finished. */
|
|
|
|
void finish() override;
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-25 14:05:01 +00:00
|
|
|
sk_sp<GrContext> makeGrContext(const GrContextOptions& options) override;
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Methods that sublcasses must call from their constructors and destructors.
|
|
|
|
*/
|
2017-12-11 15:06:31 +00:00
|
|
|
void init(sk_sp<const GrGLInterface>, std::unique_ptr<FenceSync> = nullptr);
|
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:
|
2014-10-16 06:03:54 +00:00
|
|
|
/** Subclass provides the gl interface object if construction was
|
|
|
|
* successful. */
|
2016-11-03 20:26:13 +00:00
|
|
|
sk_sp<const GrGLInterface> fGL;
|
2012-06-21 20:25:03 +00:00
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
typedef TestContext INHERITED;
|
|
|
|
};
|
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
|