From d416a5b10ff9e6d4f55a1f5b0419722132d68ff3 Mon Sep 17 00:00:00 2001 From: cdalton Date: Tue, 23 Jun 2015 13:23:44 -0700 Subject: Implement SkGLContext swapBuffers with fence syncs Improves the GPU measuring accuracy of nanobench by using fence syncs. Fence syncs are very widely supported and available on almost every platform. NO_MERGE_BUILDS BUG=skia: Review URL: https://codereview.chromium.org/1194783003 --- src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp | 36 ++++++++++++++++++------ 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'src/gpu/gl/mac') diff --git a/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp index 436c53f0bb..d2d8569938 100644 --- a/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp +++ b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp @@ -9,23 +9,28 @@ #include "AvailabilityMacros.h" #include +#include namespace { class MacGLContext : public SkGLContext { public: MacGLContext(); ~MacGLContext() override; - void makeCurrent() const override; - void swapBuffers() const 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(NULL) { + : fContext(NULL) + , fGLLibrary(RTLD_DEFAULT) { CGLPixelFormatAttribute attributes[] = { #if MAC_OS_X_VERSION_10_7 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, @@ -53,39 +58,52 @@ MacGLContext::MacGLContext() CGLSetCurrentContext(fContext); - fGL.reset(GrGLCreateNativeInterface()); - if (NULL == fGL.get()) { + SkAutoTUnref gl(GrGLCreateNativeInterface()); + if (NULL == gl.get()) { SkDebugf("Context could not create GL interface.\n"); this->destroyGLContext(); return; } - if (!fGL->validate()) { + 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.detach()); } MacGLContext::~MacGLContext() { + this->teardown(); this->destroyGLContext(); } void MacGLContext::destroyGLContext() { - fGL.reset(NULL); if (fContext) { CGLReleaseContext(fContext); fContext = NULL; } + if (RTLD_DEFAULT != fGLLibrary) { + dlclose(fGLLibrary); + } } -void MacGLContext::makeCurrent() const { +void MacGLContext::onPlatformMakeCurrent() const { CGLSetCurrentContext(fContext); } -void MacGLContext::swapBuffers() const { +void MacGLContext::onPlatformSwapBuffers() const { CGLFlushDrawable(fContext); } +GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const { + return reinterpret_cast(dlsym(fGLLibrary, procName)); +} + } // anonymous namespace SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { -- cgit v1.2.3