From 4c7f0a16312c374eba4e8d5d46435ce9eb0b9971 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Thu, 31 Mar 2016 10:07:23 -0700 Subject: rename sk_gpu_test::GLContext to sk_gpu_test::GLTestContext rename subclasses Fix up the EGL native GLTestContext GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1849463002 TBR=jvanverth@google.com Review URL: https://codereview.chromium.org/1849463002 --- tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp | 128 -------------------- .../gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp | 129 +++++++++++++++++++++ 2 files changed, 129 insertions(+), 128 deletions(-) delete mode 100644 tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp create mode 100644 tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp (limited to 'tools/gpu/gl/mac') diff --git a/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp b/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp deleted file mode 100644 index 7da99d7eb5..0000000000 --- a/tools/gpu/gl/mac/CreatePlatformGLContext_mac.cpp +++ /dev/null @@ -1,128 +0,0 @@ - -/* - * 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 -#include - -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 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(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 diff --git a/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp b/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp new file mode 100644 index 0000000000..b2cdaacd8a --- /dev/null +++ b/tools/gpu/gl/mac/CreatePlatformGLTestContext_mac.cpp @@ -0,0 +1,129 @@ + +/* + * 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/GLTestContext.h" +#include "AvailabilityMacros.h" + +#include +#include + +namespace { +class MacGLTestContext : public sk_gpu_test::GLTestContext { +public: + MacGLTestContext(); + ~MacGLTestContext() override; + +private: + void destroyGLContext(); + + void onPlatformMakeCurrent() const override; + void onPlatformSwapBuffers() const override; + GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; + + CGLContextObj fContext; + void* fGLLibrary; +}; + +MacGLTestContext::MacGLTestContext() + : 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 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()); +} + +MacGLTestContext::~MacGLTestContext() { + this->teardown(); + this->destroyGLContext(); +} + +void MacGLTestContext::destroyGLContext() { + if (fContext) { + CGLReleaseContext(fContext); + fContext = nullptr; + } + if (RTLD_DEFAULT != fGLLibrary) { + dlclose(fGLLibrary); + } +} + +void MacGLTestContext::onPlatformMakeCurrent() const { + CGLSetCurrentContext(fContext); +} + +void MacGLTestContext::onPlatformSwapBuffers() const { + CGLFlushDrawable(fContext); +} + +GrGLFuncPtr MacGLTestContext::onPlatformGetProcAddress(const char* procName) const { + return reinterpret_cast(dlsym(fGLLibrary, procName)); +} + +} // anonymous namespace + +namespace sk_gpu_test { +GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, + GLTestContext* shareContext) { + SkASSERT(!shareContext); + if (shareContext) { + return nullptr; + } + + if (kGLES_GrGLStandard == forcedGpuAPI) { + return nullptr; + } + MacGLTestContext* ctx = new MacGLTestContext; + if (!ctx->isValid()) { + delete ctx; + return nullptr; + } + return ctx; +} +} // namespace sk_gpu_test -- cgit v1.2.3