diff options
author | bsalomon <bsalomon@google.com> | 2016-03-30 18:56:19 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-30 18:56:20 -0700 |
commit | 3724e574a744491b7cfb8187ac865a70ef3d4528 (patch) | |
tree | eb3dd729cbc0adef5ce2b4a2fa048fe21baeb35a /tools/gpu/gl/mac | |
parent | 2238c9dbca4b791edc512957728a18ce14d55912 (diff) |
Move SkGLContext and some GrGLInterface implementations to skgputest module
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1815823002
CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot
Committed: https://skia.googlesource.com/skia/+/fe3456cb006110d045b26ff3f8681b893a757b58
Review URL: https://codereview.chromium.org/1815823002
Diffstat (limited to 'tools/gpu/gl/mac')
-rw-r--r-- | tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp b/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp new file mode 100644 index 0000000000..7da99d7eb5 --- /dev/null +++ b/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp @@ -0,0 +1,128 @@ + +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "SkTypes.h" + +#include "gl/GLContext.h" +#include "AvailabilityMacros.h" + +#include <OpenGL/OpenGL.h> +#include <dlfcn.h> + +namespace { +class MacGLContext : public sk_gpu_test::GLContext { +public: + MacGLContext(); + ~MacGLContext() override; + +private: + void destroyGLContext(); + + void onPlatformMakeCurrent() const override; + void onPlatformSwapBuffers() const override; + GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; + + CGLContextObj fContext; + void* fGLLibrary; +}; + +MacGLContext::MacGLContext() + : fContext(nullptr) + , fGLLibrary(RTLD_DEFAULT) { + CGLPixelFormatAttribute attributes[] = { +#if MAC_OS_X_VERSION_10_7 + kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, +#endif + kCGLPFADoubleBuffer, + (CGLPixelFormatAttribute)0 + }; + CGLPixelFormatObj pixFormat; + GLint npix; + + CGLChoosePixelFormat(attributes, &pixFormat, &npix); + + if (nullptr == pixFormat) { + SkDebugf("CGLChoosePixelFormat failed."); + return; + } + + CGLCreateContext(pixFormat, nullptr, &fContext); + CGLReleasePixelFormat(pixFormat); + + if (nullptr == fContext) { + SkDebugf("CGLCreateContext failed."); + return; + } + + CGLSetCurrentContext(fContext); + + SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); + if (nullptr == gl.get()) { + SkDebugf("Context could not create GL interface.\n"); + this->destroyGLContext(); + return; + } + if (!gl->validate()) { + SkDebugf("Context could not validate GL interface.\n"); + this->destroyGLContext(); + return; + } + + fGLLibrary = dlopen( + "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", + RTLD_LAZY); + + this->init(gl.release()); +} + +MacGLContext::~MacGLContext() { + this->teardown(); + this->destroyGLContext(); +} + +void MacGLContext::destroyGLContext() { + if (fContext) { + CGLReleaseContext(fContext); + fContext = nullptr; + } + if (RTLD_DEFAULT != fGLLibrary) { + dlclose(fGLLibrary); + } +} + +void MacGLContext::onPlatformMakeCurrent() const { + CGLSetCurrentContext(fContext); +} + +void MacGLContext::onPlatformSwapBuffers() const { + CGLFlushDrawable(fContext); +} + +GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const { + return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); +} + +} // anonymous namespace + +namespace sk_gpu_test { +GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext* shareContext) { + SkASSERT(!shareContext); + if (shareContext) { + return nullptr; + } + + if (kGLES_GrGLStandard == forcedGpuAPI) { + return nullptr; + } + MacGLContext* ctx = new MacGLContext; + if (!ctx->isValid()) { + delete ctx; + return nullptr; + } + return ctx; +} +} // namespace sk_gpu_test |