| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" | 5 #include "webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.h" |
| 6 | 6 |
| 7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
| 8 #ifndef GL_GLEXT_PROTOTYPES | 8 #ifndef GL_GLEXT_PROTOTYPES |
| 9 #define GL_GLEXT_PROTOTYPES 1 | 9 #define GL_GLEXT_PROTOTYPES 1 |
| 10 #endif | 10 #endif |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // can be used without making it current. | 132 // can be used without making it current. |
| 133 GLES2Implementation* GetImplementation(); | 133 GLES2Implementation* GetImplementation(); |
| 134 | 134 |
| 135 // Return the current error. | 135 // Return the current error. |
| 136 Error GetError(); | 136 Error GetError(); |
| 137 | 137 |
| 138 // Return true if GPU process reported GLInProcessContext lost or there was a | 138 // Return true if GPU process reported GLInProcessContext lost or there was a |
| 139 // problem communicating with the GPU process. | 139 // problem communicating with the GPU process. |
| 140 bool IsCommandBufferContextLost(); | 140 bool IsCommandBufferContextLost(); |
| 141 | 141 |
| 142 void LoseContext(uint32 current, uint32 other); |
| 143 |
| 144 void SetSignalSyncPointCallback( |
| 145 scoped_ptr< |
| 146 WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> callback); |
| 147 |
| 142 CommandBufferService* GetCommandBufferService(); | 148 CommandBufferService* GetCommandBufferService(); |
| 143 | 149 |
| 144 ::gpu::gles2::GLES2Decoder* GetDecoder(); | 150 ::gpu::gles2::GLES2Decoder* GetDecoder(); |
| 145 | 151 |
| 146 private: | 152 private: |
| 147 explicit GLInProcessContext(bool share_resources); | 153 explicit GLInProcessContext(bool share_resources); |
| 148 | 154 |
| 149 bool Initialize(bool is_offscreen, | 155 bool Initialize(bool is_offscreen, |
| 150 gfx::AcceleratedWidget window, | 156 gfx::AcceleratedWidget window, |
| 151 const gfx::Size& size, | 157 const gfx::Size& size, |
| 152 const char* allowed_extensions, | 158 const char* allowed_extensions, |
| 153 const int32* attrib_list, | 159 const int32* attrib_list, |
| 154 gfx::GpuPreference gpu_preference); | 160 gfx::GpuPreference gpu_preference); |
| 155 void Destroy(); | 161 void Destroy(); |
| 156 | 162 |
| 157 void OnContextLost(); | 163 void OnContextLost(); |
| 158 | 164 |
| 159 base::Closure context_lost_callback_; | 165 base::Closure context_lost_callback_; |
| 160 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 166 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 161 scoped_ptr<CommandBufferService> command_buffer_; | 167 scoped_ptr<CommandBufferService> command_buffer_; |
| 162 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 168 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
| 163 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 169 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
| 164 scoped_refptr<gfx::GLContext> context_; | 170 scoped_refptr<gfx::GLContext> context_; |
| 165 scoped_refptr<gfx::GLSurface> surface_; | 171 scoped_refptr<gfx::GLSurface> surface_; |
| 166 scoped_ptr<GLES2CmdHelper> gles2_helper_; | 172 scoped_ptr<GLES2CmdHelper> gles2_helper_; |
| 167 scoped_ptr<TransferBuffer> transfer_buffer_; | 173 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 168 scoped_ptr<GLES2Implementation> gles2_implementation_; | 174 scoped_ptr<GLES2Implementation> gles2_implementation_; |
| 175 scoped_ptr<WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> |
| 176 signal_sync_point_callback_; |
| 169 Error last_error_; | 177 Error last_error_; |
| 170 bool share_resources_; | 178 bool share_resources_; |
| 171 bool context_lost_; | 179 bool context_lost_; |
| 172 | 180 |
| 173 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); | 181 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); |
| 174 }; | 182 }; |
| 175 | 183 |
| 176 namespace { | 184 namespace { |
| 177 | 185 |
| 178 const int32 kCommandBufferSize = 1024 * 1024; | 186 const int32 kCommandBufferSize = 1024 * 1024; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 282 } |
| 275 | 283 |
| 276 AutoLockAndDecoderDetachThread::~AutoLockAndDecoderDetachThread() { | 284 AutoLockAndDecoderDetachThread::~AutoLockAndDecoderDetachThread() { |
| 277 std::for_each(contexts_.begin(), | 285 std::for_each(contexts_.begin(), |
| 278 contexts_.end(), | 286 contexts_.end(), |
| 279 &DetachThread); | 287 &DetachThread); |
| 280 } | 288 } |
| 281 | 289 |
| 282 } // namespace | 290 } // namespace |
| 283 | 291 |
| 292 static void CallAndDestroy( |
| 293 scoped_ptr< |
| 294 WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> callback) { |
| 295 callback->onSyncPointReached(); |
| 296 } |
| 297 |
| 284 void GLInProcessContext::PumpCommands() { | 298 void GLInProcessContext::PumpCommands() { |
| 285 if (!context_lost_) { | 299 if (!context_lost_) { |
| 286 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 300 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 287 g_all_shared_contexts.Get()); | 301 g_all_shared_contexts.Get()); |
| 288 decoder_->MakeCurrent(); | 302 decoder_->MakeCurrent(); |
| 289 gpu_scheduler_->PutChanged(); | 303 gpu_scheduler_->PutChanged(); |
| 290 ::gpu::CommandBuffer::State state = command_buffer_->GetState(); | 304 ::gpu::CommandBuffer::State state = command_buffer_->GetState(); |
| 291 if (::gpu::error::IsError(state.error)) { | 305 if (::gpu::error::IsError(state.error)) |
| 292 context_lost_ = true; | 306 context_lost_ = true; |
| 293 } | 307 } |
| 308 |
| 309 if (!context_lost_ && signal_sync_point_callback_) { |
| 310 base::MessageLoop::current()->PostTask( |
| 311 FROM_HERE, |
| 312 base::Bind(&CallAndDestroy, |
| 313 base::Passed(&signal_sync_point_callback_))); |
| 294 } | 314 } |
| 295 } | 315 } |
| 296 | 316 |
| 297 bool GLInProcessContext::GetBufferChanged(int32 transfer_buffer_id) { | 317 bool GLInProcessContext::GetBufferChanged(int32 transfer_buffer_id) { |
| 298 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); | 318 return gpu_scheduler_->SetGetBuffer(transfer_buffer_id); |
| 299 } | 319 } |
| 300 | 320 |
| 301 uint32 GLInProcessContext::GetParentTextureId() { | 321 uint32 GLInProcessContext::GetParentTextureId() { |
| 302 return 0; | 322 return 0; |
| 303 } | 323 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 381 } |
| 362 | 382 |
| 363 bool GLInProcessContext::IsCommandBufferContextLost() { | 383 bool GLInProcessContext::IsCommandBufferContextLost() { |
| 364 if (context_lost_ || !command_buffer_.get()) { | 384 if (context_lost_ || !command_buffer_.get()) { |
| 365 return true; | 385 return true; |
| 366 } | 386 } |
| 367 CommandBuffer::State state = command_buffer_->GetState(); | 387 CommandBuffer::State state = command_buffer_->GetState(); |
| 368 return ::gpu::error::IsError(state.error); | 388 return ::gpu::error::IsError(state.error); |
| 369 } | 389 } |
| 370 | 390 |
| 391 void GLInProcessContext::LoseContext(uint32 current, uint32 other) { |
| 392 gles2_implementation_->LoseContextCHROMIUM(current, other); |
| 393 gles2_implementation_->Finish(); |
| 394 DCHECK(IsCommandBufferContextLost()); |
| 395 } |
| 396 |
| 397 void GLInProcessContext::SetSignalSyncPointCallback( |
| 398 scoped_ptr< |
| 399 WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> callback) { |
| 400 signal_sync_point_callback_ = callback.Pass(); |
| 401 } |
| 402 |
| 371 CommandBufferService* GLInProcessContext::GetCommandBufferService() { | 403 CommandBufferService* GLInProcessContext::GetCommandBufferService() { |
| 372 return command_buffer_.get(); | 404 return command_buffer_.get(); |
| 373 } | 405 } |
| 374 | 406 |
| 375 ::gpu::gles2::GLES2Decoder* GLInProcessContext::GetDecoder() { | 407 ::gpu::gles2::GLES2Decoder* GLInProcessContext::GetDecoder() { |
| 376 return decoder_.get(); | 408 return decoder_.get(); |
| 377 } | 409 } |
| 378 | 410 |
| 379 // TODO(gman): Remove This | 411 // TODO(gman): Remove This |
| 380 void GLInProcessContext::DisableShaderTranslation() { | 412 void GLInProcessContext::DisableShaderTranslation() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 LOG(ERROR) << "Could not initialize command buffer."; | 479 LOG(ERROR) << "Could not initialize command buffer."; |
| 448 Destroy(); | 480 Destroy(); |
| 449 return false; | 481 return false; |
| 450 } | 482 } |
| 451 | 483 |
| 452 GLInProcessContext* context_group = NULL; | 484 GLInProcessContext* context_group = NULL; |
| 453 | 485 |
| 454 { | 486 { |
| 455 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 487 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 456 g_all_shared_contexts.Get()); | 488 g_all_shared_contexts.Get()); |
| 457 if (share_resources_ && !g_all_shared_contexts.Get().empty()) | 489 if (share_resources_ && !g_all_shared_contexts.Get().empty()) { |
| 458 context_group = *g_all_shared_contexts.Get().begin(); | 490 for (std::set<GLInProcessContext*>::iterator it = |
| 491 g_all_shared_contexts.Get().begin(); |
| 492 it != g_all_shared_contexts.Get().end(); |
| 493 ++it) { |
| 494 if (!(*it)->IsCommandBufferContextLost()) { |
| 495 context_group = *it; |
| 496 break; |
| 497 } |
| 498 } |
| 499 if (!context_group) |
| 500 share_group = new gfx::GLShareGroup; |
| 501 } |
| 459 | 502 |
| 460 // TODO(gman): This needs to be true if this is Pepper. | 503 // TODO(gman): This needs to be true if this is Pepper. |
| 461 bool bind_generates_resource = false; | 504 bool bind_generates_resource = false; |
| 462 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group ? | 505 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group ? |
| 463 context_group->decoder_->GetContextGroup() : | 506 context_group->decoder_->GetContextGroup() : |
| 464 new ::gpu::gles2::ContextGroup( | 507 new ::gpu::gles2::ContextGroup( |
| 465 NULL, NULL, NULL, bind_generates_resource))); | 508 NULL, NULL, NULL, bind_generates_resource))); |
| 466 | 509 |
| 467 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), | 510 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), |
| 468 decoder_.get(), | 511 decoder_.get(), |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 if (decoder_.get()) { | 640 if (decoder_.get()) { |
| 598 decoder_->Destroy(!context_lost); | 641 decoder_->Destroy(!context_lost); |
| 599 } | 642 } |
| 600 | 643 |
| 601 g_all_shared_contexts.Pointer()->erase(this); | 644 g_all_shared_contexts.Pointer()->erase(this); |
| 602 } | 645 } |
| 603 | 646 |
| 604 void GLInProcessContext::OnContextLost() { | 647 void GLInProcessContext::OnContextLost() { |
| 605 if (!context_lost_callback_.is_null()) | 648 if (!context_lost_callback_.is_null()) |
| 606 context_lost_callback_.Run(); | 649 context_lost_callback_.Run(); |
| 650 |
| 651 context_lost_ = true; |
| 652 if (share_resources_) { |
| 653 for (std::set<GLInProcessContext*>::iterator it = |
| 654 g_all_shared_contexts.Get().begin(); |
| 655 it != g_all_shared_contexts.Get().end(); |
| 656 ++it) |
| 657 (*it)->context_lost_ = true; |
| 658 } |
| 607 } | 659 } |
| 608 | 660 |
| 609 // static | 661 // static |
| 610 void | 662 void |
| 611 WebGraphicsContext3DInProcessCommandBufferImpl::EnableVirtualizedContext() { | 663 WebGraphicsContext3DInProcessCommandBufferImpl::EnableVirtualizedContext() { |
| 612 #if !defined(NDEBUG) | 664 #if !defined(NDEBUG) |
| 613 { | 665 { |
| 614 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 666 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 615 g_all_shared_contexts.Get()); | 667 g_all_shared_contexts.Get()); |
| 616 DCHECK(g_all_shared_contexts.Get().empty()); | 668 DCHECK(g_all_shared_contexts.Get().empty()); |
| (...skipping 1167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 | 1836 |
| 1785 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1837 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) |
| 1786 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1838 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, |
| 1787 WGC3Denum, const WGC3Dbyte*) | 1839 WGC3Denum, const WGC3Dbyte*) |
| 1788 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1840 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, |
| 1789 WGC3Denum, const WGC3Dbyte*) | 1841 WGC3Denum, const WGC3Dbyte*) |
| 1790 | 1842 |
| 1791 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, | 1843 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, |
| 1792 WGC3Dsizei, const WGC3Denum*) | 1844 WGC3Dsizei, const WGC3Denum*) |
| 1793 | 1845 |
| 1846 unsigned WebGraphicsContext3DInProcessCommandBufferImpl::insertSyncPoint() { |
| 1847 shallowFlushCHROMIUM(); |
| 1848 return 0; |
| 1849 } |
| 1850 |
| 1851 void WebGraphicsContext3DInProcessCommandBufferImpl::signalSyncPoint( |
| 1852 unsigned sync_point, |
| 1853 WebGraphicsSyncPointCallback* callback) { |
| 1854 // Take ownership of the callback. |
| 1855 context_->SetSignalSyncPointCallback(make_scoped_ptr(callback)); |
| 1856 // Stick something in the command buffer. |
| 1857 shallowFlushCHROMIUM(); |
| 1858 } |
| 1859 |
| 1860 void WebGraphicsContext3DInProcessCommandBufferImpl::loseContextCHROMIUM( |
| 1861 WGC3Denum current, WGC3Denum other) { |
| 1862 context_->LoseContext(current, other); |
| 1863 } |
| 1864 |
| 1794 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, | 1865 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, |
| 1795 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint, | 1866 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint, |
| 1796 WGC3Denum, WGC3Denum, const void*) | 1867 WGC3Denum, WGC3Denum, const void*) |
| 1797 | 1868 |
| 1798 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1869 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
| 1799 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1870 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
| 1800 WGC3Denum, WGC3Denum, const void*) | 1871 WGC3Denum, WGC3Denum, const void*) |
| 1801 | 1872 |
| 1802 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1873 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
| 1803 WGC3Denum) | 1874 WGC3Denum) |
| 1804 | 1875 |
| 1805 } // namespace gpu | 1876 } // namespace gpu |
| 1806 } // namespace webkit | 1877 } // namespace webkit |
| OLD | NEW |