gfx/skia/trunk/src/gpu/gl/angle/SkANGLEGLContext.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 2012 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  */
     9 #include "gl/SkANGLEGLContext.h"
    11 SkANGLEGLContext::AutoContextRestore::AutoContextRestore() {
    12     fOldEGLContext = eglGetCurrentContext();
    13     fOldDisplay = eglGetCurrentDisplay();
    14     fOldSurface = eglGetCurrentSurface(EGL_DRAW);
    16 }
    18 SkANGLEGLContext::AutoContextRestore::~AutoContextRestore() {
    19     if (NULL != fOldDisplay) {
    20         eglMakeCurrent(fOldDisplay, fOldSurface, fOldSurface, fOldEGLContext);
    21     }
    22 }
    24 ///////////////////////////////////////////////////////////////////////////////
    26 SkANGLEGLContext::SkANGLEGLContext()
    27     : fContext(EGL_NO_CONTEXT)
    28     , fDisplay(EGL_NO_DISPLAY)
    29     , fSurface(EGL_NO_SURFACE) {
    30 }
    32 SkANGLEGLContext::~SkANGLEGLContext() {
    33     this->destroyGLContext();
    34 }
    36 void SkANGLEGLContext::destroyGLContext() {
    37     if (fDisplay) {
    38         eglMakeCurrent(fDisplay, 0, 0, 0);
    40         if (fContext) {
    41             eglDestroyContext(fDisplay, fContext);
    42             fContext = EGL_NO_CONTEXT;
    43         }
    45         if (fSurface) {
    46             eglDestroySurface(fDisplay, fSurface);
    47             fSurface = EGL_NO_SURFACE;
    48         }
    50         //TODO should we close the display?
    51         fDisplay = EGL_NO_DISPLAY;
    52     }
    53 }
    55 const GrGLInterface* SkANGLEGLContext::createGLContext() {
    57     fDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
    59     EGLint majorVersion;
    60     EGLint minorVersion;
    61     eglInitialize(fDisplay, &majorVersion, &minorVersion);
    63     EGLint numConfigs;
    64     static const EGLint configAttribs[] = {
    65         EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
    66         EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
    67         EGL_RED_SIZE, 8,
    68         EGL_GREEN_SIZE, 8,
    69         EGL_BLUE_SIZE, 8,
    70         EGL_ALPHA_SIZE, 8,
    71         EGL_NONE
    72     };
    74     EGLConfig surfaceConfig;
    75     eglChooseConfig(fDisplay, configAttribs, &surfaceConfig, 1, &numConfigs);
    77     static const EGLint contextAttribs[] = {
    78         EGL_CONTEXT_CLIENT_VERSION, 2,
    79         EGL_NONE
    80     };
    81     fContext = eglCreateContext(fDisplay, surfaceConfig, NULL, contextAttribs);
    84     static const EGLint surfaceAttribs[] = {
    85             EGL_WIDTH, 1,
    86             EGL_HEIGHT, 1,
    87             EGL_NONE
    88         };
    89     fSurface = eglCreatePbufferSurface(fDisplay, surfaceConfig, surfaceAttribs);
    91     eglMakeCurrent(fDisplay, fSurface, fSurface, fContext);
    93     const GrGLInterface* interface = GrGLCreateANGLEInterface();
    94     if (NULL == interface) {
    95         SkDebugf("Could not create ANGLE GL interface!\n");
    96         this->destroyGLContext();
    97         return NULL;
    98     }
   100     return interface;
   101 }
   103 void SkANGLEGLContext::makeCurrent() const {
   104     if (!eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
   105         SkDebugf("Could not set the context.\n");
   106     }
   107 }
   109 void SkANGLEGLContext::swapBuffers() const {
   110     if (!eglSwapBuffers(fDisplay, fSurface)) {
   111         SkDebugf("Could not complete eglSwapBuffers.\n");
   112     }
   113 }

mercurial