| 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 |
| 11 #include <GLES2/gl2ext.h> | 11 #include <GLES2/gl2ext.h> |
| 12 #include <GLES2/gl2extchromium.h> | 12 #include <GLES2/gl2extchromium.h> |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <set> | 15 #include <set> |
| 16 #include <string> | 16 #include <string> |
| 17 | 17 |
| 18 #include "base/bind.h" | 18 #include "base/bind.h" |
| 19 #include "base/bind_helpers.h" | 19 #include "base/bind_helpers.h" |
| 20 #include "base/callback.h" | 20 #include "base/callback.h" |
| 21 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 22 #include "base/lazy_instance.h" | 22 #include "base/lazy_instance.h" |
| 23 #include "base/logging.h" | 23 #include "base/logging.h" |
| 24 #include "base/memory/singleton.h" | 24 #include "base/memory/singleton.h" |
| 25 #include "base/message_loop.h" | 25 #include "base/message_loop.h" |
| 26 #include "base/metrics/histogram.h" | 26 #include "base/metrics/histogram.h" |
| 27 #include "base/synchronization/lock.h" | 27 #include "base/synchronization/lock.h" |
| 28 #include "gpu/command_buffer/client/gles2_implementation.h" | 28 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 29 #include "gpu/command_buffer/client/gles2_lib.h" | 29 #include "gpu/command_buffer/client/gles2_lib.h" |
| 30 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" |
| 30 #include "gpu/command_buffer/client/transfer_buffer.h" | 31 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 31 #include "gpu/command_buffer/common/constants.h" | 32 #include "gpu/command_buffer/common/constants.h" |
| 32 #include "gpu/command_buffer/service/command_buffer_service.h" | 33 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 33 #include "gpu/command_buffer/service/context_group.h" | 34 #include "gpu/command_buffer/service/context_group.h" |
| 34 #include "gpu/command_buffer/service/gl_context_virtual.h" | 35 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 35 #include "gpu/command_buffer/service/gpu_scheduler.h" | 36 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 37 #include "gpu/command_buffer/service/image_manager.h" |
| 36 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 38 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 37 #include "ui/gl/gl_context.h" | 39 #include "ui/gl/gl_context.h" |
| 40 #include "ui/gl/gl_image.h" |
| 38 #include "ui/gl/gl_share_group.h" | 41 #include "ui/gl/gl_share_group.h" |
| 39 #include "ui/gl/gl_surface.h" | 42 #include "ui/gl/gl_surface.h" |
| 40 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" | 43 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" |
| 41 | 44 |
| 42 using gpu::Buffer; | 45 using gpu::Buffer; |
| 43 using gpu::CommandBuffer; | 46 using gpu::CommandBuffer; |
| 44 using gpu::CommandBufferService; | 47 using gpu::CommandBufferService; |
| 45 using gpu::gles2::GLES2CmdHelper; | 48 using gpu::gles2::GLES2CmdHelper; |
| 46 using gpu::gles2::GLES2Implementation; | 49 using gpu::gles2::GLES2Implementation; |
| 47 using gpu::GpuScheduler; | 50 using gpu::GpuScheduler; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 bool Initialize(bool is_offscreen, | 158 bool Initialize(bool is_offscreen, |
| 156 gfx::AcceleratedWidget window, | 159 gfx::AcceleratedWidget window, |
| 157 const gfx::Size& size, | 160 const gfx::Size& size, |
| 158 const char* allowed_extensions, | 161 const char* allowed_extensions, |
| 159 const int32* attrib_list, | 162 const int32* attrib_list, |
| 160 gfx::GpuPreference gpu_preference); | 163 gfx::GpuPreference gpu_preference); |
| 161 void Destroy(); | 164 void Destroy(); |
| 162 | 165 |
| 163 void OnContextLost(); | 166 void OnContextLost(); |
| 164 | 167 |
| 168 ::gpu::gles2::ImageManager* GetImageManager(); |
| 169 |
| 165 base::Closure context_lost_callback_; | 170 base::Closure context_lost_callback_; |
| 166 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 171 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 167 scoped_ptr<CommandBufferService> command_buffer_; | 172 scoped_ptr<CommandBufferService> command_buffer_; |
| 168 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 173 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
| 169 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 174 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
| 170 scoped_refptr<gfx::GLContext> context_; | 175 scoped_refptr<gfx::GLContext> context_; |
| 171 scoped_refptr<gfx::GLSurface> surface_; | 176 scoped_refptr<gfx::GLSurface> surface_; |
| 172 scoped_ptr<GLES2CmdHelper> gles2_helper_; | 177 scoped_ptr<GLES2CmdHelper> gles2_helper_; |
| 173 scoped_ptr<TransferBuffer> transfer_buffer_; | 178 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 174 scoped_ptr<GLES2Implementation> gles2_implementation_; | 179 scoped_ptr<GLES2Implementation> gles2_implementation_; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 415 |
| 411 // TODO(gman): Remove This | 416 // TODO(gman): Remove This |
| 412 void GLInProcessContext::DisableShaderTranslation() { | 417 void GLInProcessContext::DisableShaderTranslation() { |
| 413 NOTREACHED(); | 418 NOTREACHED(); |
| 414 } | 419 } |
| 415 | 420 |
| 416 GLES2Implementation* GLInProcessContext::GetImplementation() { | 421 GLES2Implementation* GLInProcessContext::GetImplementation() { |
| 417 return gles2_implementation_.get(); | 422 return gles2_implementation_.get(); |
| 418 } | 423 } |
| 419 | 424 |
| 425 ::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() { |
| 426 return decoder_->GetContextGroup()->image_manager(); |
| 427 } |
| 428 |
| 420 GLInProcessContext::GLInProcessContext(bool share_resources) | 429 GLInProcessContext::GLInProcessContext(bool share_resources) |
| 421 : last_error_(SUCCESS), | 430 : last_error_(SUCCESS), |
| 422 share_resources_(share_resources), | 431 share_resources_(share_resources), |
| 423 context_lost_(false) { | 432 context_lost_(false) { |
| 424 } | 433 } |
| 425 | 434 |
| 426 bool GLInProcessContext::Initialize( | 435 bool GLInProcessContext::Initialize( |
| 427 bool is_offscreen, | 436 bool is_offscreen, |
| 428 gfx::AcceleratedWidget window, | 437 gfx::AcceleratedWidget window, |
| 429 const gfx::Size& size, | 438 const gfx::Size& size, |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); | 603 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
| 595 | 604 |
| 596 // Create the object exposing the OpenGL API. | 605 // Create the object exposing the OpenGL API. |
| 597 gles2_implementation_.reset(new GLES2Implementation( | 606 gles2_implementation_.reset(new GLES2Implementation( |
| 598 gles2_helper_.get(), | 607 gles2_helper_.get(), |
| 599 context_group ? context_group->GetImplementation()->share_group() : NULL, | 608 context_group ? context_group->GetImplementation()->share_group() : NULL, |
| 600 transfer_buffer_.get(), | 609 transfer_buffer_.get(), |
| 601 true, | 610 true, |
| 602 false)); | 611 false)); |
| 603 | 612 |
| 613 // GLES2Implementation::Initialize() which is called next |
| 614 // needs the GpuMemoryBufferFactory so we set it before |
| 615 // Initialize is called. |
| 616 gles2_implementation_->SetGpuMemoryBufferFactory( |
| 617 new ::gpu::gles2::GpuMemoryBufferFactory(GetImageManager())); |
| 618 |
| 604 if (!gles2_implementation_->Initialize( | 619 if (!gles2_implementation_->Initialize( |
| 605 kStartTransferBufferSize, | 620 kStartTransferBufferSize, |
| 606 kMinTransferBufferSize, | 621 kMinTransferBufferSize, |
| 607 kMaxTransferBufferSize)) { | 622 kMaxTransferBufferSize)) { |
| 608 return false; | 623 return false; |
| 609 } | 624 } |
| 610 | 625 |
| 611 if (share_resources_) { | 626 if (share_resources_) { |
| 612 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 627 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 613 g_all_shared_contexts.Get()); | 628 g_all_shared_contexts.Get()); |
| (...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1698 ClearContext(); | 1713 ClearContext(); |
| 1699 gl_->DeleteBuffers(1, &buffer); | 1714 gl_->DeleteBuffers(1, &buffer); |
| 1700 } | 1715 } |
| 1701 | 1716 |
| 1702 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( | 1717 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( |
| 1703 WebGLId framebuffer) { | 1718 WebGLId framebuffer) { |
| 1704 ClearContext(); | 1719 ClearContext(); |
| 1705 gl_->DeleteFramebuffers(1, &framebuffer); | 1720 gl_->DeleteFramebuffers(1, &framebuffer); |
| 1706 } | 1721 } |
| 1707 | 1722 |
| 1723 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteImageBuffer( |
| 1724 WebGLId imagebuffer) { |
| 1725 ClearContext(); |
| 1726 gl_->DeleteImageBuffers(1, &imagebuffer); |
| 1727 } |
| 1728 |
| 1708 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( | 1729 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( |
| 1709 WebGLId program) { | 1730 WebGLId program) { |
| 1710 ClearContext(); | 1731 ClearContext(); |
| 1711 gl_->DeleteProgram(program); | 1732 gl_->DeleteProgram(program); |
| 1712 } | 1733 } |
| 1713 | 1734 |
| 1714 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer( | 1735 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer( |
| 1715 WebGLId renderbuffer) { | 1736 WebGLId renderbuffer) { |
| 1716 ClearContext(); | 1737 ClearContext(); |
| 1717 gl_->DeleteRenderbuffers(1, &renderbuffer); | 1738 gl_->DeleteRenderbuffers(1, &renderbuffer); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1822 } | 1843 } |
| 1823 | 1844 |
| 1824 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 1845 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
| 1825 // TODO(kbr): improve the precision here. | 1846 // TODO(kbr): improve the precision here. |
| 1826 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1847 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 1827 if (context_lost_callback_) { | 1848 if (context_lost_callback_) { |
| 1828 context_lost_callback_->onContextLost(); | 1849 context_lost_callback_->onContextLost(); |
| 1829 } | 1850 } |
| 1830 } | 1851 } |
| 1831 | 1852 |
| 1853 void WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 1854 createGpuMemoryBuffer2DCHROMIUM(WGC3Duint image_id, |
| 1855 WGC3Dint width, WGC3Dint height) { |
| 1856 ClearContext(); |
| 1857 gl_->CreateGpuMemoryBuffer2DCHROMIUM(image_id, width, height); |
| 1858 } |
| 1859 |
| 1832 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, | 1860 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, |
| 1833 WebGLId, WGC3Dint, const WGC3Dchar*) | 1861 WebGLId, WGC3Dint, const WGC3Dchar*) |
| 1834 | 1862 |
| 1835 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) | 1863 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) |
| 1836 | 1864 |
| 1837 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1865 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) |
| 1838 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1866 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, |
| 1839 WGC3Denum, const WGC3Dbyte*) | 1867 WGC3Denum, const WGC3Dbyte*) |
| 1840 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1868 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, |
| 1841 WGC3Denum, const WGC3Dbyte*) | 1869 WGC3Denum, const WGC3Dbyte*) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1868 | 1896 |
| 1869 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1897 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
| 1870 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1898 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
| 1871 WGC3Denum, WGC3Denum, const void*) | 1899 WGC3Denum, WGC3Denum, const void*) |
| 1872 | 1900 |
| 1873 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1901 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
| 1874 WGC3Denum) | 1902 WGC3Denum) |
| 1875 | 1903 |
| 1876 } // namespace gpu | 1904 } // namespace gpu |
| 1877 } // namespace webkit | 1905 } // namespace webkit |
| OLD | NEW |