| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gpu/renderer_gl_context.h" | 5 #include "content/renderer/gpu/renderer_gl_context.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/message_loop.h" |
| 13 #include "base/shared_memory.h" | 14 #include "base/shared_memory.h" |
| 14 #include "content/common/view_messages.h" | 15 #include "content/common/view_messages.h" |
| 15 #include "content/renderer/gpu/command_buffer_proxy.h" | 16 #include "content/renderer/gpu/command_buffer_proxy.h" |
| 16 #include "content/renderer/gpu/gpu_channel_host.h" | 17 #include "content/renderer/gpu/gpu_channel_host.h" |
| 17 #include "content/renderer/gpu/transport_texture_host.h" | 18 #include "content/renderer/gpu/transport_texture_host.h" |
| 18 #include "content/renderer/gpu/transport_texture_service.h" | 19 #include "content/renderer/gpu/transport_texture_service.h" |
| 19 #include "content/renderer/render_thread.h" | 20 #include "content/renderer/render_thread.h" |
| 20 #include "content/renderer/render_widget.h" | 21 #include "content/renderer/render_widget.h" |
| 21 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 22 #include "ipc/ipc_channel_handle.h" | 23 #include "ipc/ipc_channel_handle.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 gles2_implementation_->DeleteTextures(1, &texture); | 193 gles2_implementation_->DeleteTextures(1, &texture); |
| 193 } | 194 } |
| 194 | 195 |
| 195 void RendererGLContext::SetContextLostCallback( | 196 void RendererGLContext::SetContextLostCallback( |
| 196 Callback1<ContextLostReason>::Type* callback) { | 197 Callback1<ContextLostReason>::Type* callback) { |
| 197 context_lost_callback_.reset(callback); | 198 context_lost_callback_.reset(callback); |
| 198 } | 199 } |
| 199 | 200 |
| 200 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { | 201 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { |
| 201 if (context) { | 202 if (context) { |
| 203 DCHECK(MessageLoop::current() == context->message_loop_); |
| 202 gles2::SetGLContext(context->gles2_implementation_); | 204 gles2::SetGLContext(context->gles2_implementation_); |
| 203 | 205 |
| 204 // Don't request latest error status from service. Just use the locally | 206 // Don't request latest error status from service. Just use the locally |
| 205 // cached information from the last flush. | 207 // cached information from the last flush. |
| 206 // TODO(apatrick): I'm not sure if this should actually change the | 208 // TODO(apatrick): I'm not sure if this should actually change the |
| 207 // current context if it fails. For now it gets changed even if it fails | 209 // current context if it fails. For now it gets changed even if it fails |
| 208 // because making GL calls with a NULL context crashes. | 210 // because making GL calls with a NULL context crashes. |
| 209 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) | 211 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) |
| 210 return false; | 212 return false; |
| 211 } else { | 213 } else { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 | 274 |
| 273 RendererGLContext::RendererGLContext(GpuChannelHost* channel) | 275 RendererGLContext::RendererGLContext(GpuChannelHost* channel) |
| 274 : channel_(channel), | 276 : channel_(channel), |
| 275 parent_(base::WeakPtr<RendererGLContext>()), | 277 parent_(base::WeakPtr<RendererGLContext>()), |
| 276 parent_texture_id_(0), | 278 parent_texture_id_(0), |
| 277 command_buffer_(NULL), | 279 command_buffer_(NULL), |
| 278 gles2_helper_(NULL), | 280 gles2_helper_(NULL), |
| 279 transfer_buffer_id_(-1), | 281 transfer_buffer_id_(-1), |
| 280 gles2_implementation_(NULL), | 282 gles2_implementation_(NULL), |
| 281 last_error_(SUCCESS), | 283 last_error_(SUCCESS), |
| 282 frame_number_(0) { | 284 frame_number_(0) |
| 285 #ifndef NDEBUG |
| 286 , message_loop_(MessageLoop::current()) |
| 287 #endif |
| 288 { |
| 283 DCHECK(channel); | 289 DCHECK(channel); |
| 284 } | 290 } |
| 285 | 291 |
| 286 bool RendererGLContext::Initialize(bool onscreen, | 292 bool RendererGLContext::Initialize(bool onscreen, |
| 287 int render_view_id, | 293 int render_view_id, |
| 288 const gfx::Size& size, | 294 const gfx::Size& size, |
| 289 RendererGLContext* share_group, | 295 RendererGLContext* share_group, |
| 290 const char* allowed_extensions, | 296 const char* allowed_extensions, |
| 291 const int32* attrib_list, | 297 const int32* attrib_list, |
| 292 const GURL& active_url) { | 298 const GURL& active_url) { |
| 299 DCHECK(MessageLoop::current() == message_loop_); |
| 293 DCHECK(size.width() >= 0 && size.height() >= 0); | 300 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 294 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", | 301 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", |
| 295 "on_screen", onscreen, "num_pixels", size.GetArea()); | 302 "on_screen", onscreen, "num_pixels", size.GetArea()); |
| 296 | 303 |
| 297 if (channel_->state() != GpuChannelHost::kConnected) | 304 if (channel_->state() != GpuChannelHost::kConnected) |
| 298 return false; | 305 return false; |
| 299 | 306 |
| 300 // Ensure the gles2 library is initialized first in a thread safe way. | 307 // Ensure the gles2 library is initialized first in a thread safe way. |
| 301 g_gles2_initializer.Get(); | 308 g_gles2_initializer.Get(); |
| 302 | 309 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 transfer_buffer.ptr, | 413 transfer_buffer.ptr, |
| 407 transfer_buffer_id_, | 414 transfer_buffer_id_, |
| 408 share_resources, | 415 share_resources, |
| 409 bind_generates_resources); | 416 bind_generates_resources); |
| 410 | 417 |
| 411 return true; | 418 return true; |
| 412 } | 419 } |
| 413 | 420 |
| 414 void RendererGLContext::Destroy() { | 421 void RendererGLContext::Destroy() { |
| 415 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); | 422 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); |
| 423 DCHECK(MessageLoop::current() == message_loop_); |
| 416 SetParent(NULL); | 424 SetParent(NULL); |
| 417 | 425 |
| 418 if (gles2_implementation_) { | 426 if (gles2_implementation_) { |
| 419 // First flush the context to ensure that any pending frees of resources | 427 // First flush the context to ensure that any pending frees of resources |
| 420 // are completed. Otherwise, if this context is part of a share group, | 428 // are completed. Otherwise, if this context is part of a share group, |
| 421 // those resources might leak. Also, any remaining side effects of commands | 429 // those resources might leak. Also, any remaining side effects of commands |
| 422 // issued on this context might not be visible to other contexts in the | 430 // issued on this context might not be visible to other contexts in the |
| 423 // share group. | 431 // share group. |
| 424 gles2_implementation_->Flush(); | 432 gles2_implementation_->Flush(); |
| 425 | 433 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 446 void RendererGLContext::OnContextLost() { | 454 void RendererGLContext::OnContextLost() { |
| 447 if (context_lost_callback_.get()) { | 455 if (context_lost_callback_.get()) { |
| 448 RendererGLContext::ContextLostReason reason = kUnknown; | 456 RendererGLContext::ContextLostReason reason = kUnknown; |
| 449 if (command_buffer_) { | 457 if (command_buffer_) { |
| 450 reason = ConvertReason( | 458 reason = ConvertReason( |
| 451 command_buffer_->GetLastState().context_lost_reason); | 459 command_buffer_->GetLastState().context_lost_reason); |
| 452 } | 460 } |
| 453 context_lost_callback_->Run(reason); | 461 context_lost_callback_->Run(reason); |
| 454 } | 462 } |
| 455 } | 463 } |
| OLD | NEW |