From 7a712acc02282985dcd32feb81284e1f2b19ec7e Mon Sep 17 00:00:00 2001 From: Jesse Hall Date: Wed, 18 Apr 2012 15:02:09 -0700 Subject: 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 --- .../host/include/libOpenglRender/render_api.h | 146 +++++++++++---------- .../host/libs/libOpenglRender/render_api.cpp | 16 +-- 2 files changed, 85 insertions(+), 77 deletions(-) (limited to 'emulator') 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 } diff --git a/emulator/opengl/host/libs/libOpenglRender/render_api.cpp b/emulator/opengl/host/libs/libOpenglRender/render_api.cpp index c8d3e06..00dcd75 100644 --- a/emulator/opengl/host/libs/libOpenglRender/render_api.cpp +++ b/emulator/opengl/host/libs/libOpenglRender/render_api.cpp @@ -50,7 +50,7 @@ static IOStream *createRenderThread(int p_stream_buffer_size, #define RENDER_API_USE_THREAD //#endif -bool initLibrary(void) +int initLibrary(void) { // // Load EGL Plugin @@ -76,7 +76,7 @@ bool initLibrary(void) return true; } -bool initOpenGLRenderer(int width, int height, int portNum, +int initOpenGLRenderer(int width, int height, int portNum, OnPostFn onPost, void* onPostContext) { @@ -191,7 +191,7 @@ bool initOpenGLRenderer(int width, int height, int portNum, return true; } -bool stopOpenGLRenderer() +int stopOpenGLRenderer(void) { bool ret = false; @@ -224,7 +224,7 @@ bool stopOpenGLRenderer() return ret; } -bool createOpenGLSubwindow(FBNativeWindowType window, +int createOpenGLSubwindow(FBNativeWindowType window, int x, int y, int width, int height, float zRot) { if (s_renderThread) { @@ -240,7 +240,7 @@ bool createOpenGLSubwindow(FBNativeWindowType window, return false; } -bool destroyOpenGLSubwindow() +int destroyOpenGLSubwindow(void) { if (s_renderThread) { return FrameBuffer::removeSubWindow(); @@ -272,7 +272,7 @@ void setOpenGLDisplayRotation(float zRot) } } -void repaintOpenGLDisplay() +void repaintOpenGLDisplay(void) { if (s_renderThread) { FrameBuffer *fb = FrameBuffer::getFB(); @@ -352,8 +352,8 @@ setStreamMode(int mode) #endif /* _WIN32 */ default: // Invalid stream mode - return -1; + return false; } gRendererStreamMode = mode; - return 0; + return true; } -- cgit v1.1