gfx/skia/trunk/src/gpu/gl/mac/SkNativeGLContext_mac.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     2 /*
     3  * Copyright 2011 Google Inc.
     4  *
     5  * Use of this source code is governed by a BSD-style license that can be
     6  * found in the LICENSE file.
     7  */
     8 #include "gl/SkNativeGLContext.h"
     9 #include "AvailabilityMacros.h"
    11 SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
    12     fOldCGLContext = CGLGetCurrentContext();
    13 }
    15 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
    16     CGLSetCurrentContext(fOldCGLContext);
    17 }
    19 ///////////////////////////////////////////////////////////////////////////////
    21 SkNativeGLContext::SkNativeGLContext()
    22     : fContext(NULL) {
    23 }
    25 SkNativeGLContext::~SkNativeGLContext() {
    26     this->destroyGLContext();
    27 }
    29 void SkNativeGLContext::destroyGLContext() {
    30     if (NULL != fContext) {
    31         CGLReleaseContext(fContext);
    32     }
    33 }
    35 const GrGLInterface* SkNativeGLContext::createGLContext() {
    36     SkASSERT(NULL == fContext);
    38     CGLPixelFormatAttribute attributes[] = {
    39 #if MAC_OS_X_VERSION_10_7
    40         kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
    41 #endif
    42         kCGLPFADoubleBuffer,
    43         (CGLPixelFormatAttribute)0
    44     };
    45     CGLPixelFormatObj pixFormat;
    46     GLint npix;
    48     CGLChoosePixelFormat(attributes, &pixFormat, &npix);
    50     if (NULL == pixFormat) {
    51         SkDebugf("CGLChoosePixelFormat failed.");
    52         return NULL;
    53     }
    55     CGLCreateContext(pixFormat, NULL, &fContext);
    56     CGLReleasePixelFormat(pixFormat);
    58     if (NULL == fContext) {
    59         SkDebugf("CGLCreateContext failed.");
    60         return NULL;
    61     }
    63     CGLSetCurrentContext(fContext);
    65     const GrGLInterface* interface = GrGLCreateNativeInterface();
    66     if (NULL == interface) {
    67         SkDebugf("Context could not create GL interface.\n");
    68         this->destroyGLContext();
    69         return NULL;
    70     }
    72     return interface;
    73 }
    75 void SkNativeGLContext::makeCurrent() const {
    76     CGLSetCurrentContext(fContext);
    77 }
    79 void SkNativeGLContext::swapBuffers() const {
    80     CGLFlushDrawable(fContext);
    81 }

mercurial