| 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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 uint32 texture_id = 0; | 185 uint32 texture_id = 0; |
| 186 gles2_implementation_->GenTextures(1, &texture_id); | 186 gles2_implementation_->GenTextures(1, &texture_id); |
| 187 gles2_implementation_->Flush(); | 187 gles2_implementation_->Flush(); |
| 188 return texture_id; | 188 return texture_id; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void RendererGLContext::DeleteParentTexture(uint32 texture) { | 191 void RendererGLContext::DeleteParentTexture(uint32 texture) { |
| 192 gles2_implementation_->DeleteTextures(1, &texture); | 192 gles2_implementation_->DeleteTextures(1, &texture); |
| 193 } | 193 } |
| 194 | 194 |
| 195 void RendererGLContext::SetSwapBuffersCallback(Callback0::Type* callback) { | |
| 196 swap_buffers_callback_.reset(callback); | |
| 197 } | |
| 198 | |
| 199 void RendererGLContext::SetContextLostCallback( | 195 void RendererGLContext::SetContextLostCallback( |
| 200 Callback1<ContextLostReason>::Type* callback) { | 196 Callback1<ContextLostReason>::Type* callback) { |
| 201 context_lost_callback_.reset(callback); | 197 context_lost_callback_.reset(callback); |
| 202 } | 198 } |
| 203 | 199 |
| 204 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { | 200 bool RendererGLContext::MakeCurrent(RendererGLContext* context) { |
| 205 if (context) { | 201 if (context) { |
| 206 gles2::SetGLContext(context->gles2_implementation_); | 202 gles2::SetGLContext(context->gles2_implementation_); |
| 207 | 203 |
| 208 // Don't request latest error status from service. Just use the locally | 204 // Don't request latest error status from service. Just use the locally |
| (...skipping 13 matching lines...) Expand all Loading... |
| 222 bool RendererGLContext::SwapBuffers() { | 218 bool RendererGLContext::SwapBuffers() { |
| 223 TRACE_EVENT1("gpu", "RendererGLContext::SwapBuffers", "frame", frame_number_); | 219 TRACE_EVENT1("gpu", "RendererGLContext::SwapBuffers", "frame", frame_number_); |
| 224 frame_number_++; | 220 frame_number_++; |
| 225 | 221 |
| 226 // Don't request latest error status from service. Just use the locally cached | 222 // Don't request latest error status from service. Just use the locally cached |
| 227 // information from the last flush. | 223 // information from the last flush. |
| 228 if (command_buffer_->GetLastState().error != gpu::error::kNoError) | 224 if (command_buffer_->GetLastState().error != gpu::error::kNoError) |
| 229 return false; | 225 return false; |
| 230 | 226 |
| 231 gles2_implementation_->SwapBuffers(); | 227 gles2_implementation_->SwapBuffers(); |
| 228 |
| 232 return true; | 229 return true; |
| 233 } | 230 } |
| 234 | 231 |
| 232 bool RendererGLContext::Echo(Task* task) { |
| 233 return command_buffer_->Echo(task); |
| 234 } |
| 235 |
| 235 scoped_refptr<TransportTextureHost> | 236 scoped_refptr<TransportTextureHost> |
| 236 RendererGLContext::CreateTransportTextureHost() { | 237 RendererGLContext::CreateTransportTextureHost() { |
| 237 return channel_->transport_texture_service()->CreateTransportTextureHost( | 238 return channel_->transport_texture_service()->CreateTransportTextureHost( |
| 238 this, command_buffer_->route_id()); | 239 this, command_buffer_->route_id()); |
| 239 } | 240 } |
| 240 | 241 |
| 241 RendererGLContext::Error RendererGLContext::GetError() { | 242 RendererGLContext::Error RendererGLContext::GetError() { |
| 242 gpu::CommandBuffer::State state = command_buffer_->GetState(); | 243 gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 243 if (state.error == gpu::error::kNoError) { | 244 if (state.error == gpu::error::kNoError) { |
| 244 Error old_error = last_error_; | 245 Error old_error = last_error_; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 { | 362 { |
| 362 TRACE_EVENT0("gpu", | 363 TRACE_EVENT0("gpu", |
| 363 "RendererGLContext::Initialize::InitializeCommandBuffer"); | 364 "RendererGLContext::Initialize::InitializeCommandBuffer"); |
| 364 // Initiaize the command buffer. | 365 // Initiaize the command buffer. |
| 365 if (!command_buffer_->Initialize(kCommandBufferSize)) { | 366 if (!command_buffer_->Initialize(kCommandBufferSize)) { |
| 366 Destroy(); | 367 Destroy(); |
| 367 return false; | 368 return false; |
| 368 } | 369 } |
| 369 } | 370 } |
| 370 | 371 |
| 371 command_buffer_->SetSwapBuffersCallback( | |
| 372 NewCallback(this, &RendererGLContext::OnSwapBuffers)); | |
| 373 | |
| 374 command_buffer_->SetChannelErrorCallback( | 372 command_buffer_->SetChannelErrorCallback( |
| 375 NewCallback(this, &RendererGLContext::OnContextLost)); | 373 NewCallback(this, &RendererGLContext::OnContextLost)); |
| 376 | 374 |
| 377 // Create the GLES2 helper, which writes the command buffer protocol. | 375 // Create the GLES2 helper, which writes the command buffer protocol. |
| 378 gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_); | 376 gles2_helper_ = new gpu::gles2::GLES2CmdHelper(command_buffer_); |
| 379 if (!gles2_helper_->Initialize(kCommandBufferSize)) { | 377 if (!gles2_helper_->Initialize(kCommandBufferSize)) { |
| 380 Destroy(); | 378 Destroy(); |
| 381 return false; | 379 return false; |
| 382 } | 380 } |
| 383 | 381 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 gles2_helper_ = NULL; | 436 gles2_helper_ = NULL; |
| 439 | 437 |
| 440 if (channel_ && command_buffer_) { | 438 if (channel_ && command_buffer_) { |
| 441 channel_->DestroyCommandBuffer(command_buffer_); | 439 channel_->DestroyCommandBuffer(command_buffer_); |
| 442 command_buffer_ = NULL; | 440 command_buffer_ = NULL; |
| 443 } | 441 } |
| 444 | 442 |
| 445 channel_ = NULL; | 443 channel_ = NULL; |
| 446 } | 444 } |
| 447 | 445 |
| 448 void RendererGLContext::OnSwapBuffers() { | |
| 449 if (swap_buffers_callback_.get()) | |
| 450 swap_buffers_callback_->Run(); | |
| 451 } | |
| 452 | |
| 453 void RendererGLContext::OnContextLost() { | 446 void RendererGLContext::OnContextLost() { |
| 454 if (context_lost_callback_.get()) { | 447 if (context_lost_callback_.get()) { |
| 455 RendererGLContext::ContextLostReason reason = kUnknown; | 448 RendererGLContext::ContextLostReason reason = kUnknown; |
| 456 if (command_buffer_) { | 449 if (command_buffer_) { |
| 457 reason = ConvertReason( | 450 reason = ConvertReason( |
| 458 command_buffer_->GetLastState().context_lost_reason); | 451 command_buffer_->GetLastState().context_lost_reason); |
| 459 } | 452 } |
| 460 context_lost_callback_->Run(reason); | 453 context_lost_callback_->Run(reason); |
| 461 } | 454 } |
| 462 } | 455 } |
| OLD | NEW |