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/cpp/common.h" |
8 #include "ppapi/cpp/instance.h" | 8 #include "ppapi/cpp/instance.h" |
9 #include "ppapi/cpp/resource.h" | 9 #include "ppapi/cpp/resource.h" |
10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
11 #include "ppapi/cpp/module_impl.h" | 11 #include "ppapi/cpp/module_impl.h" |
12 | 12 |
13 extern "C" { | |
14 const PPB_OpenGLES_Dev* pepper_opengl_interface = NULL; | |
15 } | |
16 | |
17 namespace pp { | 13 namespace pp { |
18 | 14 |
19 namespace { | 15 namespace { |
20 | 16 |
21 template <> const char* interface_name<PPB_Graphics3D_Dev>() { | 17 template <> const char* interface_name<PPB_Graphics3D_Dev>() { |
22 return PPB_GRAPHICS_3D_DEV_INTERFACE; | 18 return PPB_GRAPHICS_3D_DEV_INTERFACE; |
23 } | 19 } |
24 | 20 |
25 template <> const char* interface_name<PPB_OpenGLES_Dev>() { | 21 template <> const char* interface_name<PPB_OpenGLES2_Dev>() { |
26 return PPB_OPENGLES_DEV_INTERFACE; | 22 return PPB_OPENGLES2_DEV_INTERFACE; |
27 } | |
28 | |
29 inline void InitializeOpenGLCInterface() { | |
30 if (!pepper_opengl_interface) | |
31 pepper_opengl_interface = get_interface<PPB_OpenGLES_Dev>(); | |
32 } | 23 } |
33 | 24 |
34 } // namespace | 25 } // namespace |
35 | 26 |
36 // static | 27 // static |
37 bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size, | 28 bool Graphics3D_Dev::GetConfigs(int32_t *configs, int32_t config_size, |
38 int32_t *num_config) { | 29 int32_t *num_config) { |
39 if (has_interface<PPB_Graphics3D_Dev>()) { | 30 if (has_interface<PPB_Graphics3D_Dev>()) { |
40 return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->GetConfigs( | 31 return PPBoolToBool(get_interface<PPB_Graphics3D_Dev>()->GetConfigs( |
41 configs, config_size, num_config)); | 32 configs, config_size, num_config)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 return NULL; | 68 return NULL; |
78 } | 69 } |
79 | 70 |
80 Graphics3D_Dev Graphics3D_Dev::FromResource(PP_Resource resource_id) { | 71 Graphics3D_Dev Graphics3D_Dev::FromResource(PP_Resource resource_id) { |
81 if (has_interface<PPB_Graphics3D_Dev>() && | 72 if (has_interface<PPB_Graphics3D_Dev>() && |
82 get_interface<PPB_Graphics3D_Dev>()->IsGraphics3D(resource_id)) | 73 get_interface<PPB_Graphics3D_Dev>()->IsGraphics3D(resource_id)) |
83 return Graphics3D_Dev(resource_id); | 74 return Graphics3D_Dev(resource_id); |
84 return Graphics3D_Dev(); | 75 return Graphics3D_Dev(); |
85 } | 76 } |
86 | 77 |
87 bool Graphics3D_Dev::ResetCurrent() { | |
88 return has_interface<PPB_Graphics3D_Dev>() && | |
89 get_interface<PPB_Graphics3D_Dev>()->MakeCurent(0); | |
90 } | |
91 | |
92 Graphics3D_Dev Graphics3D_Dev::GetCurrentContext() { | |
93 if (has_interface<PPB_Graphics3D_Dev>()) | |
94 return FromResource( | |
95 get_interface<PPB_Graphics3D_Dev>()->GetCurrentContext()); | |
96 return Graphics3D_Dev(); | |
97 } | |
98 | |
99 uint32_t Graphics3D_Dev::GetError() { | 78 uint32_t Graphics3D_Dev::GetError() { |
100 if (has_interface<PPB_Graphics3D_Dev>()) | 79 if (has_interface<PPB_Graphics3D_Dev>()) |
101 return get_interface<PPB_Graphics3D_Dev>()->GetError(); | 80 return get_interface<PPB_Graphics3D_Dev>()->GetError(); |
102 return PP_GRAPHICS_3D_ERROR_NOT_INITIALIZED; | 81 return PP_GRAPHICS_3D_ERROR_NOT_INITIALIZED; |
103 } | 82 } |
104 | 83 |
105 const PPB_OpenGLES_Dev* Graphics3D_Dev::GetImplementation() { | 84 const PPB_OpenGLES2_Dev* Graphics3D_Dev::GetImplementation() { |
106 return get_interface<PPB_OpenGLES_Dev>(); | 85 return get_interface<PPB_OpenGLES2_Dev>(); |
107 } | 86 } |
108 | 87 |
109 Graphics3D_Dev::Graphics3D_Dev(const Instance& instance, | 88 Graphics3D_Dev::Graphics3D_Dev(const Instance& instance, |
110 int32_t config, | 89 int32_t config, |
111 int32_t share_context, | 90 int32_t share_context, |
112 const int32_t* attrib_list) { | 91 const int32_t* attrib_list) { |
113 if (has_interface<PPB_Graphics3D_Dev>() && | 92 if (has_interface<PPB_Graphics3D_Dev>() && |
114 has_interface<PPB_OpenGLES_Dev>()) { | 93 has_interface<PPB_OpenGLES2_Dev>()) { |
115 InitializeOpenGLCInterface(); | |
116 PassRefFromConstructor(get_interface<PPB_Graphics3D_Dev>()->CreateContext( | 94 PassRefFromConstructor(get_interface<PPB_Graphics3D_Dev>()->CreateContext( |
117 instance.pp_instance(), config, share_context, attrib_list)); | 95 instance.pp_instance(), config, share_context, attrib_list)); |
118 } | 96 } |
119 } | 97 } |
120 | 98 |
121 bool Graphics3D_Dev::MakeCurrent() const { | |
122 InitializeOpenGLCInterface(); | |
123 return has_interface<PPB_Graphics3D_Dev>() && | |
124 get_interface<PPB_Graphics3D_Dev>()->MakeCurent(pp_resource()); | |
125 } | |
126 | |
127 bool Graphics3D_Dev::SwapBuffers() const { | 99 bool Graphics3D_Dev::SwapBuffers() const { |
128 return has_interface<PPB_Graphics3D_Dev>() && | 100 return has_interface<PPB_Graphics3D_Dev>() && |
129 get_interface<PPB_Graphics3D_Dev>()->SwapBuffers(pp_resource()); | 101 get_interface<PPB_Graphics3D_Dev>()->SwapBuffers(pp_resource()); |
130 } | 102 } |
131 | 103 |
132 } // namespace pp | 104 } // namespace pp |
OLD | NEW |