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