• 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 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 #include "render_api_platform_types.h"
24 
25 /* If a function with this signature is passed to initOpenGLRenderer(),
26  * it will be called by the renderer just before each new frame is displayed,
27  * providing a copy of the framebuffer contents.
28  *
29  * The callback will be called from one of the renderer's threads, so will
30  * probably need synchronization on any data structures it modifies. The
31  * pixels buffer may be overwritten as soon as the callback returns; if it needs
32  * the pixels afterwards it must copy them.
33  *
34  * The pixels buffer is intentionally not const: the callback may modify the
35  * data without copying to another buffer if it wants, e.g. in-place RGBA to RGB
36  * conversion, or in-place y-inversion.
37  *
38  * Parameters are:
39  *   context        The pointer optionally provided when the callback was
40  *                  registered. The client can use this to pass whatever
41  *                  information it wants to the callback.
42  *   width, height  Dimensions of the image, in pixels. Rows are tightly packed;
43  *                  there is no inter-row padding.
44  *   ydir           Indicates row order: 1 means top-to-bottom order, -1 means
45  *                  bottom-to-top order.
46  *   format, type   Format and type GL enums, as used in glTexImage2D() or
47  *                  glReadPixels(), describing the pixel format.
48  *   pixels         The framebuffer image.
49  *
50  * In the first implementation, ydir is always -1 (bottom to top), format and
51  * type are always GL_RGBA and GL_UNSIGNED_BYTE, and the width and height will
52  * always be the same as the ones passed to initOpenGLRenderer().
53  */
54 typedef void (*OnPostFn)(void* context, int width, int height, int ydir,
55                          int format, int type, unsigned char* pixels);
56 
57 // initLibrary - initialize the library and tries to load the corresponding
58 //     GLES translator libraries. This function must be called before anything
59 //     else to ensure that everything works. If it returns an error, then
60 //     you cannot use the library at all (this can happen under certain
61 //     environments where the desktop GL libraries are not available)
62 //
63 // returns true if the library could be initialized successfully;
64 //
65 bool initLibrary(void);
66 
67 // list of constants to be passed to setStreamMode, which determines
68 // which
69 #define STREAM_MODE_DEFAULT   0
70 #define STREAM_MODE_TCP       1
71 #define STREAM_MODE_UNIX      2
72 #define STREAM_MODE_PIPE      3
73 
74 // Change the stream mode. This must be called before initOpenGLRenderer
75 int setStreamMode(int mode);
76 
77 //
78 // initOpenGLRenderer - initialize the OpenGL renderer process.
79 //     portNum is the tcp port number the renderer is listening to.
80 //     width and height are the framebuffer dimensions that will be
81 //     reported to the guest display driver.
82 //
83 // returns true if renderer has been started successfully;
84 //
85 // This function is *NOT* thread safe and should be called first
86 // to initialize the renderer after initLibrary().
87 //
88 bool initOpenGLRenderer(int width, int height, int portNum,
89                         OnPostFn onPost, void* onPostContext);
90 
91 //
92 // createOpenGLSubwindow -
93 //     Create a native subwindow which is a child of 'window'
94 //     to be used for framebuffer display.
95 //     Framebuffer will not get displayed if a subwindow is not
96 //     created.
97 //     x,y,width,height are the dimensions of the rendering subwindow.
98 //     zRot is the rotation to apply on the framebuffer display image.
99 //
100 bool createOpenGLSubwindow(FBNativeWindowType window,
101                            int x, int y, int width, int height, float zRot);
102 
103 //
104 // destroyOpenGLSubwindow -
105 //   destroys the created native subwindow. Once destroyed,
106 //   Framebuffer content will not be visible until a new
107 //   subwindow will be created.
108 //
109 bool destroyOpenGLSubwindow();
110 
111 //
112 // setOpenGLDisplayRotation -
113 //    set the framebuffer display image rotation in units
114 //    of degrees around the z axis
115 //
116 void setOpenGLDisplayRotation(float zRot);
117 
118 //
119 // repaintOpenGLDisplay -
120 //    causes the OpenGL subwindow to get repainted with the
121 //    latest framebuffer content.
122 //
123 void repaintOpenGLDisplay();
124 
125 //
126 // stopOpenGLRenderer - stops the OpenGL renderer process.
127 //     This functions is *NOT* thread safe and should be called
128 //     only if previous initOpenGLRenderer has returned true.
129 //
130 bool stopOpenGLRenderer();
131 
132 #ifdef __cplusplus
133 }
134 #endif
135 
136 #endif
137