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" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 gles2_implementation_->DeleteTextures(1, &texture); | 192 gles2_implementation_->DeleteTextures(1, &texture); |
193 } | 193 } |
194 | 194 |
195 void RendererGLContext::SetContextLostCallback( | 195 void RendererGLContext::SetContextLostCallback( |
196 Callback1<ContextLostReason>::Type* callback) { | 196 Callback1<ContextLostReason>::Type* callback) { |
197 context_lost_callback_.reset(callback); | 197 context_lost_callback_.reset(callback); |
198 } | 198 } |
199 | 199 |
200 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { | 200 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { |
201 if (context) { | 201 if (context) { |
| 202 DCHECK(context->CalledOnValidThread()); |
202 gles2::SetGLContext(context->gles2_implementation_); | 203 gles2::SetGLContext(context->gles2_implementation_); |
203 | 204 |
204 // Don't request latest error status from service. Just use the locally | 205 // Don't request latest error status from service. Just use the locally |
205 // cached information from the last flush. | 206 // cached information from the last flush. |
206 // TODO(apatrick): I'm not sure if this should actually change the | 207 // 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 | 208 // current context if it fails. For now it gets changed even if it fails |
208 // because making GL calls with a NULL context crashes. | 209 // because making GL calls with a NULL context crashes. |
209 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) | 210 if (context->command_buffer_->GetLastState().error != gpu::error::kNoError) |
210 return false; | 211 return false; |
211 } else { | 212 } else { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 DCHECK(channel); | 284 DCHECK(channel); |
284 } | 285 } |
285 | 286 |
286 bool RendererGLContext::Initialize(bool onscreen, | 287 bool RendererGLContext::Initialize(bool onscreen, |
287 int render_view_id, | 288 int render_view_id, |
288 const gfx::Size& size, | 289 const gfx::Size& size, |
289 RendererGLContext* share_group, | 290 RendererGLContext* share_group, |
290 const char* allowed_extensions, | 291 const char* allowed_extensions, |
291 const int32* attrib_list, | 292 const int32* attrib_list, |
292 const GURL& active_url) { | 293 const GURL& active_url) { |
| 294 DCHECK(CalledOnValidThread()); |
293 DCHECK(size.width() >= 0 && size.height() >= 0); | 295 DCHECK(size.width() >= 0 && size.height() >= 0); |
294 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", | 296 TRACE_EVENT2("gpu", "RendererGLContext::Initialize", |
295 "on_screen", onscreen, "num_pixels", size.GetArea()); | 297 "on_screen", onscreen, "num_pixels", size.GetArea()); |
296 | 298 |
297 if (channel_->state() != GpuChannelHost::kConnected) | 299 if (channel_->state() != GpuChannelHost::kConnected) |
298 return false; | 300 return false; |
299 | 301 |
300 // Ensure the gles2 library is initialized first in a thread safe way. | 302 // Ensure the gles2 library is initialized first in a thread safe way. |
301 g_gles2_initializer.Get(); | 303 g_gles2_initializer.Get(); |
302 | 304 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 transfer_buffer.ptr, | 408 transfer_buffer.ptr, |
407 transfer_buffer_id_, | 409 transfer_buffer_id_, |
408 share_resources, | 410 share_resources, |
409 bind_generates_resources); | 411 bind_generates_resources); |
410 | 412 |
411 return true; | 413 return true; |
412 } | 414 } |
413 | 415 |
414 void RendererGLContext::Destroy() { | 416 void RendererGLContext::Destroy() { |
415 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); | 417 TRACE_EVENT0("gpu", "RendererGLContext::Destroy"); |
| 418 DCHECK(CalledOnValidThread()); |
416 SetParent(NULL); | 419 SetParent(NULL); |
417 | 420 |
418 if (gles2_implementation_) { | 421 if (gles2_implementation_) { |
419 // First flush the context to ensure that any pending frees of resources | 422 // 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, | 423 // are completed. Otherwise, if this context is part of a share group, |
421 // those resources might leak. Also, any remaining side effects of commands | 424 // 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 | 425 // issued on this context might not be visible to other contexts in the |
423 // share group. | 426 // share group. |
424 gles2_implementation_->Flush(); | 427 gles2_implementation_->Flush(); |
425 | 428 |
(...skipping 20 matching lines...) Expand all Loading... |
446 void RendererGLContext::OnContextLost() { | 449 void RendererGLContext::OnContextLost() { |
447 if (context_lost_callback_.get()) { | 450 if (context_lost_callback_.get()) { |
448 RendererGLContext::ContextLostReason reason = kUnknown; | 451 RendererGLContext::ContextLostReason reason = kUnknown; |
449 if (command_buffer_) { | 452 if (command_buffer_) { |
450 reason = ConvertReason( | 453 reason = ConvertReason( |
451 command_buffer_->GetLastState().context_lost_reason); | 454 command_buffer_->GetLastState().context_lost_reason); |
452 } | 455 } |
453 context_lost_callback_->Run(reason); | 456 context_lost_callback_->Run(reason); |
454 } | 457 } |
455 } | 458 } |
OLD | NEW |