2016-03-31 01:56:19 +00:00
|
|
|
|
2011-10-19 20:43:20 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2015-11-02 18:20:27 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
#include "gl/GLTestContext.h"
|
2013-03-07 19:09:11 +00:00
|
|
|
#include "AvailabilityMacros.h"
|
2011-10-19 20:43:20 +00:00
|
|
|
|
2014-10-09 12:24:15 +00:00
|
|
|
#include <OpenGL/OpenGL.h>
|
2015-06-23 20:23:44 +00:00
|
|
|
#include <dlfcn.h>
|
2014-10-08 11:14:24 +00:00
|
|
|
|
2014-10-09 12:24:15 +00:00
|
|
|
namespace {
|
2016-03-31 17:59:06 +00:00
|
|
|
class MacGLTestContext : public sk_gpu_test::GLTestContext {
|
2014-10-09 12:24:15 +00:00
|
|
|
public:
|
2016-03-31 17:59:06 +00:00
|
|
|
MacGLTestContext();
|
|
|
|
~MacGLTestContext() override;
|
2011-10-24 21:17:53 +00:00
|
|
|
|
2014-10-09 12:24:15 +00:00
|
|
|
private:
|
2014-10-16 06:03:54 +00:00
|
|
|
void destroyGLContext();
|
|
|
|
|
2015-06-23 20:23:44 +00:00
|
|
|
void onPlatformMakeCurrent() const override;
|
|
|
|
void onPlatformSwapBuffers() const override;
|
|
|
|
GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
|
|
|
|
|
2014-10-09 12:24:15 +00:00
|
|
|
CGLContextObj fContext;
|
2015-06-23 20:23:44 +00:00
|
|
|
void* fGLLibrary;
|
2014-10-09 12:24:15 +00:00
|
|
|
};
|
2011-10-24 21:17:53 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
MacGLTestContext::MacGLTestContext()
|
2015-08-27 14:41:13 +00:00
|
|
|
: fContext(nullptr)
|
2015-06-23 20:23:44 +00:00
|
|
|
, fGLLibrary(RTLD_DEFAULT) {
|
2013-02-14 15:10:59 +00:00
|
|
|
CGLPixelFormatAttribute attributes[] = {
|
2013-03-07 19:09:11 +00:00
|
|
|
#if MAC_OS_X_VERSION_10_7
|
2013-02-26 21:46:32 +00:00
|
|
|
kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
|
2013-02-14 15:10:59 +00:00
|
|
|
#endif
|
2013-10-09 18:25:38 +00:00
|
|
|
kCGLPFADoubleBuffer,
|
2013-02-14 15:10:59 +00:00
|
|
|
(CGLPixelFormatAttribute)0
|
2011-10-19 20:43:20 +00:00
|
|
|
};
|
2013-02-14 15:10:59 +00:00
|
|
|
CGLPixelFormatObj pixFormat;
|
|
|
|
GLint npix;
|
2013-02-15 07:16:57 +00:00
|
|
|
|
2013-02-14 15:10:59 +00:00
|
|
|
CGLChoosePixelFormat(attributes, &pixFormat, &npix);
|
2013-02-15 07:16:57 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == pixFormat) {
|
2013-02-14 15:10:59 +00:00
|
|
|
SkDebugf("CGLChoosePixelFormat failed.");
|
2014-10-16 06:03:54 +00:00
|
|
|
return;
|
2011-10-19 20:43:20 +00:00
|
|
|
}
|
2013-02-15 07:16:57 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
CGLCreateContext(pixFormat, nullptr, &fContext);
|
2013-02-14 15:10:59 +00:00
|
|
|
CGLReleasePixelFormat(pixFormat);
|
2013-02-15 07:16:57 +00:00
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == fContext) {
|
2013-02-14 15:10:59 +00:00
|
|
|
SkDebugf("CGLCreateContext failed.");
|
2014-10-16 06:03:54 +00:00
|
|
|
return;
|
2011-10-19 20:43:20 +00:00
|
|
|
}
|
2013-02-15 07:16:57 +00:00
|
|
|
|
2013-02-14 15:10:59 +00:00
|
|
|
CGLSetCurrentContext(fContext);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2016-11-03 20:26:13 +00:00
|
|
|
sk_sp<const GrGLInterface> gl(GrGLCreateNativeInterface());
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == gl.get()) {
|
2011-10-19 20:43:20 +00:00
|
|
|
SkDebugf("Context could not create GL interface.\n");
|
|
|
|
this->destroyGLContext();
|
2014-10-16 06:03:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
if (!gl->validate()) {
|
2014-10-16 06:03:54 +00:00
|
|
|
SkDebugf("Context could not validate GL interface.\n");
|
|
|
|
this->destroyGLContext();
|
|
|
|
return;
|
2011-10-19 20:43:20 +00:00
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
|
|
|
|
fGLLibrary = dlopen(
|
|
|
|
"/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
|
|
|
|
RTLD_LAZY);
|
|
|
|
|
2016-03-16 20:53:35 +00:00
|
|
|
this->init(gl.release());
|
2014-10-16 06:03:54 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
MacGLTestContext::~MacGLTestContext() {
|
2015-06-23 20:23:44 +00:00
|
|
|
this->teardown();
|
2014-10-16 06:03:54 +00:00
|
|
|
this->destroyGLContext();
|
|
|
|
}
|
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
void MacGLTestContext::destroyGLContext() {
|
2014-10-16 06:03:54 +00:00
|
|
|
if (fContext) {
|
|
|
|
CGLReleaseContext(fContext);
|
2015-08-27 14:41:13 +00:00
|
|
|
fContext = nullptr;
|
2014-10-16 06:03:54 +00:00
|
|
|
}
|
2015-06-23 20:23:44 +00:00
|
|
|
if (RTLD_DEFAULT != fGLLibrary) {
|
|
|
|
dlclose(fGLLibrary);
|
|
|
|
}
|
2011-10-19 20:43:20 +00:00
|
|
|
}
|
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
void MacGLTestContext::onPlatformMakeCurrent() const {
|
2013-02-14 15:10:59 +00:00
|
|
|
CGLSetCurrentContext(fContext);
|
2011-10-19 20:43:20 +00:00
|
|
|
}
|
2013-10-09 18:25:38 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
void MacGLTestContext::onPlatformSwapBuffers() const {
|
2013-10-09 18:25:38 +00:00
|
|
|
CGLFlushDrawable(fContext);
|
|
|
|
}
|
2014-10-09 12:24:15 +00:00
|
|
|
|
2016-03-31 17:59:06 +00:00
|
|
|
GrGLFuncPtr MacGLTestContext::onPlatformGetProcAddress(const char* procName) const {
|
2015-06-23 20:23:44 +00:00
|
|
|
return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName));
|
|
|
|
}
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
} // anonymous namespace
|
2014-10-09 12:24:15 +00:00
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
namespace sk_gpu_test {
|
2016-03-31 17:59:06 +00:00
|
|
|
GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI,
|
|
|
|
GLTestContext* shareContext) {
|
2016-01-20 16:07:01 +00:00
|
|
|
SkASSERT(!shareContext);
|
|
|
|
if (shareContext) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-16 06:03:54 +00:00
|
|
|
if (kGLES_GrGLStandard == forcedGpuAPI) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2014-10-16 06:03:54 +00:00
|
|
|
}
|
2016-03-31 17:59:06 +00:00
|
|
|
MacGLTestContext* ctx = new MacGLTestContext;
|
2014-10-16 06:03:54 +00:00
|
|
|
if (!ctx->isValid()) {
|
2015-08-26 20:07:48 +00:00
|
|
|
delete ctx;
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2014-10-16 06:03:54 +00:00
|
|
|
}
|
|
|
|
return ctx;
|
2014-10-09 12:24:15 +00:00
|
|
|
}
|
2016-03-31 01:56:19 +00:00
|
|
|
} // namespace sk_gpu_test
|