diff -r 000000000000 -r 6474c204b198 gfx/skia/trunk/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gfx/skia/trunk/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,64 @@ + +/* + * Copyright 2012 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gl/SkNativeGLContext.h" +#import + +#define EAGLCTX ((EAGLContext*)(fEAGLContext)) + +SkNativeGLContext::AutoContextRestore::AutoContextRestore() { + fEAGLContext = [EAGLContext currentContext]; + if (EAGLCTX) { + [EAGLCTX retain]; + } +} + +SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { + if (EAGLCTX) { + [EAGLContext setCurrentContext:EAGLCTX]; + [EAGLCTX release]; + } +} + +/////////////////////////////////////////////////////////////////////////////// + +SkNativeGLContext::SkNativeGLContext() + : fEAGLContext(NULL) { +} + +SkNativeGLContext::~SkNativeGLContext() { + this->destroyGLContext(); +} + +void SkNativeGLContext::destroyGLContext() { + if ([EAGLContext currentContext] == EAGLCTX) { + [EAGLContext setCurrentContext:nil]; + } + [EAGLCTX release]; +} + +const GrGLInterface* SkNativeGLContext::createGLContext() { + fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + [EAGLContext setCurrentContext:EAGLCTX]; + + const GrGLInterface* interface = GrGLCreateNativeInterface(); + if (!interface) { + SkDebugf("Failed to create gl interface"); + this->destroyGLContext(); + return NULL; + } + return interface; +} + +void SkNativeGLContext::makeCurrent() const { + if (![EAGLContext setCurrentContext:EAGLCTX]) { + SkDebugf("Could not set the context.\n"); + } +} + +void SkNativeGLContext::swapBuffers() const { } \ No newline at end of file