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" | |
14 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
15 #include "content/common/view_messages.h" | 14 #include "content/common/view_messages.h" |
16 #include "content/renderer/gpu/command_buffer_proxy.h" | 15 #include "content/renderer/gpu/command_buffer_proxy.h" |
17 #include "content/renderer/gpu/gpu_channel_host.h" | 16 #include "content/renderer/gpu/gpu_channel_host.h" |
18 #include "content/renderer/gpu/transport_texture_host.h" | 17 #include "content/renderer/gpu/transport_texture_host.h" |
19 #include "content/renderer/gpu/transport_texture_service.h" | 18 #include "content/renderer/gpu/transport_texture_service.h" |
20 #include "content/renderer/render_thread.h" | 19 #include "content/renderer/render_thread.h" |
21 #include "content/renderer/render_widget.h" | 20 #include "content/renderer/render_widget.h" |
22 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
23 #include "ipc/ipc_channel_handle.h" | 22 #include "ipc/ipc_channel_handle.h" |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 swap_buffers_callback_.reset(callback); | 202 swap_buffers_callback_.reset(callback); |
204 } | 203 } |
205 | 204 |
206 void RendererGLContext::SetContextLostCallback( | 205 void RendererGLContext::SetContextLostCallback( |
207 Callback1<ContextLostReason>::Type* callback) { | 206 Callback1<ContextLostReason>::Type* callback) { |
208 context_lost_callback_.reset(callback); | 207 context_lost_callback_.reset(callback); |
209 } | 208 } |
210 | 209 |
211 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { | 210 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { |
212 if (context) { | 211 if (context) { |
213 DCHECK(MessageLoop::current() == context->message_loop_); | |
214 gles2::SetGLContext(context->gles2_implementation_); | 212 gles2::SetGLContext(context->gles2_implementation_); |
215 | 213 |
216 // Don't request latest error status from service. Just use the locally | 214 // Don't request latest error status from service. Just use the locally |
217 // cached information from the last flush. | 215 // cached information from the last flush. |
218 // TODO(apatrick): I'm not sure if this should actually change the | 216 // TODO(apatrick): I'm not sure if this should actually change the |
219 // current context if it fails. For now it gets changed even if it fails | 217 // current context if it fails. For now it gets changed even if it fails |
220 // because making GL calls with a NULL context crashes. | 218 // because making GL calls with a NULL context crashes. |
221 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) | 219 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) |
222 return false; | 220 return false; |
223 } else { | 221 } else { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 277 |
280 RendererGLContext::RendererGLContext(GpuChannelHost* channel) | 278 RendererGLContext::RendererGLContext(GpuChannelHost* channel) |
281 : channel_(channel), | 279 : channel_(channel), |
282 parent_(base::WeakPtr<RendererGLContext>()), | 280 parent_(base::WeakPtr<RendererGLContext>()), |
283 parent_texture_id_(0), | 281 parent_texture_id_(0), |
284 command_buffer_(NULL), | 282 command_buffer_(NULL), |
285 gles2_helper_(NULL), | 283 gles2_helper_(NULL), |
286 transfer_buffer_id_(-1), | 284 transfer_buffer_id_(-1), |
287 gles2_implementation_(NULL), | 285 gles2_implementation_(NULL), |
288 last_error_(SUCCESS), | 286 last_error_(SUCCESS), |
289 frame_number_(0) | 287 frame_number_(0) { |
290 #ifndef NDEBUG | |
291 , message_loop_(MessageLoop::current()) | |
292 #endif | |
293 { | |
294 DCHECK(channel); | 288 DCHECK(channel); |
295 } | 289 } |
296 | 290 |
297 bool RendererGLContext::Initialize(bool onscreen, | 291 bool RendererGLContext::Initialize(bool onscreen, |
298 int render_view_id, | 292 int render_view_id, |
299 const gfx::Size& size, | 293 const gfx::Size& size, |
300 bool share_resources, | 294 bool share_resources, |
301 bool bind_generates_resource, | 295 bool bind_generates_resource, |
302 RendererGLContext* share_group, | 296 RendererGLContext* share_group, |
303 const char* allowed_extensions, | 297 const char* allowed_extensions, |
304 const int32* attrib_list, | 298 const int32* attrib_list, |
305 const GURL& active_url) { | 299 const GURL& active_url) { |
306 DCHECK(MessageLoop::current() == message_loop_); | |
307 DCHECK(size.width() >= 0 && size.height() >= 0); | 300 DCHECK(size.width() >= 0 && size.height() >= 0); |
308 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", | 301 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", |
309 "on_screen", onscreen, "num_pixels", size.GetArea()); | 302 "on_screen", onscreen, "num_pixels", size.GetArea()); |
310 | 303 |
311 if (channel_->state() != GpuChannelHost::kConnected) | 304 if (channel_->state() != GpuChannelHost::kConnected) |
312 return false; | 305 return false; |
313 | 306 |
314 // 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. |
315 g_gles2_initializer.Get(); | 308 g_gles2_initializer.Get(); |
316 | 309 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 transfer_buffer.ptr, | 408 transfer_buffer.ptr, |
416 transfer_buffer_id_, | 409 transfer_buffer_id_, |
417 share_resources, | 410 share_resources, |
418 bind_generates_resource); | 411 bind_generates_resource); |
419 | 412 |
420 return true; | 413 return true; |
421 } | 414 } |
422 | 415 |
423 void RendererGLContext::Destroy() { | 416 void RendererGLContext::Destroy() { |
424 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); | 417 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); |
425 DCHECK(MessageLoop::current() == message_loop_); | |
426 SetParent(NULL); | 418 SetParent(NULL); |
427 | 419 |
428 if (gles2_implementation_) { | 420 if (gles2_implementation_) { |
429 // First flush the context to ensure that any pending frees of resources | 421 // First flush the context to ensure that any pending frees of resources |
430 // are completed. Otherwise, if this context is part of a share group, | 422 // are completed. Otherwise, if this context is part of a share group, |
431 // those resources might leak. Also, any remaining side effects of commands | 423 // those resources might leak. Also, any remaining side effects of commands |
432 // issued on this context might not be visible to other contexts in the | 424 // issued on this context might not be visible to other contexts in the |
433 // share group. | 425 // share group. |
434 gles2_implementation_->Flush(); | 426 gles2_implementation_->Flush(); |
435 | 427 |
(...skipping 25 matching lines...) Expand all Loading... |
461 void RendererGLContext::OnContextLost() { | 453 void RendererGLContext::OnContextLost() { |
462 if (context_lost_callback_.get()) { | 454 if (context_lost_callback_.get()) { |
463 RendererGLContext::ContextLostReason reason = kUnknown; | 455 RendererGLContext::ContextLostReason reason = kUnknown; |
464 if (command_buffer_) { | 456 if (command_buffer_) { |
465 reason = ConvertReason( | 457 reason = ConvertReason( |
466 command_buffer_->GetLastState().context_lost_reason); | 458 command_buffer_->GetLastState().context_lost_reason); |
467 } | 459 } |
468 context_lost_callback_->Run(reason); | 460 context_lost_callback_->Run(reason); |
469 } | 461 } |
470 } | 462 } |
OLD | NEW |