2011-10-19 20:43:20 +00:00
|
|
|
/*
|
2013-02-28 20:16:25 +00:00
|
|
|
* Copyright 2013 Google Inc.
|
2011-10-19 20:43:20 +00:00
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2016-05-11 17:09:18 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
#include "GLTestContext.h"
|
2016-03-31 01:56:19 +00:00
|
|
|
#include "gl/GrGLUtil.h"
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class GLFenceSync : public sk_gpu_test::FenceSync {
|
2015-06-23 20:23:44 +00:00
|
|
|
public:
|
2016-10-04 18:08:45 +00:00
|
|
|
static GLFenceSync* CreateIfSupported(const sk_gpu_test::GLTestContext*);
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const override;
|
|
|
|
bool waitFence(sk_gpu_test::PlatformFence fence) const override;
|
|
|
|
void deleteFence(sk_gpu_test::PlatformFence fence) const override;
|
2015-06-23 20:23:44 +00:00
|
|
|
|
|
|
|
private:
|
2016-10-04 18:08:45 +00:00
|
|
|
GLFenceSync(const sk_gpu_test::GLTestContext*, const char* ext = "");
|
|
|
|
|
|
|
|
bool validate() { return fGLFenceSync && fGLClientWaitSync && fGLDeleteSync; }
|
2015-06-23 20:23:44 +00:00
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
static constexpr GrGLenum GL_SYNC_GPU_COMMANDS_COMPLETE = 0x9117;
|
|
|
|
static constexpr GrGLenum GL_WAIT_FAILED = 0x911d;
|
|
|
|
static constexpr GrGLbitfield GL_SYNC_FLUSH_COMMANDS_BIT = 0x00000001;
|
2015-06-23 20:23:44 +00:00
|
|
|
|
|
|
|
typedef struct __GLsync *GLsync;
|
|
|
|
|
|
|
|
typedef GLsync (GR_GL_FUNCTION_TYPE* GLFenceSyncProc) (GrGLenum, GrGLbitfield);
|
|
|
|
typedef GrGLenum (GR_GL_FUNCTION_TYPE* GLClientWaitSyncProc) (GLsync, GrGLbitfield, GrGLuint64);
|
|
|
|
typedef GrGLvoid (GR_GL_FUNCTION_TYPE* GLDeleteSyncProc) (GLsync);
|
|
|
|
|
|
|
|
GLFenceSyncProc fGLFenceSync;
|
|
|
|
GLClientWaitSyncProc fGLClientWaitSync;
|
|
|
|
GLDeleteSyncProc fGLDeleteSync;
|
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
typedef FenceSync INHERITED;
|
2015-06-23 20:23:44 +00:00
|
|
|
};
|
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
GLFenceSync* GLFenceSync::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) {
|
|
|
|
SkAutoTDelete<GLFenceSync> ret;
|
|
|
|
if (kGL_GrGLStandard == ctx->gl()->fStandard) {
|
|
|
|
if (GrGLGetVersion(ctx->gl()) < GR_GL_VER(3,2) && !ctx->gl()->hasExtension("GL_ARB_sync")) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
ret.reset(new GLFenceSync(ctx));
|
|
|
|
} else {
|
|
|
|
if (!ctx->gl()->hasExtension("GL_APPLE_sync")) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
ret.reset(new GLFenceSync(ctx, "APPLE"));
|
|
|
|
}
|
|
|
|
return ret->validate() ? ret.release() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLFenceSync::GLFenceSync(const sk_gpu_test::GLTestContext* ctx, const char* ext) {
|
|
|
|
ctx->getGLProcAddress(&fGLFenceSync, "glFenceSync");
|
|
|
|
ctx->getGLProcAddress(&fGLClientWaitSync, "glClientWaitSync");
|
|
|
|
ctx->getGLProcAddress(&fGLDeleteSync, "glDeleteSync");
|
|
|
|
}
|
|
|
|
|
|
|
|
sk_gpu_test::PlatformFence GLFenceSync::insertFence() const {
|
|
|
|
__GLsync* glsync = fGLFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
|
|
|
|
return reinterpret_cast<sk_gpu_test::PlatformFence>(glsync);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GLFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const {
|
|
|
|
GLsync glsync = reinterpret_cast<GLsync>(fence);
|
|
|
|
return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BIT, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const {
|
|
|
|
GLsync glsync = reinterpret_cast<GLsync>(fence);
|
|
|
|
fGLDeleteSync(glsync);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace sk_gpu_test {
|
|
|
|
|
2016-05-11 17:09:18 +00:00
|
|
|
GLTestContext::GLTestContext() : TestContext() {}
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
GLTestContext::~GLTestContext() {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(nullptr == fGL.get());
|
2015-06-23 20:23:44 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 18:08:45 +00:00
|
|
|
void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) {
|
2015-06-23 20:23:44 +00:00
|
|
|
SkASSERT(!fGL.get());
|
|
|
|
fGL.reset(gl);
|
2016-05-11 17:09:18 +00:00
|
|
|
fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this);
|
2015-06-23 20:23:44 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
void GLTestContext::teardown() {
|
2015-08-27 14:41:13 +00:00
|
|
|
fGL.reset(nullptr);
|
2016-05-11 17:09:18 +00:00
|
|
|
INHERITED::teardown();
|
2011-10-19 20:43:20 +00:00
|
|
|
}
|
2014-07-29 15:01:52 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
void GLTestContext::testAbandon() {
|
2016-05-11 17:09:18 +00:00
|
|
|
INHERITED::testAbandon();
|
2014-09-05 20:34:00 +00:00
|
|
|
if (fGL) {
|
2014-07-29 15:01:52 +00:00
|
|
|
fGL->abandon();
|
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 18:55:36 +00:00
|
|
|
void GLTestContext::submit() {
|
|
|
|
if (fGL) {
|
|
|
|
GR_GL_CALL(fGL.get(), Flush());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GLTestContext::finish() {
|
|
|
|
if (fGL) {
|
|
|
|
GR_GL_CALL(fGL.get(), Finish());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
GrGLint GLTestContext::createTextureRectangle(int width, int height, GrGLenum internalFormat,
|
2016-03-31 01:56:19 +00:00
|
|
|
GrGLenum externalFormat, GrGLenum externalType,
|
|
|
|
GrGLvoid* data) {
|
2016-01-20 14:18:10 +00:00
|
|
|
if (!(kGL_GrGLStandard == fGL->fStandard && GrGLGetVersion(fGL) >= GR_GL_VER(3, 1)) &&
|
2016-01-14 17:24:09 +00:00
|
|
|
!fGL->fExtensions.has("GL_ARB_texture_rectangle")) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-01-20 14:18:10 +00:00
|
|
|
|
|
|
|
if (GrGLGetGLSLVersion(fGL) < GR_GLSL_VER(1, 40)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-14 17:24:09 +00:00
|
|
|
GrGLuint id;
|
|
|
|
GR_GL_CALL(fGL, GenTextures(1, &id));
|
|
|
|
GR_GL_CALL(fGL, BindTexture(GR_GL_TEXTURE_RECTANGLE, id));
|
|
|
|
GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MAG_FILTER,
|
|
|
|
GR_GL_NEAREST));
|
|
|
|
GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_MIN_FILTER,
|
|
|
|
GR_GL_NEAREST));
|
|
|
|
GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S,
|
2016-03-31 01:56:19 +00:00
|
|
|
GR_GL_CLAMP_TO_EDGE));
|
2016-01-14 17:24:09 +00:00
|
|
|
GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T,
|
|
|
|
GR_GL_CLAMP_TO_EDGE));
|
|
|
|
GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width, height, 0,
|
|
|
|
externalFormat, externalType, data));
|
|
|
|
return id;
|
|
|
|
}
|
2016-03-31 01:56:19 +00:00
|
|
|
} // namespace sk_gpu_test
|