3 * Copyright 2012 Google Inc.
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
9 #include "gl/SkNativeGLContext.h"
10 #import <OpenGLES/EAGL.h>
12 #define EAGLCTX ((EAGLContext*)(fEAGLContext))
14 SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
15 fEAGLContext = [EAGLContext currentContext];
21 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
23 [EAGLContext setCurrentContext:EAGLCTX];
28 ///////////////////////////////////////////////////////////////////////////////
30 SkNativeGLContext::SkNativeGLContext()
31 : fEAGLContext(NULL) {
34 SkNativeGLContext::~SkNativeGLContext() {
35 this->destroyGLContext();
38 void SkNativeGLContext::destroyGLContext() {
39 if ([EAGLContext currentContext] == EAGLCTX) {
40 [EAGLContext setCurrentContext:nil];
45 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
46 if (kGL_GrGLStandard == forcedGpuAPI) {
50 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
51 [EAGLContext setCurrentContext:EAGLCTX];
53 const GrGLInterface* interface = GrGLCreateNativeInterface();
55 SkDebugf("Failed to create gl interface");
56 this->destroyGLContext();
62 void SkNativeGLContext::makeCurrent() const {
63 if (![EAGLContext setCurrentContext:EAGLCTX]) {
64 SkDebugf("Could not set the context.\n");
68 void SkNativeGLContext::swapBuffers() const { }