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/SkGLContext.h"
10 #import <OpenGLES/EAGL.h>
12 #define EAGLCTX ((EAGLContext*)(fEAGLContext))
16 class IOSGLContext : public SkGLContext {
19 ~IOSGLContext() SK_OVERRIDE;
20 void makeCurrent() const SK_OVERRIDE;
21 void swapBuffers() const SK_OVERRIDE;
24 void destroyGLContext();
29 IOSGLContext::IOSGLContext()
30 : fEAGLContext(NULL) {
32 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
33 [EAGLContext setCurrentContext:EAGLCTX];
35 fGL.reset(GrGLCreateNativeInterface());
36 if (NULL == fGL.get()) {
37 SkDebugf("Failed to create gl interface");
38 this->destroyGLContext();
41 if (!fGL->validate()) {
42 SkDebugf("Failed to validate gl interface");
43 this->destroyGLContext();
48 IOSGLContext::~IOSGLContext() {
49 this->destroyGLContext();
52 void IOSGLContext::destroyGLContext() {
55 if ([EAGLContext currentContext] == EAGLCTX) {
56 [EAGLContext setCurrentContext:nil];
64 void IOSGLContext::makeCurrent() const {
65 if (![EAGLContext setCurrentContext:EAGLCTX]) {
66 SkDebugf("Could not set the context.\n");
70 void IOSGLContext::swapBuffers() const { }
72 } // anonymous namespace
74 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) {
75 if (kGL_GrGLStandard == forcedGpuAPI) {
78 IOSGLContext* ctx = SkNEW(IOSGLContext);
79 if (!ctx->isValid()) {