Chromium Code Reviews| 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" | |
| 31 #include "gpu/command_buffer/client/image_factory.h" | |
| 30 #include "gpu/command_buffer/client/transfer_buffer.h" | 32 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 31 #include "gpu/command_buffer/common/constants.h" | 33 #include "gpu/command_buffer/common/constants.h" |
| 32 #include "gpu/command_buffer/service/command_buffer_service.h" | 34 #include "gpu/command_buffer/service/command_buffer_service.h" |
| 33 #include "gpu/command_buffer/service/context_group.h" | 35 #include "gpu/command_buffer/service/context_group.h" |
| 34 #include "gpu/command_buffer/service/gl_context_virtual.h" | 36 #include "gpu/command_buffer/service/gl_context_virtual.h" |
| 35 #include "gpu/command_buffer/service/gpu_scheduler.h" | 37 #include "gpu/command_buffer/service/gpu_scheduler.h" |
| 38 #include "gpu/command_buffer/service/image_manager.h" | |
| 36 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 39 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| 37 #include "ui/gl/gl_context.h" | 40 #include "ui/gl/gl_context.h" |
| 41 #include "ui/gl/gl_image.h" | |
| 38 #include "ui/gl/gl_share_group.h" | 42 #include "ui/gl/gl_share_group.h" |
| 39 #include "ui/gl/gl_surface.h" | 43 #include "ui/gl/gl_surface.h" |
| 40 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" | 44 #include "webkit/gpu/gl_bindings_skia_cmd_buffer.h" |
| 41 | 45 |
| 42 using gpu::Buffer; | 46 using gpu::Buffer; |
| 43 using gpu::CommandBuffer; | 47 using gpu::CommandBuffer; |
| 44 using gpu::CommandBufferService; | 48 using gpu::CommandBufferService; |
| 49 using gpu::gles2::ImageFactory; | |
|
no sievers
2013/05/10 01:21:51
nit: order
kaanb
2013/05/13 23:00:36
Done.
| |
| 45 using gpu::gles2::GLES2CmdHelper; | 50 using gpu::gles2::GLES2CmdHelper; |
| 46 using gpu::gles2::GLES2Implementation; | 51 using gpu::gles2::GLES2Implementation; |
| 52 using gpu::gles2::ImageManager; | |
| 53 using gpu::GpuMemoryBuffer; | |
| 47 using gpu::GpuScheduler; | 54 using gpu::GpuScheduler; |
| 48 using gpu::TransferBuffer; | 55 using gpu::TransferBuffer; |
| 49 using gpu::TransferBufferManager; | 56 using gpu::TransferBufferManager; |
| 50 using gpu::TransferBufferManagerInterface; | 57 using gpu::TransferBufferManagerInterface; |
| 51 | 58 |
| 52 namespace webkit { | 59 namespace webkit { |
| 53 namespace gpu { | 60 namespace gpu { |
| 54 | 61 |
| 55 class GLInProcessContext { | 62 class GLInProcessContext { |
| 56 public: | 63 public: |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 bool Initialize(bool is_offscreen, | 162 bool Initialize(bool is_offscreen, |
| 156 gfx::AcceleratedWidget window, | 163 gfx::AcceleratedWidget window, |
| 157 const gfx::Size& size, | 164 const gfx::Size& size, |
| 158 const char* allowed_extensions, | 165 const char* allowed_extensions, |
| 159 const int32* attrib_list, | 166 const int32* attrib_list, |
| 160 gfx::GpuPreference gpu_preference); | 167 gfx::GpuPreference gpu_preference); |
| 161 void Destroy(); | 168 void Destroy(); |
| 162 | 169 |
| 163 void OnContextLost(); | 170 void OnContextLost(); |
| 164 | 171 |
| 172 ::gpu::gles2::ImageManager* GetImageManager(); | |
| 173 | |
| 165 base::Closure context_lost_callback_; | 174 base::Closure context_lost_callback_; |
| 166 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; | 175 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; |
| 167 scoped_ptr<CommandBufferService> command_buffer_; | 176 scoped_ptr<CommandBufferService> command_buffer_; |
| 168 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; | 177 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; |
| 169 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; | 178 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; |
| 170 scoped_refptr<gfx::GLContext> context_; | 179 scoped_refptr<gfx::GLContext> context_; |
| 171 scoped_refptr<gfx::GLSurface> surface_; | 180 scoped_refptr<gfx::GLSurface> surface_; |
| 172 scoped_ptr<GLES2CmdHelper> gles2_helper_; | 181 scoped_ptr<GLES2CmdHelper> gles2_helper_; |
| 173 scoped_ptr<TransferBuffer> transfer_buffer_; | 182 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 174 scoped_ptr<GLES2Implementation> gles2_implementation_; | 183 scoped_ptr<GLES2Implementation> gles2_implementation_; |
| 175 scoped_ptr<WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> | 184 scoped_ptr<WebKit::WebGraphicsContext3D::WebGraphicsSyncPointCallback> |
| 176 signal_sync_point_callback_; | 185 signal_sync_point_callback_; |
| 177 Error last_error_; | 186 Error last_error_; |
| 178 bool share_resources_; | 187 bool share_resources_; |
| 179 bool context_lost_; | 188 bool context_lost_; |
| 180 | 189 |
| 181 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); | 190 DISALLOW_COPY_AND_ASSIGN(GLInProcessContext); |
| 182 }; | 191 }; |
| 183 | 192 |
| 184 namespace { | 193 namespace { |
| 185 | 194 |
| 186 const int32 kCommandBufferSize = 1024 * 1024; | 195 const int32 kCommandBufferSize = 1024 * 1024; |
| 187 // TODO(kbr): make the transfer buffer size configurable via context | 196 // TODO(kbr): make the transfer buffer size configurable via context |
| 188 // creation attributes. | 197 // creation attributes. |
| 189 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; | 198 const size_t kStartTransferBufferSize = 4 * 1024 * 1024; |
| 190 const size_t kMinTransferBufferSize = 1 * 256 * 1024; | 199 const size_t kMinTransferBufferSize = 1 * 256 * 1024; |
| 191 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; | 200 const size_t kMaxTransferBufferSize = 16 * 1024 * 1024; |
| 192 | 201 |
| 202 class ImageFactoryInProcess : public ImageFactory { | |
| 203 public: | |
| 204 explicit ImageFactoryInProcess(ImageManager* image_manager); | |
| 205 virtual ~ImageFactoryInProcess(); | |
| 206 | |
| 207 // methods from ImageFactory | |
| 208 virtual scoped_ptr<GpuMemoryBuffer> CreateGpuMemoryBuffer( | |
| 209 int width, int height, unsigned int* image_id) OVERRIDE; | |
| 210 virtual void RemoveFromManager(unsigned int image_id) OVERRIDE; | |
| 211 private: | |
| 212 scoped_refptr<ImageManager> image_manager_; | |
| 213 unsigned int next_id_; | |
| 214 | |
| 215 DISALLOW_COPY_AND_ASSIGN(ImageFactoryInProcess); | |
| 216 }; | |
| 217 | |
| 218 ImageFactoryInProcess::ImageFactoryInProcess( | |
| 219 ImageManager* image_manager) : image_manager_(image_manager), | |
| 220 next_id_(0) { | |
| 221 } | |
| 222 | |
| 223 ImageFactoryInProcess::~ImageFactoryInProcess() { | |
| 224 } | |
| 225 | |
| 226 scoped_ptr<GpuMemoryBuffer> ImageFactoryInProcess:: | |
| 227 CreateGpuMemoryBuffer(int width, int height, unsigned int* image_id) { | |
| 228 scoped_ptr<GpuMemoryBuffer> buffer = | |
| 229 ::gpu::gles2::GetProcessDefaultGpuMemoryBufferFactory().Run( | |
| 230 width, height); | |
| 231 scoped_refptr<gfx::GLImage> gl_image = | |
| 232 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), | |
| 233 gfx::Size(width, height)); | |
| 234 *image_id = ++next_id_; // Valid image_ids start from 1. | |
| 235 image_manager_->AddImage(gl_image, *image_id); | |
| 236 return buffer.Pass(); | |
| 237 } | |
| 238 | |
| 239 void ImageFactoryInProcess::RemoveFromManager(unsigned int image_id) { | |
| 240 image_manager_->RemoveImage(image_id); | |
| 241 } | |
| 242 | |
| 193 // Singleton used to initialize and terminate the gles2 library. | 243 // Singleton used to initialize and terminate the gles2 library. |
| 194 class GLES2Initializer { | 244 class GLES2Initializer { |
| 195 public: | 245 public: |
| 196 GLES2Initializer() { | 246 GLES2Initializer() { |
| 197 gles2::Initialize(); | 247 gles2::Initialize(); |
| 198 } | 248 } |
| 199 | 249 |
| 200 ~GLES2Initializer() { | 250 ~GLES2Initializer() { |
| 201 gles2::Terminate(); | 251 gles2::Terminate(); |
| 202 } | 252 } |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 | 460 |
| 411 // TODO(gman): Remove This | 461 // TODO(gman): Remove This |
| 412 void GLInProcessContext::DisableShaderTranslation() { | 462 void GLInProcessContext::DisableShaderTranslation() { |
| 413 NOTREACHED(); | 463 NOTREACHED(); |
| 414 } | 464 } |
| 415 | 465 |
| 416 GLES2Implementation* GLInProcessContext::GetImplementation() { | 466 GLES2Implementation* GLInProcessContext::GetImplementation() { |
| 417 return gles2_implementation_.get(); | 467 return gles2_implementation_.get(); |
| 418 } | 468 } |
| 419 | 469 |
| 470 ::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() { | |
| 471 return decoder_->GetContextGroup()->image_manager(); | |
| 472 } | |
| 473 | |
| 420 GLInProcessContext::GLInProcessContext(bool share_resources) | 474 GLInProcessContext::GLInProcessContext(bool share_resources) |
| 421 : last_error_(SUCCESS), | 475 : last_error_(SUCCESS), |
| 422 share_resources_(share_resources), | 476 share_resources_(share_resources), |
| 423 context_lost_(false) { | 477 context_lost_(false) { |
| 424 } | 478 } |
| 425 | 479 |
| 426 bool GLInProcessContext::Initialize( | 480 bool GLInProcessContext::Initialize( |
| 427 bool is_offscreen, | 481 bool is_offscreen, |
| 428 gfx::AcceleratedWidget window, | 482 gfx::AcceleratedWidget window, |
| 429 const gfx::Size& size, | 483 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())); | 648 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); |
| 595 | 649 |
| 596 // Create the object exposing the OpenGL API. | 650 // Create the object exposing the OpenGL API. |
| 597 gles2_implementation_.reset(new GLES2Implementation( | 651 gles2_implementation_.reset(new GLES2Implementation( |
| 598 gles2_helper_.get(), | 652 gles2_helper_.get(), |
| 599 context_group ? context_group->GetImplementation()->share_group() : NULL, | 653 context_group ? context_group->GetImplementation()->share_group() : NULL, |
| 600 transfer_buffer_.get(), | 654 transfer_buffer_.get(), |
| 601 true, | 655 true, |
| 602 false)); | 656 false)); |
| 603 | 657 |
| 658 // GLES2Implementation::Initialize() which is called next | |
| 659 // needs the ImageFactory so we set it before Initialize is called. | |
| 660 scoped_ptr<ImageFactory> image_factory( | |
| 661 new ImageFactoryInProcess(GetImageManager())); | |
|
no sievers
2013/05/10 01:21:51
That means different clients in the share group wi
kaanb
2013/05/13 23:00:36
Let me know how this change looks.
| |
| 662 // GLES2Implementation takes the ownership of |image_factory|. | |
| 663 gles2_implementation_->SetImageFactory(image_factory.Pass()); | |
| 664 | |
| 604 if (!gles2_implementation_->Initialize( | 665 if (!gles2_implementation_->Initialize( |
| 605 kStartTransferBufferSize, | 666 kStartTransferBufferSize, |
| 606 kMinTransferBufferSize, | 667 kMinTransferBufferSize, |
| 607 kMaxTransferBufferSize)) { | 668 kMaxTransferBufferSize)) { |
| 608 return false; | 669 return false; |
| 609 } | 670 } |
| 610 | 671 |
| 611 if (share_resources_) { | 672 if (share_resources_) { |
| 612 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 673 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 613 g_all_shared_contexts.Get()); | 674 g_all_shared_contexts.Get()); |
| (...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1822 } | 1883 } |
| 1823 | 1884 |
| 1824 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 1885 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { |
| 1825 // TODO(kbr): improve the precision here. | 1886 // TODO(kbr): improve the precision here. |
| 1826 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1887 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 1827 if (context_lost_callback_) { | 1888 if (context_lost_callback_) { |
| 1828 context_lost_callback_->onContextLost(); | 1889 context_lost_callback_->onContextLost(); |
| 1829 } | 1890 } |
| 1830 } | 1891 } |
| 1831 | 1892 |
| 1893 DELEGATE_TO_GL_2R(createImageCHROMIUM, CreateImageCHROMIUM, | |
| 1894 WGC3Dsizei, WGC3Dsizei, WGC3Duint); | |
| 1895 | |
| 1896 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint); | |
| 1897 | |
| 1898 DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM, | |
| 1899 WGC3Duint, WGC3Denum, GLint*); | |
| 1900 | |
| 1901 DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM, | |
| 1902 WGC3Duint, WGC3Denum, void*); | |
| 1903 | |
| 1904 DELEGATE_TO_GL_1R(unmapImageCHROMIUM, UnmapImageCHROMIUM, | |
| 1905 WGC3Duint, WGC3Dboolean); | |
| 1906 | |
| 1832 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, | 1907 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, |
| 1833 WebGLId, WGC3Dint, const WGC3Dchar*) | 1908 WebGLId, WGC3Dint, const WGC3Dchar*) |
| 1834 | 1909 |
| 1835 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) | 1910 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) |
| 1836 | 1911 |
| 1837 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1912 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) |
| 1838 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1913 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, |
| 1839 WGC3Denum, const WGC3Dbyte*) | 1914 WGC3Denum, const WGC3Dbyte*) |
| 1840 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1915 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, |
| 1841 WGC3Denum, const WGC3Dbyte*) | 1916 WGC3Denum, const WGC3Dbyte*) |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1868 | 1943 |
| 1869 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1944 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, |
| 1870 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1945 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, |
| 1871 WGC3Denum, WGC3Denum, const void*) | 1946 WGC3Denum, WGC3Denum, const void*) |
| 1872 | 1947 |
| 1873 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1948 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, |
| 1874 WGC3Denum) | 1949 WGC3Denum) |
| 1875 | 1950 |
| 1876 } // namespace gpu | 1951 } // namespace gpu |
| 1877 } // namespace webkit | 1952 } // namespace webkit |
| OLD | NEW |