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; |
| 48 using gpu::gles2::GpuMemoryBufferFactory; |
45 using gpu::gles2::GLES2CmdHelper; | 49 using gpu::gles2::GLES2CmdHelper; |
46 using gpu::gles2::GLES2Implementation; | 50 using gpu::gles2::GLES2Implementation; |
| 51 using gpu::gles2::ImageManager; |
| 52 using gpu::GpuMemoryBuffer; |
47 using gpu::GpuScheduler; | 53 using gpu::GpuScheduler; |
48 using gpu::TransferBuffer; | 54 using gpu::TransferBuffer; |
49 using gpu::TransferBufferManager; | 55 using gpu::TransferBufferManager; |
50 using gpu::TransferBufferManagerInterface; | 56 using gpu::TransferBufferManagerInterface; |
51 | 57 |
52 namespace webkit { | 58 namespace webkit { |
53 namespace gpu { | 59 namespace gpu { |
54 | 60 |
55 class GLInProcessContext { | 61 class GLInProcessContext { |
56 public: | 62 public: |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 bool Initialize(bool is_offscreen, | 161 bool Initialize(bool is_offscreen, |
156 gfx::AcceleratedWidget window, | 162 gfx::AcceleratedWidget window, |
157 const gfx::Size& size, | 163 const gfx::Size& size, |
158 const char* allowed_extensions, | 164 const char* allowed_extensions, |
159 const int32* attrib_list, | 165 const int32* attrib_list, |
160 gfx::GpuPreference gpu_preference); | 166 gfx::GpuPreference gpu_preference); |
161 void Destroy(); | 167 void Destroy(); |
162 | 168 |
163 void OnContextLost(); | 169 void OnContextLost(); |
164 | 170 |
| 171 ::gpu::gles2::ImageManager* GetImageManager(); |
| 172 |
165 base::Closure context_lost_callback_; | 173 base::Closure context_lost_callback_; |
166 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 174 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
167 scoped_ptr<CommandBufferService> command_buffer_; | 175 scoped_ptr<CommandBufferService> command_buffer_; |
168 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 176 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
169 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 177 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
170 scoped_refptr<gfx::GLContext> context_; | 178 scoped_refptr<gfx::GLContext> context_; |
171 scoped_refptr<gfx::GLSurface> surface_; | 179 scoped_refptr<gfx::GLSurface> surface_; |
172 scoped_ptr<GLES2CmdHelper> gles2_helper_; | 180 scoped_ptr<GLES2CmdHelper> gles2_helper_; |
173 scoped_ptr<TransferBuffer> transfer_buffer_; | 181 scoped_ptr<TransferBuffer> transfer_buffer_; |
174 scoped_ptr<GLES2Implementation> gles2_implementation_; | 182 scoped_ptr<GLES2Implementation> gles2_implementation_; |
175 scoped_ptr<WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> | 183 scoped_ptr<WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> |
176 signal_sync_point_callback_; | 184 signal_sync_point_callback_; |
177 Error last_error_; | 185 Error last_error_; |
178 bool share_resources_; | 186 bool share_resources_; |
179 bool context_lost_; | 187 bool context_lost_; |
180 | 188 |
181 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); | 189 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); |
182 }; | 190 }; |
183 | 191 |
184 namespace { | 192 namespace { |
185 | 193 |
186 const int32 kCommandBufferSize = 1024 * 1024; | 194 const int32 kCommandBufferSize = 1024 * 1024; |
187 // TODO(kbr): make the transfer buffer size configurable via context | 195 // TODO(kbr): make the transfer buffer size configurable via context |
188 // creation attributes. | 196 // creation attributes. |
189 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; | 197 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; |
190 const size_t kMinTransferBufferSize = 1 * 256 * 1024; | 198 const size_t kMinTransferBufferSize = 1 * 256 * 1024; |
191 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; | 199 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; |
192 | 200 |
| 201 class GpuMemoryBufferImageManagerFactory : public GpuMemoryBufferFactory { |
| 202 public: |
| 203 explicit GpuMemoryBufferImageManagerFactory(ImageManager* image_manager); |
| 204 virtual ~GpuMemoryBufferImageManagerFactory(); |
| 205 |
| 206 // methods from GpuMemoryBufferFactory |
| 207 virtual scoped_ptr<GpuMemoryBuffer> CreateGpuMemoryBuffer( |
| 208 int width, int height, int image_id) OVERRIDE; |
| 209 private: |
| 210 scoped_refptr<ImageManager> image_manager_; |
| 211 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImageManagerFactory); |
| 212 }; |
| 213 |
| 214 GpuMemoryBufferImageManagerFactory::GpuMemoryBufferImageManagerFactory( |
| 215 ImageManager* image_manager) : image_manager_(image_manager) { |
| 216 } |
| 217 |
| 218 GpuMemoryBufferImageManagerFactory::~GpuMemoryBufferImageManagerFactory() { |
| 219 } |
| 220 |
| 221 scoped_ptr<GpuMemoryBuffer> GpuMemoryBufferImageManagerFactory:: |
| 222 CreateGpuMemoryBuffer(int width, int height, int image_id) { |
| 223 scoped_ptr<GpuMemoryBuffer> buffer = |
| 224 ::gpu::gles2::GetProcessDefaultGpuMemoryBufferFactory().Run( |
| 225 width, height); |
| 226 scoped_refptr<gfx::GLImage> gl_image = |
| 227 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), |
| 228 gfx::Size(width, height)); |
| 229 image_manager_->AddImage(gl_image, image_id); |
| 230 return buffer.Pass(); |
| 231 } |
| 232 |
193 // Singleton used to initialize and terminate the gles2 library. | 233 // Singleton used to initialize and terminate the gles2 library. |
194 class GLES2Initializer { | 234 class GLES2Initializer { |
195 public: | 235 public: |
196 GLES2Initializer() { | 236 GLES2Initializer() { |
197 gles2::Initialize(); | 237 gles2::Initialize(); |
198 } | 238 } |
199 | 239 |
200 ~GLES2Initializer() { | 240 ~GLES2Initializer() { |
201 gles2::Terminate(); | 241 gles2::Terminate(); |
202 } | 242 } |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 | 450 |
411 // TODO(gman): Remove This | 451 // TODO(gman): Remove This |
412 void GLInProcessContext::DisableShaderTranslation() { | 452 void GLInProcessContext::DisableShaderTranslation() { |
413 NOTREACHED(); | 453 NOTREACHED(); |
414 } | 454 } |
415 | 455 |
416 GLES2Implementation* GLInProcessContext::GetImplementation() { | 456 GLES2Implementation* GLInProcessContext::GetImplementation() { |
417 return gles2_implementation_.get(); | 457 return gles2_implementation_.get(); |
418 } | 458 } |
419 | 459 |
| 460 ::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() { |
| 461 return decoder_->GetContextGroup()->image_manager(); |
| 462 } |
| 463 |
420 GLInProcessContext::GLInProcessContext(bool share_resources) | 464 GLInProcessContext::GLInProcessContext(bool share_resources) |
421 : last_error_(SUCCESS), | 465 : last_error_(SUCCESS), |
422 share_resources_(share_resources), | 466 share_resources_(share_resources), |
423 context_lost_(false) { | 467 context_lost_(false) { |
424 } | 468 } |
425 | 469 |
426 bool GLInProcessContext::Initialize( | 470 bool GLInProcessContext::Initialize( |
427 bool is_offscreen, | 471 bool is_offscreen, |
428 gfx::AcceleratedWidget window, | 472 gfx::AcceleratedWidget window, |
429 const gfx::Size& size, | 473 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())); | 638 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
595 | 639 |
596 // Create the object exposing the OpenGL API. | 640 // Create the object exposing the OpenGL API. |
597 gles2_implementation_.reset(new GLES2Implementation( | 641 gles2_implementation_.reset(new GLES2Implementation( |
598 gles2_helper_.get(), | 642 gles2_helper_.get(), |
599 context_group ? context_group->GetImplementation()->share_group() : NULL, | 643 context_group ? context_group->GetImplementation()->share_group() : NULL, |
600 transfer_buffer_.get(), | 644 transfer_buffer_.get(), |
601 true, | 645 true, |
602 false)); | 646 false)); |
603 | 647 |
| 648 // GLES2Implementation::Initialize() which is called next |
| 649 // needs the GpuMemoryBufferFactory so we set it before |
| 650 // Initialize is called. |
| 651 scoped_ptr<GpuMemoryBufferFactory> gpu_memory_buffer_factory( |
| 652 new GpuMemoryBufferImageManagerFactory(GetImageManager())); |
| 653 // GLES2Implementation takes the ownership of |gpu_memory_buffer_factory|. |
| 654 gles2_implementation_->SetGpuMemoryBufferFactory( |
| 655 gpu_memory_buffer_factory.Pass()); |
| 656 |
604 if (!gles2_implementation_->Initialize( | 657 if (!gles2_implementation_->Initialize( |
605 kStartTransferBufferSize, | 658 kStartTransferBufferSize, |
606 kMinTransferBufferSize, | 659 kMinTransferBufferSize, |
607 kMaxTransferBufferSize)) { | 660 kMaxTransferBufferSize)) { |
608 return false; | 661 return false; |
609 } | 662 } |
610 | 663 |
611 if (share_resources_) { | 664 if (share_resources_) { |
612 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 665 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
613 g_all_shared_contexts.Get()); | 666 g_all_shared_contexts.Get()); |
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1698 ClearContext(); | 1751 ClearContext(); |
1699 gl_->DeleteBuffers(1, &buffer); | 1752 gl_->DeleteBuffers(1, &buffer); |
1700 } | 1753 } |
1701 | 1754 |
1702 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( | 1755 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteFramebuffer( |
1703 WebGLId framebuffer) { | 1756 WebGLId framebuffer) { |
1704 ClearContext(); | 1757 ClearContext(); |
1705 gl_->DeleteFramebuffers(1, &framebuffer); | 1758 gl_->DeleteFramebuffers(1, &framebuffer); |
1706 } | 1759 } |
1707 | 1760 |
| 1761 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteImageBuffer( |
| 1762 WebGLId imagebuffer) { |
| 1763 ClearContext(); |
| 1764 gl_->DeleteImageBuffers(1, &imagebuffer); |
| 1765 } |
| 1766 |
1708 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( | 1767 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteProgram( |
1709 WebGLId program) { | 1768 WebGLId program) { |
1710 ClearContext(); | 1769 ClearContext(); |
1711 gl_->DeleteProgram(program); | 1770 gl_->DeleteProgram(program); |
1712 } | 1771 } |
1713 | 1772 |
1714 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer( | 1773 void WebGraphicsContext3DInProcessCommandBufferImpl::deleteRenderbuffer( |
1715 WebGLId renderbuffer) { | 1774 WebGLId renderbuffer) { |
1716 ClearContext(); | 1775 ClearContext(); |
1717 gl_->DeleteRenderbuffers(1, &renderbuffer); | 1776 gl_->DeleteRenderbuffers(1, &renderbuffer); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1822 } | 1881 } |
1823 | 1882 |
1824 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 1883 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
1825 // TODO(kbr): improve the precision here. | 1884 // TODO(kbr): improve the precision here. |
1826 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1885 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
1827 if (context_lost_callback_) { | 1886 if (context_lost_callback_) { |
1828 context_lost_callback_->onContextLost(); | 1887 context_lost_callback_->onContextLost(); |
1829 } | 1888 } |
1830 } | 1889 } |
1831 | 1890 |
| 1891 void WebGraphicsContext3DInProcessCommandBufferImpl:: |
| 1892 createGpuMemoryBuffer2DCHROMIUM(WGC3Duint image_id, |
| 1893 WGC3Dint width, WGC3Dint height) { |
| 1894 ClearContext(); |
| 1895 gl_->CreateGpuMemoryBuffer2DCHROMIUM(image_id, width, height); |
| 1896 } |
| 1897 |
1832 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, | 1898 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, |
1833 WebGLId, WGC3Dint, const WGC3Dchar*) | 1899 WebGLId, WGC3Dint, const WGC3Dchar*) |
1834 | 1900 |
1835 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) | 1901 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) |
1836 | 1902 |
1837 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1903 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) |
1838 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1904 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, |
1839 WGC3Denum, const WGC3Dbyte*) | 1905 WGC3Denum, const WGC3Dbyte*) |
1840 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1906 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, |
1841 WGC3Denum, const WGC3Dbyte*) | 1907 WGC3Denum, const WGC3Dbyte*) |
(...skipping 26 matching lines...) Expand all Loading... |
1868 | 1934 |
1869 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1935 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
1870 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1936 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
1871 WGC3Denum, WGC3Denum, const void*) | 1937 WGC3Denum, WGC3Denum, const void*) |
1872 | 1938 |
1873 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1939 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
1874 WGC3Denum) | 1940 WGC3Denum) |
1875 | 1941 |
1876 } // namespace gpu | 1942 } // namespace gpu |
1877 } // namespace webkit | 1943 } // namespace webkit |
OLD | NEW |