bsalomon@google.com | 2b64f84 | 2012-10-02 15:25:12 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2012 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "gl/SkNativeGLContext.h" |
| 10 | #import <OpenGLES/EAGL.h> |
| 11 | |
| 12 | #define EAGLCTX ((EAGLContext*)(fEAGLContext)) |
| 13 | |
| 14 | SkNativeGLContext::AutoContextRestore::AutoContextRestore() { |
| 15 | fEAGLContext = [EAGLContext currentContext]; |
| 16 | if (EAGLCTX) { |
| 17 | [EAGLCTX retain]; |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { |
| 22 | if (EAGLCTX) { |
| 23 | [EAGLContext setCurrentContext:EAGLCTX]; |
| 24 | [EAGLCTX release]; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | |
| 30 | SkNativeGLContext::SkNativeGLContext() |
| 31 | : fEAGLContext(NULL) { |
| 32 | } |
| 33 | |
| 34 | SkNativeGLContext::~SkNativeGLContext() { |
| 35 | this->destroyGLContext(); |
| 36 | } |
| 37 | |
| 38 | void SkNativeGLContext::destroyGLContext() { |
| 39 | if ([EAGLContext currentContext] == EAGLCTX) { |
| 40 | [EAGLContext setCurrentContext:nil]; |
| 41 | } |
| 42 | [EAGLCTX release]; |
| 43 | } |
| 44 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 45 | const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) { |
| 46 | if (kGL_GrGLStandard == forcedGpuAPI) { |
| 47 | return NULL; |
| 48 | } |
| 49 | |
bsalomon@google.com | 2b64f84 | 2012-10-02 15:25:12 +0000 | [diff] [blame] | 50 | fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; |
| 51 | [EAGLContext setCurrentContext:EAGLCTX]; |
| 52 | |
| 53 | const GrGLInterface* interface = GrGLCreateNativeInterface(); |
| 54 | if (!interface) { |
| 55 | SkDebugf("Failed to create gl interface"); |
| 56 | this->destroyGLContext(); |
| 57 | return NULL; |
| 58 | } |
| 59 | return interface; |
| 60 | } |
| 61 | |
| 62 | void SkNativeGLContext::makeCurrent() const { |
| 63 | if (![EAGLContext setCurrentContext:EAGLCTX]) { |
| 64 | SkDebugf("Could not set the context.\n"); |
| 65 | } |
| 66 | } |
djsollen@google.com | c9542ca | 2013-10-09 18:25:38 +0000 | [diff] [blame] | 67 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 68 | void SkNativeGLContext::swapBuffers() const { } |