Merge "Publish and use libOpenglRender interface header"
diff --git a/Makefile.android b/Makefile.android
index 6fccf71..7b35039 100644
--- a/Makefile.android
+++ b/Makefile.android
@@ -246,7 +246,6 @@
     emulator-libui \
     emulator-common \
 
-
 LOCAL_CFLAGS += -DCONFIG_STANDALONE_UI=1
 
 LOCAL_CFLAGS += $(EMULATOR_COMMON_CFLAGS) $(EMULATOR_LIBUI_CFLAGS)
diff --git a/Makefile.common b/Makefile.common
index f9d98af..5307b28 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -164,7 +164,7 @@
 common_LOCAL_CFLAGS =
 common_LOCAL_SRC_FILES =
 
-EMULATOR_LIBUI_CFLAGS :=
+EMULATOR_LIBUI_CFLAGS := -Isdk/emulator/opengl/host/include
 
 common_LOCAL_CFLAGS += $(EMULATOR_COMMON_CFLAGS)
 
diff --git a/Makefile.target b/Makefile.target
index 1961acf..f7122fa 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -274,7 +274,7 @@
     $(EMULATOR_TARGET_CFLAGS) \
     -DCONFIG_STANDALONE_CORE \
 
-LOCAL_CFLAGS += -Wno-missing-field-initializers
+LOCAL_CFLAGS += -Isdk/emulator/opengl/host/include -Wno-missing-field-initializers
 
 
 LOCAL_STATIC_LIBRARIES := \
diff --git a/android/opengles.c b/android/opengles.c
index f116f25..025f7dd 100644
--- a/android/opengles.c
+++ b/android/opengles.c
@@ -10,6 +10,8 @@
 ** GNU General Public License for more details.
 */
 
+#define RENDER_API_NO_PROTOTYPES 1
+
 #include "config-host.h"
 #include "android/opengles.h"
 #include "android/globals.h"
@@ -17,6 +19,7 @@
 #include <android/utils/path.h>
 #include <android/utils/bufprint.h>
 #include <android/utils/dll.h>
+#include <libOpenglRender/render_api.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -35,22 +38,14 @@
 #error Unknown HOST_LONG_BITS
 #endif
 
-/* These definitions *must* match those under:
- * development/tools/emulator/opengl/host/include/libOpenglRender/render_api.h
- */
 #define DYNLINK_FUNCTIONS  \
-  DYNLINK_FUNC(int,initLibrary,(void),(),return) \
-  DYNLINK_FUNC(int,setStreamMode,(int a),(a),return) \
-  DYNLINK_FUNC(int,initOpenGLRenderer,(int width, int height, int port, OnPostFn onPost, void* onPostContext),(width,height,port,onPost,onPostContext),return) \
-  DYNLINK_FUNC(int,createOpenGLSubwindow,(void* window, int x, int y, int width, int height, float zRot),(window,x,y,width,height,zRot),return)\
-  DYNLINK_FUNC(int,destroyOpenGLSubwindow,(void),(),return)\
-  DYNLINK_FUNC(void,repaintOpenGLDisplay,(void),(),)\
-  DYNLINK_FUNC(void,stopOpenGLRenderer,(void),(),)
-
-#define STREAM_MODE_DEFAULT  0
-#define STREAM_MODE_TCP      1
-#define STREAM_MODE_UNIX     2
-#define STREAM_MODE_PIPE     3
+  DYNLINK_FUNC(initLibrary) \
+  DYNLINK_FUNC(setStreamMode) \
+  DYNLINK_FUNC(initOpenGLRenderer) \
+  DYNLINK_FUNC(createOpenGLSubwindow) \
+  DYNLINK_FUNC(destroyOpenGLSubwindow) \
+  DYNLINK_FUNC(repaintOpenGLDisplay) \
+  DYNLINK_FUNC(stopOpenGLRenderer)
 
 #ifndef CONFIG_STANDALONE_UI
 /* Defined in android/hw-pipe-net.c */
@@ -59,15 +54,10 @@
 
 static ADynamicLibrary*  rendererLib;
 
