| 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/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 5 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include "third_party/khronos/GLES2/gl2.h" | 7 #include "third_party/khronos/GLES2/gl2.h" |
| 8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
| 9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
| 10 #endif | 10 #endif |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 bind_generates_resources_ = bind_generates_resources; | 188 bind_generates_resources_ = bind_generates_resources; |
| 189 DCHECK(!command_buffer_); | 189 DCHECK(!command_buffer_); |
| 190 | 190 |
| 191 if (!factory_) | 191 if (!factory_) |
| 192 return false; | 192 return false; |
| 193 | 193 |
| 194 if (attributes.preferDiscreteGPU) | 194 if (attributes.preferDiscreteGPU) |
| 195 gpu_preference_ = gfx::PreferDiscreteGpu; | 195 gpu_preference_ = gfx::PreferDiscreteGpu; |
| 196 | 196 |
| 197 host_ = factory_->EstablishGpuChannelSync(cause); | 197 host_ = factory_->EstablishGpuChannelSync(cause); |
| 198 if (!host_) | 198 if (!host_.get()) |
| 199 return false; | 199 return false; |
| 200 DCHECK(host_->state() == GpuChannelHost::kConnected); | 200 DCHECK(host_->state() == GpuChannelHost::kConnected); |
| 201 | 201 |
| 202 return true; | 202 return true; |
| 203 } | 203 } |
| 204 | 204 |
| 205 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL( | 205 bool WebGraphicsContext3DCommandBufferImpl::MaybeInitializeGL( |
| 206 const char* allowed_extensions) { | 206 const char* allowed_extensions) { |
| 207 if (initialized_) | 207 if (initialized_) |
| 208 return true; | 208 return true; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 269 } |
| 270 | 270 |
| 271 visible_ = true; | 271 visible_ = true; |
| 272 initialized_ = true; | 272 initialized_ = true; |
| 273 return true; | 273 return true; |
| 274 } | 274 } |
| 275 | 275 |
| 276 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( | 276 bool WebGraphicsContext3DCommandBufferImpl::InitializeCommandBuffer( |
| 277 bool onscreen, | 277 bool onscreen, |
| 278 const char* allowed_extensions) { | 278 const char* allowed_extensions) { |
| 279 if (!host_) | 279 if (!host_.get()) |
| 280 return false; | 280 return false; |
| 281 // We need to lock g_all_shared_contexts to ensure that the context we picked | 281 // We need to lock g_all_shared_contexts to ensure that the context we picked |
| 282 // for our share group isn't deleted. | 282 // for our share group isn't deleted. |
| 283 // (There's also a lock in our destructor.) | 283 // (There's also a lock in our destructor.) |
| 284 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 284 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 285 CommandBufferProxyImpl* share_group = NULL; | 285 CommandBufferProxyImpl* share_group = NULL; |
| 286 if (attributes_.shareResources) { | 286 if (attributes_.shareResources) { |
| 287 WebGraphicsContext3DCommandBufferImpl* share_group_context = | 287 WebGraphicsContext3DCommandBufferImpl* share_group_context = |
| 288 g_all_shared_contexts.Pointer()->empty() ? | 288 g_all_shared_contexts.Pointer()->empty() ? |
| 289 NULL : *g_all_shared_contexts.Pointer()->begin(); | 289 NULL : *g_all_shared_contexts.Pointer()->begin(); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 | 431 |
| 432 if (transfer_buffer_) { | 432 if (transfer_buffer_) { |
| 433 delete transfer_buffer_; | 433 delete transfer_buffer_; |
| 434 transfer_buffer_ = NULL; | 434 transfer_buffer_ = NULL; |
| 435 } | 435 } |
| 436 | 436 |
| 437 delete gles2_helper_; | 437 delete gles2_helper_; |
| 438 gles2_helper_ = NULL; | 438 gles2_helper_ = NULL; |
| 439 | 439 |
| 440 if (command_buffer_) { | 440 if (command_buffer_) { |
| 441 if (host_) | 441 if (host_.get()) |
| 442 host_->DestroyCommandBuffer(command_buffer_); | 442 host_->DestroyCommandBuffer(command_buffer_); |
| 443 else | 443 else |
| 444 delete command_buffer_; | 444 delete command_buffer_; |
| 445 command_buffer_ = NULL; | 445 command_buffer_ = NULL; |
| 446 } | 446 } |
| 447 | 447 |
| 448 host_ = NULL; | 448 host_ = NULL; |
| 449 } | 449 } |
| 450 | 450 |
| 451 // TODO(apatrick,piman): This should be renamed to something clearer. | 451 // TODO(apatrick,piman): This should be renamed to something clearer. |
| 452 int WebGraphicsContext3DCommandBufferImpl::GetGPUProcessID() { | 452 int WebGraphicsContext3DCommandBufferImpl::GetGPUProcessID() { |
| 453 return host_ ? host_->gpu_host_id() : 0; | 453 return host_.get() ? host_->gpu_host_id() : 0; |
| 454 } | 454 } |
| 455 | 455 |
| 456 int WebGraphicsContext3DCommandBufferImpl::GetChannelID() { | 456 int WebGraphicsContext3DCommandBufferImpl::GetChannelID() { |
| 457 return host_ ? host_->client_id() : 0; | 457 return host_.get() ? host_->client_id() : 0; |
| 458 } | 458 } |
| 459 | 459 |
| 460 int WebGraphicsContext3DCommandBufferImpl::GetContextID() { | 460 int WebGraphicsContext3DCommandBufferImpl::GetContextID() { |
| 461 return command_buffer_->GetRouteID(); | 461 return command_buffer_->GetRouteID(); |
| 462 } | 462 } |
| 463 | 463 |
| 464 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { | 464 void WebGraphicsContext3DCommandBufferImpl::prepareTexture() { |
| 465 TRACE_EVENT1("gpu", | 465 TRACE_EVENT1("gpu", |
| 466 "WebGraphicsContext3DCommandBufferImpl::SwapBuffers", | 466 "WebGraphicsContext3DCommandBufferImpl::SwapBuffers", |
| 467 "frame", frame_number_); | 467 "frame", frame_number_); |
| (...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 context_lost_reason_ == GL_NO_ERROR) { | 1452 context_lost_reason_ == GL_NO_ERROR) { |
| 1453 return GL_UNKNOWN_CONTEXT_RESET_ARB; | 1453 return GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 1454 } | 1454 } |
| 1455 | 1455 |
| 1456 return context_lost_reason_; | 1456 return context_lost_reason_; |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 bool WebGraphicsContext3DCommandBufferImpl::IsCommandBufferContextLost() { | 1459 bool WebGraphicsContext3DCommandBufferImpl::IsCommandBufferContextLost() { |
| 1460 // If the channel shut down unexpectedly, let that supersede the | 1460 // If the channel shut down unexpectedly, let that supersede the |
| 1461 // command buffer's state. | 1461 // command buffer's state. |
| 1462 if (host_ && host_->state() == GpuChannelHost::kLost) | 1462 if (host_.get() && host_->state() == GpuChannelHost::kLost) |
| 1463 return true; | 1463 return true; |
| 1464 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); | 1464 gpu::CommandBuffer::State state = command_buffer_->GetLastState(); |
| 1465 return state.error == gpu::error::kLostContext; | 1465 return state.error == gpu::error::kLostContext; |
| 1466 } | 1466 } |
| 1467 | 1467 |
| 1468 // static | 1468 // static |
| 1469 WebGraphicsContext3DCommandBufferImpl* | 1469 WebGraphicsContext3DCommandBufferImpl* |
| 1470 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( | 1470 WebGraphicsContext3DCommandBufferImpl::CreateOffscreenContext( |
| 1471 GpuChannelHostFactory* factory, | 1471 GpuChannelHostFactory* factory, |
| 1472 const WebGraphicsContext3D::Attributes& attributes, | 1472 const WebGraphicsContext3D::Attributes& attributes, |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1672 | 1672 |
| 1673 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( | 1673 void WebGraphicsContext3DCommandBufferImpl::OnErrorMessage( |
| 1674 const std::string& message, int id) { | 1674 const std::string& message, int id) { |
| 1675 if (error_message_callback_) { | 1675 if (error_message_callback_) { |
| 1676 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); | 1676 WebKit::WebString str = WebKit::WebString::fromUTF8(message.c_str()); |
| 1677 error_message_callback_->onErrorMessage(str, id); | 1677 error_message_callback_->onErrorMessage(str, id); |
| 1678 } | 1678 } |
| 1679 } | 1679 } |
| 1680 | 1680 |
| 1681 } // namespace content | 1681 } // namespace content |
| OLD | NEW |