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