Add SkNativeGLContext implementation for iOS.
R=caryclark@google.com Review URL: https://codereview.appspot.com/6589055 git-svn-id: http://skia.googlecode.com/svn/trunk@5767 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
4e3875348b
commit
2b64f84b4b
@ -6,7 +6,7 @@
|
||||
],
|
||||
}],
|
||||
['skia_os != "mac"', {
|
||||
'sources/': [ ['exclude', '_mac.(h|cpp)$'],
|
||||
'sources/': [ ['exclude', '_mac.(h|cpp|m|mm)$'],
|
||||
],
|
||||
}],
|
||||
['skia_os != "linux"', {
|
||||
@ -14,7 +14,7 @@
|
||||
],
|
||||
}],
|
||||
['skia_os != "ios"', {
|
||||
'sources/': [ ['exclude', '_iOS.(h|cpp)$'],
|
||||
'sources/': [ ['exclude', '_iOS.(h|cpp|m|mm)$'],
|
||||
],
|
||||
}],
|
||||
['skia_os != "android"', {
|
||||
|
@ -237,6 +237,7 @@
|
||||
'<(skia_src_path)/gpu/gl/win/SkNativeGLContext_win.cpp',
|
||||
'<(skia_src_path)/gpu/gl/unix/SkNativeGLContext_unix.cpp',
|
||||
'<(skia_src_path)/gpu/gl/android/SkNativeGLContext_android.cpp',
|
||||
'<(skia_src_path)/gpu/gl/iOS/SkNativeGLContext_iOS.mm',
|
||||
],
|
||||
'skgr_angle_gl_sources': [
|
||||
'<(skia_include_path)/gpu/gl/SkANGLEGLContext.h',
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#if defined(SK_BUILD_FOR_MAC)
|
||||
#include <AGL/agl.h>
|
||||
|
||||
#elif defined(SK_BUILD_FOR_ANDROID)
|
||||
#include <GLES2/gl2.h>
|
||||
#include <EGL/egl.h>
|
||||
@ -51,6 +50,8 @@ public:
|
||||
EGLContext fOldEGLContext;
|
||||
EGLDisplay fOldDisplay;
|
||||
EGLSurface fOldSurface;
|
||||
#elif defined(SK_BUILD_FOR_IOS)
|
||||
void* fEAGLContext;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -75,6 +76,8 @@ private:
|
||||
EGLContext fContext;
|
||||
EGLDisplay fDisplay;
|
||||
EGLSurface fSurface;
|
||||
#elif defined(SK_BUILD_FOR_IOS)
|
||||
void* fEAGLContext;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
62
src/gpu/gl/iOS/SkNativeGLContext_iOS.mm
Normal file
62
src/gpu/gl/iOS/SkNativeGLContext_iOS.mm
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
/*
|
||||
* 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 <OpenGLES/EAGL.h>
|
||||
|
||||
#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");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user