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