aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/host/libs/Translator/EGL/MacNative.m
diff options
context:
space:
mode:
authorJesse Hall <jessehall@google.com>2012-04-16 12:49:39 -0700
committerJesse Hall <jessehall@google.com>2012-04-16 15:54:18 -0700
commitce6c3389061fb9fcdefc94fab2044a8e11600b52 (patch)
treefedd1a11cbd21ec14bf00be83b8712054f8c5506 /emulator/opengl/host/libs/Translator/EGL/MacNative.m
parentad0111a77b0f0908cc945dc6e8e8949b75cb8886 (diff)
downloadsdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.zip
sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.tar.gz
sdk-ce6c3389061fb9fcdefc94fab2044a8e11600b52.tar.bz2
Move emulator GLES from development.git to sdk.git
The emulator GLES support has two interfaces: a host shared library interface used by QEMU, and a protocol between the platform and the host. The host library interface is not versioned; QEMU and the GLES renderer must match. The protocol on the other hand must be backwards compatible: a new GLES renderer must support an older platform image. Thus for branching purposes it makes more sense to put the GLES renderer in sdk.git, which is branched along with qemu.git for SDK releases. Platform images will be built against the protocol version in the platform branch of sdk.git. Change-Id: I2c3bce627ecfd0a4b3e688d1839fe10755a21e58
Diffstat (limited to 'emulator/opengl/host/libs/Translator/EGL/MacNative.m')
-rw-r--r--emulator/opengl/host/libs/Translator/EGL/MacNative.m179
1 files changed, 179 insertions, 0 deletions
diff --git a/emulator/opengl/host/libs/Translator/EGL/MacNative.m b/emulator/opengl/host/libs/Translator/EGL/MacNative.m
new file mode 100644
index 0000000..6828655
--- /dev/null
+++ b/emulator/opengl/host/libs/Translator/EGL/MacNative.m
@@ -0,0 +1,179 @@
+/*
+* Copyright (C) 2011 The Android Open Source Project
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+#include <stdio.h>
+#include <Cocoa/Cocoa.h>
+#include <OpenGL/OpenGL.h>
+#include "MacPixelFormatsAttribs.h"
+
+//
+// EmuGLContext inherit from NSOpenGLContext
+// and adds binding state for the context to know
+// if it was last bounded to a pbuffer or a window.
+// This is because after the context was bounded to
+// a Pbuffer, before we bind it to a window we must
+// release it form the pbuffer by calling the
+// clearDrawable method. We do not want to call clearDrawable
+// more than really needed since when it is called at a time
+// that a window is bounded to the context it will clear the
+// window content causing flickering effect.
+// Thererfore we call clearDrawable only when we bind the context
+// to a window and it was previously bound to a Pbuffer.
+//
+@interface EmuGLContext : NSOpenGLContext {
+ @private
+ int boundToPbuffer;
+ int boundToWin;
+}
+
+- (id) initWithFormat:(NSOpenGLPixelFormat *)pixelFormat shareContext:(NSOpenGLContext *)share;
+- (void) preBind:(int)forPbuffer;
+@end
+
+@implementation EmuGLContext
+- (id) initWithFormat:(NSOpenGLPixelFormat *)pixelFormat shareContext:(NSOpenGLContext *)share
+{
+ self = [super initWithFormat:pixelFormat shareContext:share];
+ if (self != nil) {
+ boundToPbuffer = 0;
+ boundToWin = 0;
+ }
+ return self;
+}
+
+- (void) preBind:(int)forPbuffer
+{
+ if ((!forPbuffer && boundToPbuffer)) {
+ [self clearDrawable];
+ }
+ boundToPbuffer = forPbuffer;
+ boundToWin = !boundToPbuffer;
+}
+@end
+
+int getNumPixelFormats(){
+ int size;
+ NSOpenGLPixelFormatAttribute** attrib_lists = getPixelFormatsAttributes(&size);
+ return size;
+}
+
+void* getPixelFormat(int i){
+ int size;
+ NSOpenGLPixelFormatAttribute** attrib_lists = getPixelFormatsAttributes(&size);
+ return [[NSOpenGLPixelFormat alloc] initWithAttributes:attrib_lists[i]];
+}
+
+void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val){
+ NSOpenGLPixelFormat *frmt = (NSOpenGLPixelFormat *)pixelFormat;
+ [frmt getValues:val forAttribute:attrib forVirtualScreen:0];
+}
+
+void* nsCreateContext(void* format,void* share){
+ NSOpenGLPixelFormat* frmt = (NSOpenGLPixelFormat*)format;
+ return [[EmuGLContext alloc] initWithFormat:frmt shareContext:share];
+}
+
+void nsPBufferMakeCurrent(void* context,void* nativePBuffer,int level){
+ EmuGLContext* ctx = (EmuGLContext *)context;
+ NSOpenGLPixelBuffer* pbuff = (NSOpenGLPixelBuffer *)nativePBuffer;
+ if(ctx == nil){
+ [NSOpenGLContext clearCurrentContext];
+ } else {
+ if(pbuff != nil){
+ [ctx preBind:1];
+ [ctx setPixelBuffer:pbuff cubeMapFace:0 mipMapLevel:level currentVirtualScreen:0];
+ [ctx makeCurrentContext];
+ }
+ }
+}
+
+void nsWindowMakeCurrent(void* context,void* nativeWin){
+ EmuGLContext* ctx = (EmuGLContext *)context;
+ NSView* win = (NSView *)nativeWin;
+ if(ctx == nil){
+ [NSOpenGLContext clearCurrentContext];
+ } else if (win != nil) {
+ [ctx preBind:0];
+ [ctx setView: win];
+ [ctx makeCurrentContext];
+ }
+}
+
+void nsSwapBuffers(){
+ NSOpenGLContext* ctx = [NSOpenGLContext currentContext];
+ if(ctx != nil){
+ [ctx flushBuffer];
+ }
+}
+
+void nsSwapInterval(int *interval){
+ NSOpenGLContext* ctx = [NSOpenGLContext currentContext];
+ if( ctx != nil){
+ [ctx setValues:interval forParameter:NSOpenGLCPSwapInterval];
+ }
+}
+
+
+void nsDestroyContext(void* context){
+ EmuGLContext *ctx = (EmuGLContext*)context;
+ if(ctx != nil){
+ [ctx release];
+ }
+}
+
+
+void* nsCreatePBuffer(GLenum target,GLenum format,int maxMip,int width,int height){
+ return [[NSOpenGLPixelBuffer alloc] initWithTextureTarget:target
+ textureInternalFormat:format
+ textureMaxMipMapLevel:maxMip
+ pixelsWide:width pixelsHigh:height];
+
+}
+
+void nsDestroyPBuffer(void* pbuffer){
+ NSOpenGLPixelBuffer *pbuf = (NSOpenGLPixelBuffer*)pbuffer;
+ if(pbuf != nil){
+ [pbuf release];
+ }
+}
+
+bool nsGetWinDims(void* win,unsigned int* width,unsigned int* height){
+ NSView* view = (NSView*)win;
+ if(view != nil){
+ NSRect rect = [view bounds];
+ *width = rect.size.width;
+ *height = rect.size.height;
+ return true;
+ }
+ return false;
+}
+
+bool nsCheckColor(void* win,int colorSize){
+ NSView* view = (NSView*)win;
+ if(view != nil){
+ NSWindow* wnd = [view window];
+ if(wnd != nil){
+ NSWindowDepth limit = [wnd depthLimit];
+ NSWindowDepth defaultLimit = [NSWindow defaultDepthLimit];
+
+ int depth = (limit != 0) ? NSBitsPerPixelFromDepth(limit):
+ NSBitsPerPixelFromDepth(defaultLimit);
+ return depth >= colorSize;
+
+ }
+ }
+ return false;
+
+}