| 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 "gpu/command_buffer/client/gl_in_process_context.h" | 5 #include "gpu/command_buffer/client/gl_in_process_context.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include <GLES2/gl2.h> | 10 #include <GLES2/gl2.h> |
| 11 #ifndef GL_GLEXT_PROTOTYPES | 11 #ifndef GL_GLEXT_PROTOTYPES |
| 12 #define GL_GLEXT_PROTOTYPES 1 | 12 #define GL_GLEXT_PROTOTYPES 1 |
| 13 #endif | 13 #endif |
| 14 #include <GLES2/gl2ext.h> | 14 #include <GLES2/gl2ext.h> |
| 15 #include <GLES2/gl2extchromium.h> | 15 #include <GLES2/gl2extchromium.h> |
| 16 | 16 |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
| 19 #include "base/callback.h" | 19 #include "base/callback.h" |
| 20 #include "base/lazy_instance.h" | 20 #include "base/lazy_instance.h" |
| 21 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
| 23 #include "base/memory/weak_ptr.h" | 23 #include "base/memory/weak_ptr.h" |
| 24 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
| 25 #include "base/synchronization/lock.h" | 25 #include "base/synchronization/lock.h" |
| 26 #include "gpu/command_buffer/client/gles2_implementation.h" | 26 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 27 #include "gpu/command_buffer/client/gpu_memory_buffer.h" | 27 #include "gpu/command_buffer/client/gpu_memory_buffer.h" |
| 28 #include "gpu/command_buffer/client/gpu_memory_buffer_factory.h" |
| 28 #include "gpu/command_buffer/client/image_factory.h" | 29 #include "gpu/command_buffer/client/image_factory.h" |
| 29 #include "gpu/command_buffer/client/transfer_buffer.h" | 30 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 30 #include "gpu/command_buffer/common/constants.h" | 31 #include "gpu/command_buffer/common/constants.h" |
| 31 #include "gpu/command_buffer/common/id_allocator.h" | 32 #include "gpu/command_buffer/common/id_allocator.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" |
| 36 #include "gpu/command_buffer/service/image_manager.h" | 37 #include "gpu/command_buffer/service/image_manager.h" |
| 37 #include "gpu/command_buffer/service/transfer_buffer_manager.h" | 38 #include "gpu/command_buffer/service/transfer_buffer_manager.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 63 LAZY_INSTANCE_INITIALIZER; | 64 LAZY_INSTANCE_INITIALIZER; |
| 64 | 65 |
| 65 class GLInProcessContextImpl; | 66 class GLInProcessContextImpl; |
| 66 | 67 |
| 67 static base::LazyInstance< | 68 static base::LazyInstance< |
| 68 std::set<GLInProcessContextImpl*> > | 69 std::set<GLInProcessContextImpl*> > |
| 69 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; | 70 g_all_shared_contexts = LAZY_INSTANCE_INITIALIZER; |
| 70 | 71 |
| 71 static bool g_use_virtualized_gl_context = false; | 72 static bool g_use_virtualized_gl_context = false; |
| 72 | 73 |
| 73 static GLInProcessContext::GpuMemoryBufferCreator* g_gpu_memory_buffer_creator = | 74 static GpuMemoryBufferFactory* g_gpu_memory_buffer_factory = NULL; |
| 74 NULL; | |
| 75 | 75 |
| 76 // Also calls DetachFromThreadHack on all GLES2Decoders before the lock is | 76 // Also calls DetachFromThreadHack on all GLES2Decoders before the lock is |
| 77 // released to maintain the invariant that all decoders are unbound while the | 77 // released to maintain the invariant that all decoders are unbound while the |
| 78 // lock is not held. This is to workaround DumpRenderTree using WGC3DIPCBI with | 78 // lock is not held. This is to workaround DumpRenderTree using WGC3DIPCBI with |
| 79 // shared resources on different threads. | 79 // shared resources on different threads. |
| 80 // Remove this as part of crbug.com/234964. | 80 // Remove this as part of crbug.com/234964. |
| 81 class AutoLockAndDecoderDetachThread { | 81 class AutoLockAndDecoderDetachThread { |
| 82 public: | 82 public: |
| 83 AutoLockAndDecoderDetachThread( | 83 AutoLockAndDecoderDetachThread( |
| 84 base::Lock& lock, | 84 base::Lock& lock, |
| 85 const std::set<GLInProcessContextImpl*>& contexts); | 85 const std::set<GLInProcessContextImpl*>& contexts); |
| 86 ~AutoLockAndDecoderDetachThread(); | 86 ~AutoLockAndDecoderDetachThread(); |
| 87 | 87 |
| 88 private: | 88 private: |
| 89 base::AutoLock auto_lock_; | 89 base::AutoLock auto_lock_; |
| 90 const std::set<GLInProcessContextImpl*>& contexts_; | 90 const std::set<GLInProcessContextImpl*>& contexts_; |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 size_t SharedContextCount() { |
| 94 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 95 g_all_shared_contexts.Get()); |
| 96 return g_all_shared_contexts.Get().size(); |
| 97 } |
| 98 |
| 93 class GLInProcessContextImpl | 99 class GLInProcessContextImpl |
| 94 : public GLInProcessContext, | 100 : public GLInProcessContext, |
| 95 public gles2::ImageFactory, | 101 public gles2::ImageFactory, |
| 96 public base::SupportsWeakPtr<GLInProcessContextImpl> { | 102 public base::SupportsWeakPtr<GLInProcessContextImpl> { |
| 97 public: | 103 public: |
| 98 explicit GLInProcessContextImpl(bool share_resources); | 104 explicit GLInProcessContextImpl(bool share_resources); |
| 99 virtual ~GLInProcessContextImpl(); | 105 virtual ~GLInProcessContextImpl(); |
| 100 | 106 |
| 101 bool Initialize(bool is_offscreen, | 107 bool Initialize(bool is_offscreen, |
| 102 gfx::AcceleratedWidget window, | 108 gfx::AcceleratedWidget window, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 contexts_.end(), | 179 contexts_.end(), |
| 174 &DetachThread); | 180 &DetachThread); |
| 175 } | 181 } |
| 176 | 182 |
| 177 scoped_ptr<GpuMemoryBuffer> GLInProcessContextImpl::CreateGpuMemoryBuffer( | 183 scoped_ptr<GpuMemoryBuffer> GLInProcessContextImpl::CreateGpuMemoryBuffer( |
| 178 int width, int height, GLenum internalformat, unsigned int* image_id) { | 184 int width, int height, GLenum internalformat, unsigned int* image_id) { |
| 179 // We're taking the lock here because we're accessing the ContextGroup's | 185 // We're taking the lock here because we're accessing the ContextGroup's |
| 180 // shared IdManager. | 186 // shared IdManager. |
| 181 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 187 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 182 g_all_shared_contexts.Get()); | 188 g_all_shared_contexts.Get()); |
| 183 // For Android WebView we assume the |internalformat| will always be | 189 scoped_ptr<GpuMemoryBuffer> buffer( |
| 184 // GL_RGBA8_OES. | 190 g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer(width, |
| 185 DCHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat); | 191 height, |
| 186 scoped_ptr<GpuMemoryBuffer> buffer = | 192 internalformat)); |
| 187 g_gpu_memory_buffer_creator(width, height); | 193 if (!buffer) |
| 188 | 194 return scoped_ptr<GpuMemoryBuffer>(); |
| 189 if (buffer.get() == NULL) | |
| 190 return buffer.Pass(); | |
| 191 | 195 |
| 192 scoped_refptr<gfx::GLImage> gl_image = | 196 scoped_refptr<gfx::GLImage> gl_image = |
| 193 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), | 197 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), |
| 194 gfx::Size(width, height)); | 198 gfx::Size(width, height)); |
| 195 *image_id = decoder_->GetContextGroup() | 199 *image_id = decoder_->GetContextGroup() |
| 196 ->GetIdAllocator(gles2::id_namespaces::kImages)->AllocateID(); | 200 ->GetIdAllocator(gles2::id_namespaces::kImages)->AllocateID(); |
| 197 GetImageManager()->AddImage(gl_image.get(), *image_id); | 201 GetImageManager()->AddImage(gl_image.get(), *image_id); |
| 198 return buffer.Pass(); | 202 return buffer.Pass(); |
| 199 } | 203 } |
| 200 | 204 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 allowed_extensions, | 591 allowed_extensions, |
| 588 attrib_list, | 592 attrib_list, |
| 589 gpu_preference, | 593 gpu_preference, |
| 590 callback)) | 594 callback)) |
| 591 return NULL; | 595 return NULL; |
| 592 | 596 |
| 593 return context.release(); | 597 return context.release(); |
| 594 } | 598 } |
| 595 | 599 |
| 596 // static | 600 // static |
| 597 void GLInProcessContext::SetGpuMemoryBufferCreator( | 601 void GLInProcessContext::SetGpuMemoryBufferFactory( |
| 598 GpuMemoryBufferCreator* creator) { | 602 GpuMemoryBufferFactory* factory) { |
| 599 g_gpu_memory_buffer_creator = creator; | 603 DCHECK_EQ(0u, SharedContextCount()); |
| 604 g_gpu_memory_buffer_factory = factory; |
| 600 } | 605 } |
| 601 | 606 |
| 602 // static | 607 // static |
| 603 void GLInProcessContext::EnableVirtualizedContext() { | 608 void GLInProcessContext::EnableVirtualizedContext() { |
| 604 #if !defined(NDEBUG) | 609 DCHECK_EQ(0u, SharedContextCount()); |
| 605 { | |
| 606 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | |
| 607 g_all_shared_contexts.Get()); | |
| 608 DCHECK(g_all_shared_contexts.Get().empty()); | |
| 609 } | |
| 610 #endif // !defined(NDEBUG) | |
| 611 g_use_virtualized_gl_context = true; | 610 g_use_virtualized_gl_context = true; |
| 612 } | 611 } |
| 613 | 612 |
| 614 } // namespace gpu | 613 } // namespace gpu |
| OLD | NEW |