From b68a4219081cf9c60e04fc8c1462d3af1f3c9347 Mon Sep 17 00:00:00 2001 From: Guy Zadickario Date: Thu, 30 Jun 2011 16:06:57 +0300 Subject: [PATCH] opengl renderer: Enable and fix renderer Mac support The following enables the renderer build on darwin. Moved platform specific type declarations from render_api.h to render_api_platform_types.h so it can be included from the objective c code. Fixed subwindow to use EmuGLView which overrides NSView to prevent background drawing of the view. --- .../host/include/libOpenglRender/render_api.h | 23 +---------------- .../render_api_platform_types.h | 25 +++++++++++++++++++ .../host/libs/libOpenglRender/Android.mk | 4 --- .../host/libs/libOpenglRender/FrameBuffer.cpp | 11 ++++---- .../host/libs/libOpenglRender/FrameBuffer.h | 5 ---- .../libs/libOpenglRender/NativeMacSubWindow.m | 24 +++++++++++++++--- .../libs/libOpenglRender/NativeSubWindow.h | 10 +++++++- .../libs/libOpenglRender/WindowSurface.cpp | 7 ++++++ .../emulator/opengl/host/renderer/Android.mk | 3 --- .../tests/emulator_test_renderer/Android.mk | 5 ---- 10 files changed, 68 insertions(+), 49 deletions(-) create mode 100644 tools/emulator/opengl/host/include/libOpenglRender/render_api_platform_types.h diff --git a/tools/emulator/opengl/host/include/libOpenglRender/render_api.h b/tools/emulator/opengl/host/include/libOpenglRender/render_api.h index 26b843b59..fa563164a 100644 --- a/tools/emulator/opengl/host/include/libOpenglRender/render_api.h +++ b/tools/emulator/opengl/host/include/libOpenglRender/render_api.h @@ -17,28 +17,7 @@ #define _OPENGL_RENDERER_RENDER_API_H #include "IOStream.h" - -#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ -#include - -typedef HDC FBNativeDisplayType; -typedef HWND FBNativeWindowType; - -#elif defined(__linux__) - -#include -#include - -typedef Window FBNativeWindowType; - -#elif defined(__APPLE__) - -typedef void* FBNativeWindowType; - -#else -#warning "Unsupported platform" -#endif - +#include "render_api_platform_types.h" // // initOpenGLRenderer - initialize the OpenGL renderer process. diff --git a/tools/emulator/opengl/host/include/libOpenglRender/render_api_platform_types.h b/tools/emulator/opengl/host/include/libOpenglRender/render_api_platform_types.h new file mode 100644 index 000000000..6f2a8a529 --- /dev/null +++ b/tools/emulator/opengl/host/include/libOpenglRender/render_api_platform_types.h @@ -0,0 +1,25 @@ +#ifndef _RENDER_API_PLATFORM_TYPES_H +#define _RENDER_API_PLATFORM_TYPES_H + +#if defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) /* Win32 and WinCE */ +#include + +typedef HDC FBNativeDisplayType; +typedef HWND FBNativeWindowType; + +#elif defined(__linux__) + +#include +#include + +typedef Window FBNativeWindowType; + +#elif defined(__APPLE__) + +typedef void* FBNativeWindowType; + +#else +#warning "Unsupported platform" +#endif + +#endif // of _RENDER_API_PLATFORM_TYPES_H diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk b/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk index 6dc35c00a..1096e1067 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk +++ b/tools/emulator/opengl/host/libs/libOpenglRender/Android.mk @@ -1,7 +1,5 @@ LOCAL_PATH := $(call my-dir) -ifneq ($(HOST_OS),darwin) - ### libOpenglRender ################################################# $(call emugl-begin-host-shared-library,libOpenglRender) @@ -51,5 +49,3 @@ LOCAL_STATIC_LIBRARIES += libutils liblog #$(call emugl-export,CFLAGS,-DCHECK_GL_ERROR) $(call emugl-end-module) - -endif # HOST_OS != darwin diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp index 81007424c..2c114c1d6 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.cpp @@ -27,7 +27,7 @@ HandleType FrameBuffer::s_nextHandle = 0; #ifdef WITH_GLES2 static const char *getGLES2ExtensionString(EGLDisplay p_dpy, - FBNativeWindowType p_window) + EGLNativeWindowType p_window) { EGLConfig config; EGLSurface surface; @@ -44,14 +44,12 @@ static const char *getGLES2ExtensionString(EGLDisplay p_dpy, return NULL; } -#if defined(__linux__) || defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) surface = s_egl.eglCreateWindowSurface(p_dpy, config, - (EGLNativeWindowType)p_window, + p_window, NULL); if (surface == EGL_NO_SURFACE) { return NULL; } -#endif GLint gl2ContextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, @@ -165,6 +163,8 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window, fb->m_nativeWindow = p_window; + fb->m_subWin = createSubWindow(p_window,&fb->m_subWinDisplay,p_x,p_y,p_width,p_height); + // // if GLES2 plugin has loaded - try to make GLES2 context and // get GLES2 extension string @@ -172,7 +172,7 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window, const char *gl2Extensions = NULL; #ifdef WITH_GLES2 if (fb->m_caps.hasGL2) { - gl2Extensions = getGLES2ExtensionString(fb->m_eglDisplay, p_window); + gl2Extensions = getGLES2ExtensionString(fb->m_eglDisplay, fb->m_subWin); if (!gl2Extensions) { // Could not create GLES2 context - drop GL2 capability fb->m_caps.hasGL2 = false; @@ -209,7 +209,6 @@ bool FrameBuffer::initialize(FBNativeWindowType p_window, } EGLNativeDisplayType dpy; - fb->m_subWin = createSubWindow(p_window,&fb->m_subWinDisplay,p_x,p_y,p_width,p_height); fb->m_eglSurface = s_egl.eglCreateWindowSurface(fb->m_eglDisplay, eglConfig, fb->m_subWin, NULL); diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h index acc2ba3d1..3e3e2e24b 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h +++ b/tools/emulator/opengl/host/libs/libOpenglRender/FrameBuffer.h @@ -25,11 +25,6 @@ #include #include -#if defined(__linux__) || defined(_WIN32) || defined(__VC32__) && !defined(__CYGWIN__) -#else -#warning "Unsupported Platform" -#endif - typedef uint32_t HandleType; typedef std::map RenderContextMap; typedef std::map WindowSurfaceMap; diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/NativeMacSubWindow.m b/tools/emulator/opengl/host/libs/libOpenglRender/NativeMacSubWindow.m index 9ed3ae685..269b7ea0d 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/NativeMacSubWindow.m +++ b/tools/emulator/opengl/host/libs/libOpenglRender/NativeMacSubWindow.m @@ -16,22 +16,40 @@ #include "NativeSubWindow.h" #include +/* + * EmuGLView inherit from NSView and override the isOpaque + * method to return YES. That prevents drawing of underlying window/view + * when the view needs to be redrawn. + */ +@interface EmuGLView : NSView { +} @end + +@implementation EmuGLView + + - (BOOL)isOpaque { + return YES; + } + +@end + EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, EGLNativeDisplayType* display_out, int x, int y,int width, int height){ NSRect contentRect = NSMakeRect(x, y, width, height); - NSView *glView = [[NSView alloc] initWithFrame:contentRect]; + NSView *glView = [[EmuGLView alloc] initWithFrame:contentRect]; if (glView) { NSWindow *win = (NSWindow *)p_window; [[win contentView] addSubview:glView]; [win makeKeyAndOrderFront:nil]; - } + } + return (EGLNativeWindowType)glView; } void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win){ if(win){ - delete win; + NSView *glView = (NSView *)win; + [glView release]; } } diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/NativeSubWindow.h b/tools/emulator/opengl/host/libs/libOpenglRender/NativeSubWindow.h index da94e5e26..196597844 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/NativeSubWindow.h +++ b/tools/emulator/opengl/host/libs/libOpenglRender/NativeSubWindow.h @@ -17,7 +17,11 @@ #define NATIVE_SUB_WINDOW_H #include -#include "libOpenglRender/render_api.h" +#include "libOpenglRender/render_api_platform_types.h" + +#ifdef __cplusplus +extern "C" { +#endif EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, EGLNativeDisplayType* display_out, @@ -26,4 +30,8 @@ EGLNativeWindowType createSubWindow(FBNativeWindowType p_window, void destroySubWindow(EGLNativeDisplayType dis,EGLNativeWindowType win); +#ifdef __cplusplus +} +#endif + #endif diff --git a/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp b/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp index 8bf7ab2cd..ede66ce24 100644 --- a/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp +++ b/tools/emulator/opengl/host/libs/libOpenglRender/WindowSurface.cpp @@ -228,7 +228,14 @@ void WindowSurface::copyToColorBuffer() GL_RGBA, GL_UNSIGNED_BYTE, data); } +// +// XXX: for some reason flipping the image is not required on +// Mac. Need to find the reason, currently unkbown. +// +#ifndef __APPLE__ #define FLIP_BUFFER 1 +#endif + #if FLIP_BUFFER //We need to flip the pixels int bpp = 4; diff --git a/tools/emulator/opengl/host/renderer/Android.mk b/tools/emulator/opengl/host/renderer/Android.mk index 7354edad0..934931b5f 100644 --- a/tools/emulator/opengl/host/renderer/Android.mk +++ b/tools/emulator/opengl/host/renderer/Android.mk @@ -1,7 +1,5 @@ LOCAL_PATH:=$(call my-dir) -# OS X not supported for now -ifneq ($(HOST_OS),darwin) # host renderer process ########################### include $(CLEAR_VARS) @@ -31,4 +29,3 @@ LOCAL_SHARED_LIBRARIES := libOpenglRender \ lib_renderControl_dec include $(BUILD_HOST_EXECUTABLE) -endif # HOST_OS != darwin diff --git a/tools/emulator/opengl/tests/emulator_test_renderer/Android.mk b/tools/emulator/opengl/tests/emulator_test_renderer/Android.mk index 7f5d4f5e4..9d524c130 100644 --- a/tools/emulator/opengl/tests/emulator_test_renderer/Android.mk +++ b/tools/emulator/opengl/tests/emulator_test_renderer/Android.mk @@ -1,8 +1,5 @@ LOCAL_PATH:=$(call my-dir) -# For now, OS X is not supported -ifneq ($(HOST_OS),darwin) - $(call emugl-begin-host-executable,emulator_test_renderer) $(call emugl-import,libOpenglRender) @@ -23,5 +20,3 @@ endif LOCAL_STATIC_LIBRARIES += libSDL libSDLmain $(call emugl-end-module) - -endif # HOST_OS != darwin