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 #include "ppapi/cpp/dev/graphics_3d_dev.h" | 5 #include "ppapi/cpp/dev/graphics_3d_dev.h" |
6 | 6 |
7 #include "ppapi/cpp/common.h" | 7 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/cpp/instance.h" | |
9 #include "ppapi/cpp/resource.h" | |
10 #include "ppapi/cpp/module.h" | |
11 #include "ppapi/cpp/module_impl.h" | 8 #include "ppapi/cpp/module_impl.h" |
| 9 #include "ppapi/cpp/var.h" |
12 | 10 |
13 namespace pp { | 11 namespace pp { |
14 | 12 |
15 namespace { | 13 namespace { |
16 | 14 |
17 template <> const char* interface_name<PPB_Graphics3D_Dev>() { | 15 template <> const char* interface_name<PPB_Graphics3D_Dev>() { |
18 return PPB_GRAPHICS_3D_DEV_INTERFACE; | 16 return PPB_GRAPHICS_3D_DEV_INTERFACE; |
19 } | 17 } |
20 | 18 |
21 template <> const char* interface_name<PPB_OpenGLES2_Dev>() { | |
22 return PPB_OPENGLES2_DEV_INTERFACE; | |
23 } | |
24 | |
25 } // namespace | 19 } // namespace |
26 | 20 |
27 // static | 21 // static |
28 bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size, | 22 int32_t Graphics3D_Dev::GetConfigs(int32_t *configs, |
29 int32_t *num_config) { | 23 int32_t config_size, |
30 if (has_interface<PPB_Graphics3D_Dev>()) { | 24 int32_t *num_config) { |
31 return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->GetConfigs( | 25 if (!has_interface<PPB_Graphics3D_Dev>()) |
32 configs, config_size, num_config)); | 26 return PP_ERROR_NOINTERFACE; |
33 } | 27 |
34 return false; | 28 return get_interface<PPB_Graphics3D_Dev>()->GetConfigs( |
| 29 configs, config_size, num_config); |
35 } | 30 } |
36 | 31 |
37 // static | 32 // static |
38 bool Graphics3D_Dev::ChooseConfig(const int32_t *attrib_list, int32_t *configs, | 33 int32_t Graphics3D_Dev::GetConfigAttribs(PP_Config3D_Dev config, |
39 int32_t config_size, int32_t *num_config) { | 34 int32_t* attrib_list) { |
40 if (has_interface<PPB_Graphics3D_Dev>()) { | 35 if (!has_interface<PPB_Graphics3D_Dev>()) |
41 return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->ChooseConfig( | 36 return PP_ERROR_NOINTERFACE; |
42 attrib_list, configs, config_size, num_config)); | 37 |
43 } | 38 return get_interface<PPB_Graphics3D_Dev>()->GetConfigAttribs( |
44 return false; | 39 config, attrib_list); |
45 } | 40 } |
46 | 41 |
47 // static | 42 // static |
48 bool Graphics3D_Dev::GetConfigAttrib(int32_t config, int32_t attribute, | 43 Var Graphics3D_Dev::GetString(int32_t name) { |
49 int32_t *value) { | 44 if (!has_interface<PPB_Graphics3D_Dev>()) |
50 if (has_interface<PPB_Graphics3D_Dev>()) { | 45 return Var(); |
51 return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->GetConfigAttrib( | |
52 config, attribute, value)); | |
53 } | |
54 return false; | |
55 } | |
56 | 46 |
57 // static | 47 return Var(Var::PassRef(), |
58 const char* Graphics3D_Dev::QueryString(int32_t name) { | 48 get_interface<PPB_Graphics3D_Dev>()->GetString(name)); |
59 if (has_interface<PPB_Graphics3D_Dev>()) | |
60 return get_interface<PPB_Graphics3D_Dev>()->QueryString(name); | |
61 return NULL; | |
62 } | |
63 | |
64 // static | |
65 void* Graphics3D_Dev::GetProcAddress(const char* name) { | |
66 if (has_interface<PPB_Graphics3D_Dev>()) | |
67 return get_interface<PPB_Graphics3D_Dev>()->GetProcAddress(name); | |
68 return NULL; | |
69 } | |
70 | |
71 Graphics3D_Dev Graphics3D_Dev::FromResource(PP_Resource resource_id) { | |
72 if (has_interface<PPB_Graphics3D_Dev>() && | |
73 get_interface<PPB_Graphics3D_Dev>()->IsGraphics3D(resource_id)) | |
74 return Graphics3D_Dev(resource_id); | |
75 return Graphics3D_Dev(); | |
76 } | |
77 | |
78 uint32_t Graphics3D_Dev::GetError() { | |
79 if (has_interface<PPB_Graphics3D_Dev>()) | |
80 return get_interface<PPB_Graphics3D_Dev>()->GetError(); | |
81 return PP_GRAPHICS_3D_ERROR_NOT_INITIALIZED; | |
82 } | |
83 | |
84 const PPB_OpenGLES2_Dev* Graphics3D_Dev::GetImplementation() { | |
85 return get_interface<PPB_OpenGLES2_Dev>(); | |
86 } | |
87 | |
88 Graphics3D_Dev::Graphics3D_Dev(const Instance& instance, | |
89 int32_t config, | |
90 int32_t share_context, | |
91 const int32_t* attrib_list) { | |
92 if (has_interface<PPB_Graphics3D_Dev>() && | |
93 has_interface<PPB_OpenGLES2_Dev>()) { | |
94 PassRefFromConstructor(get_interface<PPB_Graphics3D_Dev>()->CreateContext( | |
95 instance.pp_instance(), config, share_context, attrib_list)); | |
96 } | |
97 } | |
98 | |
99 bool Graphics3D_Dev::SwapBuffers() const { | |
100 return has_interface<PPB_Graphics3D_Dev>() && | |
101 get_interface<PPB_Graphics3D_Dev>()->SwapBuffers(pp_resource()); | |
102 } | 49 } |
103 | 50 |
104 } // namespace pp | 51 } // namespace pp |
| 52 |
OLD | NEW |