| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 // Terminate the library. This must be called after any other functions | 83 // Terminate the library. This must be called after any other functions |
| 84 // have completed. | 84 // have completed. |
| 85 static bool Terminate(); | 85 static bool Terminate(); |
| 86 | 86 |
| 87 ~GLInProcessContext(); | 87 ~GLInProcessContext(); |
| 88 | 88 |
| 89 void PumpCommands(); | 89 void PumpCommands(); |
| 90 bool GetBufferChanged(int32 transfer_buffer_id); | 90 bool GetBufferChanged(int32 transfer_buffer_id); |
| 91 | 91 |
| 92 // Create a GLInProcessContext that renders to an offscreen frame buffer. If | 92 // Create a GLInProcessContext, if |is_offscreen| is true, renders to an |
| 93 // parent is not NULL, that GLInProcessContext can access a copy of the | 93 // offscreen context. |attrib_list| must be NULL or a NONE-terminated list |
| 94 // created GLInProcessContext's frame buffer that is updated every time | 94 // of attribute/value pairs. |
| 95 // SwapBuffers is called. It is not as general as shared GLInProcessContexts | 95 static GLInProcessContext* CreateContext( |
| 96 // in other implementations of OpenGL. If parent is not NULL, it must be used | 96 bool is_offscreen, |
| 97 // on the same thread as the parent. A child GLInProcessContext may not | 97 gfx::AcceleratedWidget window, |
| 98 // outlive its parent. attrib_list must be NULL or a NONE-terminated list of | |
| 99 // attribute/value pairs. | |
| 100 static GLInProcessContext* CreateOffscreenContext( | |
| 101 const gfx::Size& size, | 98 const gfx::Size& size, |
| 102 bool share_resources, | 99 bool share_resources, |
| 103 const char* allowed_extensions, | 100 const char* allowed_extensions, |
| 104 const int32* attrib_list, | 101 const int32* attrib_list, |
| 105 gfx::GpuPreference gpu_preference); | 102 gfx::GpuPreference gpu_preference); |
| 106 | 103 |
| 107 // For an offscreen frame buffer GLInProcessContext, return the texture ID | 104 // For an offscreen frame buffer GLInProcessContext, return the texture ID |
| 108 // with respect to the parent GLInProcessContext. Returns zero if | 105 // with respect to the parent GLInProcessContext. Returns zero if |
| 109 // GLInProcessContext does not have a parent. | 106 // GLInProcessContext does not have a parent. |
| 110 uint32 GetParentTextureId(); | 107 uint32 GetParentTextureId(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 141 // problem communicating with the GPU process. | 138 // problem communicating with the GPU process. |
| 142 bool IsCommandBufferContextLost(); | 139 bool IsCommandBufferContextLost(); |
| 143 | 140 |
| 144 CommandBufferService* GetCommandBufferService(); | 141 CommandBufferService* GetCommandBufferService(); |
| 145 | 142 |
| 146 ::gpu::gles2::GLES2Decoder* GetDecoder(); | 143 ::gpu::gles2::GLES2Decoder* GetDecoder(); |
| 147 | 144 |
| 148 private: | 145 private: |
| 149 explicit GLInProcessContext(bool share_resources); | 146 explicit GLInProcessContext(bool share_resources); |
| 150 | 147 |
| 151 bool Initialize(const gfx::Size& size, | 148 bool Initialize(bool is_offscreen, |
| 149 gfx::AcceleratedWidget window, |
| 150 const gfx::Size& size, |
| 152 const char* allowed_extensions, | 151 const char* allowed_extensions, |
| 153 const int32* attrib_list, | 152 const int32* attrib_list, |
| 154 gfx::GpuPreference gpu_preference); | 153 gfx::GpuPreference gpu_preference); |
| 155 void Destroy(); | 154 void Destroy(); |
| 156 | 155 |
| 157 void OnContextLost(); | 156 void OnContextLost(); |
| 158 | 157 |
| 159 base::Closure context_lost_callback_; | 158 base::Closure context_lost_callback_; |
| 160 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 159 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 161 scoped_ptr<CommandBufferService> command_buffer_; | 160 scoped_ptr<CommandBufferService> command_buffer_; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 | 200 |
| 202 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = | 201 static base::LazyInstance<GLES2Initializer> g_gles2_initializer = |
| 203 LAZY_INSTANCE_INITIALIZER; | 202 LAZY_INSTANCE_INITIALIZER; |
| 204 | 203 |
| 205 } // namespace anonymous | 204 } // namespace anonymous |
| 206 | 205 |
| 207 GLInProcessContext::~GLInProcessContext() { | 206 GLInProcessContext::~GLInProcessContext() { |
| 208 Destroy(); | 207 Destroy(); |
| 209 } | 208 } |
| 210 | 209 |
| 211 GLInProcessContext* GLInProcessContext::CreateOffscreenContext( | 210 GLInProcessContext* GLInProcessContext::CreateContext( |
| 211 bool is_offscreen, |
| 212 gfx::AcceleratedWidget window, |
| 212 const gfx::Size& size, | 213 const gfx::Size& size, |
| 213 bool share_resources, | 214 bool share_resources, |
| 214 const char* allowed_extensions, | 215 const char* allowed_extensions, |
| 215 const int32* attrib_list, | 216 const int32* attrib_list, |
| 216 gfx::GpuPreference gpu_preference) { | 217 gfx::GpuPreference gpu_preference) { |
| 217 scoped_ptr<GLInProcessContext> context( | 218 scoped_ptr<GLInProcessContext> context( |
| 218 new GLInProcessContext(share_resources)); | 219 new GLInProcessContext(share_resources)); |
| 219 if (!context->Initialize( | 220 if (!context->Initialize( |
| 221 is_offscreen, |
| 222 window, |
| 220 size, | 223 size, |
| 221 allowed_extensions, | 224 allowed_extensions, |
| 222 attrib_list, | 225 attrib_list, |
| 223 gpu_preference)) | 226 gpu_preference)) |
| 224 return NULL; | 227 return NULL; |
| 225 | 228 |
| 226 return context.release(); | 229 return context.release(); |
| 227 } | 230 } |
| 228 | 231 |
| 229 // In the normal command buffer implementation, all commands are passed over IPC | 232 // In the normal command buffer implementation, all commands are passed over IPC |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 GLES2Implementation* GLInProcessContext::GetImplementation() { | 381 GLES2Implementation* GLInProcessContext::GetImplementation() { |
| 379 return gles2_implementation_.get(); | 382 return gles2_implementation_.get(); |
| 380 } | 383 } |
| 381 | 384 |
| 382 GLInProcessContext::GLInProcessContext(bool share_resources) | 385 GLInProcessContext::GLInProcessContext(bool share_resources) |
| 383 : last_error_(SUCCESS), | 386 : last_error_(SUCCESS), |
| 384 share_resources_(share_resources), | 387 share_resources_(share_resources), |
| 385 context_lost_(false) { | 388 context_lost_(false) { |
| 386 } | 389 } |
| 387 | 390 |
| 388 bool GLInProcessContext::Initialize(const gfx::Size& size, | 391 bool GLInProcessContext::Initialize( |
| 389 const char* allowed_extensions, | 392 bool is_offscreen, |
| 390 const int32* attrib_list, | 393 gfx::AcceleratedWidget window, |
| 391 gfx::GpuPreference gpu_preference) { | 394 const gfx::Size& size, |
| 395 const char* allowed_extensions, |
| 396 const int32* attrib_list, |
| 397 gfx::GpuPreference gpu_preference) { |
| 392 // Use one share group for all contexts. | 398 // Use one share group for all contexts. |
| 393 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, | 399 CR_DEFINE_STATIC_LOCAL(scoped_refptr<gfx::GLShareGroup>, share_group, |
| 394 (new gfx::GLShareGroup)); | 400 (new gfx::GLShareGroup)); |
| 395 | 401 |
| 396 DCHECK(size.width() >= 0 && size.height() >= 0); | 402 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 397 | 403 |
| 398 // Ensure the gles2 library is initialized first in a thread safe way. | 404 // Ensure the gles2 library is initialized first in a thread safe way. |
| 399 g_gles2_initializer.Get(); | 405 g_gles2_initializer.Get(); |
| 400 | 406 |
| 401 std::vector<int32> attribs; | 407 std::vector<int32> attribs; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 context_group->decoder_->GetContextGroup() : | 460 context_group->decoder_->GetContextGroup() : |
| 455 new ::gpu::gles2::ContextGroup( | 461 new ::gpu::gles2::ContextGroup( |
| 456 NULL, NULL, NULL, bind_generates_resource))); | 462 NULL, NULL, NULL, bind_generates_resource))); |
| 457 | 463 |
| 458 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), | 464 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), |
| 459 decoder_.get(), | 465 decoder_.get(), |
| 460 decoder_.get())); | 466 decoder_.get())); |
| 461 | 467 |
| 462 decoder_->set_engine(gpu_scheduler_.get()); | 468 decoder_->set_engine(gpu_scheduler_.get()); |
| 463 | 469 |
| 464 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, gfx::Size(1, 1)); | 470 if (is_offscreen) |
| 471 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); |
| 472 else |
| 473 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); |
| 465 | 474 |
| 466 if (!surface_.get()) { | 475 if (!surface_.get()) { |
| 467 LOG(ERROR) << "Could not create GLSurface."; | 476 LOG(ERROR) << "Could not create GLSurface."; |
| 468 Destroy(); | 477 Destroy(); |
| 469 return false; | 478 return false; |
| 470 } | 479 } |
| 471 | 480 |
| 472 context_ = gfx::GLContext::CreateGLContext(share_group.get(), | 481 context_ = gfx::GLContext::CreateGLContext(share_group.get(), |
| 473 surface_.get(), | 482 surface_.get(), |
| 474 gpu_preference); | 483 gpu_preference); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 } | 576 } |
| 568 | 577 |
| 569 g_all_shared_contexts.Pointer()->erase(this); | 578 g_all_shared_contexts.Pointer()->erase(this); |
| 570 } | 579 } |
| 571 | 580 |
| 572 void GLInProcessContext::OnContextLost() { | 581 void GLInProcessContext::OnContextLost() { |
| 573 if (!context_lost_callback_.is_null()) | 582 if (!context_lost_callback_.is_null()) |
| 574 context_lost_callback_.Run(); | 583 context_lost_callback_.Run(); |
| 575 } | 584 } |
| 576 | 585 |
| 586 |
| 587 // static |
| 588 WebGraphicsContext3DInProcessCommandBufferImpl* |
| 589 WebGraphicsContext3DInProcessCommandBufferImpl::CreateViewContext( |
| 590 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
| 591 gfx::AcceleratedWidget window) { |
| 592 return new WebGraphicsContext3DInProcessCommandBufferImpl( |
| 593 attributes, false, window); |
| 594 } |
| 595 |
| 596 // static |
| 597 WebGraphicsContext3DInProcessCommandBufferImpl* |
| 598 WebGraphicsContext3DInProcessCommandBufferImpl::CreateOffscreenContext( |
| 599 const WebKit::WebGraphicsContext3D::Attributes& attributes) { |
| 600 return new WebGraphicsContext3DInProcessCommandBufferImpl( |
| 601 attributes, true, gfx::kNullAcceleratedWidget); |
| 602 } |
| 603 |
| 577 WebGraphicsContext3DInProcessCommandBufferImpl:: | 604 WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 578 WebGraphicsContext3DInProcessCommandBufferImpl( | 605 WebGraphicsContext3DInProcessCommandBufferImpl( |
| 579 const WebKit::WebGraphicsContext3D::Attributes& attributes) | 606 const WebKit::WebGraphicsContext3D::Attributes& attributes, |
| 580 : initialized_(false), | 607 bool is_offscreen, |
| 608 gfx::AcceleratedWidget window) |
| 609 : is_offscreen_(is_offscreen), |
| 610 window_(window), |
| 611 initialized_(false), |
| 581 initialize_failed_(false), | 612 initialize_failed_(false), |
| 582 context_(NULL), | 613 context_(NULL), |
| 583 gl_(NULL), | 614 gl_(NULL), |
| 584 context_lost_callback_(NULL), | 615 context_lost_callback_(NULL), |
| 585 context_lost_reason_(GL_NO_ERROR), | 616 context_lost_reason_(GL_NO_ERROR), |
| 586 attributes_(attributes), | 617 attributes_(attributes), |
| 587 cached_width_(0), | 618 cached_width_(0), |
| 588 cached_height_(0), | 619 cached_height_(0), |
| 589 bound_fbo_(0) { | 620 bound_fbo_(0) { |
| 590 } | 621 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 618 | 649 |
| 619 const char* preferred_extensions = "*"; | 650 const char* preferred_extensions = "*"; |
| 620 | 651 |
| 621 // TODO(kbr): More work will be needed in this implementation to | 652 // TODO(kbr): More work will be needed in this implementation to |
| 622 // properly support GPU switching. Like in the out-of-process | 653 // properly support GPU switching. Like in the out-of-process |
| 623 // command buffer implementation, all previously created contexts | 654 // command buffer implementation, all previously created contexts |
| 624 // will need to be lost either when the first context requesting the | 655 // will need to be lost either when the first context requesting the |
| 625 // discrete GPU is created, or the last one is destroyed. | 656 // discrete GPU is created, or the last one is destroyed. |
| 626 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; | 657 gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu; |
| 627 | 658 |
| 628 context_ = GLInProcessContext::CreateOffscreenContext( | 659 context_ = GLInProcessContext::CreateContext( |
| 660 is_offscreen_, |
| 661 window_, |
| 629 gfx::Size(1, 1), | 662 gfx::Size(1, 1), |
| 630 attributes_.shareResources, | 663 attributes_.shareResources, |
| 631 preferred_extensions, | 664 preferred_extensions, |
| 632 attribs, | 665 attribs, |
| 633 gpu_preference); | 666 gpu_preference); |
| 634 | 667 |
| 635 if (!context_) { | 668 if (!context_) { |
| 636 initialize_failed_ = true; | 669 initialize_failed_ = true; |
| 637 return false; | 670 return false; |
| 638 } | 671 } |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 | 1749 |
| 1717 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1750 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
| 1718 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1751 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
| 1719 WGC3Denum, WGC3Denum, const void*) | 1752 WGC3Denum, WGC3Denum, const void*) |
| 1720 | 1753 |
| 1721 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1754 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
| 1722 WGC3Denum) | 1755 WGC3Denum) |
| 1723 | 1756 |
| 1724 } // namespace gpu | 1757 } // namespace gpu |
| 1725 } // namespace webkit | 1758 } // namespace webkit |
| OLD | NEW |