diff options
author | cdalton <cdalton@nvidia.com> | 2015-06-23 13:23:44 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-23 13:23:44 -0700 |
commit | d416a5b10ff9e6d4f55a1f5b0419722132d68ff3 (patch) | |
tree | f9f39528fd8fd7c033882c137d711e12939c6fa2 /src/gpu/gl/mac | |
parent | b607767703ff7898611cf88c1218d5d69535e984 (diff) |
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
Diffstat (limited to 'src/gpu/gl/mac')
-rw-r--r-- | src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
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 <OpenGL/OpenGL.h> +#include <dlfcn.h> 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<const GrGLInterface> 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<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); +} + } // anonymous namespace SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { |