gfx/skia/trunk/src/gpu/gl/mesa/SkMesaGLContext.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 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
michael@0 9 #include <GL/osmesa.h>
michael@0 10
michael@0 11 #include "gl/SkMesaGLContext.h"
michael@0 12 #include "gl/GrGLDefines.h"
michael@0 13
michael@0 14 SkMesaGLContext::AutoContextRestore::AutoContextRestore() {
michael@0 15 fOldContext = (Context)OSMesaGetCurrentContext();
michael@0 16 if (NULL != (OSMesaContext)fOldContext) {
michael@0 17 OSMesaGetColorBuffer((OSMesaContext)fOldContext,
michael@0 18 &fOldWidth, &fOldHeight,
michael@0 19 &fOldFormat, &fOldImage);
michael@0 20 }
michael@0 21 }
michael@0 22
michael@0 23 SkMesaGLContext::AutoContextRestore::~AutoContextRestore() {
michael@0 24 if (NULL != (OSMesaContext)fOldContext) {
michael@0 25 OSMesaMakeCurrent((OSMesaContext)fOldContext, fOldImage,
michael@0 26 fOldFormat, fOldWidth, fOldHeight);
michael@0 27 }
michael@0 28 }
michael@0 29
michael@0 30 ///////////////////////////////////////////////////////////////////////////////
michael@0 31
michael@0 32 SkMesaGLContext::SkMesaGLContext()
michael@0 33 : fContext(static_cast<Context>(NULL))
michael@0 34 , fImage(NULL) {
michael@0 35 GR_STATIC_ASSERT(sizeof(Context) == sizeof(OSMesaContext));
michael@0 36 }
michael@0 37
michael@0 38 SkMesaGLContext::~SkMesaGLContext() {
michael@0 39 this->destroyGLContext();
michael@0 40 }
michael@0 41
michael@0 42 void SkMesaGLContext::destroyGLContext() {
michael@0 43 if (fImage) {
michael@0 44 sk_free(fImage);
michael@0 45 fImage = NULL;
michael@0 46 }
michael@0 47
michael@0 48 if (fContext) {
michael@0 49 OSMesaDestroyContext((OSMesaContext)fContext);
michael@0 50 fContext = static_cast<Context>(NULL);
michael@0 51 }
michael@0 52 }
michael@0 53
michael@0 54 static const GrGLint gBOGUS_SIZE = 16;
michael@0 55
michael@0 56 const GrGLInterface* SkMesaGLContext::createGLContext() {
michael@0 57 /* Create an RGBA-mode context */
michael@0 58 #if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
michael@0 59 /* specify Z, stencil, accum sizes */
michael@0 60 fContext = (Context)OSMesaCreateContextExt(OSMESA_BGRA, 0, 0, 0, NULL);
michael@0 61 #else
michael@0 62 fContext = (Context)OSMesaCreateContext(OSMESA_BGRA, NULL);
michael@0 63 #endif
michael@0 64 if (!fContext) {
michael@0 65 SkDebugf("OSMesaCreateContext failed!\n");
michael@0 66 this->destroyGLContext();
michael@0 67 return NULL;
michael@0 68 }
michael@0 69 // Allocate the image buffer
michael@0 70 fImage = (GrGLubyte *) sk_malloc_throw(gBOGUS_SIZE * gBOGUS_SIZE *
michael@0 71 4 * sizeof(GrGLubyte));
michael@0 72 if (!fImage) {
michael@0 73 SkDebugf("Alloc image buffer failed!\n");
michael@0 74 this->destroyGLContext();
michael@0 75 return NULL;
michael@0 76 }
michael@0 77
michael@0 78 // Bind the buffer to the context and make it current
michael@0 79 if (!OSMesaMakeCurrent((OSMesaContext)fContext,
michael@0 80 fImage,
michael@0 81 GR_GL_UNSIGNED_BYTE,
michael@0 82 gBOGUS_SIZE,
michael@0 83 gBOGUS_SIZE)) {
michael@0 84 SkDebugf("OSMesaMakeCurrent failed!\n");
michael@0 85 this->destroyGLContext();
michael@0 86 return NULL;
michael@0 87 }
michael@0 88
michael@0 89 const GrGLInterface* interface = GrGLCreateMesaInterface();
michael@0 90 if (!interface) {
michael@0 91 SkDebugf("Could not create GL interface!\n");
michael@0 92 this->destroyGLContext();
michael@0 93 return NULL;
michael@0 94 }
michael@0 95 return interface;
michael@0 96
michael@0 97 }
michael@0 98
michael@0 99 void SkMesaGLContext::makeCurrent() const {
michael@0 100 if (fContext) {
michael@0 101 if (!OSMesaMakeCurrent((OSMesaContext)fContext, fImage,
michael@0 102 GR_GL_UNSIGNED_BYTE, gBOGUS_SIZE, gBOGUS_SIZE)) {
michael@0 103 SkDebugf("Could not make MESA context current.");
michael@0 104 }
michael@0 105 }
michael@0 106 }
michael@0 107
michael@0 108 void SkMesaGLContext::swapBuffers() const { }

mercurial