• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef _OPENGL_RENDERER_RENDER_API_H
17 #define _OPENGL_RENDERER_RENDER_API_H
18 
19 /* This header and its declarations must be usable from C code.
20  *
21  * If RENDER_API_NO_PROTOTYPES is #defined before including this header, only
22  * the interface function pointer types will be declared, not the prototypes.
23  * This allows the client to use those names for its function pointer variables.
24  *
25  * All interfaces which can fail return an int, with zero indicating failure
26  * and anything else indicating success.
27  */
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stdlib.h>
34 #include "render_api_platform_types.h"
35 
36 #if defined(RENDER_API_NO_PROTOTYPES)
37 #define DECL(ret, name, args) \
38 	typedef ret (* name##Fn) args
39 #else
40 #define DECL(ret, name, args) \
41 	typedef ret (* name##Fn) args ; \
42 	ret name args
43 #endif
44 
45 /* initLibrary - initialize the library and tries to load the corresponding
46  *     GLES translator libraries. This function must be called before anything
47  *     else to ensure that everything works. If it returns an error, then
48  *     you cannot use the library at all (this can happen under certain
49  *     environments where the desktop GL libraries are not available)
50  */
51 DECL(int, initLibrary, (void));
52 
53 /* list of constants to be passed to setStreamMode */
54 #define STREAM_MODE_DEFAULT   0
55 #define STREAM_MODE_TCP       1
56 #define STREAM_MODE_UNIX      2
57 #define STREAM_MODE_PIPE      3
58 
59 /* Change the stream mode. This must be called before initOpenGLRenderer */
60 DECL(int, setStreamMode, (int mode));
61 
62 /* initOpenGLRenderer - initialize the OpenGL renderer process.
63  *
64  * width and height are the framebuffer dimensions that will be reported to the
65  * guest display driver.
66  *
67  * addr is a buffer of addrLen bytes that will receive the address that clients
68  * should connect to. The interpretation depends on the transport:
69  *   - TCP: The buffer contains the port number as a string. The server is
70  *     listening only on the loopback address.
71  *   - Win32 and UNIX named pipes: The buffer contains the full path clients
72  *     should connect to.
73  *
74  * This function is *NOT* thread safe and should be called first
75  * to initialize the renderer after initLibrary().
76  */
77 DECL(int, initOpenGLRenderer, (int width, int height, char* addr, size_t addrLen));
78 
79 /* getHardwareStrings - describe the GPU hardware and driver.
80  *    The underlying GL's vendor/renderer/version strings are returned to the
81  *    caller. The pointers become invalid after a call to stopOpenGLRenderer().
82  */
83 DECL(void, getHardwareStrings, (const char** vendor, const char** renderer,
84 		const char** version));
85 
86 /* A per-frame callback can be registered with setPostCallback(); to remove it
87  * pass NULL for both parameters. While a callback is registered, the renderer
88  * will call it just before each new frame is displayed, providing a copy of
89  * the framebuffer contents.
90  *
91  * The callback will be called from one of the renderer's threads, so will
92  * probably need synchronization on any data structures it modifies. The
93  * pixels buffer may be overwritten as soon as the callback returns; if it
94  * needs the pixels afterwards it must copy them.
95  *
96  * The pixels buffer is intentionally not const: the callback may modify the
97  * data without copying to another buffer if it wants, e.g. in-place RGBA to
98  * RGB conversion, or in-place y-inversion.
99  *
100  * Parameters are:
101  *   context        The pointer optionally provided when the callback was
102  *                  registered. The client can use this to pass whatever
103  *                  information it wants to the callback.
104  *   width, height  Dimensions of the image, in pixels. Rows are tightly
105  *                  packed; there is no inter-row padding.
106  *   ydir           Indicates row order: 1 means top-to-bottom order, -1 means
107  *                  bottom-to-top order.
108  *   format, type   Format and type GL enums, as used in glTexImage2D() or
109  *                  glReadPixels(), describing the pixel format.
110  *   pixels         The framebuffer image.
111  *
112  * In the first implementation, ydir is always -1 (bottom to top), format and
113  * type are always GL_RGBA and GL_UNSIGNED_BYTE, and the width and height will
114  * always be the same as the ones passed to initOpenGLRenderer().
115  */
116 typedef void (*OnPostFn)(void* context, int width, int height, int ydir,
117                          int format, int type, unsigned char* pixels);
118 DECL(void, setPostCallback, (OnPostFn onPost, void* onPostContext));
119 
120 /* createOpenGLSubwindow -
121  *     Create a native subwindow which is a child of 'window'
122  *     to be used for framebuffer display.
123  *     Framebuffer will not get displayed if a subwindow is not
124  *     created.
125  *     x,y,width,height are the dimensions of the rendering subwindow.
126  *     zRot is the rotation to apply on the framebuffer display image.
127  */
128 DECL(int, createOpenGLSubwindow, (FBNativeWindowType window,
129 		int x, int y, int width, int height, float zRot));
130 
131 /* destroyOpenGLSubwindow -
132  *   destroys the created native subwindow. Once destroyed,
133  *   Framebuffer content will not be visible until a new
134  *   subwindow will be created.
135  */
136 DECL(int, destroyOpenGLSubwindow, (void));
137 
138 /* setOpenGLDisplayRotation -
139  *    set the framebuffer display image rotation in units
140  *    of degrees around the z axis
141  */
142 DECL(void, setOpenGLDisplayRotation, (float zRot));
143 
144 /* repaintOpenGLDisplay -
145  *    causes the OpenGL subwindow to get repainted with the
146  *    latest framebuffer content.
147  */
148 DECL(void, repaintOpenGLDisplay, (void));
149 
150 /* stopOpenGLRenderer - stops the OpenGL renderer process.
151  *     This functions is *NOT* thread safe and should be called
152  *     only if previous initOpenGLRenderer has returned true.
153  */
154 DECL(int, stopOpenGLRenderer, (void));
155 
156 #ifdef __cplusplus
157 }
158 #endif
159 
160 #endif
161