| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "gl/SkGLContext.h" | 8 #include "gl/SkGLContext.h" |
| 9 #include "AvailabilityMacros.h" | 9 #include "AvailabilityMacros.h" |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 void onPlatformMakeCurrent() const override; | 23 void onPlatformMakeCurrent() const override; |
| 24 void onPlatformSwapBuffers() const override; | 24 void onPlatformSwapBuffers() const override; |
| 25 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; | 25 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; |
| 26 | 26 |
| 27 CGLContextObj fContext; | 27 CGLContextObj fContext; |
| 28 void* fGLLibrary; | 28 void* fGLLibrary; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 MacGLContext::MacGLContext() | 31 MacGLContext::MacGLContext() |
| 32 : fContext(NULL) | 32 : fContext(nullptr) |
| 33 , fGLLibrary(RTLD_DEFAULT) { | 33 , fGLLibrary(RTLD_DEFAULT) { |
| 34 CGLPixelFormatAttribute attributes[] = { | 34 CGLPixelFormatAttribute attributes[] = { |
| 35 #if MAC_OS_X_VERSION_10_7 | 35 #if MAC_OS_X_VERSION_10_7 |
| 36 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core
, | 36 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core
, |
| 37 #endif | 37 #endif |
| 38 kCGLPFADoubleBuffer, | 38 kCGLPFADoubleBuffer, |
| 39 (CGLPixelFormatAttribute)0 | 39 (CGLPixelFormatAttribute)0 |
| 40 }; | 40 }; |
| 41 CGLPixelFormatObj pixFormat; | 41 CGLPixelFormatObj pixFormat; |
| 42 GLint npix; | 42 GLint npix; |
| 43 | 43 |
| 44 CGLChoosePixelFormat(attributes, &pixFormat, &npix); | 44 CGLChoosePixelFormat(attributes, &pixFormat, &npix); |
| 45 | 45 |
| 46 if (NULL == pixFormat) { | 46 if (nullptr == pixFormat) { |
| 47 SkDebugf("CGLChoosePixelFormat failed."); | 47 SkDebugf("CGLChoosePixelFormat failed."); |
| 48 return; | 48 return; |
| 49 } | 49 } |
| 50 | 50 |
| 51 CGLCreateContext(pixFormat, NULL, &fContext); | 51 CGLCreateContext(pixFormat, nullptr, &fContext); |
| 52 CGLReleasePixelFormat(pixFormat); | 52 CGLReleasePixelFormat(pixFormat); |
| 53 | 53 |
| 54 if (NULL == fContext) { | 54 if (nullptr == fContext) { |
| 55 SkDebugf("CGLCreateContext failed."); | 55 SkDebugf("CGLCreateContext failed."); |
| 56 return; | 56 return; |
| 57 } | 57 } |
| 58 | 58 |
| 59 CGLSetCurrentContext(fContext); | 59 CGLSetCurrentContext(fContext); |
| 60 | 60 |
| 61 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); | 61 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); |
| 62 if (NULL == gl.get()) { | 62 if (nullptr == gl.get()) { |
| 63 SkDebugf("Context could not create GL interface.\n"); | 63 SkDebugf("Context could not create GL interface.\n"); |
| 64 this->destroyGLContext(); | 64 this->destroyGLContext(); |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 if (!gl->validate()) { | 67 if (!gl->validate()) { |
| 68 SkDebugf("Context could not validate GL interface.\n"); | 68 SkDebugf("Context could not validate GL interface.\n"); |
| 69 this->destroyGLContext(); | 69 this->destroyGLContext(); |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 | 72 |
| 73 fGLLibrary = dlopen( | 73 fGLLibrary = dlopen( |
| 74 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.
dylib", | 74 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.
dylib", |
| 75 RTLD_LAZY); | 75 RTLD_LAZY); |
| 76 | 76 |
| 77 this->init(gl.detach()); | 77 this->init(gl.detach()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 MacGLContext::~MacGLContext() { | 80 MacGLContext::~MacGLContext() { |
| 81 this->teardown(); | 81 this->teardown(); |
| 82 this->destroyGLContext(); | 82 this->destroyGLContext(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void MacGLContext::destroyGLContext() { | 85 void MacGLContext::destroyGLContext() { |
| 86 if (fContext) { | 86 if (fContext) { |
| 87 CGLReleaseContext(fContext); | 87 CGLReleaseContext(fContext); |
| 88 fContext = NULL; | 88 fContext = nullptr; |
| 89 } | 89 } |
| 90 if (RTLD_DEFAULT != fGLLibrary) { | 90 if (RTLD_DEFAULT != fGLLibrary) { |
| 91 dlclose(fGLLibrary); | 91 dlclose(fGLLibrary); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 void MacGLContext::onPlatformMakeCurrent() const { | 95 void MacGLContext::onPlatformMakeCurrent() const { |
| 96 CGLSetCurrentContext(fContext); | 96 CGLSetCurrentContext(fContext); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void MacGLContext::onPlatformSwapBuffers() const { | 99 void MacGLContext::onPlatformSwapBuffers() const { |
| 100 CGLFlushDrawable(fContext); | 100 CGLFlushDrawable(fContext); |
| 101 } | 101 } |
| 102 | 102 |
| 103 GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const { | 103 GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const { |
| 104 return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); | 104 return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); |
| 105 } | 105 } |
| 106 | 106 |
| 107 } // anonymous namespace | 107 } // anonymous namespace |
| 108 | 108 |
| 109 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { | 109 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { |
| 110 if (kGLES_GrGLStandard == forcedGpuAPI) { | 110 if (kGLES_GrGLStandard == forcedGpuAPI) { |
| 111 return NULL; | 111 return nullptr; |
| 112 } | 112 } |
| 113 MacGLContext* ctx = new MacGLContext; | 113 MacGLContext* ctx = new MacGLContext; |
| 114 if (!ctx->isValid()) { | 114 if (!ctx->isValid()) { |
| 115 delete ctx; | 115 delete ctx; |
| 116 return NULL; | 116 return nullptr; |
| 117 } | 117 } |
| 118 return ctx; | 118 return ctx; |
| 119 } | 119 } |
| OLD | NEW |