OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2012 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 |
| 6 /** |
| 7 * Defines the <code>PPB_Graphics3D</code> struct representing a 3D graphics |
| 8 * context within the browser. |
| 9 */ |
| 10 |
| 11 label Chrome { |
| 12 M15 = 1.0 |
| 13 }; |
| 14 |
| 15 #inline c |
| 16 /* Add 3D graphics enums */ |
| 17 #include "ppapi/c/pp_graphics_3d.h" |
| 18 #endinl |
| 19 |
| 20 /** |
| 21 * <code>PPB_Graphics3D</code> defines the interface for a 3D graphics context. |
| 22 * <strong>Example usage from plugin code:</strong> |
| 23 * |
| 24 * <strong>Setup:</strong> |
| 25 * <code> |
| 26 * PP_Resource context; |
| 27 * int32_t attribs[] = {PP_GRAPHICS3DATTRIB_WIDTH, 800, |
| 28 * PP_GRAPHICS3DATTRIB_HEIGHT, 800, |
| 29 * PP_GRAPHICS3DATTRIB_NONE}; |
| 30 * context = g3d->Create(instance, attribs, &context); |
| 31 * inst->BindGraphics(instance, context); |
| 32 * </code> |
| 33 * |
| 34 * <strong>Present one frame:</strong> |
| 35 * <code> |
| 36 * gles2->Clear(context, GL_COLOR_BUFFER); |
| 37 * g3d->SwapBuffers(context); |
| 38 * </code> |
| 39 * |
| 40 * <strong>Shutdown:</strong> |
| 41 * <code> |
| 42 * core->ReleaseResource(context); |
| 43 * </code> |
| 44 */ |
| 45 [macro="PPB_GRAPHICS_3D_INTERFACE"] |
| 46 interface PPB_Graphics3D { |
| 47 /** |
| 48 * GetAttribMaxValue() retrieves the maximum supported value for the |
| 49 * given attribute. This function may be used to check if a particular |
| 50 * attribute value is supported before attempting to create a context. |
| 51 * |
| 52 * @param[in] instance The module instance. |
| 53 * @param[in] attribute The attribute for which maximum value is queried. |
| 54 * Attributes that can be queried for include: |
| 55 * - <code>PP_GRAPHICS3DATTRIB_ALPHA_SIZE</code> |
| 56 * - <code>PP_GRAPHICS3DATTRIB_BLUE_SIZE</code> |
| 57 * - <code>PP_GRAPHICS3DATTRIB_GREEN_SIZE</code> |
| 58 * - <code>PP_GRAPHICS3DATTRIB_RED_SIZE</code> |
| 59 * - <code>PP_GRAPHICS3DATTRIB_DEPTH_SIZE</code> |
| 60 * - <code>PP_GRAPHICS3DATTRIB_STENCIL_SIZE</code> |
| 61 * - <code>PP_GRAPHICS3DATTRIB_SAMPLES</code> |
| 62 * - <code>PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS</code> |
| 63 * - <code>PP_GRAPHICS3DATTRIB_WIDTH</code> |
| 64 * - <code>PP_GRAPHICS3DATTRIB_HEIGHT</code> |
| 65 * @param[out] value The maximum supported value for <code>attribute</code> |
| 66 * |
| 67 * @return Returns <code>PP_TRUE</code> on success or the following on error: |
| 68 * - <code>PP_ERROR_BADRESOURCE</code> if <code>instance</code> is invalid |
| 69 * - <code>PP_ERROR_BADARGUMENT</code> if <code>attribute</code> is invalid |
| 70 * or <code>value</code> is 0 |
| 71 */ |
| 72 int32_t GetAttribMaxValue( |
| 73 [in] PP_Resource instance, |
| 74 [in] int32_t attribute, |
| 75 [out] int32_t value); |
| 76 |
| 77 /** |
| 78 * Create() creates and initializes a 3D rendering context. |
| 79 * The returned context is off-screen to start with. It must be attached to |
| 80 * a plugin instance using <code>PPB_Instance::BindGraphics</code> to draw |
| 81 * on the web page. |
| 82 * |
| 83 * @param[in] instance The module instance. |
| 84 * |
| 85 * @param[in] share_context The 3D context with which the created context |
| 86 * would share resources. If <code>share_context</code> is not 0, then all |
| 87 * shareable data, as defined by the client API (note that for OpenGL and |
| 88 * OpenGL ES, shareable data excludes texture objects named 0) will be shared |
| 89 * by <code>share_context<code>, all other contexts <code>share_context</code> |
| 90 * already shares with, and the newly created context. An arbitrary number of |
| 91 * <code>PPB_Graphics3D</code> can share data in this fashion. |
| 92 * |
| 93 * @param[out] attrib_list specifies a list of attributes for the context. |
| 94 * It is a list of attribute name-value pairs in which each attribute is |
| 95 * immediately followed by the corresponding desired value. The list is |
| 96 * terminated with <code>PP_GRAPHICS3DATTRIB_NONE</code>. |
| 97 * The <code>attrib_list<code> may be 0 or empty (first attribute is |
| 98 * <code>PP_GRAPHICS3DATTRIB_NONE</code>). If an attribute is not |
| 99 * specified in <code>attrib_list</code>, then the default value is used |
| 100 * (it is said to be specified implicitly). |
| 101 * Attributes for the context are chosen according to an attribute-specific |
| 102 * criteria. Attributes can be classified into two categories: |
| 103 * - AtLeast: The attribute value in the returned context meets or exceeds |
| 104 * the value specified in <code>attrib_list</code>. |
| 105 * - Exact: The attribute value in the returned context is equal to |
| 106 * the value specified in <code>attrib_list</code>. |
| 107 * |
| 108 * Attributes that can be specified in <code>attrib_list</code> include: |
| 109 * - <code>PP_GRAPHICS3DATTRIB_ALPHA_SIZE</code>: |
| 110 * Category: AtLeast Default: 0. |
| 111 * - <code>PP_GRAPHICS3DATTRIB_BLUE_SIZE</code>: |
| 112 * Category: AtLeast Default: 0. |
| 113 * - <code>PP_GRAPHICS3DATTRIB_GREEN_SIZE</code>: |
| 114 * Category: AtLeast Default: 0. |
| 115 * - <code>PP_GRAPHICS3DATTRIB_RED_SIZE</code>: |
| 116 * Category: AtLeast Default: 0. |
| 117 * - <code>PP_GRAPHICS3DATTRIB_DEPTH_SIZE</code>: |
| 118 * Category: AtLeast Default: 0. |
| 119 * - <code>PP_GRAPHICS3DATTRIB_STENCIL_SIZE</code>: |
| 120 * Category: AtLeast Default: 0. |
| 121 * - <code>PP_GRAPHICS3DATTRIB_SAMPLES</code>: |
| 122 * Category: AtLeast Default: 0. |
| 123 * - <code>PP_GRAPHICS3DATTRIB_SAMPLE_BUFFERS</code>: |
| 124 * Category: AtLeast Default: 0. |
| 125 * - <code>PP_GRAPHICS3DATTRIB_WIDTH</code>: |
| 126 * Category: Exact Default: 0. |
| 127 * - <code>PP_GRAPHICS3DATTRIB_HEIGHT</code>: |
| 128 * Category: Exact Default: 0. |
| 129 * - <code>PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR</code>: |
| 130 * Category: Exact Default: Implementation defined. |
| 131 * |
| 132 * @return A <code>PP_Resource</code> containing the 3D graphics context if |
| 133 * successful or 0 if unsuccessful. |
| 134 */ |
| 135 PP_Resource Create( |
| 136 [in] PP_Instance instance, |
| 137 [in] PP_Resource share_context, |
| 138 [in] int32_t[] attrib_list); |
| 139 |
| 140 /** |
| 141 * IsGraphics3D() determines if the given resource is a valid |
| 142 * <code>Graphics3D</code> context. |
| 143 * |
| 144 * @param[in] resource A <code>Graphics3D</code> context resource. |
| 145 * |
| 146 * @return PP_TRUE if the given resource is a valid <code>Graphics3D</code>, |
| 147 * <code>PP_FALSE</code> if it is an invalid resource or is a resource of |
| 148 * another type. |
| 149 */ |
| 150 PP_Bool IsGraphics3D( |
| 151 [in] PP_Resource resource); |
| 152 |
| 153 /** |
| 154 * GetAttribs() retrieves the value for each attribute in |
| 155 * <code>attrib_list</code>. |
| 156 * |
| 157 * @param[in] context The 3D graphics context. |
| 158 * @param[in,out] attrib_list The list of attributes that are queried. |
| 159 * <code>attrib_list</code> has the same structure as described for |
| 160 * <code>PPB_Graphics3D::Create</code>. It is both input and output |
| 161 * structure for this function. All attributes specified in |
| 162 * <code>PPB_Graphics3D::Create</code> can be queried for. |
| 163 * |
| 164 * @return Returns <code>PP_OK</code> on success or: |
| 165 * - <code>PP_ERROR_BADRESOURCE</code> if context is invalid |
| 166 * - <code>PP_ERROR_BADARGUMENT</code> if attrib_list is 0 or any attribute |
| 167 * in the <code>attrib_list</code> is not a valid attribute. |
| 168 * |
| 169 * <strong>Example usage:</strong> To get the values for rgb bits in the |
| 170 * color buffer, this function must be called as following: |
| 171 * <code> |
| 172 * int attrib_list[] = {PP_GRAPHICS3DATTRIB_RED_SIZE, 0, |
| 173 * PP_GRAPHICS3DATTRIB_GREEN_SIZE, 0, |
| 174 * PP_GRAPHICS3DATTRIB_BLUE_SIZE, 0, |
| 175 * PP_GRAPHICS3DATTRIB_NONE}; |
| 176 * GetAttribs(context, attrib_list); |
| 177 * int red_bits = attrib_list[1]; |
| 178 * int green_bits = attrib_list[3]; |
| 179 * int blue_bits = attrib_list[5]; |
| 180 * </code> |
| 181 */ |
| 182 int32_t GetAttribs( |
| 183 [in] PP_Resource context, |
| 184 [inout] int32_t[] attrib_list); |
| 185 |
| 186 /** |
| 187 * SetAttribs() sets the values for each attribute in |
| 188 * <code>attrib_list</code>. |
| 189 * |
| 190 * @param[in] context The 3D graphics context. |
| 191 * @param[in] attrib_list The list of attributes whose values need to be set. |
| 192 * <code>attrib_list</code> has the same structure as described for |
| 193 * <code>PPB_Graphics3D::Create</code>. |
| 194 * Attributes that can be specified are: |
| 195 * - <code>PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR</code> |
| 196 * |
| 197 * @return Returns <code>PP_OK</code> on success or: |
| 198 * - <code>PP_ERROR_BADRESOURCE</code> if <code>context</code> is invalid. |
| 199 * - <code>PP_ERROR_BADARGUMENT</code> if <code>attrib_list</code> is 0 or |
| 200 * any attribute in the <code>attrib_list</code> is not a valid attribute. |
| 201 */ |
| 202 int32_t SetAttribs( |
| 203 [in] PP_Resource context, |
| 204 [in] int32_t[] attrib_list); |
| 205 |
| 206 /** |
| 207 * GetError() returns the current state of the given 3D context. |
| 208 * |
| 209 * The recoverable error conditions that have no side effect are |
| 210 * detected and returned immediately by all functions in this interface. |
| 211 * In addition the implementation may get into a fatal state while |
| 212 * processing a command. In this case the application must detroy the |
| 213 * context and reinitialize client API state and objects to continue |
| 214 * rendering. |
| 215 * |
| 216 * Note that the same error code is also returned in the SwapBuffers callback. |
| 217 * It is recommended to handle error in the SwapBuffers callback because |
| 218 * GetError is synchronous. This function may be useful in rare cases where |
| 219 * drawing a frame is expensive and you want to verify the result of |
| 220 * ResizeBuffers before attemptimg to draw a frame. |
| 221 * |
| 222 * @param[in] The 3D graphics context. |
| 223 * @return Returns: |
| 224 * - <code>PP_OK</code> if no error |
| 225 * - <code>PP_ERROR_NOMEMORY</code> |
| 226 * - <code>PP_ERROR_CONTEXT_LOST</code> |
| 227 */ |
| 228 int32_t GetError( |
| 229 [in] PP_Resource context); |
| 230 |
| 231 /** |
| 232 * ResizeBuffers() resizes the backing surface for context. |
| 233 * |
| 234 * If the surface could not be resized due to insufficient resources, |
| 235 * <code>PP_ERROR_NOMEMORY</code> error is returned on the next |
| 236 * <code>SwapBuffers</code> callback. |
| 237 * |
| 238 * @param[in] context The 3D graphics context. |
| 239 * @param[in] width The width of the backing surface. |
| 240 * @param[in] height The height of the backing surface. |
| 241 * @return Returns <code>PP_OK</code> on success or: |
| 242 * - <code>PP_ERROR_BADRESOURCE</code> if context is invalid. |
| 243 * - <code>PP_ERROR_BADARGUMENT</code> if the value specified for |
| 244 * <code>width</code> or <code>height</code> is less than zero. |
| 245 */ |
| 246 int32_t ResizeBuffers( |
| 247 [in] PP_Resource context, |
| 248 [in] int32_t width, |
| 249 [in] int32_t height); |
| 250 |
| 251 /** |
| 252 * SwapBuffers() makes the contents of the color buffer available for |
| 253 * compositing. This function has no effect on off-screen surfaces - ones not |
| 254 * bound to any plugin instance. The contents of ancillary buffers are always |
| 255 * undefined after calling <code>SwapBuffers</code>. The contents of the color |
| 256 * buffer are undefined if the value of the |
| 257 * <code>PP_GRAPHICS3DATTRIB_SWAP_BEHAVIOR</code> attribute of context is not |
| 258 * <code>PP_GRAPHICS3DATTRIB_BUFFER_PRESERVED</code>. |
| 259 * |
| 260 * <code>SwapBuffers</code> runs in asynchronous mode. Specify a callback |
| 261 * function and the argument for that callback function. The callback function |
| 262 * will be executed on the calling thread after the color buffer has been |
| 263 * composited with rest of the html page. While you are waiting for a |
| 264 * SwapBuffers callback, additional calls to SwapBuffers will fail. |
| 265 * |
| 266 * Because the callback is executed (or thread unblocked) only when the |
| 267 * plugin's current state is actually on the screen, this function provides a |
| 268 * way to rate limit animations. By waiting until the image is on the screen |
| 269 * before painting the next frame, you can ensure you're not generating |
| 270 * updates faster than the screen can be updated. |
| 271 * |
| 272 * SwapBuffers performs an implicit flush operation on context. |
| 273 * If the context gets into an unrecoverable error condition while |
| 274 * processing a command, the error code will be returned as the argument |
| 275 * for the callback. The callback may return the following error codes: |
| 276 * - <code>PP_ERROR_NOMEMORY</code> |
| 277 * - <code>PP_ERROR_CONTEXT_LOST</code> |
| 278 * Note that the same error code may also be obtained by calling GetError. |
| 279 * |
| 280 * @param[in] context The 3D graphics context. |
| 281 * @param[in] callback The callback that will executed when |
| 282 * <code>SwapBuffers</code> completes. |
| 283 * |
| 284 * @return Returns PP_OK on success or: |
| 285 * - <code>PP_ERROR_BADRESOURCE</code> if context is invalid. |
| 286 * - <code>PP_ERROR_BADARGUMENT</code> if callback is invalid. |
| 287 * |
| 288 */ |
| 289 int32_t SwapBuffers( |
| 290 [in] PP_Resource context, |
| 291 [in] PP_CompletionCallback callback); |
| 292 }; |
| 293 |
OLD | NEW |