Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | |
michael@0 | 2 | /* |
michael@0 | 3 | * Copyright 2011 Google Inc. |
michael@0 | 4 | * |
michael@0 | 5 | * Use of this source code is governed by a BSD-style license that can be |
michael@0 | 6 | * found in the LICENSE file. |
michael@0 | 7 | */ |
michael@0 | 8 | #include "gl/SkNativeGLContext.h" |
michael@0 | 9 | #include "AvailabilityMacros.h" |
michael@0 | 10 | |
michael@0 | 11 | SkNativeGLContext::AutoContextRestore::AutoContextRestore() { |
michael@0 | 12 | fOldCGLContext = CGLGetCurrentContext(); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { |
michael@0 | 16 | CGLSetCurrentContext(fOldCGLContext); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | /////////////////////////////////////////////////////////////////////////////// |
michael@0 | 20 | |
michael@0 | 21 | SkNativeGLContext::SkNativeGLContext() |
michael@0 | 22 | : fContext(NULL) { |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | SkNativeGLContext::~SkNativeGLContext() { |
michael@0 | 26 | this->destroyGLContext(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | void SkNativeGLContext::destroyGLContext() { |
michael@0 | 30 | if (NULL != fContext) { |
michael@0 | 31 | CGLReleaseContext(fContext); |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | const GrGLInterface* SkNativeGLContext::createGLContext() { |
michael@0 | 36 | SkASSERT(NULL == fContext); |
michael@0 | 37 | |
michael@0 | 38 | CGLPixelFormatAttribute attributes[] = { |
michael@0 | 39 | #if MAC_OS_X_VERSION_10_7 |
michael@0 | 40 | kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, |
michael@0 | 41 | #endif |
michael@0 | 42 | kCGLPFADoubleBuffer, |
michael@0 | 43 | (CGLPixelFormatAttribute)0 |
michael@0 | 44 | }; |
michael@0 | 45 | CGLPixelFormatObj pixFormat; |
michael@0 | 46 | GLint npix; |
michael@0 | 47 | |
michael@0 | 48 | CGLChoosePixelFormat(attributes, &pixFormat, &npix); |
michael@0 | 49 | |
michael@0 | 50 | if (NULL == pixFormat) { |
michael@0 | 51 | SkDebugf("CGLChoosePixelFormat failed."); |
michael@0 | 52 | return NULL; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | CGLCreateContext(pixFormat, NULL, &fContext); |
michael@0 | 56 | CGLReleasePixelFormat(pixFormat); |
michael@0 | 57 | |
michael@0 | 58 | if (NULL == fContext) { |
michael@0 | 59 | SkDebugf("CGLCreateContext failed."); |
michael@0 | 60 | return NULL; |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | CGLSetCurrentContext(fContext); |
michael@0 | 64 | |
michael@0 | 65 | const GrGLInterface* interface = GrGLCreateNativeInterface(); |
michael@0 | 66 | if (NULL == interface) { |
michael@0 | 67 | SkDebugf("Context could not create GL interface.\n"); |
michael@0 | 68 | this->destroyGLContext(); |
michael@0 | 69 | return NULL; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | return interface; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | void SkNativeGLContext::makeCurrent() const { |
michael@0 | 76 | CGLSetCurrentContext(fContext); |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | void SkNativeGLContext::swapBuffers() const { |
michael@0 | 80 | CGLFlushDrawable(fContext); |
michael@0 | 81 | } |