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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <set> | 10 #include <set> |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 const int32_t kDefaultCommandBufferSize = 1024 * 1024; | 45 const int32_t kDefaultCommandBufferSize = 1024 * 1024; |
| 46 const unsigned int kDefaultStartTransferBufferSize = 4 * 1024 * 1024; | 46 const unsigned int kDefaultStartTransferBufferSize = 4 * 1024 * 1024; |
| 47 const unsigned int kDefaultMinTransferBufferSize = 1 * 256 * 1024; | 47 const unsigned int kDefaultMinTransferBufferSize = 1 * 256 * 1024; |
| 48 const unsigned int kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; | 48 const unsigned int kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; |
| 49 | 49 |
| 50 class GLInProcessContextImpl | 50 class GLInProcessContextImpl |
| 51 : public GLInProcessContext, | 51 : public GLInProcessContext, |
| 52 public GpuControlClient, | |
| 52 public base::SupportsWeakPtr<GLInProcessContextImpl> { | 53 public base::SupportsWeakPtr<GLInProcessContextImpl> { |
| 53 public: | 54 public: |
| 54 explicit GLInProcessContextImpl( | 55 explicit GLInProcessContextImpl( |
| 55 const GLInProcessContextSharedMemoryLimits& mem_limits); | 56 const GLInProcessContextSharedMemoryLimits& mem_limits); |
| 56 ~GLInProcessContextImpl() override; | 57 ~GLInProcessContextImpl() override; |
| 57 | 58 |
| 58 bool Initialize(scoped_refptr<gfx::GLSurface> surface, | 59 bool Initialize(scoped_refptr<gfx::GLSurface> surface, |
| 59 bool is_offscreen, | 60 bool is_offscreen, |
| 60 bool use_global_share_group, | 61 bool use_global_share_group, |
| 61 GLInProcessContext* share_context, | 62 GLInProcessContext* share_context, |
| 62 gfx::AcceleratedWidget window, | 63 gfx::AcceleratedWidget window, |
| 63 const gfx::Size& size, | 64 const gfx::Size& size, |
| 64 const gpu::gles2::ContextCreationAttribHelper& attribs, | 65 const gpu::gles2::ContextCreationAttribHelper& attribs, |
| 65 gfx::GpuPreference gpu_preference, | 66 gfx::GpuPreference gpu_preference, |
| 66 const scoped_refptr<InProcessCommandBuffer::Service>& service, | 67 const scoped_refptr<InProcessCommandBuffer::Service>& service, |
| 67 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 68 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 68 ImageFactory* image_factory); | 69 ImageFactory* image_factory); |
| 69 | 70 |
| 70 // GLInProcessContext implementation: | 71 // GLInProcessContext implementation. |
| 71 void SetContextLostCallback(const base::Closure& callback) override; | |
| 72 gles2::GLES2Implementation* GetImplementation() override; | 72 gles2::GLES2Implementation* GetImplementation() override; |
| 73 size_t GetMappedMemoryLimit() override; | 73 size_t GetMappedMemoryLimit() override; |
| 74 void SetLock(base::Lock* lock) override; | 74 void SetLock(base::Lock* lock) override; |
| 75 | 75 |
| 76 // GpuControlClient implementation. These methods are called on the GPU thread | |
|
danakj
2016/04/06 02:14:15
It all gets quite hairy in here. The InProcessComm
danakj
2016/04/06 02:19:58
Oh no I realized this class should not be calling
danakj
2016/04/06 02:25:44
It seems like what's weird here (or different) is
| |
| 77 // by the in-process GpuControl. | |
| 78 void OnGpuControlErrorMessage(const char* message, int32_t id) override {} | |
| 79 void OnGpuControlLostContext() override; | |
| 80 | |
| 76 #if defined(OS_ANDROID) | 81 #if defined(OS_ANDROID) |
| 77 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( | 82 scoped_refptr<gfx::SurfaceTexture> GetSurfaceTexture( |
| 78 uint32_t stream_id) override; | 83 uint32_t stream_id) override; |
| 79 uint32_t CreateStreamTexture(uint32_t texture_id) override; | 84 uint32_t CreateStreamTexture(uint32_t texture_id) override; |
| 80 #endif | 85 #endif |
| 81 | 86 |
| 82 private: | 87 private: |
| 83 void Destroy(); | 88 void Destroy(); |
| 84 void OnContextLost(); | 89 bool IsContextLost() const; |
| 85 void OnSignalSyncPoint(const base::Closure& callback); | 90 void OnSignalSyncPoint(const base::Closure& callback); |
| 86 | 91 |
| 87 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; | 92 scoped_ptr<gles2::GLES2CmdHelper> gles2_helper_; |
| 88 scoped_ptr<TransferBuffer> transfer_buffer_; | 93 scoped_ptr<TransferBuffer> transfer_buffer_; |
| 89 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; | 94 scoped_ptr<gles2::GLES2Implementation> gles2_implementation_; |
| 90 scoped_ptr<InProcessCommandBuffer> command_buffer_; | 95 scoped_ptr<InProcessCommandBuffer> command_buffer_; |
| 91 | 96 |
| 92 const GLInProcessContextSharedMemoryLimits mem_limits_; | 97 const GLInProcessContextSharedMemoryLimits mem_limits_; |
| 98 mutable base::Lock context_lost_lock_; | |
|
danakj
2016/04/06 02:14:15
We used to wrap callbacks inside callbacks to get
| |
| 93 bool context_lost_; | 99 bool context_lost_; |
| 94 base::Closure context_lost_callback_; | |
| 95 base::Lock* lock_; | |
| 96 | 100 |
| 97 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); | 101 DISALLOW_COPY_AND_ASSIGN(GLInProcessContextImpl); |
| 98 }; | 102 }; |
| 99 | 103 |
| 100 base::LazyInstance<base::Lock> g_all_shared_contexts_lock = | 104 base::LazyInstance<base::Lock> g_all_shared_contexts_lock = |
| 101 LAZY_INSTANCE_INITIALIZER; | 105 LAZY_INSTANCE_INITIALIZER; |
| 102 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = | 106 base::LazyInstance<std::set<GLInProcessContextImpl*> > g_all_shared_contexts = |
| 103 LAZY_INSTANCE_INITIALIZER; | 107 LAZY_INSTANCE_INITIALIZER; |
| 104 | 108 |
| 105 GLInProcessContextImpl::GLInProcessContextImpl( | 109 GLInProcessContextImpl::GLInProcessContextImpl( |
| 106 const GLInProcessContextSharedMemoryLimits& mem_limits) | 110 const GLInProcessContextSharedMemoryLimits& mem_limits) |
| 107 : mem_limits_(mem_limits), context_lost_(false), lock_(nullptr) { | 111 : mem_limits_(mem_limits) {} |
| 108 } | |
| 109 | 112 |
| 110 GLInProcessContextImpl::~GLInProcessContextImpl() { | 113 GLInProcessContextImpl::~GLInProcessContextImpl() { |
| 111 { | 114 { |
| 112 base::AutoLock lock(g_all_shared_contexts_lock.Get()); | 115 base::AutoLock lock(g_all_shared_contexts_lock.Get()); |
| 113 g_all_shared_contexts.Get().erase(this); | 116 g_all_shared_contexts.Get().erase(this); |
| 114 } | 117 } |
| 115 Destroy(); | 118 Destroy(); |
| 116 } | 119 } |
| 117 | 120 |
| 118 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { | 121 gles2::GLES2Implementation* GLInProcessContextImpl::GetImplementation() { |
| 119 return gles2_implementation_.get(); | 122 return gles2_implementation_.get(); |
| 120 } | 123 } |
| 121 | 124 |
| 122 size_t GLInProcessContextImpl::GetMappedMemoryLimit() { | 125 size_t GLInProcessContextImpl::GetMappedMemoryLimit() { |
| 123 return mem_limits_.mapped_memory_reclaim_limit; | 126 return mem_limits_.mapped_memory_reclaim_limit; |
| 124 } | 127 } |
| 125 | 128 |
| 126 void GLInProcessContextImpl::SetLock(base::Lock* lock) { | 129 void GLInProcessContextImpl::SetLock(base::Lock* lock) { |
| 130 // TODO(danakj): This isn't used... remove from the GLInProcessContext api? | |
| 127 command_buffer_->SetLock(lock); | 131 command_buffer_->SetLock(lock); |
| 128 lock_ = lock; | |
| 129 } | 132 } |
| 130 | 133 |
| 131 void GLInProcessContextImpl::SetContextLostCallback( | 134 void GLInProcessContextImpl::OnGpuControlLostContext() { |
| 132 const base::Closure& callback) { | 135 // This is called on the GPU thread. |
| 133 context_lost_callback_ = callback; | 136 base::AutoLock lock(context_lost_lock_); |
| 137 context_lost_ = true; | |
| 134 } | 138 } |
| 135 | 139 |
| 136 void GLInProcessContextImpl::OnContextLost() { | 140 bool GLInProcessContextImpl::IsContextLost() const { |
| 137 scoped_ptr<base::AutoLock> lock; | 141 base::AutoLock lock(context_lost_lock_); |
| 138 if (lock_) | 142 return context_lost_; |
| 139 lock.reset(new base::AutoLock(*lock_)); | |
| 140 context_lost_ = true; | |
| 141 if (!context_lost_callback_.is_null()) { | |
| 142 context_lost_callback_.Run(); | |
| 143 } | |
| 144 } | 143 } |
| 145 | 144 |
| 146 bool GLInProcessContextImpl::Initialize( | 145 bool GLInProcessContextImpl::Initialize( |
| 147 scoped_refptr<gfx::GLSurface> surface, | 146 scoped_refptr<gfx::GLSurface> surface, |
| 148 bool is_offscreen, | 147 bool is_offscreen, |
| 149 bool use_global_share_group, | 148 bool use_global_share_group, |
| 150 GLInProcessContext* share_context, | 149 GLInProcessContext* share_context, |
| 151 gfx::AcceleratedWidget window, | 150 gfx::AcceleratedWidget window, |
| 152 const gfx::Size& size, | 151 const gfx::Size& size, |
| 153 const gles2::ContextCreationAttribHelper& attribs, | 152 const gles2::ContextCreationAttribHelper& attribs, |
| 154 gfx::GpuPreference gpu_preference, | 153 gfx::GpuPreference gpu_preference, |
| 155 const scoped_refptr<InProcessCommandBuffer::Service>& service, | 154 const scoped_refptr<InProcessCommandBuffer::Service>& service, |
| 156 GpuMemoryBufferManager* gpu_memory_buffer_manager, | 155 GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 157 ImageFactory* image_factory) { | 156 ImageFactory* image_factory) { |
| 158 DCHECK(!use_global_share_group || !share_context); | 157 DCHECK(!use_global_share_group || !share_context); |
| 159 DCHECK(size.width() >= 0 && size.height() >= 0); | 158 DCHECK(size.width() >= 0 && size.height() >= 0); |
| 160 | 159 |
| 161 std::vector<int32_t> attrib_vector; | 160 std::vector<int32_t> attrib_vector; |
| 162 attribs.Serialize(&attrib_vector); | 161 attribs.Serialize(&attrib_vector); |
| 163 | 162 |
| 164 base::Closure wrapped_callback = | |
| 165 base::Bind(&GLInProcessContextImpl::OnContextLost, AsWeakPtr()); | |
| 166 command_buffer_.reset(new InProcessCommandBuffer(service)); | 163 command_buffer_.reset(new InProcessCommandBuffer(service)); |
| 167 | 164 |
| 168 scoped_ptr<base::AutoLock> scoped_shared_context_lock; | 165 scoped_ptr<base::AutoLock> scoped_shared_context_lock; |
| 169 scoped_refptr<gles2::ShareGroup> share_group; | 166 scoped_refptr<gles2::ShareGroup> share_group; |
| 170 InProcessCommandBuffer* share_command_buffer = NULL; | 167 InProcessCommandBuffer* share_command_buffer = NULL; |
| 171 if (use_global_share_group) { | 168 if (use_global_share_group) { |
| 172 scoped_shared_context_lock.reset( | 169 scoped_shared_context_lock.reset( |
| 173 new base::AutoLock(g_all_shared_contexts_lock.Get())); | 170 new base::AutoLock(g_all_shared_contexts_lock.Get())); |
| 174 for (std::set<GLInProcessContextImpl*>::const_iterator it = | 171 for (std::set<GLInProcessContextImpl*>::const_iterator it = |
| 175 g_all_shared_contexts.Get().begin(); | 172 g_all_shared_contexts.Get().begin(); |
| 176 it != g_all_shared_contexts.Get().end(); | 173 it != g_all_shared_contexts.Get().end(); |
| 177 it++) { | 174 it++) { |
| 178 const GLInProcessContextImpl* context = *it; | 175 const GLInProcessContextImpl* context = *it; |
| 179 if (!context->context_lost_) { | 176 if (!context->IsContextLost()) { |
| 180 share_group = context->gles2_implementation_->share_group(); | 177 share_group = context->gles2_implementation_->share_group(); |
| 181 share_command_buffer = context->command_buffer_.get(); | 178 share_command_buffer = context->command_buffer_.get(); |
| 182 DCHECK(share_group.get()); | 179 DCHECK(share_group.get()); |
| 183 DCHECK(share_command_buffer); | 180 DCHECK(share_command_buffer); |
| 184 break; | 181 break; |
| 185 } | 182 } |
| 186 } | 183 } |
| 187 } else if (share_context) { | 184 } else if (share_context) { |
| 188 GLInProcessContextImpl* impl = | 185 GLInProcessContextImpl* impl = |
| 189 static_cast<GLInProcessContextImpl*>(share_context); | 186 static_cast<GLInProcessContextImpl*>(share_context); |
| 190 share_group = impl->gles2_implementation_->share_group(); | 187 share_group = impl->gles2_implementation_->share_group(); |
| 191 share_command_buffer = impl->command_buffer_.get(); | 188 share_command_buffer = impl->command_buffer_.get(); |
| 192 DCHECK(share_group.get()); | 189 DCHECK(share_group.get()); |
| 193 DCHECK(share_command_buffer); | 190 DCHECK(share_command_buffer); |
| 194 } | 191 } |
| 195 | 192 |
| 193 command_buffer_->SetGpuControlClient(this); | |
| 194 | |
| 196 if (!command_buffer_->Initialize(surface, | 195 if (!command_buffer_->Initialize(surface, |
| 197 is_offscreen, | 196 is_offscreen, |
| 198 window, | 197 window, |
| 199 size, | 198 size, |
| 200 attrib_vector, | 199 attrib_vector, |
| 201 gpu_preference, | 200 gpu_preference, |
| 202 wrapped_callback, | |
| 203 share_command_buffer, | 201 share_command_buffer, |
| 204 gpu_memory_buffer_manager, | 202 gpu_memory_buffer_manager, |
| 205 image_factory)) { | 203 image_factory)) { |
| 206 LOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; | 204 LOG(ERROR) << "Failed to initialize InProcessCommmandBuffer"; |
| 207 return false; | 205 return false; |
| 208 } | 206 } |
| 209 | 207 |
| 210 // Create the GLES2 helper, which writes the command buffer protocol. | 208 // Create the GLES2 helper, which writes the command buffer protocol. |
| 211 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); | 209 gles2_helper_.reset(new gles2::GLES2CmdHelper(command_buffer_.get())); |
| 212 if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size)) { | 210 if (!gles2_helper_->Initialize(mem_limits_.command_buffer_size)) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 320 gpu_preference, | 318 gpu_preference, |
| 321 service, | 319 service, |
| 322 gpu_memory_buffer_manager, | 320 gpu_memory_buffer_manager, |
| 323 image_factory)) | 321 image_factory)) |
| 324 return NULL; | 322 return NULL; |
| 325 | 323 |
| 326 return context.release(); | 324 return context.release(); |
| 327 } | 325 } |
| 328 | 326 |
| 329 } // namespace gpu | 327 } // namespace gpu |
| OLD | NEW |