gfx/skia/trunk/src/gpu/gl/angle/SkANGLEGLContext.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial