aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/host/include/libOpenglRender
diff options
context:
space:
mode:
authorJesse Hall <jessehall@google.com>2012-04-18 15:02:09 -0700
committerJesse Hall <jessehall@google.com>2012-04-18 15:24:17 -0700
commit7a712acc02282985dcd32feb81284e1f2b19ec7e (patch)
treeaedf935e93ec0fa0069fe004111f1394bbc61030 /emulator/opengl/host/include/libOpenglRender
parent7dbe1f1d1ff1e956e11c5db01ae164360ee2280a (diff)
downloadsdk-7a712acc02282985dcd32feb81284e1f2b19ec7e.zip
sdk-7a712acc02282985dcd32feb81284e1f2b19ec7e.tar.gz
sdk-7a712acc02282985dcd32feb81284e1f2b19ec7e.tar.bz2
Publish and use libOpenglRender interface header
The emulator opengles.c file duplicated the function declarations from libOpenglRenderer's render_api.h instead of including it directly. This led to multiple bugs since the declarations didn't actually match, but there was no way for the compiler or dynamic loader to check this. This change makes opengles.c include render_api.h to get function pointer prototypes, and changes the prototypes/implementation as necessary to make both sides actually match. It should be much more difficult to introduce interface mismatch bugs now. Two bugs this change would have prevented: (a) The interface mismatch caused by inconsistent branching which led to GPU acceleration crashing on Windows. With this change, we would have caught the problem at compile time. (b) The emulator verbose log has always been printing "Can't start OpenGLES renderer?" even when the renderer started fine. This is because the renderer was returning a bool (true == success) but the emulator's declaration said it returned int, and the emulator assumed 0 meant success. This difference in return type should now be caught at compile time. Change-Id: Iab3b6960e221edd135b515a166cf991b62bb60c9
Diffstat (limited to 'emulator/opengl/host/include/libOpenglRender')
-rw-r--r--emulator/opengl/host/include/libOpenglRender/render_api.h146
1 files changed, 77 insertions, 69 deletions
diff --git a/emulator/opengl/host/include/libOpenglRender/render_api.h b/emulator/opengl/host/include/libOpenglRender/render_api.h
index 9c76b3e..1004932 100644
--- a/emulator/opengl/host/include/libOpenglRender/render_api.h
+++ b/emulator/opengl/host/include/libOpenglRender/render_api.h
@@ -16,12 +16,31 @@
#ifndef _OPENGL_RENDERER_RENDER_API_H
#define _OPENGL_RENDERER_RENDER_API_H
+/* This header and its declarations must be usable from C code.
+ *
+ * If RENDER_API_NO_PROTOTYPES is #defined before including this header, only
+ * the interface function pointer types will be declared, not the prototypes.
+ * This allows the client to use those names for its function pointer variables.
+ *
+ * All interfaces which can fail return an int, with zero indicating failure
+ * and anything else indicating success.
+ */
+
#ifdef __cplusplus
extern "C" {
#endif
#include "render_api_platform_types.h"
+#if defined(RENDER_API_NO_PROTOTYPES)
+#define DECL(ret, name, args) \
+ typedef ret (* name##Fn) args
+#else
+#define DECL(ret, name, args) \
+ typedef ret (* name##Fn) args ; \
+ ret name args
+#endif
+
/* If a function with this signature is passed to initOpenGLRenderer(),
* it will be called by the renderer just before each new frame is displayed,
* providing a copy of the framebuffer contents.
@@ -54,80 +73,69 @@ extern "C" {
typedef void (*OnPostFn)(void* context, int width, int height, int ydir,
int format, int type, unsigned char* pixels);
-// initLibrary - initialize the library and tries to load the corresponding
-// GLES translator libraries. This function must be called before anything
-// else to ensure that everything works. If it returns an error, then
-// you cannot use the library at all (this can happen under certain
-// environments where the desktop GL libraries are not available)
-//
-// returns true if the library could be initialized successfully;
-//
-bool initLibrary(void);
-
-// list of constants to be passed to setStreamMode, which determines
-// which
+/* initLibrary - initialize the library and tries to load the corresponding
+ * GLES translator libraries. This function must be called before anything
+ * else to ensure that everything works. If it returns an error, then
+ * you cannot use the library at all (this can happen under certain
+ * environments where the desktop GL libraries are not available)
+ */
+DECL(int, initLibrary, (void));
+
+/* list of constants to be passed to setStreamMode */
#define STREAM_MODE_DEFAULT 0
#define STREAM_MODE_TCP 1
#define STREAM_MODE_UNIX 2
#define STREAM_MODE_PIPE 3
-// Change the stream mode. This must be called before initOpenGLRenderer
-int setStreamMode(int mode);
-
-//
-// initOpenGLRenderer - initialize the OpenGL renderer process.
-// portNum is the tcp port number the renderer is listening to.
-// width and height are the framebuffer dimensions that will be
-// reported to the guest display driver.
-//
-// returns true if renderer has been started successfully;
-//
-// This function is *NOT* thread safe and should be called first
-// to initialize the renderer after initLibrary().
-//
-bool initOpenGLRenderer(int width, int height, int portNum,
- OnPostFn onPost, void* onPostContext);
-
-//
-// createOpenGLSubwindow -
-// Create a native subwindow which is a child of 'window'
-// to be used for framebuffer display.
-// Framebuffer will not get displayed if a subwindow is not
-// created.
-// x,y,width,height are the dimensions of the rendering subwindow.
-// zRot is the rotation to apply on the framebuffer display image.
-//
-bool createOpenGLSubwindow(FBNativeWindowType window,
- int x, int y, int width, int height, float zRot);
-
-//
-// destroyOpenGLSubwindow -
-// destroys the created native subwindow. Once destroyed,
-// Framebuffer content will not be visible until a new
-// subwindow will be created.
-//
-bool destroyOpenGLSubwindow();
-
-//
-// setOpenGLDisplayRotation -
-// set the framebuffer display image rotation in units
-// of degrees around the z axis
-//
-void setOpenGLDisplayRotation(float zRot);
-
-//
-// repaintOpenGLDisplay -
-// causes the OpenGL subwindow to get repainted with the
-// latest framebuffer content.
-//
-void repaintOpenGLDisplay();
-
-//
-// stopOpenGLRenderer - stops the OpenGL renderer process.
-// This functions is *NOT* thread safe and should be called
-// only if previous initOpenGLRenderer has returned true.
-//
-bool stopOpenGLRenderer();
+/* Change the stream mode. This must be called before initOpenGLRenderer */
+DECL(int, setStreamMode, (int mode));
+
+/* initOpenGLRenderer - initialize the OpenGL renderer process.
+ * portNum is the tcp port number the renderer is listening to.
+ * width and height are the framebuffer dimensions that will be
+ * reported to the guest display driver.
+ *
+ * This function is *NOT* thread safe and should be called first
+ * to initialize the renderer after initLibrary().
+ */
+DECL(int, initOpenGLRenderer, (int width, int height, int portNum,
+ OnPostFn onPost, void* onPostContext));
+
+/* createOpenGLSubwindow -
+ * Create a native subwindow which is a child of 'window'
+ * to be used for framebuffer display.
+ * Framebuffer will not get displayed if a subwindow is not
+ * created.
+ * x,y,width,height are the dimensions of the rendering subwindow.
+ * zRot is the rotation to apply on the framebuffer display image.
+ */
+DECL(int, createOpenGLSubwindow, (FBNativeWindowType window,
+ int x, int y, int width, int height, float zRot));
+
+/* destroyOpenGLSubwindow -
+ * destroys the created native subwindow. Once destroyed,
+ * Framebuffer content will not be visible until a new
+ * subwindow will be created.
+ */
+DECL(int, destroyOpenGLSubwindow, (void));
+
+/* setOpenGLDisplayRotation -
+ * set the framebuffer display image rotation in units
+ * of degrees around the z axis
+ */
+DECL(void, setOpenGLDisplayRotation, (float zRot));
+
+/* repaintOpenGLDisplay -
+ * causes the OpenGL subwindow to get repainted with the
+ * latest framebuffer content.
+ */
+DECL(void, repaintOpenGLDisplay, (void));
+
+/* stopOpenGLRenderer - stops the OpenGL renderer process.
+ * This functions is *NOT* thread safe and should be called
+ * only if previous initOpenGLRenderer has returned true.
+ */
+DECL(int, stopOpenGLRenderer, (void));
#ifdef __cplusplus
}