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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 Error GetError(); | 139 Error GetError(); |
137 | 140 |
138 // Return true if GPU process reported GLInProcessContext lost or there was a | 141 // Return true if GPU process reported GLInProcessContext lost or there was a |
139 // problem communicating with the GPU process. | 142 // problem communicating with the GPU process. |
140 bool IsCommandBufferContextLost(); | 143 bool IsCommandBufferContextLost(); |
141 | 144 |
142 CommandBufferService* GetCommandBufferService(); | 145 CommandBufferService* GetCommandBufferService(); |
143 | 146 |
144 ::gpu::gles2::GLES2Decoder* GetDecoder(); | 147 ::gpu::gles2::GLES2Decoder* GetDecoder(); |
145 | 148 |
| 149 |
146 private: | 150 private: |
147 explicit GLInProcessContext(bool share_resources); | 151 explicit GLInProcessContext(bool share_resources); |
148 | 152 |
149 bool Initialize(bool is_offscreen, | 153 bool Initialize(bool is_offscreen, |
150 gfx::AcceleratedWidget window, | 154 gfx::AcceleratedWidget window, |
151 const gfx::Size& size, | 155 const gfx::Size& size, |
152 const char* allowed_extensions, | 156 const char* allowed_extensions, |
153 const int32* attrib_list, | 157 const int32* attrib_list, |
154 gfx::GpuPreference gpu_preference); | 158 gfx::GpuPreference gpu_preference); |
155 void Destroy(); | 159 void Destroy(); |
156 | 160 |
157 void OnContextLost(); | 161 void OnContextLost(); |
158 | 162 |
| 163 ::gpu::gles2::ImageManager* GetImageManager(); |
| 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_; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 384 |
379 // TODO(gman): Remove This | 385 // TODO(gman): Remove This |
380 void GLInProcessContext::DisableShaderTranslation() { | 386 void GLInProcessContext::DisableShaderTranslation() { |
381 NOTREACHED(); | 387 NOTREACHED(); |
382 } | 388 } |
383 | 389 |
384 GLES2Implementation* GLInProcessContext::GetImplementation() { | 390 GLES2Implementation* GLInProcessContext::GetImplementation() { |
385 return gles2_implementation_.get(); | 391 return gles2_implementation_.get(); |
386 } | 392 } |
387 | 393 |
| 394 ::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() { |
| 395 return decoder_->GetContextGroup()->image_manager(); |
| 396 } |
| 397 |
388 GLInProcessContext::GLInProcessContext(bool share_resources) | 398 GLInProcessContext::GLInProcessContext(bool share_resources) |
389 : last_error_(SUCCESS), | 399 : last_error_(SUCCESS), |
390 share_resources_(share_resources), | 400 share_resources_(share_resources), |
391 context_lost_(false) { | 401 context_lost_(false) { |
392 } | 402 } |
393 | 403 |
394 bool GLInProcessContext::Initialize( | 404 bool GLInProcessContext::Initialize( |
395 bool is_offscreen, | 405 bool is_offscreen, |
396 gfx::AcceleratedWidget window, | 406 gfx::AcceleratedWidget window, |
397 const gfx::Size& size, | 407 const gfx::Size& size, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 if (share_resources_ && !g_all_shared_contexts.Get().empty()) | 467 if (share_resources_ && !g_all_shared_contexts.Get().empty()) |
458 context_group = *g_all_shared_contexts.Get().begin(); | 468 context_group = *g_all_shared_contexts.Get().begin(); |
459 | 469 |
460 // TODO(gman): This needs to be true if this is Pepper. | 470 // TODO(gman): This needs to be true if this is Pepper. |
461 bool bind_generates_resource = false; | 471 bool bind_generates_resource = false; |
462 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group ? | 472 decoder_.reset(::gpu::gles2::GLES2Decoder::Create(context_group ? |
463 context_group->decoder_->GetContextGroup() : | 473 context_group->decoder_->GetContextGroup() : |
464 new ::gpu::gles2::ContextGroup( | 474 new ::gpu::gles2::ContextGroup( |
465 NULL, NULL, NULL, bind_generates_resource))); | 475 NULL, NULL, NULL, bind_generates_resource))); |
466 | 476 |
| 477 ::gpu::SetProcessDefaultImageManager(GetImageManager()); |
| 478 |
467 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), | 479 gpu_scheduler_.reset(new GpuScheduler(command_buffer_.get(), |
468 decoder_.get(), | 480 decoder_.get(), |
469 decoder_.get())); | 481 decoder_.get())); |
470 | 482 |
471 decoder_->set_engine(gpu_scheduler_.get()); | 483 decoder_->set_engine(gpu_scheduler_.get()); |
472 | 484 |
473 if (is_offscreen) | 485 if (is_offscreen) |
474 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); | 486 surface_ = gfx::GLSurface::CreateOffscreenGLSurface(false, size); |
475 else | 487 else |
476 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); | 488 surface_ = gfx::GLSurface::CreateViewGLSurface(false, window); |
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1637 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() { | 1649 WebGLId WebGraphicsContext3DInProcessCommandBufferImpl::createTexture() { |
1638 ClearContext(); | 1650 ClearContext(); |
1639 GLuint o; | 1651 GLuint o; |
1640 gl_->GenTextures(1, &o); | 1652 gl_->GenTextures(1, &o); |
1641 return o; | 1653 return o; |
1642 } | 1654 } |
1643 | 1655 |
1644 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer( | 1656 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteBuffer( |
1645 WebGLId buffer) { | 1657 WebGLId buffer) { |
1646 ClearContext(); | 1658 ClearContext(); |
| 1659 // It is safe to call this method even though the buffer being deleted |
| 1660 // isn't a GPU memory buffer as it eventually translates to a |
| 1661 // hash_map::erase() which doesn't throw an exception if the key |
| 1662 // isn't in the hash_map |
| 1663 DeleteImageForGpuMemoryBuffer(buffer); |
1647 gl_->DeleteBuffers(1, &buffer); | 1664 gl_->DeleteBuffers(1, &buffer); |
1648 } | 1665 } |
1649 | 1666 |
1650 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( | 1667 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( |
1651 WebGLId framebuffer) { | 1668 WebGLId framebuffer) { |
1652 ClearContext(); | 1669 ClearContext(); |
1653 gl_->DeleteFramebuffers(1, &framebuffer); | 1670 gl_->DeleteFramebuffers(1, &framebuffer); |
1654 } | 1671 } |
1655 | 1672 |
1656 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( | 1673 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 } | 1787 } |
1771 | 1788 |
1772 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 1789 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
1773 // TODO(kbr): improve the precision here. | 1790 // TODO(kbr): improve the precision here. |
1774 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1791 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
1775 if (context_lost_callback_) { | 1792 if (context_lost_callback_) { |
1776 context_lost_callback_->onContextLost(); | 1793 context_lost_callback_->onContextLost(); |
1777 } | 1794 } |
1778 } | 1795 } |
1779 | 1796 |
| 1797 void WebGraphicsContext3DInProcessCommandBufferImpl::imageBufferDataCHROMIUM( |
| 1798 WGC3Denum target, WGC3Dsizei width, WGC3Dsizei height) { |
| 1799 ClearContext(); |
| 1800 gl_->ImageBufferDataCHROMIUM(target, width, height); |
| 1801 } |
| 1802 |
1780 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, | 1803 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, |
1781 WebGLId, WGC3Dint, const WGC3Dchar*) | 1804 WebGLId, WGC3Dint, const WGC3Dchar*) |
1782 | 1805 |
1783 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) | 1806 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) |
1784 | 1807 |
1785 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1808 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) |
1786 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1809 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, |
1787 WGC3Denum, const WGC3Dbyte*) | 1810 WGC3Denum, const WGC3Dbyte*) |
1788 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1811 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, |
1789 WGC3Denum, const WGC3Dbyte*) | 1812 WGC3Denum, const WGC3Dbyte*) |
1790 | 1813 |
1791 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, | 1814 DELEGATE_TO_GL_2(drawBuffersEXT, DrawBuffersEXT, |
1792 WGC3Dsizei, const WGC3Denum*) | 1815 WGC3Dsizei, const WGC3Denum*) |
1793 | 1816 |
1794 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, | 1817 DELEGATE_TO_GL_9(asyncTexImage2DCHROMIUM, AsyncTexImage2DCHROMIUM, |
1795 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint, | 1818 WGC3Denum, WGC3Dint, WGC3Denum, WGC3Dsizei, WGC3Dsizei, WGC3Dint, |
1796 WGC3Denum, WGC3Denum, const void*) | 1819 WGC3Denum, WGC3Denum, const void*) |
1797 | 1820 |
1798 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1821 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
1799 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1822 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
1800 WGC3Denum, WGC3Denum, const void*) | 1823 WGC3Denum, WGC3Denum, const void*) |
1801 | 1824 |
1802 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1825 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
1803 WGC3Denum) | 1826 WGC3Denum) |
1804 | 1827 |
1805 } // namespace gpu | 1828 } // namespace gpu |
1806 } // namespace webkit | 1829 } // namespace webkit |
OLD | NEW |