 Chromium Code Reviews
 Chromium Code Reviews Issue 14456004:
  GPU client side changes for GpuMemoryBuffers  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
    
  
    Issue 14456004:
  GPU client side changes for GpuMemoryBuffers  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@glapi| 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, unsigned int* image_id) OVERRIDE; | |
| 209 private: | |
| 210 scoped_refptr<ImageManager> image_manager_; | |
| 211 unsigned int next_id_; | |
| 212 | |
| 213 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImageManagerFactory); | |
| 214 }; | |
| 215 | |
| 216 GpuMemoryBufferImageManagerFactory::GpuMemoryBufferImageManagerFactory( | |
| 217 ImageManager* image_manager) : image_manager_(image_manager), | |
| 218 next_id_(0) { | |
| 219 } | |
| 220 | |
| 221 GpuMemoryBufferImageManagerFactory::~GpuMemoryBufferImageManagerFactory() { | |
| 222 } | |
| 223 | |
| 224 scoped_ptr<GpuMemoryBuffer> GpuMemoryBufferImageManagerFactory:: | |
| 225 CreateGpuMemoryBuffer(int width, int height, unsigned int* image_id) { | |
| 226 scoped_ptr<GpuMemoryBuffer> buffer = | |
| 227 ::gpu::gles2::GetProcessDefaultGpuMemoryBufferFactory().Run( | |
| 228 width, height); | |
| 
reveman
2013/05/08 04:23:06
The factory being a callback is awkward.
 
kaanb
2013/05/09 05:13:13
Acknowledged.
 | |
| 229 scoped_refptr<gfx::GLImage> gl_image = | |
| 230 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), | |
| 231 gfx::Size(width, height)); | |
| 232 *image_id = ++next_id_; // Valid image_ids start from 1. | |
| 233 image_manager_->AddImage(gl_image, *image_id); | |
| 234 return buffer.Pass(); | |
| 235 } | |
| 236 | |
| 193 // Singleton used to initialize and terminate the gles2 library. | 237 // Singleton used to initialize and terminate the gles2 library. | 
| 194 class GLES2Initializer { | 238 class GLES2Initializer { | 
| 195 public: | 239 public: | 
| 196 GLES2Initializer() { | 240 GLES2Initializer() { | 
| 197 gles2::Initialize(); | 241 gles2::Initialize(); | 
| 198 } | 242 } | 
| 199 | 243 | 
| 200 ~GLES2Initializer() { | 244 ~GLES2Initializer() { | 
| 201 gles2::Terminate(); | 245 gles2::Terminate(); | 
| 202 } | 246 } | 
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 410 | 454 | 
| 411 // TODO(gman): Remove This | 455 // TODO(gman): Remove This | 
| 412 void GLInProcessContext::DisableShaderTranslation() { | 456 void GLInProcessContext::DisableShaderTranslation() { | 
| 413 NOTREACHED(); | 457 NOTREACHED(); | 
| 414 } | 458 } | 
| 415 | 459 | 
| 416 GLES2Implementation* GLInProcessContext::GetImplementation() { | 460 GLES2Implementation* GLInProcessContext::GetImplementation() { | 
| 417 return gles2_implementation_.get(); | 461 return gles2_implementation_.get(); | 
| 418 } | 462 } | 
| 419 | 463 | 
| 464 ::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() { | |
| 465 return decoder_->GetContextGroup()->image_manager(); | |
| 466 } | |
| 467 | |
| 420 GLInProcessContext::GLInProcessContext(bool share_resources) | 468 GLInProcessContext::GLInProcessContext(bool share_resources) | 
| 421 : last_error_(SUCCESS), | 469 : last_error_(SUCCESS), | 
| 422 share_resources_(share_resources), | 470 share_resources_(share_resources), | 
| 423 context_lost_(false) { | 471 context_lost_(false) { | 
| 424 } | 472 } | 
| 425 | 473 | 
| 426 bool GLInProcessContext::Initialize( | 474 bool GLInProcessContext::Initialize( | 
| 427 bool is_offscreen, | 475 bool is_offscreen, | 
| 428 gfx::AcceleratedWidget window, | 476 gfx::AcceleratedWidget window, | 
| 429 const gfx::Size& size, | 477 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())); | 642 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); | 
| 595 | 643 | 
| 596 // Create the object exposing the OpenGL API. | 644 // Create the object exposing the OpenGL API. | 
| 597 gles2_implementation_.reset(new GLES2Implementation( | 645 gles2_implementation_.reset(new GLES2Implementation( | 
| 598 gles2_helper_.get(), | 646 gles2_helper_.get(), | 
| 599 context_group ? context_group->GetImplementation()->share_group() : NULL, | 647 context_group ? context_group->GetImplementation()->share_group() : NULL, | 
| 600 transfer_buffer_.get(), | 648 transfer_buffer_.get(), | 
| 601 true, | 649 true, | 
| 602 false)); | 650 false)); | 
| 603 | 651 | 
| 652 // GLES2Implementation::Initialize() which is called next | |
| 653 // needs the GpuMemoryBufferFactory so we set it before | |
| 654 // Initialize is called. | |
| 655 scoped_ptr<GpuMemoryBufferFactory> gpu_memory_buffer_factory( | |
| 656 new GpuMemoryBufferImageManagerFactory(GetImageManager())); | |
| 657 // GLES2Implementation takes the ownership of |gpu_memory_buffer_factory|. | |
| 658 gles2_implementation_->SetGpuMemoryBufferFactory( | |
| 659 gpu_memory_buffer_factory.Pass()); | |
| 660 | |
| 604 if (!gles2_implementation_->Initialize( | 661 if (!gles2_implementation_->Initialize( | 
| 605 kStartTransferBufferSize, | 662 kStartTransferBufferSize, | 
| 606 kMinTransferBufferSize, | 663 kMinTransferBufferSize, | 
| 607 kMaxTransferBufferSize)) { | 664 kMaxTransferBufferSize)) { | 
| 608 return false; | 665 return false; | 
| 609 } | 666 } | 
| 610 | 667 | 
| 611 if (share_resources_) { | 668 if (share_resources_) { | 
| 612 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 669 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 
| 613 g_all_shared_contexts.Get()); | 670 g_all_shared_contexts.Get()); | 
| (...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1822 } | 1879 } | 
| 1823 | 1880 | 
| 1824 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 1881 void WebGraphicsContext3DInProcessCommandBufferImpl::OnContextLost() { | 
| 1825 // TODO(kbr): improve the precision here. | 1882 // TODO(kbr): improve the precision here. | 
| 1826 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 1883 context_lost_reason_ = GL_UNKNOWN_CONTEXT_RESET_ARB; | 
| 1827 if (context_lost_callback_) { | 1884 if (context_lost_callback_) { | 
| 1828 context_lost_callback_->onContextLost(); | 1885 context_lost_callback_->onContextLost(); | 
| 1829 } | 1886 } | 
| 1830 } | 1887 } | 
| 1831 | 1888 | 
| 1889 DELEGATE_TO_GL_2R(createImageCHROMIUM, CreateImageCHROMIUM, | |
| 1890 WGC3Dsizei, WGC3Dsizei, WGC3Duint); | |
| 1891 | |
| 1892 DELEGATE_TO_GL_1(destroyImageCHROMIUM, DestroyImageCHROMIUM, WGC3Duint); | |
| 1893 | |
| 1894 DELEGATE_TO_GL_3(getImageParameterivCHROMIUM, GetImageParameterivCHROMIUM, | |
| 1895 WGC3Duint, WGC3Denum, GLint*); | |
| 1896 | |
| 1897 DELEGATE_TO_GL_2R(mapImageCHROMIUM, MapImageCHROMIUM, | |
| 1898 WGC3Duint, WGC3Denum, void*); | |
| 1899 | |
| 1900 DELEGATE_TO_GL_1R(unmapImageCHROMIUM, UnmapImageCHROMIUM, | |
| 1901 WGC3Duint, WGC3Dboolean); | |
| 1902 | |
| 1832 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, | 1903 DELEGATE_TO_GL_3(bindUniformLocationCHROMIUM, BindUniformLocationCHROMIUM, | 
| 1833 WebGLId, WGC3Dint, const WGC3Dchar*) | 1904 WebGLId, WGC3Dint, const WGC3Dchar*) | 
| 1834 | 1905 | 
| 1835 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) | 1906 DELEGATE_TO_GL(shallowFlushCHROMIUM, ShallowFlushCHROMIUM) | 
| 1836 | 1907 | 
| 1837 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 1908 DELEGATE_TO_GL_1(genMailboxCHROMIUM, GenMailboxCHROMIUM, WGC3Dbyte*) | 
| 1838 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 1909 DELEGATE_TO_GL_2(produceTextureCHROMIUM, ProduceTextureCHROMIUM, | 
| 1839 WGC3Denum, const WGC3Dbyte*) | 1910 WGC3Denum, const WGC3Dbyte*) | 
| 1840 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 1911 DELEGATE_TO_GL_2(consumeTextureCHROMIUM, ConsumeTextureCHROMIUM, | 
| 1841 WGC3Denum, const WGC3Dbyte*) | 1912 WGC3Denum, const WGC3Dbyte*) | 
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1868 | 1939 | 
| 1869 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 1940 DELEGATE_TO_GL_9(asyncTexSubImage2DCHROMIUM, AsyncTexSubImage2DCHROMIUM, | 
| 1870 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 1941 WGC3Denum, WGC3Dint, WGC3Dint, WGC3Dint, WGC3Dsizei, WGC3Dsizei, | 
| 1871 WGC3Denum, WGC3Denum, const void*) | 1942 WGC3Denum, WGC3Denum, const void*) | 
| 1872 | 1943 | 
| 1873 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 1944 DELEGATE_TO_GL_1(waitAsyncTexImage2DCHROMIUM, WaitAsyncTexImage2DCHROMIUM, | 
| 1874 WGC3Denum) | 1945 WGC3Denum) | 
| 1875 | 1946 | 
| 1876 } // namespace gpu | 1947 } // namespace gpu | 
| 1877 } // namespace webkit | 1948 } // namespace webkit | 
| OLD | NEW |