OLD | NEW |
| (Empty) |
1 /* Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 * Use of this source code is governed by a BSD-style license that can be | |
3 * found in the LICENSE file. | |
4 */ | |
5 #ifndef PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ | |
6 #define PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ | |
7 | |
8 #include "ppapi/c/dev/pp_graphics_3d_dev.h" | |
9 | |
10 #include "ppapi/c/pp_bool.h" | |
11 #include "ppapi/c/pp_instance.h" | |
12 #include "ppapi/c/pp_resource.h" | |
13 | |
14 // Example usage from plugin code: | |
15 // | |
16 // // Setup. | |
17 // PP_Resource context; | |
18 // int32_t attribs[] = {PP_GRAPHICS3DATTRIB_WIDTH, 800, | |
19 // PP_GRAPHICS3DATTRIB_HEIGHT, 800, | |
20 // PP_GRAPHICS3DATTRIB_NONE}; | |
21 // context = g3d->Create(instance, attribs, &context); | |
22 // inst->BindGraphics(instance, context); | |
23 // | |
24 // // Present one frame. | |
25 // gles2->Clear(context, GL_COLOR_BUFFER); | |
26 // g3d->SwapBuffers(context); | |
27 // | |
28 // // Shutdown. | |
29 // core->ReleaseResource(context); | |
30 | |
31 #define PPB_GRAPHICS_3D_DEV_INTERFACE_0_9 "PPB_Graphics3D(Dev);0.9" | |
32 #define PPB_GRAPHICS_3D_DEV_INTERFACE PPB_GRAPHICS_3D_DEV_INTERFACE_0_9 | |
33 | |
34 struct PPB_Graphics3D_Dev { | |
35 // Retrieves the maximum supported value for the given attribute. | |
36 // | |
37 // This function may be used to check if a particular attribute value is | |
38 // supported before attempting to create a context. | |
39 // Attributes that can be queried for include: | |
40 // - PP_GRAPHICS3DATTRIB_ALPHA_SIZE | |
41 // - PP_GRAPHICS3DATTRIB_BLUE_SIZE | |
42 // - PP_GRAPHICS3DATTRIB_GREEN_SIZE | |
43 // - PP_GRAPHICS3DATTRIB_RED_SIZE | |
44 // - PP_GRAPHICS3DATTRIB_DEPTH_SIZE | |
45 // - PP_GRAPHICS3DATTRIB_STENCIL_SIZE | |
46 // - PP_GRAPHICS3DATTRIB_SAMPLES | |
47 // - PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS | |
48 // - PP_GRAPHICS3DATTRIB_WIDTH | |
49 // - PP_GRAPHICS3DATTRIB_HEIGHT | |
50 // | |
51 // On failure the following error codes may be returned: | |
52 // - PP_ERROR_BADRESOURCE if instance is invalid. | |
53 // - PP_ERROR_BADARGUMENT if attribute is invalid or value is NULL | |
54 int32_t (*GetAttribMaxValue)(PP_Resource instance, | |
55 int32_t attribute, int32_t* value); | |
56 | |
57 // Creates and initializes a rendering context and returns a handle to it. | |
58 // The returned context is off-screen to start with. It must be attached to | |
59 // a plugin instance using PPB_Instance::BindGraphics to draw on the web page. | |
60 // | |
61 // If share_context is not NULL, then all shareable data, as defined | |
62 // by the client API (note that for OpenGL and OpenGL ES, shareable data | |
63 // excludes texture objects named 0) will be shared by share_context, all | |
64 // other contexts share_context already shares with, and the newly created | |
65 // context. An arbitrary number of PPB_Graphics3D_Dev can share data in | |
66 // this fashion. | |
67 // | |
68 // attrib_list specifies a list of attributes for the context. It is a list | |
69 // of attribute name-value pairs in which each attribute is immediately | |
70 // followed by the corresponding desired value. The list is terminated with | |
71 // PP_GRAPHICS3DATTRIB_NONE. The attrib_list may be NULL or empty | |
72 // (first attribute is PP_GRAPHICS3DATTRIB_NONE). If an attribute is not | |
73 // specified in attrib_list, then the default value is used (it is said to | |
74 // be specified implicitly). | |
75 // | |
76 // Attributes for the context are chosen according to an attribute-specific | |
77 // criteria. Attributes can be classified into two categories: | |
78 // - AtLeast: The attribute value in the returned context meets or exceeds | |
79 // the value specified in attrib_list. | |
80 // - Exact: The attribute value in the returned context is equal to | |
81 // the value specified in attrib_list. | |
82 // | |
83 // Attributes that can be specified in attrib_list include: | |
84 // - PP_GRAPHICS3DATTRIB_ALPHA_SIZE: Category: AtLeast Default: 0. | |
85 // - PP_GRAPHICS3DATTRIB_BLUE_SIZE: Category: AtLeast Default: 0. | |
86 // - PP_GRAPHICS3DATTRIB_GREEN_SIZE: Category: AtLeast Default: 0. | |
87 // - PP_GRAPHICS3DATTRIB_RED_SIZE: Category: AtLeast Default: 0. | |
88 // - PP_GRAPHICS3DATTRIB_DEPTH_SIZE: Category: AtLeast Default: 0. | |
89 // - PP_GRAPHICS3DATTRIB_STENCIL_SIZE: Category: AtLeast Default: 0. | |
90 // - PP_GRAPHICS3DATTRIB_SAMPLES: Category: AtLeast Default: 0. | |
91 // - PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS: Category: AtLeast Default: 0. | |
92 // - PP_GRAPHICS3DATTRIB_WIDTH: Category: Exact Default: 0. | |
93 // - PP_GRAPHICS3DATTRIB_HEIGHT: Category: Exact Default: 0. | |
94 // - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR: | |
95 // Category: Exact Default: Implementation defined. | |
96 // | |
97 // On failure NULL resource is returned. | |
98 PP_Resource (*Create)(PP_Instance instance, | |
99 PP_Resource share_context, | |
100 const int32_t* attrib_list); | |
101 | |
102 // Returns PP_TRUE if the given resource is a valid PPB_Graphics3D_Dev, | |
103 // PP_FALSE if it is an invalid resource or is a resource of another type. | |
104 PP_Bool (*IsGraphics3D)(PP_Resource resource); | |
105 | |
106 // Retrieves the value for each attribute in attrib_list. The list | |
107 // has the same structure as described for PPB_Graphics3D_Dev::Create. | |
108 // It is both input and output structure for this function. | |
109 // | |
110 // All attributes specified in PPB_Graphics3D_Dev::Create can be queried for. | |
111 // On failure the following error codes may be returned: | |
112 // - PP_ERROR_BADRESOURCE if context is invalid. | |
113 // - PP_ERROR_BADARGUMENT if attrib_list is NULL or any attribute in the | |
114 // attrib_list is not a valid attribute. | |
115 // | |
116 // Example usage: To get the values for rgb bits in the color buffer, | |
117 // this function must be called as following: | |
118 // int attrib_list[] = {PP_GRAPHICS3DATTRIB_RED_SIZE, 0, | |
119 // PP_GRAPHICS3DATTRIB_GREEN_SIZE, 0, | |
120 // PP_GRAPHICS3DATTRIB_BLUE_SIZE, 0, | |
121 // PP_GRAPHICS3DATTRIB_NONE}; | |
122 // GetAttribs(context, attrib_list); | |
123 // int red_bits = attrib_list[1]; | |
124 // int green_bits = attrib_list[3]; | |
125 // int blue_bits = attrib_list[5]; | |
126 int32_t (*GetAttribs)(PP_Resource context, int32_t* attrib_list); | |
127 | |
128 // Sets the values for each attribute in attrib_list. The list | |
129 // has the same structure as described for PPB_Graphics3D_Dev::Create. | |
130 // | |
131 // Attributes that can be specified are: | |
132 // - PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR | |
133 // | |
134 // On failure the following error codes may be returned: | |
135 // - PP_ERROR_BADRESOURCE if context is invalid. | |
136 // - PP_ERROR_BADARGUMENT if attrib_list is NULL or any attribute in the | |
137 // attrib_list is not a valid attribute. | |
138 int32_t (*SetAttribs)(PP_Resource context, int32_t* attrib_list); | |
139 | |
140 // The recoverable error conditions that have no side effect are | |
141 // detected and returned immediately by all functions in this interface. | |
142 // In addition the implementation may get into a fatal state while | |
143 // processing a command. In this case the application must detroy the | |
144 // context and reinitialize client API state and objects to continue | |
145 // rendering. | |
146 // | |
147 // Note that the same error code is also returned in the SwapBuffers callback. | |
148 // It is recommended to handle error in the SwapBuffers callback because | |
149 // GetError is synchronous. This function may be useful in rare cases where | |
150 // drawing a frame is expensive and you want to verify the result of | |
151 // ResizeBuffers before attemptimg to draw a frame. | |
152 // | |
153 // The following error codes may be returned: | |
154 // - PP_ERROR_NOMEMORY | |
155 // - PP_ERROR_CONTEXT_LOST | |
156 int32_t (*GetError)(PP_Resource context); | |
157 | |
158 // Resizes the backing surface for context. | |
159 // | |
160 // On failure the following error codes may be returned: | |
161 // - PP_ERROR_BADRESOURCE if context is invalid. | |
162 // - PP_ERROR_BADARGUMENT if the value specified for width or height | |
163 // is less than zero. | |
164 // | |
165 // If the surface could not be resized due to insufficient resources, | |
166 // PP_ERROR_NOMEMORY error is returned on the next SwapBuffers callback. | |
167 int32_t (*ResizeBuffers)(PP_Resource context, | |
168 int32_t width, int32_t height); | |
169 | |
170 // Makes the contents of the color buffer available for compositing. | |
171 // This function has no effect on off-screen surfaces - ones not bound | |
172 // to any plugin instance. The contents of ancillary buffers are always | |
173 // undefined after calling SwapBuffers. The contents of the color buffer are | |
174 // undefined if the value of the PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR attribute | |
175 // of context is not PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED. | |
176 // | |
177 // SwapBuffers runs in asynchronous mode. Specify a callback function and the | |
178 // argument for that callback function. The callback function will be executed | |
179 // on the calling thread after the color buffer has been composited with | |
180 // rest of the html page. While you are waiting for a SwapBuffers callback, | |
181 // additional calls to SwapBuffers will fail. | |
182 // | |
183 // Because the callback is executed (or thread unblocked) only when the | |
184 // plugin's current state is actually on the screen, this function provides a | |
185 // way to rate limit animations. By waiting until the image is on the screen | |
186 // before painting the next frame, you can ensure you're not generating | |
187 // updates faster than the screen can be updated. | |
188 // | |
189 // SwapBuffers performs an implicit flush operation on context. | |
190 // If the context gets into an unrecoverable error condition while | |
191 // processing a command, the error code will be returned as the argument | |
192 // for the callback. The callback may return the following error codes: | |
193 // - PP_ERROR_NOMEMORY | |
194 // - PP_ERROR_CONTEXT_LOST | |
195 // Note that the same error code may also be obtained by calling GetError. | |
196 // | |
197 // On failure SwapBuffers may return the following error codes: | |
198 // - PP_ERROR_BADRESOURCE if context is invalid. | |
199 // - PP_ERROR_BADARGUMENT if callback is invalid. | |
200 int32_t (*SwapBuffers)(PP_Resource context, | |
201 struct PP_CompletionCallback callback); | |
202 }; | |
203 | |
204 #endif /* PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ */ | |
OLD | NEW |