| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/ppb_graphics_3d_impl.h" | 5 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 bound_to_instance_(false), | 62 bound_to_instance_(false), |
| 63 commit_pending_(false), | 63 commit_pending_(false), |
| 64 weak_ptr_factory_(this) { | 64 weak_ptr_factory_(this) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { | 67 PPB_Graphics3D_Impl::~PPB_Graphics3D_Impl() { |
| 68 DestroyGLES2Impl(); | 68 DestroyGLES2Impl(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // static | 71 // static |
| 72 PP_Bool PPB_Graphics3D_Impl::IsGpuBlacklisted() { | |
| 73 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
| 74 if (command_line) | |
| 75 return PP_FromBool(command_line->HasSwitch(switches::kDisablePepper3d)); | |
| 76 return PP_TRUE; | |
| 77 } | |
| 78 | |
| 79 // static | |
| 80 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, | 72 PP_Resource PPB_Graphics3D_Impl::Create(PP_Instance instance, |
| 81 PP_Resource share_context, | 73 PP_Resource share_context, |
| 82 const int32_t* attrib_list) { | 74 const int32_t* attrib_list) { |
| 83 PPB_Graphics3D_API* share_api = NULL; | 75 PPB_Graphics3D_API* share_api = NULL; |
| 84 if (IsGpuBlacklisted()) | |
| 85 return 0; | |
| 86 if (share_context) { | 76 if (share_context) { |
| 87 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); | 77 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 88 if (enter.failed()) | 78 if (enter.failed()) |
| 89 return 0; | 79 return 0; |
| 90 share_api = enter.object(); | 80 share_api = enter.object(); |
| 91 } | 81 } |
| 92 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 82 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 93 new PPB_Graphics3D_Impl(instance)); | 83 new PPB_Graphics3D_Impl(instance)); |
| 94 if (!graphics_3d->Init(share_api, attrib_list)) | 84 if (!graphics_3d->Init(share_api, attrib_list)) |
| 95 return 0; | 85 return 0; |
| 96 return graphics_3d->GetReference(); | 86 return graphics_3d->GetReference(); |
| 97 } | 87 } |
| 98 | 88 |
| 99 // static | 89 // static |
| 100 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, | 90 PP_Resource PPB_Graphics3D_Impl::CreateRaw(PP_Instance instance, |
| 101 PP_Resource share_context, | 91 PP_Resource share_context, |
| 102 const int32_t* attrib_list) { | 92 const int32_t* attrib_list) { |
| 103 PPB_Graphics3D_API* share_api = NULL; | 93 PPB_Graphics3D_API* share_api = NULL; |
| 104 if (IsGpuBlacklisted()) | |
| 105 return 0; | |
| 106 if (share_context) { | 94 if (share_context) { |
| 107 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); | 95 EnterResourceNoLock<PPB_Graphics3D_API> enter(share_context, true); |
| 108 if (enter.failed()) | 96 if (enter.failed()) |
| 109 return 0; | 97 return 0; |
| 110 share_api = enter.object(); | 98 share_api = enter.object(); |
| 111 } | 99 } |
| 112 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( | 100 scoped_refptr<PPB_Graphics3D_Impl> graphics_3d( |
| 113 new PPB_Graphics3D_Impl(instance)); | 101 new PPB_Graphics3D_Impl(instance)); |
| 114 if (!graphics_3d->InitRaw(share_api, attrib_list)) | 102 if (!graphics_3d->InitRaw(share_api, attrib_list)) |
| 115 return 0; | 103 return 0; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 share_gles2); | 224 share_gles2); |
| 237 } | 225 } |
| 238 | 226 |
| 239 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, | 227 bool PPB_Graphics3D_Impl::InitRaw(PPB_Graphics3D_API* share_context, |
| 240 const int32_t* attrib_list) { | 228 const int32_t* attrib_list) { |
| 241 PepperPluginInstanceImpl* plugin_instance = | 229 PepperPluginInstanceImpl* plugin_instance = |
| 242 HostGlobals::Get()->GetInstance(pp_instance()); | 230 HostGlobals::Get()->GetInstance(pp_instance()); |
| 243 if (!plugin_instance) | 231 if (!plugin_instance) |
| 244 return false; | 232 return false; |
| 245 | 233 |
| 246 PlatformContext3D* share_platform_context = NULL; | 234 const WebPreferences& prefs = static_cast<RenderViewImpl*>(plugin_instance-> |
| 247 if (share_context) { | 235 GetRenderView())->webkit_preferences(); |
| 248 PPB_Graphics3D_Impl* share_graphics = | 236 // 3D access might be disabled or blacklisted. |
| 249 static_cast<PPB_Graphics3D_Impl*>(share_context); | 237 if (!prefs.pepper_3d_enabled) |
| 250 share_platform_context = share_graphics->platform_context(); | 238 return false; |
| 251 } | |
| 252 | |
| 253 // If accelerated compositing of plugins is disabled, fail to create a 3D | 239 // If accelerated compositing of plugins is disabled, fail to create a 3D |
| 254 // context, because it won't be visible. This allows graceful fallback in the | 240 // context, because it won't be visible. This allows graceful fallback in the |
| 255 // modules. | 241 // modules. |
| 256 const WebPreferences& prefs = static_cast<RenderViewImpl*>(plugin_instance-> | |
| 257 GetRenderView())->webkit_preferences(); | |
| 258 if (!prefs.accelerated_compositing_for_plugins_enabled) | 242 if (!prefs.accelerated_compositing_for_plugins_enabled) |
| 259 return false; | 243 return false; |
| 260 | 244 |
| 261 platform_context_.reset(new PlatformContext3D); | 245 platform_context_.reset(new PlatformContext3D); |
| 262 if (!platform_context_) | 246 if (!platform_context_) |
| 263 return false; | 247 return false; |
| 264 | 248 |
| 249 PlatformContext3D* share_platform_context = NULL; |
| 250 if (share_context) { |
| 251 PPB_Graphics3D_Impl* share_graphics = |
| 252 static_cast<PPB_Graphics3D_Impl*>(share_context); |
| 253 share_platform_context = share_graphics->platform_context(); |
| 254 } |
| 255 |
| 265 if (!platform_context_->Init(attrib_list, share_platform_context)) | 256 if (!platform_context_->Init(attrib_list, share_platform_context)) |
| 266 return false; | 257 return false; |
| 267 | 258 |
| 268 platform_context_->SetContextLostCallback( | 259 platform_context_->SetContextLostCallback( |
| 269 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, | 260 base::Bind(&PPB_Graphics3D_Impl::OnContextLost, |
| 270 weak_ptr_factory_.GetWeakPtr())); | 261 weak_ptr_factory_.GetWeakPtr())); |
| 271 | 262 |
| 272 platform_context_->SetOnConsoleMessageCallback( | 263 platform_context_->SetOnConsoleMessageCallback( |
| 273 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, | 264 base::Bind(&PPB_Graphics3D_Impl::OnConsoleMessage, |
| 274 weak_ptr_factory_.GetWeakPtr())); | 265 weak_ptr_factory_.GetWeakPtr())); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 PPP_GRAPHICS_3D_INTERFACE)); | 327 PPP_GRAPHICS_3D_INTERFACE)); |
| 337 // We have to check *again* that the instance exists, because it could have | 328 // We have to check *again* that the instance exists, because it could have |
| 338 // been deleted during GetPluginInterface(). Even the PluginModule could be | 329 // been deleted during GetPluginInterface(). Even the PluginModule could be |
| 339 // deleted, but in that case, the instance should also be gone, so the | 330 // deleted, but in that case, the instance should also be gone, so the |
| 340 // GetInstance check covers both cases. | 331 // GetInstance check covers both cases. |
| 341 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) | 332 if (ppp_graphics_3d && HostGlobals::Get()->GetInstance(this_pp_instance)) |
| 342 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); | 333 ppp_graphics_3d->Graphics3DContextLost(this_pp_instance); |
| 343 } | 334 } |
| 344 | 335 |
| 345 } // namespace content | 336 } // namespace content |
| OLD | NEW |