implementing mac OS support for translator's libs
Change-Id: Ifa12cf1177db49197ad8496f4e0ef8098d43aa8d
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/Android.mk b/tools/emulator/opengl/host/libs/Translator/EGL/Android.mk
index 4e97836..5c078e9 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/Android.mk
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/Android.mk
@@ -14,7 +14,11 @@
endif
ifeq ($(HOST_OS),darwin)
- OS_SRCS = EglMacApi.cpp
+ OS_SRCS = EglMacApi.cpp \
+ MacNative.m \
+ MacPixelFormatsAttribs.m
+
+ LOCAL_LDLIBS := -Wl,-framework,AppKit
endif
ifeq ($(HOST_OS),windows)
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
index 8f3bc66..1e47f0f 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp
@@ -164,9 +164,9 @@
#elif __linux__
#define LIB_GLES_CM_NAME "libGLES_CM_translator.so"
#define LIB_GLES_V2_NAME "libGLES_V2_translator.so"
-#else
-#define LIB_GLES_CM_NAME "libGLES_CM_translator"
-#define LIB_GLES_V2_NAME "libGLES_V2_translator"
+#elif __APPLE__
+#define LIB_GLES_CM_NAME "libGLES_CM_translator.dylib"
+#define LIB_GLES_V2_NAME "libGLES_V2_translator.dylib"
#endif
EGLAPI EGLBoolean EGLAPIENTRY eglInitialize(EGLDisplay display, EGLint *major, EGLint *minor) {
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
index d658e12..8ff8fae 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglMacApi.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright (C) 2011 The Android Open Source Project
*
@@ -15,69 +14,177 @@
* limitations under the License.
*/
#include "EglOsApi.h"
+#include "MacNative.h"
+#define MAX_PBUFFER_MIPMAP_LEVEL 1
-
-//TODO: implementation for mac for all funcs
namespace EglOS {
-EGLNativeDisplayType getDefaultDisplay() {return NULL;}
+static std::list<EGLNativePixelFormatType> s_nativeConfigs;
+
+EGLNativeDisplayType getDefaultDisplay() {return 0;}
bool releaseDisplay(EGLNativeDisplayType dpy) {
- return false;
+ return true;
}
-EglConfig* pixelFormatToConfig(EGLNativeDisplayType dpy,int renderableType,EGLNativePixelFormatType* frmt){
- return NULL;
+static EglConfig* pixelFormatToConfig(int index,int renderableType,EGLNativePixelFormatType* frmt){
+ if(!frmt) return NULL;
+
+ EGLint red,green,blue,alpha,depth,stencil;
+ EGLint supportedSurfaces,visualType,visualId;
+ EGLint transparentType,samples;
+ EGLint tRed,tGreen,tBlue;
+ EGLint pMaxWidth,pMaxHeight,pMaxPixels;
+ EGLint configId,level;
+ EGLint window,pbuffer;
+ EGLint doubleBuffer,colorSize;
+
+ getPixelFormatAttrib(*frmt,MAC_HAS_DOUBLE_BUFFER,&doubleBuffer);
+ if(!doubleBuffer) return NULL; //pixel double buffer
+
+ supportedSurfaces = 0;
+
+ getPixelFormatAttrib(*frmt,MAC_DRAW_TO_WINDOW,&window);
+ getPixelFormatAttrib(*frmt,MAC_DRAW_TO_PBUFFER,&pbuffer);
+
+ if(window) supportedSurfaces |= EGL_WINDOW_BIT;
+ if(pbuffer) supportedSurfaces |= EGL_PBUFFER_BIT;
+
+ if(!supportedSurfaces) return NULL;
+
+ //default values
+ visualId = 0;
+ visualType = EGL_NONE;
+ EGLenum caveat = EGL_NONE;
+ EGLBoolean renderable = EGL_FALSE;
+ pMaxWidth = PBUFFER_MAX_WIDTH;
+ pMaxHeight = PBUFFER_MAX_HEIGHT;
+ pMaxPixels = PBUFFER_MAX_PIXELS;
+ samples = 0;
+ level = 0;
+ tRed = tGreen = tBlue = 0;
+
+ transparentType = EGL_NONE;
+
+ getPixelFormatAttrib(*frmt,MAC_SAMPLES_PER_PIXEL,&samples);
+ getPixelFormatAttrib(*frmt,MAC_COLOR_SIZE,&colorSize);
+ getPixelFormatAttrib(*frmt,MAC_ALPHA_SIZE,&alpha);
+ getPixelFormatAttrib(*frmt,MAC_DEPTH_SIZE,&depth);
+ getPixelFormatAttrib(*frmt,MAC_STENCIL_SIZE,&stencil);
+
+ red = green = blue = (colorSize / 4); //TODO: ask guy if it is OK
+
+ return new EglConfig(red,green,blue,alpha,caveat,(EGLint)index,depth,level,pMaxWidth,pMaxHeight,pMaxPixels,renderable,renderableType,
+ visualId,visualType,samples,stencil,supportedSurfaces,transparentType,tRed,tGreen,tBlue,*frmt);
+}
+
+
+static void initNativeConfigs(){
+ int nConfigs = getNumPixelFormats();
+ if(s_nativeConfigs.empty()){
+ for(int i=0; i < nConfigs ;i++){
+ EGLNativePixelFormatType frmt = getPixelFormat(i);
+ if(frmt){
+ s_nativeConfigs.push_back(frmt);
+ }
+ }
+ }
}
void queryConfigs(EGLNativeDisplayType dpy,int renderableType,ConfigsList& listOut) {
+ int i = 0 ;
+ initNativeConfigs();
+ for(std::list<EGLNativePixelFormatType>::iterator it = s_nativeConfigs.begin(); it != s_nativeConfigs.end();it++){
+ EGLNativePixelFormatType frmt = *it;
+ EglConfig* conf = pixelFormatToConfig(i++,renderableType,&frmt);
+ if(conf){
+ listOut.push_front(conf);
+ };
+ }
}
bool validNativeWin(EGLNativeDisplayType dpy, EGLNativeWindowType win) {
- return true;
+ unsigned int width,height;
+ return nsGetWinDims(win,&width,&height);
}
+//no support for pixmap in mac
bool validNativePixmap(EGLNativeDisplayType dpy, EGLNativePixmapType pix) {
+
return true;
}
bool checkWindowPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativeWindowType win,EglConfig* cfg,unsigned int* width,unsigned int* height) {
- return false;
+ int r,g,b;
+ bool ret = nsGetWinDims(win,width,height);
+
+ cfg->getConfAttrib(EGL_RED_SIZE,&r);
+ cfg->getConfAttrib(EGL_GREEN_SIZE,&g);
+ cfg->getConfAttrib(EGL_BLUE_SIZE,&b);
+ bool match = nsCheckColor(win,r + g + b);
+
+ return ret && match;
}
+//no support for pixmap in mac
bool checkPixmapPixelFormatMatch(EGLNativeDisplayType dpy,EGLNativePixmapType pix,EglConfig* cfg,unsigned int* width,unsigned int* height) {
return false;
}
EGLNativePbufferType createPbuffer(EGLNativeDisplayType dpy,EglConfig* cfg,EglPbufferSurface* srfc){
- return NULL;
+ EGLint width,height,hasMipmap,tmp;
+ EGLint target,format;
+ srfc->getDim(&width,&height,&tmp);
+ srfc->getTexInfo(&format,&target);
+ srfc->getAttrib(EGL_MIPMAP_TEXTURE,&hasMipmap);
+ EGLint maxMipmap = hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL:0;
+ return nsCreatePBuffer(target,format,maxMipmap,width,height);
}
bool releasePbuffer(EGLNativeDisplayType dis,EGLNativePbufferType pb) {
+ nsDestroyPBuffer(pb);
return true;
}
EGLNativeContextType createContext(EGLNativeDisplayType dpy,EglConfig* cfg,EGLNativeContextType sharedContext) {
- return NULL;
+ return nsCreateContext(cfg->nativeConfig(),sharedContext);
}
bool destroyContext(EGLNativeDisplayType dpy,EGLNativeContextType ctx) {
- return false;
+ nsDestroyContext(ctx);
+ return true;
}
-
-
bool makeCurrent(EGLNativeDisplayType dpy,EglSurface* read,EglSurface* draw,EGLNativeContextType ctx){
- return false;
+ //dont supporting diffrent read & draw surfaces on Mac
+ if(read->native() != draw->native()) return false;
+ switch(draw->type()){
+ case EglSurface::WINDOW:
+ nsWindowMakeCurrent(ctx,draw->native());
+ break;
+ case EglSurface::PBUFFER:
+ {
+ EGLint hasMipmap;
+ draw->getAttrib(EGL_MIPMAP_TEXTURE,&hasMipmap);
+ int mipmapLevel = hasMipmap ? MAX_PBUFFER_MIPMAP_LEVEL:0;
+ nsPBufferMakeCurrent(ctx,draw->native(),mipmapLevel);
+ break;
+ }
+ case EglSurface::PIXMAP: // not supported on Mac
+ default:
+ return false;
+ }
+ return true;
}
void swapBuffers(EGLNativeDisplayType dpy,EGLNativeWindowType win) {
+ nsSwapBuffers();
}
-void waitNative() {
-}
+void waitNative(){}
void swapInterval(EGLNativeDisplayType dpy,EGLNativeWindowType win,int interval){
+ nsSwapInterval(&interval);
}
};
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h b/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h
index 204bbc6..29a8843 100644
--- a/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglSurface.h
@@ -42,6 +42,7 @@
bool destroy(){return m_destroy;};
EglConfig* getConfig(){return m_config;};
unsigned int getHndl(){return m_hndl;};
+ virtual ~EglSurface(){};
private:
static unsigned int s_nextSurfaceHndl;
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/MacNative.h b/tools/emulator/opengl/host/libs/Translator/EGL/MacNative.h
new file mode 100644
index 0000000..63145ec
--- /dev/null
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/MacNative.h
@@ -0,0 +1,50 @@
+#ifndef MAC_NATIVE_H
+#define MAC_NATIVE_H
+
+/*
+* 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.
+*/
+
+typedef enum { // Mac equivalence
+ MAC_HAS_DOUBLE_BUFFER = 5, // NSOpenGLPFADoubleBuffer
+ MAC_DRAW_TO_WINDOW = 80, // NSOpenGLPFAWindow
+ MAC_DRAW_TO_PBUFFER = 90, // NSOpenGLPFAPixelBuffer
+ MAC_SAMPLES_PER_PIXEL = 56, // NSOpenGLPFASamples
+ MAC_COLOR_SIZE = 8, // NSOpenGLPFAColorSize
+ MAC_ALPHA_SIZE = 11, // NSOpenGLPFAAlphaSize
+ MAC_DEPTH_SIZE = 12, // NSOpenGLPFADepthSize
+ MAC_STENCIL_SIZE = 13 // NSOpenGLPFAStencilSize
+ } MacPixelFormatAttribs;
+
+
+extern "C"{
+
+int getNumPixelFormats();
+void* getPixelFormat(int i);
+void getPixelFormatAttrib(void* pixelFormat,int attrib,int* val);
+void* nsCreateContext(void* format,void* share);
+void nsWindowMakeCurrent(void* context,void* nativeWin);
+void nsPBufferMakeCurrent(void* context,void* nativePBuffer,int level);
+void nsSwapBuffers();
+void nsSwapInterval(int *interval);
+void nsDestroyContext(void* context);
+void* nsCreatePBuffer(GLenum target,GLenum format,int maxMip,int width,int height);
+void nsDestroyPBuffer(void* pbuffer);
+bool nsGetWinDims(void* win,unsigned int* width,unsigned int* height);
+bool nsCheckColor(void* win,int colorSize);
+
+}
+
+#endif
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/MacNative.m b/tools/emulator/opengl/host/libs/Translator/EGL/MacNative.m
new file mode 100644
index 0000000..e240bc1
--- /dev/null
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/MacNative.m
@@ -0,0 +1,137 @@
+/*
+* 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"
+
+
+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 [[NSOpenGLContext alloc] initWithFormat:frmt shareContext:share];
+}
+
+void nsPBufferMakeCurrent(void* context,void* nativePBuffer,int level){
+ NSOpenGLContext* ctx = (NSOpenGLContext *)context;
+ NSOpenGLPixelBuffer* pbuff = (NSOpenGLPixelBuffer *)nativePBuffer;
+ if(ctx == nil){
+ [NSOpenGLContext clearCurrentContext];
+ } else {
+ if(pbuff != nil){
+ [ctx clearDrawable];
+ [ctx setPixelBuffer:pbuff cubeMapFace:0 mipMapLevel:level currentVirtualScreen:0];
+ [ctx makeCurrentContext];
+ }
+ }
+}
+
+void nsWindowMakeCurrent(void* context,void* nativeWin){
+ NSOpenGLContext* ctx = (NSOpenGLContext *)context;
+ NSView* win = (NSView *)nativeWin;
+ if(ctx == nil){
+ [NSOpenGLContext clearCurrentContext];
+ } else {
+ if(win != nil){
+ [ctx clearDrawable];
+ [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){
+ NSOpenGLContext *ctx = (NSOpenGLContext*)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;
+
+}
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.h b/tools/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.h
new file mode 100644
index 0000000..112aeec
--- /dev/null
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.h
@@ -0,0 +1,23 @@
+#ifndef MAC_PIXELS_FORMATS_ATTRIBS_H
+#define MAC_PIXELS_FORMATS_ATTRIBS_H
+
+/*
+* 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 <Cocoa/Cocoa.h>
+NSOpenGLPixelFormatAttribute** getPixelFormatsAttributes(int* size);
+
+#endif
diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.m b/tools/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.m
new file mode 100644
index 0000000..abbaf08
--- /dev/null
+++ b/tools/emulator/opengl/host/libs/Translator/EGL/MacPixelFormatsAttribs.m
@@ -0,0 +1,214 @@
+#include "MacPixelFormatsAttribs.h"
+
+/*
+* 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.
+*/
+
+static NSOpenGLPixelFormatAttribute attrs32_1[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,32,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFAStencilSize ,8,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs32_2[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,32,
+ NSOpenGLPFAAlphaSize ,8,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFAStencilSize ,8,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs32_3[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,32,
+ NSOpenGLPFAAlphaSize ,8,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs32_4[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,32,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs32_5[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,32,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFASamples ,2,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs32_6[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,32,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFASamples ,4,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs32_7[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,32,
+ NSOpenGLPFAAlphaSize ,8,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFAStencilSize ,8,
+ NSOpenGLPFASamples ,4,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs16_1[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,16,
+ NSOpenGLPFADepthSize ,24,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs16_2[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,16,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFAStencilSize ,8,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs64_1[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,64,
+ NSOpenGLPFAAlphaSize ,16,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs64_2[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,64,
+ NSOpenGLPFAAlphaSize ,16,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFAStencilSize ,8,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs64_3[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,64,
+ NSOpenGLPFAAlphaSize ,16,
+ NSOpenGLPFADepthSize ,24,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs64_4[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,64,
+ NSOpenGLPFADepthSize ,24,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs64_5[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,64,
+ NSOpenGLPFADepthSize ,24,
+ NSOpenGLPFAStencilSize ,8,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs128_1[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,128,
+ NSOpenGLPFAAlphaSize ,32,
+ 0
+};
+
+static NSOpenGLPixelFormatAttribute attrs128_2[] =
+{
+ NSOpenGLPFADoubleBuffer,
+ NSOpenGLPFAWindow,
+ NSOpenGLPFAPixelBuffer,
+ NSOpenGLPFAColorSize ,128,
+ NSOpenGLPFAAlphaSize ,32,
+ NSOpenGLPFADepthSize ,24,
+ 0
+};
+
+NSOpenGLPixelFormatAttribute** getPixelFormatsAttributes(int* size){
+static NSOpenGLPixelFormatAttribute* arr[] =
+{
+ attrs16_1,
+ attrs16_2,
+ attrs32_1,
+ attrs32_2,
+ attrs32_3,
+ attrs32_4,
+ attrs32_5,
+ attrs32_6,
+ attrs32_7,
+ attrs64_1,
+ attrs64_2,
+ attrs64_3,
+ attrs64_4,
+ attrs64_5,
+ attrs128_1,
+ attrs128_2
+};
+ *size = sizeof(arr)/sizeof(arr[0]);
+ return arr;
+}
diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk b/tools/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk
index 59052b2..36fbc0d 100644
--- a/tools/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk
+++ b/tools/emulator/opengl/host/libs/Translator/GLES_CM/Android.mk
@@ -4,8 +4,6 @@
include $(CLEAR_VARS)
translator_path := $(LOCAL_PATH)/..
-#exclude darwin builds
-ifeq (, $(findstring $(HOST_OS), darwin))
LOCAL_SRC_FILES := \
GLEScmImp.cpp \
@@ -40,4 +38,3 @@
include $(BUILD_HOST_SHARED_LIBRARY)
-endif
diff --git a/tools/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk b/tools/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk
index 74c8f6f..40990d9 100644
--- a/tools/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk
+++ b/tools/emulator/opengl/host/libs/Translator/GLES_V2/Android.mk
@@ -4,8 +4,6 @@
include $(CLEAR_VARS)
translator_path := $(LOCAL_PATH)/..
-#exclude darwin builds
-ifeq (, $(findstring $(HOST_OS), darwin))
LOCAL_SRC_FILES := \
GLESv2Imp.cpp \
@@ -27,4 +25,3 @@
include $(BUILD_HOST_SHARED_LIBRARY)
-endif
diff --git a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp
index 8ed30f1..c7f17b3 100644
--- a/tools/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp
+++ b/tools/emulator/opengl/host/libs/Translator/GLcommon/GLDispatch.cpp
@@ -29,15 +29,14 @@
static GL_FUNC_PTR getGLFuncAddress(const char *funcName) {
GL_FUNC_PTR ret = NULL;
#ifdef __linux__
- static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("GL");
+ static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("libGL.so");
ret = (GL_FUNC_PTR)glXGetProcAddress((const GLubyte*)funcName);
#elif defined(WIN32)
static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("opengl32");
ret = (GL_FUNC_PTR)wglGetProcAddress(funcName);
-#else //mac
- static osUtils::dynLibrary* libGL = NULL;
+#elif defined(__APPLE__)
+ static osUtils::dynLibrary* libGL = osUtils::dynLibrary::open("libGL.dylib");
#endif
-
if(!ret && libGL){
ret = libGL->findSymbol(funcName);
}
diff --git a/tools/emulator/opengl/host/libs/Translator/include/EGL/eglplatform.h b/tools/emulator/opengl/host/libs/Translator/include/EGL/eglplatform.h
index f5ce901..a85eea7 100644
--- a/tools/emulator/opengl/host/libs/Translator/include/EGL/eglplatform.h
+++ b/tools/emulator/opengl/host/libs/Translator/include/EGL/eglplatform.h
@@ -83,14 +83,14 @@
#elif defined(__APPLE__)
-typedef int EGLNativePixelFormatType;
-#define PIXEL_FORMAT_INITIALIZER 0
+typedef void* EGLNativePixelFormatType;
+#define PIXEL_FORMAT_INITIALIZER NULL
+typedef void* EGLNativeContextType;
+typedef void* EGLNativePbufferType;
+typedef unsigned int EGLNativeDisplayType;
+typedef void* EGLNativePixmapType;
+typedef void* EGLNativeWindowType;
-typedef struct _EGLNativeContextType* EGLNativeContextType;
-typedef struct _EGLNativePbufferType* EGLNativePbufferType;
-typedef struct _EGLNativeDisplayType* EGLNativeDisplayType;
-typedef int EGLNativePixmapType;
-typedef int EGLNativeWindowType;
#elif defined(__unix__)
diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk b/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk
index a67ebfa..573c5b4 100644
--- a/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk
+++ b/tools/emulator/opengl/tests/translator_tests/GLES_CM/Android.mk
@@ -1,11 +1,8 @@
-ifneq ($(HOST_OS),darwin)
LOCAL_PATH:= $(call my-dir)
-
include $(CLEAR_VARS)
-#
-# This is built on linux host only !!!
-#
+translator_path := $(LOCAL_PATH)/../../../host/libs/Translator
+
PREBUILT := $(HOST_PREBUILT_TAG)
SDL_CONFIG ?= prebuilt/$(PREBUILT)/sdl/bin/sdl-config
SDL_CFLAGS := $(shell $(SDL_CONFIG) --cflags)
@@ -14,18 +11,28 @@
LOCAL_SRC_FILES:= \
triangleCM.cpp
+
LOCAL_SHARED_LIBRARIES := \
libGLcommon \
libEGL_translator \
- libGLES_CM_translator \
- libGLcommon
+ libGLES_CM_translator
LOCAL_CFLAGS += $(SDL_CFLAGS) -g -O0
LOCAL_LDLIBS += $(SDL_LDLIBS)
+
LOCAL_MODULE:= triangleCM
LOCAL_MODULE_TAGS := debug
-LOCAL_STATIC_LIBRARIES += libSDL libSDLmain
+LOCAL_STATIC_LIBRARIES += libSDL libSDLmain
+
+ifeq ($(HOST_OS),darwin)
+
+LOCAL_LDLIBS += -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit
+LOCAL_STATIC_LIBRARIES += libMac_view
+LOCAL_C_INCLUDES += \
+ $(LOCAL_PATH)/../MacCommon \
+ $(translator_path)/include
+endif
include $(BUILD_HOST_EXECUTABLE)
-endif
+
diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp b/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp
index af8cc95..56922c8 100644
--- a/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp
+++ b/tools/emulator/opengl/tests/translator_tests/GLES_CM/triangleCM.cpp
@@ -10,6 +10,10 @@
#include <EGL/egl.h>
#include <GLES/gl.h>
+#ifdef __APPLE__
+extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height);
+#endif
+
#undef HAVE_MALLOC_H
#include <SDL.h>
#include <SDL_syswm.h>
@@ -120,8 +124,10 @@
#ifdef _WIN32
HWND windowId = NULL;
- #else
+ #elif __linux__
Window windowId = NULL;
+ #elif __APPLE__
+ void* windowId = NULL;
#endif
// // Inialize SDL window
@@ -142,8 +148,11 @@
SDL_GetWMInfo(&wminfo);
#ifdef _WIN32
windowId = wminfo.window;
- #else
+ #elif __linux__
windowId = wminfo.info.x11.window;
+ #elif __APPLE__
+ windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
+
#endif
int major,minor,num_config;
@@ -156,6 +165,7 @@
eglChooseConfig(d, attribute_list, configs, 150, &num_config);
printf("config returned %d\n",num_config);
egl_surface = eglCreateWindowSurface(d,configs[0],windowId,NULL);
+ printf("before creating context..\n");
ctx = eglCreateContext(d,configs[0],EGL_NO_CONTEXT,NULL);
printf("SURFACE == %p CONTEXT == %p\n",egl_surface,ctx);
if(eglMakeCurrent(d,egl_surface,egl_surface,ctx)!= EGL_TRUE){
diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk b/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk
index 63b9548..b57ed57 100644
--- a/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk
+++ b/tools/emulator/opengl/tests/translator_tests/GLES_V2/Android.mk
@@ -1,10 +1,8 @@
-ifneq ($(HOST_OS),darwin)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-#
-# This is built on linux host only !!!
-#
+translator_path := $(LOCAL_PATH)/../../../host/libs/Translator
+
PREBUILT := $(HOST_PREBUILT_TAG)
SDL_CONFIG ?= prebuilt/$(PREBUILT)/sdl/bin/sdl-config
SDL_CFLAGS := $(shell $(SDL_CONFIG) --cflags)
@@ -13,18 +11,29 @@
LOCAL_SRC_FILES:= \
triangleV2.cpp
+
LOCAL_SHARED_LIBRARIES := \
libGLcommon \
libEGL_translator \
- libGLES_V2_translator \
- libGLcommon
+ libGLES_V2_translator
LOCAL_CFLAGS += $(SDL_CFLAGS) -g -O0
LOCAL_LDLIBS += $(SDL_LDLIBS)
+
LOCAL_MODULE:= triangleV2
LOCAL_MODULE_TAGS := debug
LOCAL_STATIC_LIBRARIES += libSDL libSDLmain
-include $(BUILD_HOST_EXECUTABLE)
+ifeq ($(HOST_OS),darwin)
+
+LOCAL_LDLIBS += -Wl,-framework,AudioToolbox -Wl,-framework,AudioUnit
+LOCAL_C_INCLUDES += \
+ $(translator_path)/include \
+ $(LOCAL_PATH)/../MacCommon
+LOCAL_STATIC_LIBRARIES += libMac_view
+
endif
+
+include $(BUILD_HOST_EXECUTABLE)
+
diff --git a/tools/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp b/tools/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp
index f5cace2..0321b7d 100644
--- a/tools/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp
+++ b/tools/emulator/opengl/tests/translator_tests/GLES_V2/triangleV2.cpp
@@ -10,6 +10,10 @@
#include <EGL/egl.h>
#include <GLES2/gl2.h>
+#ifdef __APPLE__
+extern "C" void * createGLView(void *nsWindowPtr, int x, int y, int width, int height);
+#endif
+
#undef HAVE_MALLOC_H
#include <SDL.h>
#include <SDL_syswm.h>
@@ -233,8 +237,10 @@
#ifdef _WIN32
HWND windowId = NULL;
- #else
+ #elif __linux__
Window windowId = NULL;
+ #elif __APPLE__
+ void* windowId = NULL;
#endif
// // Inialize SDL window
@@ -255,8 +261,10 @@
SDL_GetWMInfo(&wminfo);
#ifdef _WIN32
windowId = wminfo.window;
- #else
+ #elif __linux__
windowId = wminfo.info.x11.window;
+ #elif __APPLE__
+ windowId = createGLView(wminfo.nsWindowPtr,0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
#endif
int major,minor,num_config;
diff --git a/tools/emulator/opengl/tests/translator_tests/MacCommon/Android.mk b/tools/emulator/opengl/tests/translator_tests/MacCommon/Android.mk
new file mode 100644
index 0000000..e72ed82
--- /dev/null
+++ b/tools/emulator/opengl/tests/translator_tests/MacCommon/Android.mk
@@ -0,0 +1,20 @@
+
+LOCAL_PATH := $(call my-dir)
+
+ifeq ($(HOST_OS),darwin)
+include $(CLEAR_VARS)
+
+
+LOCAL_LDLIBS := -Wl,-framework,AppKit
+
+LOCAL_SRC_FILES := setup_gl.m
+
+
+
+LOCAL_CFLAGS := -g -O0
+LOCAL_MODULE_TAGS := debug
+LOCAL_MODULE := libMac_view
+
+
+include $(BUILD_HOST_STATIC_LIBRARY)
+endif
diff --git a/tools/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m b/tools/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m
new file mode 100644
index 0000000..43b72ba
--- /dev/null
+++ b/tools/emulator/opengl/tests/translator_tests/MacCommon/setup_gl.m
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include <Cocoa/Cocoa.h>
+
+ void * createGLView(void *nsWindowPtr, int x, int y, int width, int height)
+{
+ NSRect contentRect = NSMakeRect(x, y, width, height);
+ NSView *glView = [[NSView alloc] initWithFrame:contentRect];
+ if (glView == nil) {
+ printf("couldn't create opengl view\n");
+ return nil;
+ }
+ [glView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
+ NSWindow *win = (NSWindow *)nsWindowPtr;
+ [[win contentView] addSubview:glView];
+ [win makeKeyAndOrderFront:nil];
+ return (void *)glView;
+}
+
+