| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/mus/surfaces/surfaces_context_provider.h" | 5 #include "components/mus/surfaces/surfaces_context_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 12 #include "components/mus/gles2/command_buffer_driver.h" | 12 #include "components/mus/gles2/command_buffer_driver.h" |
| 13 #include "components/mus/gles2/command_buffer_impl.h" | 13 #include "components/mus/gles2/command_buffer_impl.h" |
| 14 #include "components/mus/gles2/command_buffer_local.h" | 14 #include "components/mus/gles2/command_buffer_local.h" |
| 15 #include "components/mus/gles2/gpu_state.h" | 15 #include "components/mus/gles2/gpu_state.h" |
| 16 #include "components/mus/surfaces/surfaces_context_provider_delegate.h" | 16 #include "components/mus/surfaces/surfaces_context_provider_delegate.h" |
| 17 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 17 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
| 18 #include "gpu/command_buffer/client/gles2_implementation.h" | 18 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 19 #include "gpu/command_buffer/client/shared_memory_limits.h" |
| 19 #include "gpu/command_buffer/client/transfer_buffer.h" | 20 #include "gpu/command_buffer/client/transfer_buffer.h" |
| 20 | 21 |
| 21 namespace mus { | 22 namespace mus { |
| 22 | 23 |
| 23 namespace { | |
| 24 const size_t kDefaultCommandBufferSize = 1024 * 1024; | |
| 25 const size_t kDefaultStartTransferBufferSize = 1 * 1024 * 1024; | |
| 26 const size_t kDefaultMinTransferBufferSize = 1 * 256 * 1024; | |
| 27 const size_t kDefaultMaxTransferBufferSize = 16 * 1024 * 1024; | |
| 28 } | |
| 29 | |
| 30 SurfacesContextProvider::SurfacesContextProvider( | 24 SurfacesContextProvider::SurfacesContextProvider( |
| 31 gfx::AcceleratedWidget widget, | 25 gfx::AcceleratedWidget widget, |
| 32 const scoped_refptr<GpuState>& state) | 26 const scoped_refptr<GpuState>& state) |
| 33 : delegate_(nullptr), widget_(widget), command_buffer_local_(nullptr) { | 27 : delegate_(nullptr), widget_(widget), command_buffer_local_(nullptr) { |
| 34 command_buffer_local_ = new CommandBufferLocal(this, widget_, state); | 28 command_buffer_local_ = new CommandBufferLocal(this, widget_, state); |
| 35 } | 29 } |
| 36 | 30 |
| 37 void SurfacesContextProvider::SetDelegate( | 31 void SurfacesContextProvider::SetDelegate( |
| 38 SurfacesContextProviderDelegate* delegate) { | 32 SurfacesContextProviderDelegate* delegate) { |
| 39 DCHECK(!delegate_); | 33 DCHECK(!delegate_); |
| 40 delegate_ = delegate; | 34 delegate_ = delegate; |
| 41 } | 35 } |
| 42 | 36 |
| 43 // This routine needs to be safe to call more than once. | 37 // This routine needs to be safe to call more than once. |
| 44 // This is called when we have an accelerated widget. | 38 // This is called when we have an accelerated widget. |
| 45 bool SurfacesContextProvider::BindToCurrentThread() { | 39 bool SurfacesContextProvider::BindToCurrentThread() { |
| 46 if (implementation_) | 40 if (implementation_) |
| 47 return true; | 41 return true; |
| 48 | 42 |
| 49 // SurfacesContextProvider should always live on the same thread as the | 43 // SurfacesContextProvider should always live on the same thread as the |
| 50 // Window Manager. | 44 // Window Manager. |
| 51 DCHECK(CalledOnValidThread()); | 45 DCHECK(CalledOnValidThread()); |
| 52 if (!command_buffer_local_->Initialize()) | 46 if (!command_buffer_local_->Initialize()) |
| 53 return false; | 47 return false; |
| 48 |
| 49 constexpr gpu::SharedMemoryLimits default_limits; |
| 54 gles2_helper_.reset( | 50 gles2_helper_.reset( |
| 55 new gpu::gles2::GLES2CmdHelper(command_buffer_local_)); | 51 new gpu::gles2::GLES2CmdHelper(command_buffer_local_)); |
| 56 if (!gles2_helper_->Initialize(kDefaultCommandBufferSize)) | 52 if (!gles2_helper_->Initialize(default_limits.command_buffer_size)) |
| 57 return false; | 53 return false; |
| 58 gles2_helper_->SetAutomaticFlushes(false); | 54 gles2_helper_->SetAutomaticFlushes(false); |
| 59 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); | 55 transfer_buffer_.reset(new gpu::TransferBuffer(gles2_helper_.get())); |
| 60 capabilities_.gpu = command_buffer_local_->GetCapabilities(); | 56 capabilities_ = command_buffer_local_->GetCapabilities(); |
| 61 bool bind_generates_resource = | 57 bool bind_generates_resource = |
| 62 !!capabilities_.gpu.bind_generates_resource_chromium; | 58 !!capabilities_.bind_generates_resource_chromium; |
| 63 // TODO(piman): Some contexts (such as compositor) want this to be true, so | 59 // TODO(piman): Some contexts (such as compositor) want this to be true, so |
| 64 // this needs to be a public parameter. | 60 // this needs to be a public parameter. |
| 65 bool lose_context_when_out_of_memory = false; | 61 bool lose_context_when_out_of_memory = false; |
| 66 bool support_client_side_arrays = false; | 62 bool support_client_side_arrays = false; |
| 67 implementation_.reset(new gpu::gles2::GLES2Implementation( | 63 implementation_.reset(new gpu::gles2::GLES2Implementation( |
| 68 gles2_helper_.get(), NULL, transfer_buffer_.get(), | 64 gles2_helper_.get(), NULL, transfer_buffer_.get(), |
| 69 bind_generates_resource, lose_context_when_out_of_memory, | 65 bind_generates_resource, lose_context_when_out_of_memory, |
| 70 support_client_side_arrays, command_buffer_local_)); | 66 support_client_side_arrays, command_buffer_local_)); |
| 71 return implementation_->Initialize( | 67 return implementation_->Initialize( |
| 72 kDefaultStartTransferBufferSize, kDefaultMinTransferBufferSize, | 68 default_limits.start_transfer_buffer_size, |
| 73 kDefaultMaxTransferBufferSize, gpu::gles2::GLES2Implementation::kNoLimit); | 69 default_limits.min_transfer_buffer_size, |
| 70 default_limits.max_transfer_buffer_size, |
| 71 default_limits.mapped_memory_reclaim_limit); |
| 74 } | 72 } |
| 75 | 73 |
| 76 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { | 74 gpu::gles2::GLES2Interface* SurfacesContextProvider::ContextGL() { |
| 77 DCHECK(implementation_); | 75 DCHECK(implementation_); |
| 78 return implementation_.get(); | 76 return implementation_.get(); |
| 79 } | 77 } |
| 80 | 78 |
| 81 gpu::ContextSupport* SurfacesContextProvider::ContextSupport() { | 79 gpu::ContextSupport* SurfacesContextProvider::ContextSupport() { |
| 82 return implementation_.get(); | 80 return implementation_.get(); |
| 83 } | 81 } |
| 84 | 82 |
| 85 class GrContext* SurfacesContextProvider::GrContext() { | 83 class GrContext* SurfacesContextProvider::GrContext() { |
| 86 return NULL; | 84 return NULL; |
| 87 } | 85 } |
| 88 | 86 |
| 89 void SurfacesContextProvider::InvalidateGrContext(uint32_t state) {} | 87 void SurfacesContextProvider::InvalidateGrContext(uint32_t state) {} |
| 90 | 88 |
| 91 cc::ContextProvider::Capabilities | 89 gpu::Capabilities SurfacesContextProvider::ContextCapabilities() { |
| 92 SurfacesContextProvider::ContextCapabilities() { | |
| 93 return capabilities_; | 90 return capabilities_; |
| 94 } | 91 } |
| 95 | 92 |
| 96 void SurfacesContextProvider::SetupLock() {} | 93 void SurfacesContextProvider::SetupLock() {} |
| 97 | 94 |
| 98 base::Lock* SurfacesContextProvider::GetLock() { | 95 base::Lock* SurfacesContextProvider::GetLock() { |
| 99 return &context_lock_; | 96 return &context_lock_; |
| 100 } | 97 } |
| 101 | 98 |
| 102 void SurfacesContextProvider::SetLostContextCallback( | 99 void SurfacesContextProvider::SetLostContextCallback( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 124 swap_buffers_completion_callback_.Run(result); | 121 swap_buffers_completion_callback_.Run(result); |
| 125 } | 122 } |
| 126 } | 123 } |
| 127 | 124 |
| 128 void SurfacesContextProvider::SetSwapBuffersCompletionCallback( | 125 void SurfacesContextProvider::SetSwapBuffersCompletionCallback( |
| 129 gfx::GLSurface::SwapCompletionCallback callback) { | 126 gfx::GLSurface::SwapCompletionCallback callback) { |
| 130 swap_buffers_completion_callback_ = callback; | 127 swap_buffers_completion_callback_ = callback; |
| 131 } | 128 } |
| 132 | 129 |
| 133 } // namespace mus | 130 } // namespace mus |
| OLD | NEW |