| 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 "chrome/renderer/pepper_platform_context_3d_impl.h" | 5 #include "chrome/renderer/pepper_platform_context_3d_impl.h" |
| 6 | 6 |
| 7 #include "chrome/renderer/command_buffer_proxy.h" | 7 #include "chrome/renderer/command_buffer_proxy.h" |
| 8 #include "chrome/renderer/gpu_channel_host.h" | 8 #include "chrome/renderer/gpu_channel_host.h" |
| 9 #include "chrome/renderer/render_thread.h" | 9 #include "chrome/renderer/render_thread.h" |
| 10 #include "content/renderer/ggl.h" | 10 #include "content/renderer/ggl.h" |
| 11 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 11 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 12 #include "gpu/command_buffer/client/gles2_implementation.h" | 12 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 13 | 13 |
| 14 #ifdef ENABLE_GPU | 14 #ifdef ENABLE_GPU |
| 15 PlatformContext3DImpl::PlatformContext3DImpl(ggl::Context* parent_context) | 15 PlatformContext3DImpl::PlatformContext3DImpl(ggl::Context* parent_context) |
| 16 : parent_context_(parent_context), | 16 : parent_context_(ggl::GetWeakContextReference(parent_context)), |
| 17 parent_texture_id_(0), | 17 parent_texture_id_(0), |
| 18 command_buffer_(NULL), | 18 command_buffer_(NULL), |
| 19 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 19 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 PlatformContext3DImpl::~PlatformContext3DImpl() { | 22 PlatformContext3DImpl::~PlatformContext3DImpl() { |
| 23 if (command_buffer_) { | 23 if (command_buffer_) { |
| 24 DCHECK(channel_.get()); | 24 DCHECK(channel_.get()); |
| 25 channel_->DestroyCommandBuffer(command_buffer_); | 25 channel_->DestroyCommandBuffer(command_buffer_); |
| 26 command_buffer_ = NULL; | 26 command_buffer_ = NULL; |
| 27 } | 27 } |
| 28 | 28 |
| 29 channel_ = NULL; | 29 channel_ = NULL; |
| 30 | 30 |
| 31 if (parent_context_ && parent_texture_id_ != 0) { | 31 if (parent_context_.get() && parent_texture_id_ != 0) { |
| 32 ggl::GetImplementation(parent_context_)->FreeTextureId(parent_texture_id_); | 32 ggl::GetImplementation(parent_context_)->FreeTextureId(parent_texture_id_); |
| 33 } | 33 } |
| 34 | 34 |
| 35 } | 35 } |
| 36 | 36 |
| 37 bool PlatformContext3DImpl::Init() { | 37 bool PlatformContext3DImpl::Init() { |
| 38 // Ignore initializing more than once. | 38 // Ignore initializing more than once. |
| 39 if (command_buffer_) | 39 if (command_buffer_) |
| 40 return true; | 40 return true; |
| 41 | 41 |
| 42 // Parent may already have been deleted. |
| 43 if (!parent_context_.get()) |
| 44 return false; |
| 45 |
| 42 RenderThread* render_thread = RenderThread::current(); | 46 RenderThread* render_thread = RenderThread::current(); |
| 43 if (!render_thread) | 47 if (!render_thread) |
| 44 return false; | 48 return false; |
| 45 | 49 |
| 46 channel_ = render_thread->GetGpuChannel(); | 50 channel_ = render_thread->GetGpuChannel(); |
| 47 if (!channel_.get()) | 51 if (!channel_.get()) |
| 48 return false; | 52 return false; |
| 49 | 53 |
| 50 DCHECK(channel_->state() == GpuChannelHost::kConnected); | 54 DCHECK(channel_->state() == GpuChannelHost::kConnected); |
| 51 | 55 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return command_buffer_; | 100 return command_buffer_; |
| 97 } | 101 } |
| 98 | 102 |
| 99 void PlatformContext3DImpl::SetContextLostCallback(Callback0::Type* callback) { | 103 void PlatformContext3DImpl::SetContextLostCallback(Callback0::Type* callback) { |
| 100 context_lost_callback_.reset(callback); | 104 context_lost_callback_.reset(callback); |
| 101 } | 105 } |
| 102 | 106 |
| 103 void PlatformContext3DImpl::OnContextLost() { | 107 void PlatformContext3DImpl::OnContextLost() { |
| 104 DCHECK(command_buffer_); | 108 DCHECK(command_buffer_); |
| 105 | 109 |
| 106 // We will lose the parent context soon (it will be reallocated by the main | |
| 107 // page). | |
| 108 parent_context_ = NULL; | |
| 109 parent_texture_id_ = 0; | |
| 110 if (context_lost_callback_.get()) | 110 if (context_lost_callback_.get()) |
| 111 context_lost_callback_->Run(); | 111 context_lost_callback_->Run(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 #endif // ENABLE_GPU | 114 #endif // ENABLE_GPU |
| OLD | NEW |