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 "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, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 contexts_.end(), | 173 contexts_.end(), |
| 174 &DetachThread); | 174 &DetachThread); |
| 175 } | 175 } |
| 176 | 176 |
| 177 scoped_ptr<GpuMemoryBuffer> GLInProcessContextImpl::CreateGpuMemoryBuffer( | 177 scoped_ptr<GpuMemoryBuffer> GLInProcessContextImpl::CreateGpuMemoryBuffer( |
| 178 int width, int height, GLenum internalformat, unsigned int* image_id) { | 178 int width, int height, GLenum internalformat, unsigned int* image_id) { |
| 179 // We're taking the lock here because we're accessing the ContextGroup's | 179 // We're taking the lock here because we're accessing the ContextGroup's |
| 180 // shared IdManager. | 180 // shared IdManager. |
| 181 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 181 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 182 g_all_shared_contexts.Get()); | 182 g_all_shared_contexts.Get()); |
| 183 // For Android WebView we assume the |internalformat| will always be | 183 scoped_ptr<GpuMemoryBuffer> buffer( |
| 184 // GL_RGBA8_OES. | 184 g_gpu_memory_buffer_factory->CreateGpuMemoryBuffer(width, |
| 185 DCHECK_EQ(static_cast<GLenum>(GL_RGBA8_OES), internalformat); | 185 height, |
| 186 scoped_ptr<GpuMemoryBuffer> buffer = | 186 internalformat)); |
| 187 g_gpu_memory_buffer_creator(width, height); | 187 if (!buffer) |
| 188 | 188 return scoped_ptr<GpuMemoryBuffer>(); |
| 189 if (buffer.get() == NULL) | |
| 190 return buffer.Pass(); | |
| 191 | 189 |
| 192 scoped_refptr<gfx::GLImage> gl_image = | 190 scoped_refptr<gfx::GLImage> gl_image = |
| 193 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), | 191 gfx::GLImage::CreateGLImageForGpuMemoryBuffer(buffer->GetNativeBuffer(), |
| 194 gfx::Size(width, height)); | 192 gfx::Size(width, height)); |
| 195 *image_id = decoder_->GetContextGroup() | 193 *image_id = decoder_->GetContextGroup() |
| 196 ->GetIdAllocator(gles2::id_namespaces::kImages)->AllocateID(); | 194 ->GetIdAllocator(gles2::id_namespaces::kImages)->AllocateID(); |
| 197 GetImageManager()->AddImage(gl_image.get(), *image_id); | 195 GetImageManager()->AddImage(gl_image.get(), *image_id); |
| 198 return buffer.Pass(); | 196 return buffer.Pass(); |
| 199 } | 197 } |
| 200 | 198 |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 587 allowed_extensions, | 585 allowed_extensions, |
| 588 attrib_list, | 586 attrib_list, |
| 589 gpu_preference, | 587 gpu_preference, |
| 590 callback)) | 588 callback)) |
| 591 return NULL; | 589 return NULL; |
| 592 | 590 |
| 593 return context.release(); | 591 return context.release(); |
| 594 } | 592 } |
| 595 | 593 |
| 596 // static | 594 // static |
| 597 void GLInProcessContext::SetGpuMemoryBufferCreator( | 595 void GLInProcessContext::SetGpuMemoryBufferFactory( |
| 598 GpuMemoryBufferCreator* creator) { | 596 GpuMemoryBufferFactory* factory) { |
| 599 g_gpu_memory_buffer_creator = creator; | 597 #if !defined(NDEBUG) |
|
kaanb
2013/07/26 05:59:13
isn't it possible to replace this with a function?
reveman
2013/07/26 15:40:57
I don't think there's a good reason to avoid this
| |
| 598 { | |
| 599 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | |
| 600 g_all_shared_contexts.Get()); | |
| 601 DCHECK(g_all_shared_contexts.Get().empty()); | |
| 602 } | |
| 603 #endif // !defined(NDEBUG) | |
| 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 #if !defined(NDEBUG) |
| 605 { | 610 { |
| 606 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), | 611 AutoLockAndDecoderDetachThread lock(g_decoder_lock.Get(), |
| 607 g_all_shared_contexts.Get()); | 612 g_all_shared_contexts.Get()); |
| 608 DCHECK(g_all_shared_contexts.Get().empty()); | 613 DCHECK(g_all_shared_contexts.Get().empty()); |
| 609 } | 614 } |
| 610 #endif // !defined(NDEBUG) | 615 #endif // !defined(NDEBUG) |
| 611 g_use_virtualized_gl_context = true; | 616 g_use_virtualized_gl_context = true; |
| 612 } | 617 } |
| 613 | 618 |
| 614 } // namespace gpu | 619 } // namespace gpu |
| OLD | NEW |