gfx/skia/trunk/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/gpu/gl/iOS/SkNativeGLContext_iOS.mm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2012 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +
    1.12 +#include "gl/SkNativeGLContext.h"
    1.13 +#import <OpenGLES/EAGL.h>
    1.14 +
    1.15 +#define EAGLCTX ((EAGLContext*)(fEAGLContext))
    1.16 +
    1.17 +SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
    1.18 +    fEAGLContext = [EAGLContext currentContext];
    1.19 +    if (EAGLCTX) {
    1.20 +        [EAGLCTX retain];
    1.21 +    }
    1.22 +}
    1.23 +
    1.24 +SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
    1.25 +    if (EAGLCTX) {
    1.26 +        [EAGLContext setCurrentContext:EAGLCTX];
    1.27 +        [EAGLCTX release];
    1.28 +    }
    1.29 +}
    1.30 +
    1.31 +///////////////////////////////////////////////////////////////////////////////
    1.32 +
    1.33 +SkNativeGLContext::SkNativeGLContext()
    1.34 +    : fEAGLContext(NULL) {
    1.35 +}
    1.36 +
    1.37 +SkNativeGLContext::~SkNativeGLContext() {
    1.38 +    this->destroyGLContext();
    1.39 +}
    1.40 +
    1.41 +void SkNativeGLContext::destroyGLContext() {
    1.42 +    if ([EAGLContext currentContext] == EAGLCTX) {
    1.43 +        [EAGLContext setCurrentContext:nil];
    1.44 +    }
    1.45 +    [EAGLCTX release];
    1.46 +}
    1.47 +
    1.48 +const GrGLInterface* SkNativeGLContext::createGLContext() {
    1.49 +    fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
    1.50 +    [EAGLContext setCurrentContext:EAGLCTX];
    1.51 +    
    1.52 +    const GrGLInterface* interface = GrGLCreateNativeInterface();
    1.53 +    if (!interface) {
    1.54 +        SkDebugf("Failed to create gl interface");
    1.55 +        this->destroyGLContext();
    1.56 +        return NULL;
    1.57 +    }
    1.58 +    return interface;
    1.59 +}
    1.60 +
    1.61 +void SkNativeGLContext::makeCurrent() const {
    1.62 +    if (![EAGLContext setCurrentContext:EAGLCTX]) {
    1.63 +        SkDebugf("Could not set the context.\n");
    1.64 +    }
    1.65 +}
    1.66 +
    1.67 +void SkNativeGLContext::swapBuffers() const { }
    1.68 \ No newline at end of file

mercurial