Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: webkit/gpu/webgraphicscontext3d_in_process_command_buffer_impl.cc

Issue 14456004: GPU client side changes for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Incorporate code reviews Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
48 using gpu::TransferBuffer; 51 using gpu::TransferBuffer;
49 using gpu::TransferBufferManager; 52 using gpu::TransferBufferManager;
50 using gpu::TransferBufferManagerInterface; 53 using gpu::TransferBufferManagerInterface;
51 54
55 namespace gpu {
56 namespace gles2 {
joth 2013/05/03 02:04:11 move this class to namespace webkit { namespace g
kaanb 2013/05/03 02:37:31 Done.
57
58 class GpuMemoryBufferImageManagerFactory : public GpuMemoryBufferFactory {
59 public:
60 explicit GpuMemoryBufferImageManagerFactory(ImageManager* image_manager);
61 virtual ~GpuMemoryBufferImageManagerFactory();
62
63 // methods from GpuMemoryBufferFactory
64 virtual scoped_ptr<GpuMemoryBuffer> CreateGpuMemoryBuffer(
65 int width, int height, int image_id) OVERRIDE;
66 private:
67 ImageManager* image_manager_;
joth 2013/05/03 02:04:11 scoped_refptr<>
kaanb 2013/05/03 02:37:31 Done.
68 DISALLOW_COPY_AND_ASSIGN(GpuMemoryBufferImageManagerFactory);
69 };
70
71 GpuMemoryBufferImageManagerFactory::GpuMemoryBufferImageManagerFactory(
72 ImageManager* image_manager) : image_manager_(image_manager) {
73 }
74
75 GpuMemoryBufferImageManagerFactory::~GpuMemoryBufferImageManagerFactory() {
76 }
77
78 scoped_ptr<GpuMemoryBuffer> GpuMemoryBufferImageManagerFactory::
79 CreateGpuMemoryBuffer(int width, int height, int image_id) {
80 scoped_ptr<GpuMemoryBuffer> buffer =
81 GetProcessDefaultGpuMemoryBufferFactory().Run(width, height);
82 scoped_refptr<gfx::GLImage> gl_image =
83 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(),
84 gfx::Size(width, height));
85 image_manager_->AddImage(gl_image, image_id);
86 return buffer.Pass();
87 }
88
89 }
90 }
91
92
52 namespace webkit { 93 namespace webkit {
53 namespace gpu { 94 namespace gpu {
54 95
55 class GLInProcessContext { 96 class GLInProcessContext {
56 public: 97 public:
57 // These are the same error codes as used by EGL. 98 // These are the same error codes as used by EGL.
58 enum Error { 99 enum Error {
59 SUCCESS = 0x3000, 100 SUCCESS = 0x3000,
60 NOT_INITIALIZED = 0x3001, 101 NOT_INITIALIZED = 0x3001,
61 BAD_ATTRIBUTE = 0x3004, 102 BAD_ATTRIBUTE = 0x3004,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 bool Initialize(bool is_offscreen, 196 bool Initialize(bool is_offscreen,
156 gfx::AcceleratedWidget window, 197 gfx::AcceleratedWidget window,
157 const gfx::Size& size, 198 const gfx::Size& size,
158 const char* allowed_extensions, 199 const char* allowed_extensions,
159 const int32* attrib_list, 200 const int32* attrib_list,
160 gfx::GpuPreference gpu_preference); 201 gfx::GpuPreference gpu_preference);
161 void Destroy(); 202 void Destroy();
162 203
163 void OnContextLost(); 204 void OnContextLost();
164 205
206 ::gpu::gles2::ImageManager* GetImageManager();
207
165 base::Closure context_lost_callback_; 208 base::Closure context_lost_callback_;
166 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_; 209 scoped_ptr<TransferBufferManagerInterface> transfer_buffer_manager_;
167 scoped_ptr<CommandBufferService> command_buffer_; 210 scoped_ptr<CommandBufferService> command_buffer_;
168 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_; 211 scoped_ptr< ::gpu::GpuScheduler> gpu_scheduler_;
169 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_; 212 scoped_ptr< ::gpu::gles2::GLES2Decoder> decoder_;
170 scoped_refptr<gfx::GLContext> context_; 213 scoped_refptr<gfx::GLContext> context_;
171 scoped_refptr<gfx::GLSurface> surface_; 214 scoped_refptr<gfx::GLSurface> surface_;
172 scoped_ptr<GLES2CmdHelper> gles2_helper_; 215 scoped_ptr<GLES2CmdHelper> gles2_helper_;
173 scoped_ptr<TransferBuffer> transfer_buffer_; 216 scoped_ptr<TransferBuffer> transfer_buffer_;
174 scoped_ptr<GLES2Implementation> gles2_implementation_; 217 scoped_ptr<GLES2Implementation> gles2_implementation_;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 453
411 // TODO(gman): Remove This 454 // TODO(gman): Remove This
412 void GLInProcessContext::DisableShaderTranslation() { 455 void GLInProcessContext::DisableShaderTranslation() {
413 NOTREACHED(); 456 NOTREACHED();
414 } 457 }
415 458
416 GLES2Implementation* GLInProcessContext::GetImplementation() { 459 GLES2Implementation* GLInProcessContext::GetImplementation() {
417 return gles2_implementation_.get(); 460 return gles2_implementation_.get();
418 } 461 }
419 462
463 ::gpu::gles2::ImageManager* GLInProcessContext::GetImageManager() {
464 return decoder_->GetContextGroup()->image_manager();
465 }
466
420 GLInProcessContext::GLInProcessContext(bool share_resources) 467 GLInProcessContext::GLInProcessContext(bool share_resources)
421 : last_error_(SUCCESS), 468 : last_error_(SUCCESS),
422 share_resources_(share_resources), 469 share_resources_(share_resources),
423 context_lost_(false) { 470 context_lost_(false) {
424 } 471 }
425 472
426 bool GLInProcessContext::Initialize( 473 bool GLInProcessContext::Initialize(
427 bool is_offscreen, 474 bool is_offscreen,
428 gfx::AcceleratedWidget window, 475 gfx::AcceleratedWidget window,
429 const gfx::Size& size, 476 const gfx::Size& size,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get())); 641 transfer_buffer_.reset(new TransferBuffer(gles2_helper_.get()));
595 642
596 // Create the object exposing the OpenGL API. 643 // Create the object exposing the OpenGL API.
597 gles2_implementation_.reset(new GLES2Implementation( 644 gles2_implementation_.reset(new GLES2Implementation(
598 gles2_helper_.get(), 645 gles2_helper_.get(),
599 context_group ? context_group->GetImplementation()->share_group() : NULL, 646 context_group ? context_group->GetImplementation()->share_group() : NULL,
600 transfer_buffer_.get(), 647 transfer_buffer_.get(),
601 true, 648 true,
602 false)); 649 false));
603 650
651 // GLES2Implementation::Initialize() which is called next
652 // needs the GpuMemoryBufferFactory so we set it before
653 // Initialize is called.
654 gles2_implementation_->SetGpuMemoryBufferFactory(
655 new ::gpu::gles2::GpuMemoryBufferImageManagerFactory(GetImageManager()));
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
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
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698