-/* Define the pointers and the wrapper functions to call them */
-#define DYNLINK_FUNC(result,name,sig,params,ret) \
-    static result (*_ptr_##name) sig; \
-    static result name sig { \
-        ret (*_ptr_##name) params ; \
-    }
-
+/* Define the function pointers */
+#define DYNLINK_FUNC(name) \
+    static name##Fn name = NULL;
 DYNLINK_FUNCTIONS
-
 #undef DYNLINK_FUNC
 
 static int
@@ -75,10 +65,11 @@
 {
     void*  symbol;
     char*  error;
-#define DYNLINK_FUNC(result,name,sig,params,ret) \
-    symbol = adynamicLibrary_findSymbol( rendererLib, #name, &error ); \
+
+#define DYNLINK_FUNC(name) \
+    symbol = adynamicLibrary_findSymbol(rendererLib, #name, &error); \
     if (symbol != NULL) { \
-        _ptr_##name = symbol; \
+        name = symbol; \
     } else { \
         derror("GLES emulation: Could not find required symbol (%s): %s", #name, error); \
         free(error); \
@@ -86,6 +77,7 @@
     }
 DYNLINK_FUNCTIONS
 #undef DYNLINK_FUNC
+
     return 0;
 }
 
@@ -126,10 +118,10 @@
         /* XXX: NEED Win32 pipe implementation */
         setStreamMode(STREAM_MODE_TCP);
 #else
-	setStreamMode(STREAM_MODE_UNIX);
+	    setStreamMode(STREAM_MODE_UNIX);
 #endif
     } else {
-	setStreamMode(STREAM_MODE_TCP);
+	    setStreamMode(STREAM_MODE_TCP);
     }
     return 0;
 
@@ -148,7 +140,7 @@
         return -1;
     }
 
-    if (initOpenGLRenderer(width, height, ANDROID_OPENGLES_BASE_PORT, onPost, onPostContext) != 0) {
+    if (!initOpenGLRenderer(width, height, ANDROID_OPENGLES_BASE_PORT, onPost, onPostContext)) {
         D("Can't start OpenGLES renderer?");
         return -1;
     }
@@ -167,7 +159,8 @@
 android_showOpenglesWindow(void* window, int x, int y, int width, int height, float rotation)
 {
     if (rendererLib) {
-        return createOpenGLSubwindow(window, x, y, width, height, rotation);
+        int success = createOpenGLSubwindow((FBNativeWindowType)window, x, y, width, height, rotation);
+        return success ? 0 : -1;
     } else {
         return -1;
     }
@@ -177,7 +170,8 @@
 android_hideOpenglesWindow(void)
 {
     if (rendererLib) {
-        return destroyOpenGLSubwindow();
+        int success = destroyOpenGLSubwindow();
+        return success ? 0 : -1;
     } else {
         return -1;
     }
diff --git a/vl-android.c b/vl-android.c
index 5a41e2d..b43f7fe 100644
--- a/vl-android.c
+++ b/vl-android.c
@@ -3876,14 +3876,15 @@
         int  gles_emul = 0;
 
         if (android_hw->hw_gpu_enabled) {
-            if (android_initOpenglesEmulation() == 0) {
+            /* Set framebuffer change notification callback when starting
+             * GLES emulation. Currently only multi-touch emulation is
+             * interested in FB changes (to transmit them to the device), so
+             * the callback is set within MT emulation.*/
+            if (android_initOpenglesEmulation() == 0 &&
+                android_startOpenglesRenderer(android_hw->hw_lcd_width,
+                    android_hw->hw_lcd_height,
+                    multitouch_opengles_fb_update, NULL) == 0) {
                 gles_emul = 1;
-                /* Set framebuffer change notification callback when starting
-                 * GLES emulation. Currently only multi-touch emulation is
-                 * interested in FB changes (to transmit them to the device), so
-                 * the callback is set within MT emulation.*/
-                android_startOpenglesRenderer(android_hw->hw_lcd_width, android_hw->hw_lcd_height,
-                                              multitouch_opengles_fb_update, NULL);
             } else {
                 dwarning("Could not initialize OpenglES emulation, using software renderer.");
             }