OLD | NEW |
1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 #ifndef PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ | 5 #ifndef PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ |
6 #define PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ | 6 #define PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ |
7 | 7 |
8 #include "ppapi/c/pp_bool.h" | 8 #include "ppapi/c/dev/pp_graphics_3d_dev.h" |
9 #include "ppapi/c/pp_instance.h" | |
10 #include "ppapi/c/pp_module.h" | |
11 #include "ppapi/c/pp_resource.h" | |
12 #include "ppapi/c/pp_stdint.h" | |
13 | 9 |
14 // Example usage from plugin code: | 10 // Example usage from plugin code: |
15 // | 11 // |
16 // PP_Resource context = device->Create(module, config, contextAttribList); | 12 // // Setup. |
17 // CHECK(context); | 13 // PP_Resource context, surface; |
| 14 // int32_t config, num_config; |
| 15 // g3d->GetConfigs(&config, 1, &num_config); |
| 16 // int32_t attribs[] = {PP_GRAPHICS_3D_SURFACE_WIDTH, 800, |
| 17 // PP_GRAPHICS_3D_SURFACE_HEIGHT, 800, |
| 18 // PP_GRAPHICS_3D_ATTRIB_NONE}; |
| 19 // c3d->Create(instance, config, NULL, NULL, &context); |
| 20 // s3d->Create(instance, config, attribs, &surface); |
| 21 // c3d->BindSurfaces(context, surface, surface); |
| 22 // inst->BindGraphics(instance, surface); |
18 // | 23 // |
19 // // Present one frame. | 24 // // Present one frame. |
20 // CHECK(device->MakeCurrent(context)); | 25 // gles2->Clear(context, GL_COLOR_BUFFER); |
21 // glClear(GL_COLOR_BUFFER); | 26 // c3d->SwapBuffers(context); |
22 // CHECK(device->MakeCurrent(NULL)); | |
23 // CHECK(device->SwapBuffers(context)); | |
24 // | 27 // |
25 // // Shutdown. | 28 // // Shutdown. |
26 // core->ReleaseResource(context); | 29 // core->ReleaseResource(context); |
| 30 // core->ReleaseResource(surface); |
27 | 31 |
28 #define PPB_GRAPHICS_3D_DEV_INTERFACE "PPB_Graphics3D(Dev);0.2" | 32 #define PPB_GRAPHICS_3D_DEV_INTERFACE "PPB_Graphics3D(Dev);0.2" |
29 | 33 |
30 // These are the same error codes as used by EGL. | 34 struct PPB_Graphics3D_Dev { |
31 enum { | 35 // TODO(alokp): Do these functions need module argument. |
32 PP_GRAPHICS_3D_ERROR_SUCCESS = 0x3000, | |
33 PP_GRAPHICS_3D_ERROR_NOT_INITIALIZED = 0x3001, | |
34 PP_GRAOHICS_3D_ERROR_BAD_CONTEXT = 0x3006, | |
35 PP_GRAPHICS_3D_ERROR_BAD_PARAMETER = 0x300C, | |
36 PP_GRAPHICS_3D_ERROR_CONTEXT_LOST = 0x300E | |
37 }; | |
38 | 36 |
39 // QueryString targets, matching EGL ones. | 37 // Retrieves the list of all available PP_Config3D_Devs. |
40 enum { | 38 // configs is a pointer to a buffer containing config_size elements. |
41 EGL_VENDOR = 0x3053, | 39 // On success, PP_OK is returned. The number of configurations is returned |
42 EGL_VERSION = 0x3054, | 40 // in num_config, and elements 0 through num_config - 1 of configs are filled |
43 EGL_EXTENSIONS = 0x3055, | 41 // in with valid PP_Config3D_Devs. No more than config_size |
44 EGL_CLIENT_APIS = 0x308D | 42 // PP_Config3D_Devs will be returned even if more are available. |
45 }; | 43 // However, if GetConfigs is called with configs = NULL, then no |
46 | 44 // configurations are returned, but the total number of configurations |
47 struct PPB_Graphics3D_Dev { | 45 // available will be returned in num_config. |
48 PP_Bool (*IsGraphics3D)(PP_Resource resource); | 46 // |
49 | 47 // On failure following error codes are returned: |
50 // EGL-like configuration ---------------------------------------------------- | 48 // PP_ERROR_BADARGUMENT if num_config is NULL. |
51 PP_Bool (*GetConfigs)(int32_t* configs, | 49 // PP_ERROR_FAILED for everything else. |
| 50 int32_t (*GetConfigs)(PP_Config3D_Dev* configs, |
52 int32_t config_size, | 51 int32_t config_size, |
53 int32_t* num_config); | 52 int32_t* num_config); |
54 | 53 |
55 PP_Bool (*ChooseConfig)(const int32_t* attrib_list, | 54 // Retrieves the values for each attribute in attrib_list. |
56 int32_t* configs, | 55 // attrib_list is a list of attribute name-value pairs terminated with |
57 int32_t config_size, | 56 // PP_GRAPHICS3DCONFIGATTRIB_NONE. It is both input and output structure |
58 int32_t* num_config); | 57 // for this function. |
| 58 // |
| 59 // On success PP_OK is returned and attrib_list is populated with |
| 60 // values of the attributes specified in attrib_list. |
| 61 // On failure following error codes are returned: |
| 62 // PP_GRAPHICS3DERROR_BAD_CONFIG if config is not valid |
| 63 // PP_ERROR_BADARGUMENT if attrib_list is NULL or malformed |
| 64 // PP_GRAPHICS3DERROR_BAD_ATTRIBUTE if any of the attributes in the |
| 65 // attrib_list is not recognized. |
| 66 // |
| 67 // Example usage: To get the values for rgb bits in the color buffer, |
| 68 // this function must be called as following: |
| 69 // int attrib_list[] = {PP_GRAPHICS3DCONFIGATTRIB_RED_SIZE, 0, |
| 70 // PP_GRAPHICS3DCONFIGATTRIB_GREEN_SIZE, 0, |
| 71 // PP_GRAPHICS3DCONFIGATTRIB_BLUE_SIZE, 0, |
| 72 // PP_GRAPHICS3DCONFIGATTRIB_NONE}; |
| 73 // GetConfigAttribs(config, attrib_list); |
| 74 // int red_bits = attrib_list[1]; |
| 75 // int green_bits = attrib_list[3]; |
| 76 // int blue_bits = attrib_list[5]; |
| 77 int32_t (*GetConfigAttribs)(PP_Config3D_Dev config, |
| 78 int32_t* attrib_list); |
59 | 79 |
60 // TODO(apatrick): What to do if the browser window is moved to | 80 // Returns a string describing some aspect of the Graphics3D implementation. |
61 // another display? Do the configs potentially change? | 81 // name may be one of: |
62 PP_Bool (*GetConfigAttrib)(int32_t config, int32_t attribute, int32_t* value); | 82 // - PP_GRAPHICS3DSTRING_CLIENT_APIS: describes which client rendering APIs |
63 | 83 // are supported. It is zero-terminated and contains a space-separated list |
64 const char* (*QueryString)(int32_t name); | 84 // of API names, which must include at least one of "OpenGL" or "OpenGL_ES". |
65 // --------------------------------------------------------------------------- | 85 // - PP_GRAPHICS3DSTRING_EXTENSIONS: describes which extensions are supported |
66 | 86 // by the implementation. The string is zero-terminated and contains a |
67 | 87 // space-separated list of extension names; extension names themselves do |
68 // Create a reference counted 3D context. Releasing a context while it is | 88 // not contain spaces. If there are no extensions, then the empty string is |
69 // current automatically sets the current context to NULL. This is only true | 89 // returned. |
70 // for the releasing thread. Releasing a context while it is current on | 90 // - PP_GRAPHICS3DSTRING_VENDOR: Implementation dependent. |
71 // another thread leads to undefined behavior. | 91 // - PP_GRAPHICS3DSTRING_VERSION: The format of the string is: |
72 PP_Resource (*CreateContext)(PP_Instance instance, | 92 // <major version.minor version><space><vendor specific info> |
73 int32_t config, | 93 // Both the major and minor portions of the version number are numeric. |
74 int32_t share_context, | 94 // The vendor-specific information is optional; if present, its format and |
75 const int32_t* attrib_list); | 95 // contents are implementation specific. |
76 | 96 // On failure, PP_VARTYPE_UNDEFINED is returned. |
77 // Get the address of any GL functions, whether core or part of an extension. | 97 struct PP_Var (*GetString)(int32_t name); |
78 // Any thread. | |
79 void* (*GetProcAddress)(const char* name); | |
80 | |
81 // Snapshots the rendered frame and makes it available for composition with | |
82 // the rest of the page. The alpha channel is used for translucency effects. | |
83 // One means fully opaque. Zero means fully transparent. Any thread. | |
84 // TODO(apatrick): premultiplied alpha or linear alpha? Premultiplied alpha is | |
85 // better for correct alpha blending effect. Most existing OpenGL code assumes | |
86 // linear. I could convert from linear to premultiplied during the copy from | |
87 // back-buffer to offscreen "front-buffer". | |
88 PP_Bool (*SwapBuffers)(PP_Resource context); | |
89 | |
90 // Returns the current error for this thread. This is not associated with a | |
91 // particular context. It is distinct from the GL error returned by | |
92 // glGetError. | |
93 uint32_t (*GetError)(); | |
94 }; | 98 }; |
95 | 99 |
96 #endif /* PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ */ | 100 #endif /* PPAPI_C_DEV_PPB_GRAPHICS_3D_DEV_H_ */ |
97 | 101 |
OLD | NEW |