michael@0: michael@0: /* michael@0: * Copyright 2012 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #include "gl/SkNativeGLContext.h" michael@0: #import michael@0: michael@0: #define EAGLCTX ((EAGLContext*)(fEAGLContext)) michael@0: michael@0: SkNativeGLContext::AutoContextRestore::AutoContextRestore() { michael@0: fEAGLContext = [EAGLContext currentContext]; michael@0: if (EAGLCTX) { michael@0: [EAGLCTX retain]; michael@0: } michael@0: } michael@0: michael@0: SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { michael@0: if (EAGLCTX) { michael@0: [EAGLContext setCurrentContext:EAGLCTX]; michael@0: [EAGLCTX release]; michael@0: } michael@0: } michael@0: michael@0: /////////////////////////////////////////////////////////////////////////////// michael@0: michael@0: SkNativeGLContext::SkNativeGLContext() michael@0: : fEAGLContext(NULL) { michael@0: } michael@0: michael@0: SkNativeGLContext::~SkNativeGLContext() { michael@0: this->destroyGLContext(); michael@0: } michael@0: michael@0: void SkNativeGLContext::destroyGLContext() { michael@0: if ([EAGLContext currentContext] == EAGLCTX) { michael@0: [EAGLContext setCurrentContext:nil]; michael@0: } michael@0: [EAGLCTX release]; michael@0: } michael@0: michael@0: const GrGLInterface* SkNativeGLContext::createGLContext() { michael@0: fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; michael@0: [EAGLContext setCurrentContext:EAGLCTX]; michael@0: michael@0: const GrGLInterface* interface = GrGLCreateNativeInterface(); michael@0: if (!interface) { michael@0: SkDebugf("Failed to create gl interface"); michael@0: this->destroyGLContext(); michael@0: return NULL; michael@0: } michael@0: return interface; michael@0: } michael@0: michael@0: void SkNativeGLContext::makeCurrent() const { michael@0: if (![EAGLContext setCurrentContext:EAGLCTX]) { michael@0: SkDebugf("Could not set the context.\n"); michael@0: } michael@0: } michael@0: michael@0: void SkNativeGLContext::swapBuffers() const { }